2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
27 $Date: 2009/06/22 16:26:54 $
41 //-----------------------------------------------------------------------------
42 SETTINGS::SETTINGS(const char * cf)
44 confFile = string(cf);
46 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 int SETTINGS::ParseYesNo(const string & value, bool * val)
55 if (0 == strcasecmp(value.c_str(), "yes"))
60 if (0 == strcasecmp(value.c_str(), "no"))
66 strError = "Incorrect value \'" + value + "\'.";
69 //-----------------------------------------------------------------------------
70 int SETTINGS::ParseInt(const string & value, int * val)
73 *val = strtol(value.c_str(), &res, 10);
76 strError = "Cannot convert \'" + value + "\' to integer.";
81 //-----------------------------------------------------------------------------
82 int SETTINGS::ParseIntInRange(const string & value, int min, int max, int * val)
84 if (ParseInt(value, val) != 0)
87 if (*val < min || *val > max)
89 strError = "Value \'" + value + "\' out of range.";
96 //-----------------------------------------------------------------------------
97 int SETTINGS::ParseModuleSettings(const DOTCONFDocumentNode * node, vector<PARAM_VALUE> * params)
101 const DOTCONFDocumentNode * childNode;
105 pv.param = node->getName();
107 if (node->getValue(1))
109 strError = "Unexpected value \'" + string(node->getValue(1)) + "\'.";
113 value = node->getValue(0);
117 strError = "Module name expected.";
121 childNode = node->getChildNode();
124 pv.param = childNode->getName();
126 while ((value = childNode->getValue(i)) != NULL)
128 //printfd(__FILE__, "--> param=\'%s\' value=\'%s\'\n", childNode->getName(), value);
129 pv.value.push_back(value);
132 params->push_back(pv);
134 childNode = childNode->getNextNode();
137 /*for (unsigned i = 0; i < params->size(); i++)
139 printfd(__FILE__, "param \'%s\'\n", (*params)[i].param.c_str());
140 for (unsigned j = 0; j < (*params)[i].value.size(); j++)
142 printfd(__FILE__, "value \'%s\'\n", (*params)[i].value[j].c_str());
148 //-----------------------------------------------------------------------------
149 string SETTINGS::GetStrError() const
153 //-----------------------------------------------------------------------------
154 int SETTINGS::ReadSettings()
156 const char * requiredOptions[] = {
162 int sourceStoreModulesCount = 0;
163 int destStoreModulesCount = 0;
165 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
166 conf.setRequiredOptionNames(requiredOptions);
168 //printfd(__FILE__, "Conffile: %s\n", confFile.c_str());
170 if(conf.setContent(confFile.c_str()) != 0)
172 strError = "Cannot read file " + confFile + ".";
176 const DOTCONFDocumentNode * node = conf.getFirstNode();
180 if (strcasecmp(node->getName(), "ModulesPath") == 0)
182 modulesPath = node->getValue(0);
183 //printfd(__FILE__, "ModulesPath: %s\n", logFile.c_str());
186 if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
188 // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ StoreModule
189 //printfd(__FILE__, "StoreModule\n");
191 if (node->getValue(1))
193 // StoreModule ÄÏÌÖÅÎ ÉÍÅÔØ 1 ÁÔÒÉÂÕÔ
194 strError = "Unexpected \'" + string(node->getValue(1)) + "\'.";
198 if (sourceStoreModulesCount)
200 // äÏÌÖÅÎ ÂÙÔØ ÔÏÌØËÏ ÏÄÉÎ ÍÏÄÕÌØ StoreModule!
201 strError = "Should be only one source StoreModule.";
204 sourceStoreModulesCount++;
206 //storeModuleSettings.clear(); //TODO To make constructor
207 //printfd(__FILE__, "StoreModule %s\n", node->getValue());
208 sourceStoreModuleSettings.moduleName = node->getValue(0);
209 ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
212 if (strcasecmp(node->getName(), "DestStoreModule") == 0)
214 // íÙ ×ÎÕÔÒÉ ÓÅËÃÉÉ StoreModule
215 //printfd(__FILE__, "StoreModule\n");
217 if (node->getValue(1))
219 // StoreModule ÄÏÌÖÅÎ ÉÍÅÔØ 1 ÁÔÒÉÂÕÔ
220 strError = "Unexpected \'" + string(node->getValue(1)) + "\'.";
224 if (destStoreModulesCount)
226 // äÏÌÖÅÎ ÂÙÔØ ÔÏÌØËÏ ÏÄÉÎ ÍÏÄÕÌØ StoreModule!
227 strError = "Should be only one dest StoreModule.";
230 destStoreModulesCount++;
232 //storeModuleSettings.clear(); //TODO To make constructor
233 //printfd(__FILE__, "StoreModule %s\n", node->getValue());
234 destStoreModuleSettings.moduleName = node->getValue(0);
235 ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
238 node = node->getNextNode();
241 //sort(modulesSettings.begin(), modulesSettings.end());
242 //modulesSettings.erase(unique(modulesSettings.begin(), modulesSettings.end()), modulesSettings.end());
246 //-----------------------------------------------------------------------------
247 int SETTINGS::Reload ()
249 return ReadSettings();
251 //-----------------------------------------------------------------------------
252 const MODULE_SETTINGS & SETTINGS::GetSourceStoreModuleSettings() const
254 return sourceStoreModuleSettings;
256 //-----------------------------------------------------------------------------
257 const MODULE_SETTINGS & SETTINGS::GetDestStoreModuleSettings() const
259 return destStoreModuleSettings;
261 //-----------------------------------------------------------------------------
262 const string & SETTINGS::GetModulesPath() const
266 //-----------------------------------------------------------------------------