diff --git a/src/app/CFGFileParser.cpp b/src/app/CFGFileParser.cpp index d5ae89b..eb86f8a 100644 --- a/src/app/CFGFileParser.cpp +++ b/src/app/CFGFileParser.cpp @@ -1,6 +1,6 @@ #include "CFGFileParser.h" -CFGFileParser::CFGFileParser(SDCardManager &sdCardManager, const char *file):AbstractParser(file), _state(INIT), _type(PARAMETER), _sdCardManager(sdCardManager) +CFGFileParser::CFGFileParser(SDCardManager &sdCardManager, const char *file):AbstractParser(file), _state(INIT), _type(PARAMETER), _quotedParameter(false), _quotedValue(false), _sdCardManager(sdCardManager) { } @@ -10,7 +10,7 @@ void *CFGFileParser::parseFile() //Here is the logic for the file parser File file; - CFGDictionary *dictioRef = new CFGDictionary; + CFGDictionary *dictioRef = new CFGDictionary; char readChar(0), *parsedParameter(NULL), *parsedValue(NULL); file = _sdCardManager.open(_resource); @@ -23,6 +23,7 @@ void *CFGFileParser::parseFile() while(file.available()) { readChar = (char)file.read(); + //Do work switch(_state) { @@ -77,10 +78,11 @@ void *CFGFileParser::parseFile() if(parsedParameter != NULL) { //printf("%s --> %s\n", parsedParameter, parsedValue); - dictioRef->addParameter(parsedParameter, parsedValue == NULL ? "":parsedValue); + dictioRef->addParameter(parsedParameter, new CFGParameterValue(parsedParameter, parsedValue == NULL ? "":parsedValue, _quotedParameter, _quotedValue)); free(parsedParameter);free(parsedValue); - parsedParameter = NULL; - parsedValue = NULL; + parsedParameter = NULL;parsedValue = NULL; + _quotedParameter = false;_quotedValue = false; + } } else if(readChar == ' ') _state = PARAM_SECTION; @@ -104,7 +106,14 @@ void *CFGFileParser::parseFile() _state = ERROR; break; case OPENING_QUOTE: - if(readChar == '\'') _state = PARAM_SECTION; + if(readChar == '\'') + { + _state = PARAM_SECTION; + if(_type == PARAMETER) + _quotedParameter = true; + else + _quotedValue = true; + } else if((readChar >= 65 && readChar <= 90) || (readChar >= 97 && readChar <= 122) || readChar == ' ' || readChar == '_' || (readChar >= 48 && readChar <= 57)) { //printf("%c",readChar); diff --git a/src/app/CFGFileParser.h b/src/app/CFGFileParser.h index aedbedd..7edb6d3 100644 --- a/src/app/CFGFileParser.h +++ b/src/app/CFGFileParser.h @@ -5,6 +5,7 @@ #include "CFGDictionary.h" #include "SDCardManager.h" #include "definition.h" +#include "CFGParameterValue.h" class CFGFileParser : public AbstractParser { @@ -21,6 +22,8 @@ private: enum Type {PARAMETER, VALUE}; State _state; Type _type; + boolean _quotedParameter; + boolean _quotedValue; SDCardManager &_sdCardManager; }; diff --git a/src/app/ConnectivityManager.cpp b/src/app/ConnectivityManager.cpp index 6b8f3ab..5a1cf1a 100644 --- a/src/app/ConnectivityManager.cpp +++ b/src/app/ConnectivityManager.cpp @@ -15,22 +15,22 @@ ConnectivityManager::ConnectivityManager(SDCardManager *sdCardManager) : _error( else { CFGFileParser cfgFileParser(*sdCardManager, AP_CFG_FILE); - CFGDictionary *cfgDictionary = (CFGDictionary *) cfgFileParser.parseFile(); + CFGDictionary *cfgDictionary = (CFGDictionary *) cfgFileParser.parseFile(); if(cfgDictionary == NULL) { if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR; } else { - if(!softAP((*cfgDictionary)("SSID").stringValue(), strcmp((*cfgDictionary)("PASSWORD").stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD").stringValue(), (*cfgDictionary)("CHANNEL").intValue(), (*cfgDictionary)("SSID_HIDDEN").booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION").intValue()))_error &= AP_SETUP_ERR; + if(!softAP((*cfgDictionary)("SSID").getValue().stringValue(), strcmp((*cfgDictionary)("PASSWORD").getValue().stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD").getValue().stringValue(), (*cfgDictionary)("CHANNEL").getValue().intValue(), (*cfgDictionary)("SSID_HIDDEN").getValue().booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION").getValue().intValue()))_error &= AP_SETUP_ERR; delete cfgDictionary; } CFGFileParser cfgFileParserSTA(*sdCardManager, STA_CFG_FILE); - cfgDictionary = (CFGDictionary *) cfgFileParserSTA.parseFile(); + cfgDictionary = (CFGDictionary *) cfgFileParserSTA.parseFile(); if(cfgDictionary != NULL) { - if(!begin((*cfgDictionary)("SSID").stringValue(), (*cfgDictionary)("PASSWORD").stringValue()))_error &= AP_SETUP_ERR; + if(!begin((*cfgDictionary)("SSID").getValue().stringValue(), (*cfgDictionary)("PASSWORD").getValue().stringValue()))_error &= AP_SETUP_ERR; delete cfgDictionary; } } diff --git a/src/app/app.ino b/src/app/app.ino index 1fa8004..dad345c 100644 --- a/src/app/app.ino +++ b/src/app/app.ino @@ -3,6 +3,7 @@ #include "SAB.h" #include "views.h" #include "CFGDictionary.h" +#include "CFGParameterValue.h" SAB sab;