core-legacy/include/router.h

65 lines
1.2 KiB
C
Raw Normal View History

2020-05-05 09:42:02 +00:00
#ifndef CORE_ROUTER_H
#define CORE_ROUTER_H
#include <mongoose.h>
#define ENDPOINTS_MAX_COUNT 128
2020-05-05 09:42:02 +00:00
typedef enum
{
ENDPOINT_ARG_TYPE_INT,
ENDPOINT_ARG_TYPE_STR
} endpoint_arg_type_e;
typedef enum
{
HTTP_METHOD_GET = (1 << 0),
HTTP_METHOD_POST = (1 << 1),
HTTP_METHOD_PUT = (1 << 2),
HTTP_METHOD_DELETE = (1 << 3),
HTTP_METHOD_OPTIONS = (1 << 4)
} http_method_e;
2020-05-05 09:42:02 +00:00
typedef struct
{
endpoint_arg_type_e type;
union
{
int v_int;
const char *v_str;
2020-05-05 09:42:02 +00:00
} value;
} endpoint_args_t;
typedef void (*endpoint_func_f)(struct mg_connection *c, endpoint_args_t *args, struct http_message *hm);
typedef struct
{
const char *full_route;
2020-05-05 09:42:02 +00:00
char **route;
char *route_keeper;
int method;
int options;
2020-05-05 09:42:02 +00:00
endpoint_func_f func;
int trailing_slash;
2020-05-05 09:42:02 +00:00
int args_count;
endpoint_args_t *args;
int possible_route;
int args_found;
} endpoint_t;
void
router_init();
endpoint_t*
router_register_endpoint(const char *route, int method, endpoint_func_f func);
2020-05-05 09:42:02 +00:00
endpoint_t*
router_find_endpoint(const char *uri_str, size_t uri_len, struct mg_str *method_str);
2020-05-05 09:42:02 +00:00
void
router_free();
#endif /* CORE_ROUTER_H */