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 "stg/dotconfpp.h"
31 #include "stg/module_settings.h"
32 #include "stg/common.h"
34 #include "settings_impl.h"
36 int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
43 pv.param = node->getName();
45 if (node->getValue(1))
47 strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
48 printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
52 const char * value = node->getValue(0);
56 strError = "Module name expected.";
57 printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
61 const DOTCONFDocumentNode * childNode = node->getChildNode();
64 pv.param = childNode->getName();
66 while ((value = childNode->getValue(i)) != NULL)
68 pv.value.push_back(value);
71 params->push_back(pv);
73 childNode = childNode->getNextNode();
78 //-----------------------------------------------------------------------------
79 int SETTINGS_IMPL::ReadSettings()
81 const char * requiredOptions[] = {
87 int sourceStoreModulesCount = 0;
88 int destStoreModulesCount = 0;
90 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
91 conf.setRequiredOptionNames(requiredOptions);
93 if(conf.setContent(confFile.c_str()) != 0)
95 strError = "Cannot read file " + confFile + ".";
96 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
100 const DOTCONFDocumentNode * node = conf.getFirstNode();
104 if (strcasecmp(node->getName(), "ModulesPath") == 0)
106 modulesPath = node->getValue(0);
109 if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
111 if (node->getValue(1))
113 strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
114 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
118 if (sourceStoreModulesCount)
120 strError = "Should be only one source StoreModule.";
121 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
124 ++sourceStoreModulesCount;
126 sourceStoreModuleSettings.moduleName = node->getValue(0);
127 ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
130 if (strcasecmp(node->getName(), "DestStoreModule") == 0)
132 if (node->getValue(1))
134 strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
135 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
139 if (destStoreModulesCount)
141 strError = "Should be only one dest StoreModule.";
142 printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
145 ++destStoreModulesCount;
147 destStoreModuleSettings.moduleName = node->getValue(0);
148 ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
151 node = node->getNextNode();
156 //-----------------------------------------------------------------------------