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 $
30 #include "dotconfpp.h"
31 #include "module_settings.h"
32 #include "settings_impl.h"
35 int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
42 pv.param = node->getName();
44 if (node->getValue(1))
46 strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
47 printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
51 const char * value = node->getValue(0);
55 strError = "Module name expected.";
56 printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
60 const DOTCONFDocumentNode * childNode = node->getChildNode();
63 pv.param = childNode->getName();
65 while ((value = childNode->getValue(i)) != NULL)
67 pv.value.push_back(value);
70 params->push_back(pv);
72 childNode = childNode->getNextNode();
77 //-----------------------------------------------------------------------------
78 int SETTINGS_IMPL::ReadSettings()
80 const char * requiredOptions[] = {
86 int sourceStoreModulesCount = 0;
87 int destStoreModulesCount = 0;
89 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
90 conf.setRequiredOptionNames(requiredOptions);
92 if(conf.setContent(confFile.c_str()) != 0)
94 strError = "Cannot read file " + confFile + ".";
95 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
99 const DOTCONFDocumentNode * node = conf.getFirstNode();
103 if (strcasecmp(node->getName(), "ModulesPath") == 0)
105 modulesPath = node->getValue(0);
108 if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
110 if (node->getValue(1))
112 strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
113 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
117 if (sourceStoreModulesCount)
119 strError = "Should be only one source StoreModule.";
120 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
123 ++sourceStoreModulesCount;
125 sourceStoreModuleSettings.moduleName = node->getValue(0);
126 ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
129 if (strcasecmp(node->getName(), "DestStoreModule") == 0)
131 if (node->getValue(1))
133 strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
134 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
138 if (destStoreModulesCount)
140 strError = "Should be only one dest StoreModule.";
141 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
144 ++destStoreModulesCount;
146 destStoreModuleSettings.moduleName = node->getValue(0);
147 ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
150 node = node->getNextNode();
155 //-----------------------------------------------------------------------------