From c248830042939991ce4700d0de57fcaad38dd3b0 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 22 Sep 2024 17:40:39 +0200 Subject: [PATCH] fix api_data as command data --- src/command.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 04febabee..cad49e506 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -148,10 +148,10 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec const char * device_p = device_s; const char * data_p = nullptr; strlcpy(device_s, d, device_end - d + 1); - data_p = device_end + 1; - int8_t id_d = -1; - uint8_t device_type = EMSdevice::device_name_2_device_type(device_p); - if (device_type >= EMSdevice::DeviceType::BOILER) { + data_p = device_end + 1; + int8_t id_d = -1; + uint8_t device_type1 = EMSdevice::device_name_2_device_type(device_p); + if (device_type1 >= EMSdevice::DeviceType::BOILER) { data_p = parse_command_string(data_p, id_d); } if (data_p == nullptr) { @@ -161,17 +161,17 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec char data_s[COMMAND_MAX_LENGTH]; strlcpy(data_s, Helpers::toLower(data_p).c_str(), 30); if (strstr(data_s, "/value") == nullptr) { - strcat(data_s, "/value"); + strlcat(data_s, "/value", sizeof(data_s) - 6); } - if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) { + if (Command::call(device_type1, data_s, "", true, id_d, output) != CommandRet::OK) { return CommandRet::INVALID; } - const char * api_data = output["api_data"]; - if (api_data) { + if (output["api_data"].is()) { + std::string api_data = output["api_data"]; output.clear(); - return Command::call(device_type, command_p, api_data, is_admin, id_n, output); + return Command::call(device_type, command_p, api_data.c_str(), is_admin, id_n, output); } return CommandRet::INVALID;