Skip to content

Commit

Permalink
Merge pull request #584 from perexg/topic/config-jsondoc-alloc
Browse files Browse the repository at this point in the history
use one allocation size for DynamicJsonDocument settings
  • Loading branch information
fvanroie authored Dec 1, 2023
2 parents 894370b + 58970f4 commit 031c35d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/hasp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void configWrite()
settingsChanged = F(D_CONFIG_CHANGED);

/* Read Config File */
DynamicJsonDocument doc(8 * 256);
DynamicJsonDocument doc(MAX_CONFIG_JSON_ALLOC_SIZE);
LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), configFile.c_str());
configRead(doc, false);
LOG_INFO(TAG_CONF, F(D_FILE_LOADED), configFile.c_str());
Expand Down Expand Up @@ -515,7 +515,7 @@ void configWrite()

void configSetup()
{
DynamicJsonDocument settings(1024 + 512);
DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE);

for(uint32_t i = 0; i < 2; i++) {
if(i == 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/hasp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "hasplib.h"

#define MAX_CONFIG_JSON_ALLOC_SIZE (2048)

/* ===== Default Event Processors ===== */
void configSetup(void);
void configLoop(void);
Expand Down
4 changes: 2 additions & 2 deletions src/sys/svc/hasp_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static void webHandleApi()
{ // http://plate01/api
if(!http_is_authenticated("api")) return;

DynamicJsonDocument doc(2048);
DynamicJsonDocument doc(max(MAX_CONFIG_JSON_ALLOC_SIZE, 2048));
String contentType = http_get_content_type(F(".json"));
String endpoint((char*)0);
endpoint = webServer.pathArg(0);
Expand Down Expand Up @@ -1109,7 +1109,7 @@ static inline int handleFilesystemFile(String path)
configFile = FPSTR(FP_HASP_CONFIG_FILE);

if(path.endsWith(configFile.c_str())) { // "//config.json" is also a valid path!
DynamicJsonDocument settings(2048);
DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE);
DeserializationError error = configParseFile(configFile, settings);

if(error) return 500; // Internal Server Error
Expand Down
2 changes: 1 addition & 1 deletion src/sys/svc/hasp_http_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ int handleFileRead(AsyncWebServerRequest* request, String path)

if(!strncasecmp(file.name(), configFile.c_str(), configFile.length())) {
file.close();
DynamicJsonDocument settings(8 * 256);
DynamicJsonDocument settings(MAX_CONFIG_JSON_ALLOC_SIZE);
DeserializationError error = configParseFile(configFile, settings);

if(error) return 500; // Internal Server Error
Expand Down

0 comments on commit 031c35d

Please sign in to comment.