intermediate save of file server debug
This commit is contained in:
parent
be81499a00
commit
00a60102b4
|
|
@ -210,9 +210,13 @@ esp_err_t download_get_handler(httpd_req_t *req)
|
||||||
FILE *fd = NULL;
|
FILE *fd = NULL;
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
|
|
||||||
const char *filename = get_path_from_uri(filepath, ((struct file_server_data*) req->user_ctx)->base_path,
|
const char *filename = get_path_from_uri(filepath, ((struct file_server_data*) req->user_ctx)->base_path2,
|
||||||
req->uri,
|
req->uri,
|
||||||
sizeof(filepath));
|
sizeof(filepath));
|
||||||
|
ESP_LOGW(TAG, "FILE_GET_URI %s", req->uri);
|
||||||
|
ESP_LOGW(TAG, "FILE_GET_FILEPATH %s", filepath);
|
||||||
|
ESP_LOGW(TAG, "FILE_GET_FILENAME %s", filename);
|
||||||
|
|
||||||
if (!filename)
|
if (!filename)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Filename is too long");
|
ESP_LOGE(TAG, "Filename is too long");
|
||||||
|
|
@ -224,7 +228,7 @@ esp_err_t download_get_handler(httpd_req_t *req)
|
||||||
/* If name has trailing '/', respond with directory contents */
|
/* If name has trailing '/', respond with directory contents */
|
||||||
if (filename[strlen(filename) - 1] == '/')
|
if (filename[strlen(filename) - 1] == '/')
|
||||||
{
|
{
|
||||||
return http_resp_dir_html(req, "/data");
|
return http_resp_dir_html(req, "/data/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(filepath, &file_stat) == -1)
|
if (stat(filepath, &file_stat) == -1)
|
||||||
|
|
@ -305,9 +309,13 @@ esp_err_t upload_post_handler(httpd_req_t *req)
|
||||||
|
|
||||||
/* Skip leading "/upload" from URI to get filename */
|
/* Skip leading "/upload" from URI to get filename */
|
||||||
/* Note sizeof() counts NULL termination hence the -1 */
|
/* Note sizeof() counts NULL termination hence the -1 */
|
||||||
const char *filename = get_path_from_uri(filepath, ((struct file_server_data*) req->user_ctx)->base_path,
|
const char *filename = get_path_from_uri(filepath, ((struct file_server_data*) req->user_ctx)->base_path2,
|
||||||
req->uri + sizeof("/files/upload") - 1,
|
req->uri + sizeof("/files/upload") - 1,
|
||||||
sizeof(filepath));
|
sizeof(filepath));
|
||||||
|
ESP_LOGW(TAG, "FILE_POST_URI %s", req->uri);
|
||||||
|
ESP_LOGW(TAG, "FILE_POST_FILEPATH %s", filepath);
|
||||||
|
ESP_LOGW(TAG, "FILE_POST_FILENAME %s", filename);
|
||||||
|
|
||||||
if (!filename)
|
if (!filename)
|
||||||
{
|
{
|
||||||
/* Respond with 500 Internal Server Error */
|
/* Respond with 500 Internal Server Error */
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ static esp_err_t CheckAuth(httpd_req_t *req)
|
||||||
#define IS_FILE_EXT(filename, ext) \
|
#define IS_FILE_EXT(filename, ext) \
|
||||||
(strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
|
(strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
|
||||||
|
|
||||||
|
|
||||||
/* Set HTTP response content type according to file extension */
|
/* Set HTTP response content type according to file extension */
|
||||||
static esp_err_t set_content_type_from_file(httpd_req_t *req,
|
static esp_err_t set_content_type_from_file(httpd_req_t *req,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
|
|
@ -174,6 +173,11 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
ESP_LOGI(TAG, "POST request handle");
|
ESP_LOGI(TAG, "POST request handle");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (true)
|
||||||
|
{
|
||||||
|
return upload_post_handler(req);
|
||||||
|
}
|
||||||
|
|
||||||
char *buf = ((struct file_server_data*) req->user_ctx)->scratch;
|
char *buf = ((struct file_server_data*) req->user_ctx)->scratch;
|
||||||
int received;
|
int received;
|
||||||
int remaining = req->content_len;
|
int remaining = req->content_len;
|
||||||
|
|
@ -206,25 +210,13 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
if (received)
|
if (received)
|
||||||
{
|
{
|
||||||
char filepath[FILE_PATH_MAX];
|
char filepath[FILE_PATH_MAX];
|
||||||
|
const char *filename;
|
||||||
const char *filename = get_path_from_uri(filepath,
|
|
||||||
((struct file_server_data*) req->user_ctx)->base_path,
|
|
||||||
req->uri,
|
|
||||||
sizeof(filepath));
|
|
||||||
|
|
||||||
ESP_LOGW(TAG, "URI %s", req->uri);
|
|
||||||
if (memmem(filename, strlen(filename), "/files/upload/", sizeof("/files/upload/")))
|
|
||||||
{
|
|
||||||
ESP_LOGW(TAG, "filepath %s", filepath);
|
|
||||||
return upload_post_handler(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = get_path_from_uri(filepath,
|
filename = get_path_from_uri(filepath,
|
||||||
((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))
|
if (!memcmp(filename, "/api", 4))
|
||||||
{
|
{
|
||||||
return RestApiHandler(req);
|
return RestApiHandler(req);
|
||||||
|
|
@ -268,6 +260,14 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
ESP_LOGI(TAG, "GET request handle");
|
ESP_LOGI(TAG, "GET request handle");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ESP_LOGW(TAG, "URI %s", req->uri);
|
||||||
|
//if (!strcmp(req->uri, "/files/"))
|
||||||
|
if(memmem(req->uri, strlen(req->uri), "/files/", 7))
|
||||||
|
{
|
||||||
|
return download_get_handler(req);
|
||||||
|
}
|
||||||
|
|
||||||
char filepath[FILE_PATH_MAX];
|
char filepath[FILE_PATH_MAX];
|
||||||
espfs_file_t *file;
|
espfs_file_t *file;
|
||||||
struct espfs_stat_t stat;
|
struct espfs_stat_t stat;
|
||||||
|
|
@ -275,6 +275,9 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
uint32_t bufSize; //size of ram buffer for chunk of data, read from file
|
uint32_t bufSize; //size of ram buffer for chunk of data, read from file
|
||||||
uint32_t readBytes; //number of bytes, read from file. used for information only
|
uint32_t readBytes; //number of bytes, read from file. used for information only
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char *filename = get_path_from_uri(filepath,
|
const char *filename = get_path_from_uri(filepath,
|
||||||
((struct file_server_data*) req->user_ctx)->base_path,
|
((struct file_server_data*) req->user_ctx)->base_path,
|
||||||
req->uri,
|
req->uri,
|
||||||
|
|
@ -288,11 +291,7 @@ static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGW(TAG, "URI %s", req->uri);
|
|
||||||
if (!strcmp(filename, "/files/"))
|
|
||||||
{
|
|
||||||
return download_get_handler(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Redirect request to /index.html */
|
/* Redirect request to /index.html */
|
||||||
if (filename[strlen(filename) - 1] == '/')
|
if (filename[strlen(filename) - 1] == '/')
|
||||||
|
|
@ -464,8 +463,6 @@ file_send_error:
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static httpd_handle_t start_webserver(void)
|
static httpd_handle_t start_webserver(void)
|
||||||
{
|
{
|
||||||
httpd_handle_t server = NULL;
|
httpd_handle_t server = NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user