From e71157b9ec9e9b7bc6284a313b5aeb891e2ab7c6 Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Sat, 29 Jul 2017 12:45:45 +0200 Subject: [PATCH] Important Update: - ApplicationCore: - Rename ConfigParser -> JSONparser - Make JSONparser a public parameter - DataTreeCore: - Bug fix: Insufficient memory allocation on SetValue if Len = -1 --- ApplicationCore.cpp | 20 ++++++++++---------- ApplicationCore.h | 4 +--- DataTreeCore.cpp | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ApplicationCore.cpp b/ApplicationCore.cpp index 06eaddc..56a3d65 100644 --- a/ApplicationCore.cpp +++ b/ApplicationCore.cpp @@ -40,7 +40,7 @@ CApplication::CApplication( EDebugLevel pLogLevel ) // Create Configuration DataTree = new CDataTree(); - ConfigParser = new CJSONparse( DataTree ); + JSONparser = new CJSONparse( DataTree ); // Selector Selector = NULL; @@ -73,7 +73,7 @@ CApplication::~CApplication() if (Selector) delete Selector; if (Log) delete Log; if (DataTree) delete DataTree; - if (ConfigParser) delete ConfigParser; + if (JSONparser) delete JSONparser; // Free Process Name if (ProcessName) free( ProcessName ); @@ -119,13 +119,13 @@ bool CApplication::LoadConfig( int argc, char *argv[], const char * pConfigPath } // Load Application List - if (ConfigParser->ReadFromFile( pConfigPath, ConfigFile )) { + if (JSONparser->ReadFromFile( pConfigPath, ConfigFile )) { if (Log) Log->Message( dlLow, dlLow, "%s: Config file loaded (%s)", ProcessName, ConfigFile ); } else { - if (Log) Log->Message( dlLow, dlLow, "%s: Fail to load config file (%s)- %s", ProcessName, ConfigFile, ConfigParser->GetError() ); + if (Log) Log->Message( dlLow, dlLow, "%s: Fail to load config file (%s)- %s", ProcessName, ConfigFile, JSONparser->GetError() ); return false; } - //ConfigParser->WriteToScreen( pConfigPath, 2 ); + //JSONparser->WriteToScreen( pConfigPath, 2 ); // Loaded successfully return true; @@ -136,9 +136,9 @@ bool CApplication::SaveConfig() { // Save updated configuration if (ConfigFile && *ConfigFile) - ConfigParser->WriteToFile( "config", ConfigFile ); + JSONparser->WriteToFile( "config", ConfigFile ); if (AddressFile && *AddressFile ) - ConfigParser->WriteToFile( "address", AddressFile ); + JSONparser->WriteToFile( "address", AddressFile ); return true; } //--------------------------------------------------------------------------- @@ -192,12 +192,12 @@ bool CApplication::LoadConfigData() // Load Address List if ((AddressFile = (char*)DataTree->GetStr( ConfigMember, "AddressList/Path", NULL ))) { - if (ConfigParser->ReadFromFile( "address", AddressFile )) { + if (JSONparser->ReadFromFile( "address", AddressFile )) { if (Log) Log->Message( dlLow, dlLow, "%s: Address file loaded (%s)", ProcessName, AddressFile ); } else { - if (Log) Log->Message( dlLow, dlLow, "%s: Fail to load Address file (%s) - %s", ProcessName, AddressFile, ConfigParser->GetError() ); + if (Log) Log->Message( dlLow, dlLow, "%s: Fail to load Address file (%s) - %s", ProcessName, AddressFile, JSONparser->GetError() ); } - //ConfigParser->WriteToScreen( pAddressListPath, 2 ); + //JSONparser->WriteToScreen( pAddressListPath, 2 ); } // Configure Selector diff --git a/ApplicationCore.h b/ApplicationCore.h index 5c22fd0..cc5c389 100644 --- a/ApplicationCore.h +++ b/ApplicationCore.h @@ -47,9 +47,6 @@ protected: // List TFunctionItem * FirstFunction; - // Configuration - CJSONparse * ConfigParser = NULL; - // Output EDebugLevel LogLevel; int LogOutput; @@ -66,6 +63,7 @@ public: CDataTree * DataTree; CLogCore * Log; CSelect * Selector; + CJSONparse * JSONparser = NULL; // Life Cycle CApplication( EDebugLevel pDebugLevel ); diff --git a/DataTreeCore.cpp b/DataTreeCore.cpp index 2e882ae..f80a6e3 100644 --- a/DataTreeCore.cpp +++ b/DataTreeCore.cpp @@ -371,7 +371,7 @@ bool CDataTree::SetValue( TDataMember * Member, EDataType Type, const char * Va // Check Length if (Len == -1) { - Len = strlen( Value ); + Len = strlen(Value)+1; } // Create copy of value