diff options
Diffstat (limited to 'src/configmanager.cpp')
-rw-r--r-- | src/configmanager.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
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 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "xmlnode.h" | ||
4 | #include "xmlfilereader.h" | ||
5 | #include "configmanager.h" | ||
6 | #include "multilog.h" | ||
7 | #include "multilogtext.h" | ||
8 | #include "config.h" | ||
9 | |||
10 | #ifndef DEF_DEF_LANG | ||
11 | # error You must define a default default language in DEF_DEF_LANG | ||
12 | #endif | ||
13 | |||
14 | ConfigManager::ConfigManager() : | ||
15 | sDefLang( DEF_DEF_LANG ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | ConfigManager::~ConfigManager() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void ConfigManager::loadConfig( const char *lpProfile ) | ||
24 | { | ||
25 | // Try a few locations... | ||
26 | char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL}; | ||
27 | |||
28 | for( int j = 0; locs[j] != NULL; j++ ) | ||
29 | { | ||
30 | if( parseConfig( locs[j], lpProfile ) ) | ||
31 | { | ||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) | ||
38 | { | ||
39 | XmlNode *pRoot, *pCur; | ||
40 | XmlFileReader doc( lpFileName ); | ||
41 | |||
42 | pRoot = doc.getRoot(); | ||
43 | if( pRoot == NULL ) | ||
44 | { | ||
45 | return false; | ||
46 | } | ||
47 | |||
48 | if( strcmp("config", pRoot->getName() ) ) | ||
49 | { | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | for( int j = 0;; j++ ) | ||
54 | { | ||
55 | pCur = pRoot->getChild( "profile", j ); | ||
56 | if( pCur == NULL ) | ||
57 | return false; | ||
58 | |||
59 | if( !strcmp( pCur->getProperty("id"), lpProfile ) ) | ||
60 | { | ||
61 | return processProfile( pCur ); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | return false; | ||
66 | } | ||
67 | |||
68 | bool ConfigManager::processProfile( XmlNode *pBase ) | ||
69 | { | ||
70 | XmlNode *pCur; | ||
71 | |||
72 | for( int j = 0; (pCur = pBase->getChild("listen", j)); j++ ) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | for( int j = 0; (pCur = pBase->getChild("log", j)); j++ ) | ||
77 | { | ||
78 | if( !strcmp( pCur->getProperty("type"), "text" ) ) | ||
79 | { | ||
80 | int nLevel = atoi( pCur->getProperty("level") ); | ||
81 | int nArchive = atoi( pCur->getProperty("archive") ); | ||
82 | |||
83 | printf("Adding log file: %s\n", pCur->getProperty("file") ); | ||
84 | |||
85 | MultiLog::getInstance().addChannel( | ||
86 | new MultiLogText( | ||
87 | pCur->getProperty("file"), | ||
88 | pCur->getProperty("format") | ||
89 | ) | ||
90 | ); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | XmlNode *pDefs; | ||
95 | if( pDefs = pBase->getChild("defaults") ) | ||
96 | { | ||
97 | if( pCur = pDefs->getChild("language") ) | ||
98 | { | ||
99 | sDefLang = pCur->getContent(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if( pCur = pBase->getChild("backend") ) | ||
104 | { | ||
105 | sBackend = pCur->getProperty("plugin"); | ||
106 | sBackend = sBackend; | ||
107 | pBackend = pBase->getCopy(); | ||
108 | } | ||
109 | |||
110 | return true; | ||
111 | } | ||
112 | |||
113 | std::string &ConfigManager::getDefLanguage() | ||
114 | { | ||
115 | return sDefLang; | ||
116 | } | ||
117 | |||
118 | std::string &ConfigManager::getBackend() | ||
119 | { | ||
120 | return sBackend; | ||
121 | } | ||