2020-05-30 22:23:57 +00:00
|
|
|
#ifndef CORE_ENDPOINT_H
|
|
|
|
#define CORE_ENDPOINT_H
|
|
|
|
|
|
|
|
#include <cJSON.h>
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ENDPOINT_ARG_TYPE_INT,
|
|
|
|
ENDPOINT_ARG_TYPE_STR
|
|
|
|
} endpoint_arg_type_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;
|
2020-11-15 15:36:44 +00:00
|
|
|
char *content;
|
2020-05-30 22:23:57 +00:00
|
|
|
int alloced_content;
|
|
|
|
} endpoint_response_t;
|
|
|
|
|
2020-05-31 00:07:25 +00:00
|
|
|
typedef void (*endpoint_func_f)(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
|
2020-05-30 22:23:57 +00:00
|
|
|
|
|
|
|
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
|
2020-05-31 00:07:25 +00:00
|
|
|
endpoint_func_index(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
|
2020-05-30 22:23:57 +00:00
|
|
|
|
|
|
|
void
|
2020-05-31 00:07:25 +00:00
|
|
|
endpoint_func_not_found(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
|
2020-05-30 22:23:57 +00:00
|
|
|
|
2020-11-13 22:20:07 +00:00
|
|
|
void
|
|
|
|
endpoint_response_msg(endpoint_response_t *response, int status_code, const char *content, int content_length);
|
|
|
|
|
2020-05-30 22:23:57 +00:00
|
|
|
void
|
|
|
|
endpoint_response_text(endpoint_response_t *response, int status_code, const char *content, int content_length);
|
|
|
|
|
|
|
|
void
|
|
|
|
endpoint_response_json(endpoint_response_t *response, int status_code, const cJSON *json_root);
|
|
|
|
|
2020-11-15 15:36:44 +00:00
|
|
|
void
|
|
|
|
endpoint_response_free_content(endpoint_response_t *response);
|
|
|
|
|
2020-05-30 22:23:57 +00:00
|
|
|
#endif /* CORE_ENDPOINT_H */
|