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
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
25 #include "stg/dotconfpp.h"
26 #include "stg/module_settings.h"
27 #include "stg/common.h"
34 confFile("sgauthstress.conf")
37 //-----------------------------------------------------------------------------
38 int ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
40 assert(node && "DOTCONFDocumentNode must not be NULL!");
42 const DOTCONFDocumentNode * childNode = node->getChildNode();
46 pv.param = childNode->getName();
49 while ((value = childNode->getValue(i++)) != NULL)
50 pv.value.push_back(value);
51 params->push_back(pv);
52 childNode = childNode->getNextNode();
57 //-----------------------------------------------------------------------------
58 int SETTINGS::ReadSettings()
60 const char * requiredOptions[] = {
70 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
71 conf.setRequiredOptionNames(requiredOptions);
73 if(conf.setContent(confFile.c_str()) != 0)
75 strError = "Cannot read file " + confFile + ".";
76 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
80 const DOTCONFDocumentNode * node = conf.getFirstNode();
82 int storeModulesCount = 0;
85 if (strcasecmp(node->getName(), "ModulesPath") == 0)
86 modulesPath = node->getValue(0);
87 else if (strcasecmp(node->getName(), "Login") == 0)
88 login = node->getValue(0);
89 else if (strcasecmp(node->getName(), "Password") == 0)
90 password = node->getValue(0);
91 else if (strcasecmp(node->getName(), "ServerName") == 0)
92 serverName = node->getValue(0);
93 else if (strcasecmp(node->getName(), "ServerPort") == 0)
95 if (ParseIntInRange(node->getValue(0), 1, 65535, &port))
97 strError = "Parameter 'ServerPort' is not valid.";
98 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
102 else if (strcasecmp(node->getName(), "LocalPort") == 0)
104 if (ParseIntInRange(node->getValue(0), 0, 65535, &localPort))
106 strError = "Parameter 'LocalPort' is not valid.";
107 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
111 else if (strcasecmp(node->getName(), "StoreModule") == 0)
113 if (node->getValue(1))
115 strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
116 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
120 if (storeModulesCount)
122 strError = "Should be only one source StoreModule.";
123 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
128 storeModuleSettings.moduleName = node->getValue(0);
129 if (ParseModuleSettings(node, &storeModuleSettings.moduleParams))
131 strError = "Failed to parse store module settings";
132 printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str());
137 node = node->getNextNode();