// // Created by xajhuang on 2022/11/4. // #ifndef VCPE_PROJECT_HTTP_SVR_H #define VCPE_PROJECT_HTTP_SVR_H #ifdef __cplusplus extern "C" { #endif #ifdef HTTPSERVER_ON #include "mongoose.h" #define HTTP_HEAD_CONTENT_TYPE_JSON "Content-Type: application/json\r\n" #define HTTP_HEAD_CONTENT_TYPE_HTML "Content-Type: text/html\r\n" #define MAX_URI (1024) typedef enum { PRI_LOWEASE = 0, PRI_LOW, PRI_NORMAL, PRI_HIGH, PRI_HIGHEST, } HTTP_ROUTE_PRIORITY; #define DEF_HTTP_METHOD(HTTP_METHOD) \ HTTP_METHOD(GET, "GET") \ HTTP_METHOD(POST, "POST") \ HTTP_METHOD(PUT, "PUT") \ HTTP_METHOD(DELETE, "DELETE") \ HTTP_METHOD(HEAD, "HEAD") \ HTTP_METHOD(CONNECT, "CONNECT") \ HTTP_METHOD(OPTIONS, "OPTIONS") \ HTTP_METHOD(TRACE, "TRACE") \ HTTP_METHOD(PATCH, "PATCH") #define GENERATE_HTTP_METHOD_ENUM(ENUM, x) ENUM, typedef enum { DEF_HTTP_METHOD(GENERATE_HTTP_METHOD_ENUM) } HTTP_METHOD; typedef struct { int httpCode; int errCode; const char *pRspHeads; void *pRspData; } HTTP_RSP_CTX, *PHTTP_RSP_CTX; typedef void (*HTTP_REQUEST_CB)(struct mg_http_message *, void *, PHTTP_RSP_CTX); typedef struct { char routeName[MAX_URI]; HTTP_METHOD method; HTTP_ROUTE_PRIORITY priority; HTTP_REQUEST_CB cb; void *pUserData; } HTTP_ROUTE_INFO, *PHTTP_ROUTE_INFO; int http_svr_init(); int http_svr_uinit(); int http_add_route(const char *path, HTTP_METHOD method, HTTP_ROUTE_PRIORITY priority, HTTP_REQUEST_CB cb, void *pUserData); #endif #ifdef __cplusplus } #endif #endif //VCPE_PROJECT_HTTP_SVR_H