#ifndef CORE_ROUTER_H #define CORE_ROUTER_H #include #define ENDPOINTS_MAX_COUNT 128 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; typedef struct { endpoint_arg_type_e type; union { int v_int; const char *v_str; } value; } endpoint_args_t; typedef struct { int status_code; const char *content_type; size_t content_length; const char *content; int alloced_content; } endpoint_response_t; typedef void (*endpoint_func_f)(struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response); typedef struct { const char *full_route; char **route; char *route_keeper; int method; int options; endpoint_func_f func; int trailing_slash; 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); endpoint_t* router_find_endpoint(const char *uri_str, size_t uri_len, struct mg_str *method_str); void router_free(); #endif /* CORE_ROUTER_H */