1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include <stdlib.h>
#include <string.h>
#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;
}
|