mqtt file handler added

This commit is contained in:
Bogdan Pilyugin 2024-03-11 15:40:48 +02:00
parent 6712ed4b42
commit 981440adda
3 changed files with 110 additions and 1 deletions

43
include/MQTTFiles.h Normal file
View File

@ -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_ */

25
src/MQTTFiles.c Normal file
View File

@ -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

View File

@ -420,7 +420,6 @@ static void funct_file_delete(char *argres, int rw)
{ {
char filepath[FILE_PATH_MAX]; char filepath[FILE_PATH_MAX];
struct stat file_stat; struct stat file_stat;
const char *filename = argres; const char *filename = argres;
if (!filename) 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; 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_list", &funct_file_list, VAR_FUNCT, R, 0, 0 },
{ 0, "file_delete", &funct_file_delete, 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 },
}; };