From 97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 9 Aug 2006 06:08:59 +0000 Subject: The start of the configmanager to libbu++, they are good, but make congo not build now, for a while, and don't actually work yet, so just don't use this revision of libbu++. --- src/configmanager.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/configmanager.cpp (limited to 'src/configmanager.cpp') diff --git a/src/configmanager.cpp b/src/configmanager.cpp new file mode 100644 index 0000000..c3ad695 --- /dev/null +++ b/src/configmanager.cpp @@ -0,0 +1,121 @@ +#include +#include +#include "xmlnode.h" +#include "xmlfilereader.h" +#include "configmanager.h" +#include "multilog.h" +#include "multilogtext.h" +#include "config.h" + +#ifndef DEF_DEF_LANG +# error You must define a default default language in DEF_DEF_LANG +#endif + +ConfigManager::ConfigManager() : + sDefLang( DEF_DEF_LANG ) +{ +} + +ConfigManager::~ConfigManager() +{ +} + +void ConfigManager::loadConfig( const char *lpProfile ) +{ + // Try a few locations... + char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL}; + + for( int j = 0; locs[j] != NULL; j++ ) + { + if( parseConfig( locs[j], lpProfile ) ) + { + break; + } + } +} + +bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) +{ + XmlNode *pRoot, *pCur; + XmlFileReader doc( lpFileName ); + + pRoot = doc.getRoot(); + if( pRoot == NULL ) + { + return false; + } + + if( strcmp("config", pRoot->getName() ) ) + { + return false; + } + + for( int j = 0;; j++ ) + { + pCur = pRoot->getChild( "profile", j ); + if( pCur == NULL ) + return false; + + if( !strcmp( pCur->getProperty("id"), lpProfile ) ) + { + return processProfile( pCur ); + } + } + + return false; +} + +bool ConfigManager::processProfile( XmlNode *pBase ) +{ + XmlNode *pCur; + + for( int j = 0; (pCur = pBase->getChild("listen", j)); j++ ) + { + } + + for( int j = 0; (pCur = pBase->getChild("log", j)); j++ ) + { + if( !strcmp( pCur->getProperty("type"), "text" ) ) + { + int nLevel = atoi( pCur->getProperty("level") ); + int nArchive = atoi( pCur->getProperty("archive") ); + + printf("Adding log file: %s\n", pCur->getProperty("file") ); + + MultiLog::getInstance().addChannel( + new MultiLogText( + pCur->getProperty("file"), + pCur->getProperty("format") + ) + ); + } + } + + XmlNode *pDefs; + if( pDefs = pBase->getChild("defaults") ) + { + if( pCur = pDefs->getChild("language") ) + { + sDefLang = pCur->getContent(); + } + } + + if( pCur = pBase->getChild("backend") ) + { + sBackend = pCur->getProperty("plugin"); + sBackend = sBackend; + pBackend = pBase->getCopy(); + } + + return true; +} + +std::string &ConfigManager::getDefLanguage() +{ + return sDefLang; +} + +std::string &ConfigManager::getBackend() +{ + return sBackend; +} -- cgit v1.2.3