created REST API entry point and user handler
This commit is contained in:
parent
0f386c35d0
commit
1b1454a160
|
|
@ -51,6 +51,13 @@ struct file_server_data *server_data = NULL;
|
||||||
httpd_handle_t server = NULL;
|
httpd_handle_t server = NULL;
|
||||||
static const char *TAG = "HTTPServer";
|
static const char *TAG = "HTTPServer";
|
||||||
|
|
||||||
|
//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))
|
||||||
|
{
|
||||||
|
HTTPUserRestAPI = api_handler;
|
||||||
|
}
|
||||||
|
|
||||||
static esp_err_t CheckAuth(httpd_req_t *req)
|
static esp_err_t CheckAuth(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
unsigned char pass[18] = { 0 }; //max length of login:password decoded string
|
unsigned char pass[18] = { 0 }; //max length of login:password decoded string
|
||||||
|
|
@ -168,6 +175,16 @@ static const char* get_path_from_uri(char *dest, const char *base_path,
|
||||||
return dest + base_pathlen;
|
return dest + base_pathlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static esp_err_t RestApiHandler(httpd_req_t *req)
|
||||||
|
{
|
||||||
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
|
ESP_LOGI(TAG, "REST API handler");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
httpd_resp_sendstr(req, "{\"apiver\":\"1.00\",\"result\":\"OK\"}"); // Response body can be empty
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static esp_err_t POSTHandler(httpd_req_t *req)
|
static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
|
|
@ -209,6 +226,12 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
((struct file_server_data*) req->user_ctx)->base_path,
|
((struct file_server_data*) req->user_ctx)->base_path,
|
||||||
req->uri,
|
req->uri,
|
||||||
sizeof(filepath));
|
sizeof(filepath));
|
||||||
|
|
||||||
|
if (!memcmp(filename, "/api", 4))
|
||||||
|
{
|
||||||
|
return RestApiHandler(req);
|
||||||
|
}
|
||||||
|
|
||||||
http_res = HTTPPostApp(req, filename, buf);
|
http_res = HTTPPostApp(req, filename, buf);
|
||||||
|
|
||||||
if (http_res == HTTP_IO_DONE)
|
if (http_res == HTTP_IO_DONE)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user