From 981440adda60a73bebd0088f2983a58c19482f61 Mon Sep 17 00:00:00 2001 From: bogd Date: Mon, 11 Mar 2024 15:40:48 +0200 Subject: [PATCH] mqtt file handler added --- include/MQTTFiles.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/MQTTFiles.c | 25 +++++++++++++++++++++++++ src/RestApiHandler.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 include/MQTTFiles.h create mode 100644 src/MQTTFiles.c diff --git a/include/MQTTFiles.h b/include/MQTTFiles.h new file mode 100644 index 0000000..448c324 --- /dev/null +++ b/include/MQTTFiles.h @@ -0,0 +1,43 @@ + /* Copyright 2024 Bogdan Pilyugin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * File name: MQTTFiles.h + * Project: WebguiappTemplate + * Created on: 2024-03-11 + * Author: bogd + * Description: + */ + +#ifndef COMPONENTS_WEBGUIAPP_INCLUDE_MQTTFILES_H_ +#define COMPONENTS_WEBGUIAPP_INCLUDE_MQTTFILES_H_ + + + +typedef struct +{ + bool isActive; + int operType; + int dataLengthTotal; + int dataLengthReady; + + +} mqtt_files_cb; + + + + + + + +#endif /* COMPONENTS_WEBGUIAPP_INCLUDE_MQTTFILES_H_ */ diff --git a/src/MQTTFiles.c b/src/MQTTFiles.c new file mode 100644 index 0000000..b3d249e --- /dev/null +++ b/src/MQTTFiles.c @@ -0,0 +1,25 @@ + /* Copyright 2024 Bogdan Pilyugin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * File name: MQTTFiles.c + * Project: WebguiappTemplate + * Created on: 2024-03-11 + * Author: bogd + * Description: + */ + +#include MQTTFiles.h + + + diff --git a/src/RestApiHandler.c b/src/RestApiHandler.c index d097692..ec5c2aa 100644 --- a/src/RestApiHandler.c +++ b/src/RestApiHandler.c @@ -420,7 +420,6 @@ static void funct_file_delete(char *argres, int rw) { char filepath[FILE_PATH_MAX]; struct stat file_stat; - const char *filename = argres; if (!filename) { @@ -451,6 +450,46 @@ static void funct_file_delete(char *argres, int rw) } +static void funct_file_get(char *argres, int rw) +{ + char filepath[FILE_PATH_MAX]; + struct stat file_stat; + const char *filename = argres; + if (!filename) + { + snprintf(argres, VAR_MAX_VALUE_LENGTH, "\"ERROR:DIR_NOT_FOUND\""); + return; + } + + if (filename[strlen(filename) - 1] == '/') + { + ESP_LOGE("FILE_API", "Invalid filename : %s", filename); + snprintf(argres, VAR_MAX_VALUE_LENGTH, "\"ERROR:DIR_NOT_FOUND\""); + return; + } + + strcpy(filepath, dirpath); + strcat(filepath, filename); + + ESP_LOGI("FILE_API", " filepath to delete : %s", filepath); + + if (stat(filepath, &file_stat) == -1) + { + ESP_LOGE("FILE_API", "File does not exist : %s", filename); + snprintf(argres, VAR_MAX_VALUE_LENGTH, "\"ERROR:DIR_NOT_FOUND\""); + /* Respond with 400 Bad Request */ + return; + } + + + +} + +static void funct_file_put(char *argres, int rw) +{ + +} + const int hw_rev = CONFIG_BOARD_HARDWARE_REVISION; @@ -641,6 +680,8 @@ const rest_var_t SystemVariables[] = { 0, "file_list", &funct_file_list, VAR_FUNCT, R, 0, 0 }, { 0, "file_delete", &funct_file_delete, VAR_FUNCT, R, 0, 0 }, + { 0, "file_get", &funct_file_get, VAR_FUNCT, R, 0, 0 }, + { 0, "file_put", &funct_file_put, VAR_FUNCT, R, 0, 0 }, };