add: status for mqtt

fix: refactor connection handlers
This commit is contained in:
Tobias Reisinger 2020-06-26 01:01:46 +02:00
parent 2bc11ee829
commit 6c6e5023da
19 changed files with 534 additions and 183 deletions

View file

@ -4,11 +4,13 @@
#include <router.h>
#include <macros.h>
#include <endpoint.h>
#include <status.h>
#include <endpoints/api_v1_schedules.h>
#include <endpoints/api_v1_controllers.h>
#include <endpoints/api_v1_relays.h>
#include <endpoints/api_v1_tags.h>
#include <endpoints/api_v1_ws.h>
static endpoint_t endpoints[ROUTER_ENDPOINTS_MAX_COUNT];
static endpoint_t endpoint_not_found;
@ -38,6 +40,10 @@ get_method_str_for_int(int method_int)
{
return mg_mk_str("OPTIONS");
}
if(method_int == HTTP_METHOD_WEBSOCKET)
{
return mg_mk_str("WEBSOCKET");
}
return mg_mk_str("GET");
}
@ -81,6 +87,9 @@ router_init()
router_register_endpoint("/api/v1/tags/", HTTP_METHOD_GET, api_v1_tags_GET);
router_register_endpoint("/api/v1/tags/{str}", HTTP_METHOD_GET, api_v1_tags_STR_GET);
router_register_endpoint("/api/v1/tags/{str}", HTTP_METHOD_DELETE, api_v1_tags_STR_DELETE);
router_register_endpoint("/api/v1/ws/relays", HTTP_METHOD_WEBSOCKET, api_v1_ws_relays);
}
endpoint_t*
@ -182,26 +191,31 @@ router_register_endpoint(const char *route, int method, endpoint_func_f func)
static int
get_method_int_for_str(struct mg_str *method_str)
{
if(strncmp(method_str->p, "GET", method_str->len) == 0)
if(mg_vcmp(method_str, "GET") == 0)
{
return HTTP_METHOD_GET;
}
if(strncmp(method_str->p, "POST", method_str->len) == 0)
if(mg_vcmp(method_str, "POST") == 0)
{
return HTTP_METHOD_POST;
}
if(strncmp(method_str->p, "PUT", method_str->len) == 0)
if(mg_vcmp(method_str, "PUT") == 0)
{
return HTTP_METHOD_PUT;
}
if(strncmp(method_str->p, "DELETE", method_str->len) == 0)
if(mg_vcmp(method_str, "DELETE") == 0)
{
return HTTP_METHOD_DELETE;
}
if(strncmp(method_str->p, "OPTIONS", method_str->len) == 0)
if(mg_vcmp(method_str, "OPTIONS") == 0)
{
return HTTP_METHOD_OPTIONS;
}
if(mg_vcmp(method_str, "WEBSOCKET") == 0)
{
return HTTP_METHOD_WEBSOCKET;
}
return HTTP_METHOD_GET;
}