From 41d178ca7b507ec5ebf2b72f890c897f50319e64 Mon Sep 17 00:00:00 2001 From: Astellar Date: Sun, 20 Jun 2010 01:50:19 +0400 Subject: [PATCH] [10081] Use ACE config library instead dotconfpp NOTE: all config versions update because in old state it's not compatible with new way loading. Look for *.conf.dist.in chnages in commit for update configs. Signed-off-by: VladimirMangos --- src/mangosd/mangosd.conf.dist.in | 4 +- src/realmd/realmd.conf.dist.in | 4 +- src/shared/Config/Config.cpp | 84 ++++++++++++++++---------------- src/shared/Config/Config.h | 7 ++- src/shared/Config/ConfigEnv.h | 1 - src/shared/SystemConfig.h.in | 4 +- src/shared/revision_nr.h | 2 +- 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in index f5ba807ed..58d337a00 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -1,7 +1,9 @@ ##################################### # MaNGOS Configuration file # ##################################### -ConfVersion=2010051901 + +[MangosdConf] +ConfVersion=2010062001 ################################################################################################################### # CONNECTIONS AND DIRECTORIES diff --git a/src/realmd/realmd.conf.dist.in b/src/realmd/realmd.conf.dist.in index 20e179217..99ada0219 100644 --- a/src/realmd/realmd.conf.dist.in +++ b/src/realmd/realmd.conf.dist.in @@ -1,7 +1,9 @@ ############################################ # MaNGOS realmd configuration file # ############################################ -ConfVersion=2007062001 + +[RealmdConf] +ConfVersion=2010062001 ################################################################################################################### # REALMD SETTINGS diff --git a/src/shared/Config/Config.cpp b/src/shared/Config/Config.cpp index b4eeacd2c..80201329a 100644 --- a/src/shared/Config/Config.cpp +++ b/src/shared/Config/Config.cpp @@ -17,12 +17,35 @@ */ #include "ConfigEnv.h" +#include "ace/Configuration_Import_Export.h" + #include "Policies/SingletonImp.h" INSTANTIATE_SINGLETON_1(Config); +static bool GetValueHelper(ACE_Configuration_Heap *mConf, const char *name, ACE_TString &result) +{ + if (!mConf) + return false; + + ACE_TString section_name; + ACE_Configuration_Section_Key section_key; + ACE_Configuration_Section_Key root_key = mConf->root_section(); + + int i = 0; + while (mConf->enumerate_sections(root_key, i, section_name) == 0) + { + mConf->open_section(root_key, section_name.c_str(), 0, section_key); + if (mConf->get_string_value(section_key, name, result) == 0) + return true; + ++i; + } + + return false; +} + Config::Config() -: mIgnoreCase(true), mConf(NULL) +: mConf(NULL) { } @@ -31,9 +54,8 @@ Config::~Config() delete mConf; } -bool Config::SetSource(const char *file, bool ignorecase) +bool Config::SetSource(const char *file) { - mIgnoreCase = ignorecase; mFilename = file; return Reload(); @@ -42,43 +64,33 @@ bool Config::SetSource(const char *file, bool ignorecase) bool Config::Reload() { delete mConf; + mConf = new ACE_Configuration_Heap; - mConf = new DOTCONFDocument(mIgnoreCase ? - DOTCONFDocument::CASEINSENSETIVE : - DOTCONFDocument::CASESENSITIVE); - - if (mConf->setContent(mFilename.c_str()) == -1) + if (mConf->open() == 0) { - delete mConf; - mConf = NULL; - return false; + ACE_Ini_ImpExp config_importer(*mConf); + if (config_importer.import_config(mFilename.c_str()) == 0) + return true; } - return true; + delete mConf; + mConf = NULL; + return false; } std::string Config::GetStringDefault(const char* name, const char* def) { - if (!mConf) - return std::string(def); - - DOTCONFDocumentNode const *node = mConf->findNode(name); - if (!node || !node->getValue()) - return std::string(def); - - return std::string(node->getValue()); + ACE_TString val; + return GetValueHelper(mConf, name, val) ? val.c_str() : def; } bool Config::GetBoolDefault(const char* name, bool def) { - if (!mConf) + ACE_TString val; + if (!GetValueHelper(mConf, name, val)) return def; - DOTCONFDocumentNode const *node = mConf->findNode(name); - if (!node || !node->getValue()) - return def; - - const char* str = node->getValue(); + const char* str = val.c_str(); if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 || strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 || strcmp(str, "1") == 0) @@ -90,25 +102,13 @@ bool Config::GetBoolDefault(const char* name, bool def) int32 Config::GetIntDefault(const char* name, int32 def) { - if (!mConf) - return def; - - DOTCONFDocumentNode const *node = mConf->findNode(name); - if (!node || !node->getValue()) - return def; - - return atoi(node->getValue()); + ACE_TString val; + return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def; } float Config::GetFloatDefault(const char* name, float def) { - if (!mConf) - return def; - - DOTCONFDocumentNode const *node = mConf->findNode(name); - if (!node || !node->getValue()) - return def; - - return (float)atof(node->getValue()); + ACE_TString val; + return GetValueHelper(mConf, name, val) ? (float)atof(val.c_str()) : def; } diff --git a/src/shared/Config/Config.h b/src/shared/Config/Config.h index 296018408..7f33e99f4 100644 --- a/src/shared/Config/Config.h +++ b/src/shared/Config/Config.h @@ -22,7 +22,7 @@ #include #include "Platform/Define.h" -class DOTCONFDocument; +class ACE_Configuration_Heap; class MANGOS_DLL_SPEC Config { @@ -31,7 +31,7 @@ class MANGOS_DLL_SPEC Config Config(); ~Config(); - bool SetSource(const char *file, bool ignorecase = true); + bool SetSource(const char *file); bool Reload(); std::string GetStringDefault(const char* name, const char* def); @@ -44,8 +44,7 @@ class MANGOS_DLL_SPEC Config private: std::string mFilename; - bool mIgnoreCase; - DOTCONFDocument *mConf; + ACE_Configuration_Heap *mConf; }; #define sConfig MaNGOS::Singleton::Instance() diff --git a/src/shared/Config/ConfigEnv.h b/src/shared/Config/ConfigEnv.h index e9801b641..76f93347d 100644 --- a/src/shared/Config/ConfigEnv.h +++ b/src/shared/Config/ConfigEnv.h @@ -21,7 +21,6 @@ #define CONFIGENVIRONMENT_H #include "Common.h" -#include "dotconfpp/dotconfpp.h" #include "Config.h" #endif diff --git a/src/shared/SystemConfig.h.in b/src/shared/SystemConfig.h.in index 57f7e0b89..85edbc023 100644 --- a/src/shared/SystemConfig.h.in +++ b/src/shared/SystemConfig.h.in @@ -36,10 +36,10 @@ // Format is YYYYMMDDRR where RR is the change in the conf file // for that day. #ifndef _MANGOSDCONFVERSION -# define _MANGOSDCONFVERSION 2010051901 +# define _MANGOSDCONFVERSION 2010062001 #endif #ifndef _REALMDCONFVERSION -# define _REALMDCONFVERSION 2007062001 +# define _REALMDCONFVERSION 2010062001 #endif #if MANGOS_ENDIAN == MANGOS_BIGENDIAN diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 2e194d857..fb8211e82 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10080" + #define REVISION_NR "10081" #endif // __REVISION_NR_H__