added user application HTTP handler with dedicated URI
This commit is contained in:
parent
5ebff8842e
commit
114321c91b
|
|
@ -33,11 +33,11 @@ void regHookBeforeUpdate(void (*before_update)(void));
|
|||
//MQTT incoming data callback
|
||||
void regUserEventHandler(void (*event_handler)(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data), void* user_arg);
|
||||
|
||||
//User handler of output '~var~' styled dynamic variables. Calls on give out files in response to GET requests.
|
||||
//void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var, int arg));
|
||||
//User App POST GET handlers register and set URL for this handlers
|
||||
void regHTTPUserAppHandlers(char *url,
|
||||
esp_err_t (*get)(httpd_req_t *req),
|
||||
esp_err_t (*post)(httpd_req_t *req));
|
||||
|
||||
//User handler of variables 'var1=value1&var2=value2' styled in POST requests.
|
||||
//void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData));
|
||||
|
||||
//User handler for various payload types
|
||||
void regCustomPayloadTypeHandler(sys_error_code (*payload_handler)(data_message_t *MSG));
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ httpd_handle_t server = NULL;
|
|||
static const char *TAG = "HTTPServer";
|
||||
|
||||
const char url_api[] = "/api";
|
||||
|
||||
//Pointer to external user defined rest api handler
|
||||
static int (*HTTPUserRestAPI)(char *url, char *req, int len, char *resp) = NULL;
|
||||
void regHTTPUserRestAPI(int (*api_handler)(char *url, char *req, int len, char *resp))
|
||||
|
|
@ -44,6 +43,20 @@ void regHTTPUserRestAPI(int (*api_handler)(char *url, char *req, int len, char *
|
|||
HTTPUserRestAPI = api_handler;
|
||||
}
|
||||
|
||||
char *userappurl = NULL;
|
||||
static esp_err_t (*HTTPUserAppGETHandler)(httpd_req_t *req) = NULL;
|
||||
static esp_err_t (*HTTPUserAppPOSTHandler)(httpd_req_t *req) = NULL;
|
||||
|
||||
void regHTTPUserAppHandlers(char *url,
|
||||
esp_err_t (*get)(httpd_req_t *req),
|
||||
esp_err_t (*post)(httpd_req_t *req))
|
||||
{
|
||||
userappurl = url;
|
||||
HTTPUserAppGETHandler = get;
|
||||
HTTPUserAppPOSTHandler = post;
|
||||
|
||||
}
|
||||
|
||||
static esp_err_t CheckAuth(httpd_req_t *req)
|
||||
{
|
||||
unsigned char pass[18] = { 0 }; //max length of login:password decoded string
|
||||
|
|
@ -179,6 +192,12 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
|||
ESP_LOGI(TAG, "POST request handle URL: %s", req->uri);
|
||||
#endif
|
||||
|
||||
if(userappurl && HTTPUserAppPOSTHandler)
|
||||
{
|
||||
if (memmem(req->uri, strlen(req->uri), userappurl, strlen(userappurl)))
|
||||
return HTTPUserAppPOSTHandler(req);
|
||||
}
|
||||
|
||||
if (memmem(req->uri, strlen(req->uri), "/storage/upload/", sizeof("/storage/upload/") - 1))
|
||||
return upload_post_handler(req);
|
||||
if (memmem(req->uri, strlen(req->uri), "/storage/delete/", sizeof("/storage/delete/") - 1))
|
||||
|
|
@ -255,6 +274,12 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
|||
ESP_LOGI(TAG, "GET request handle URL: %s", req->uri);
|
||||
#endif
|
||||
|
||||
if(userappurl && HTTPUserAppGETHandler)
|
||||
{
|
||||
if (memmem(req->uri, strlen(req->uri), userappurl, strlen(userappurl)))
|
||||
return HTTPUserAppGETHandler(req);
|
||||
}
|
||||
|
||||
//Route to file server GET handler
|
||||
if (memmem(req->uri, strlen(req->uri), "/storage/", sizeof("/storage/") - 1))
|
||||
return download_get_handler(req);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user