diff --git a/code/components/jomjol_configfile/configFile.cpp b/code/components/jomjol_configfile/configFile.cpp index 2119b70b..0e1dd70a 100644 --- a/code/components/jomjol_configfile/configFile.cpp +++ b/code/components/jomjol_configfile/configFile.cpp @@ -82,25 +82,3 @@ bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof) disabled = ((*rt)[0] == ';'); return true; } - -std::vector ConfigFile::ZerlegeZeile(std::string input, std::string delimiter) -{ - std::vector Output; -// std::string delimiter = " =,"; - - input = trim(input, delimiter); - size_t pos = findDelimiterPos(input, delimiter); - std::string token; - while (pos != std::string::npos) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push_back(token); - input.erase(0, pos + 1); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); - } - Output.push_back(input); - - return Output; - -} diff --git a/code/components/jomjol_configfile/configFile.h b/code/components/jomjol_configfile/configFile.h index 65b0143c..c34605e9 100644 --- a/code/components/jomjol_configfile/configFile.h +++ b/code/components/jomjol_configfile/configFile.h @@ -9,7 +9,6 @@ public: bool isNewParagraph(std::string input); bool GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof); bool getNextLine(std::string* rt, bool &disabled, bool &eof); - std::vector ZerlegeZeile(std::string input, std::string delimiter = " =, \t"); private: FILE* pFile; diff --git a/code/components/jomjol_controlGPIO/server_GPIO.cpp b/code/components/jomjol_controlGPIO/server_GPIO.cpp index 324809d8..401487e4 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.cpp +++ b/code/components/jomjol_controlGPIO/server_GPIO.cpp @@ -327,7 +327,7 @@ bool GpioHandler::readConfig() bool registerISR = false; while (configFile.getNextLine(&line, disabledLine, eof) && !configFile.isNewParagraph(line)) { - zerlegt = configFile.ZerlegeZeile(line); + zerlegt = ZerlegeZeile(line); // const std::regex pieces_regex("IO([0-9]{1,2})"); // std::smatch pieces_match; // if (std::regex_match(zerlegt[0], pieces_match, pieces_regex) && (pieces_match.size() == 2)) diff --git a/code/components/jomjol_flowcontroll/ClassFlow.cpp b/code/components/jomjol_flowcontroll/ClassFlow.cpp index 178fb74b..89c5b9b0 100644 --- a/code/components/jomjol_flowcontroll/ClassFlow.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlow.cpp @@ -15,30 +15,6 @@ void ClassFlow::SetInitialParameter(void) disabled = false; } - - - -std::vector ClassFlow::ZerlegeZeile(std::string input, std::string delimiter) -{ - std::vector Output; - - input = trim(input, delimiter); - size_t pos = findDelimiterPos(input, delimiter); - std::string token; - while (pos != std::string::npos) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push_back(token); - input.erase(0, pos + 1); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); - } - Output.push_back(input); - - return Output; - -} - bool ClassFlow::isNewParagraph(string input) { if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '['))) diff --git a/code/components/jomjol_flowcontroll/ClassFlow.h b/code/components/jomjol_flowcontroll/ClassFlow.h index 92184d32..fa947f16 100644 --- a/code/components/jomjol_flowcontroll/ClassFlow.h +++ b/code/components/jomjol_flowcontroll/ClassFlow.h @@ -26,7 +26,6 @@ struct HTMLInfo class ClassFlow { protected: - std::vector ZerlegeZeile(string input, string delimiter = " =, \t"); bool isNewParagraph(string input); bool GetNextParagraph(FILE* pfile, string& aktparamgraph); bool getNextLine(FILE* pfile, string* rt); diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 63bd3683..e996f2a8 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -319,7 +319,7 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); if ((toUpper(zerlegt[0]) == "LOGIMAGELOCATION") && (zerlegt.size() > 1)) { this->LogImageLocation = "/sdcard" + zerlegt[1]; diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index d7bcf23a..2090ed07 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -445,7 +445,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph, " ="); + zerlegt = ZerlegeZeile(aktparamgraph, " ="); if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1)) { if (toUpper(zerlegt[1]) == "TRUE") diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp index bbf78628..5ced8538 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp @@ -80,7 +80,7 @@ bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str()); - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1)) { this->user = zerlegt[1]; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 50465cec..65061657 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -103,7 +103,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1)) { this->user = zerlegt[1]; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index 08fdfade..0d577304 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -78,7 +78,7 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); if ((zerlegt[0] == "LogImageLocation") && (zerlegt.size() > 1)) { LogImageLocation = "/sdcard" + zerlegt[1]; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index cede216d..7f428d81 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -479,7 +479,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); std::string _param = GetParameterName(zerlegt[0]); if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (zerlegt.size() > 1)) diff --git a/code/components/jomjol_flowcontroll/ClassFlowWriteList.cpp b/code/components/jomjol_flowcontroll/ClassFlowWriteList.cpp index 4d406728..40d5ca02 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowWriteList.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowWriteList.cpp @@ -50,7 +50,7 @@ bool ClassFlowWriteList::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - zerlegt = this->ZerlegeZeile(aktparamgraph); + zerlegt = ZerlegeZeile(aktparamgraph); /* if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1)) { diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 3e4e4936..d06b819a 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -541,20 +541,52 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter delimiter = _delimiter; } + return ZerlegeZeile(input, delimiter); +} + + + +std::vector ZerlegeZeile(std::string input, std::string delimiter) +{ + std::vector Output; + input = trim(input, delimiter); - size_t pos = findDelimiterPos(input, delimiter); - std::string token; - while (pos != std::string::npos) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push_back(token); - input.erase(0, pos + 1); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); + + /* The input can have multiple formats: + * - key = value + * - key = value1 value2 value3 ... + * - key value1 value2 value3 ... + * + * Examples: + * - ImageSize = VGA + * - IO0 = input disabled 10 false false + * - main.dig1 28 144 55 100 false + * + * This causes issues eg. if a password key has a whitespace or equal sign in its value. + * As a workaround and to not break any legacy usage, we enforce to only use the + * equal sign, if the key is "password" + */ + if (input.find("password") != string::npos) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence + size_t pos = input.find("="); + Output.push_back(trim(input.substr(0, pos), "")); + Output.push_back(trim(input.substr(pos +1, string::npos), "")); + } + else { // Legacy Mode + size_t pos = findDelimiterPos(input, delimiter); + std::string token; + while (pos != std::string::npos) { + token = input.substr(0, pos); + token = trim(token, delimiter); + Output.push_back(token); + input.erase(0, pos + 1); + input = trim(input, delimiter); + pos = findDelimiterPos(input, delimiter); + } + Output.push_back(input); } - Output.push_back(input); return Output; + } diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 32d7d448..21170a9e 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -42,6 +42,7 @@ time_t addDays(time_t startTime, int days); void memCopyGen(uint8_t* _source, uint8_t* _target, int _size); std::vector HelperZerlegeZeile(std::string input, std::string _delimiter); +std::vector ZerlegeZeile(std::string input, std::string delimiter = " =, \t"); /////////////////////////// size_t getInternalESPHeapSize(); diff --git a/sd-card/html/readconfigcommon.js b/sd-card/html/readconfigcommon.js index 6cf0b291..5f20bcc6 100644 --- a/sd-card/html/readconfigcommon.js +++ b/sd-card/html/readconfigcommon.js @@ -50,17 +50,40 @@ function ZerlegeZeile(input, delimiter = " =\t\r") // delimiter = " =,\t"; input = trim(input, delimiter); - var pos = findDelimiterPos(input, delimiter); - var token; - while (pos > -1) { - token = input.substr(0, pos); - token = trim(token, delimiter); - Output.push(token); - input = input.substr(pos+1, input.length); - input = trim(input, delimiter); - pos = findDelimiterPos(input, delimiter); + + /* The input can have multiple formats: + * - key = value + * - key = value1 value2 value3 ... + * - key value1 value2 value3 ... + * + * Examples: + * - ImageSize = VGA + * - IO0 = input disabled 10 false false + * - main.dig1 28 144 55 100 false + * + * This causes issues eg. if a password key has a whitespace or equal sign in its value. + * As a workaround and to not break any legacy usage, we enforce to only use the + * equal sign, if the key is "password" + */ + if (input.includes("password")) { // Line contains a password, use the equal sign as the only delimiter and only split on first occurrence + console.log(input); + var pos = input.indexOf("="); + Output.push(trim(input.substr(0, pos), delimiter)); + Output.push(trim(input.substr(pos +1, input.length), delimiter)); + } + else { // Legacy Mode + var pos = findDelimiterPos(input, delimiter); + var token; + while (pos > -1) { + token = input.substr(0, pos); + token = trim(token, delimiter); + Output.push(token); + input = input.substr(pos+1, input.length); + input = trim(input, delimiter); + pos = findDelimiterPos(input, delimiter); + } + Output.push(input); } - Output.push(input); return Output;