]> git.stg.codes - stg.git/blob - projects/sgconv/settings_impl.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / projects / sgconv / settings_impl.cpp
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 /*
26 $Revision: 1.6 $
27 $Date: 2009/06/22 16:26:54 $
28 */
29
30 #include "stg/dotconfpp.h"
31 #include "stg/module_settings.h"
32 #include "stg/common.h"
33
34 #include "settings_impl.h"
35
36 int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
37 {
38 if (!node)
39     return 0;
40
41 PARAM_VALUE pv;
42
43 pv.param = node->getName();
44
45 if (node->getValue(1))
46     {
47     strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
48     printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
49     return -1;
50     }
51
52 const char * value = node->getValue(0);
53
54 if (!value)
55     {
56     strError = "Module name expected.";
57     printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
58     return -1;
59     }
60
61 const DOTCONFDocumentNode * childNode = node->getChildNode();
62 while (childNode)
63     {
64     pv.param = childNode->getName();
65     int i = 0;
66     while ((value = childNode->getValue(i)) != NULL)
67         {
68         pv.value.push_back(value);
69         ++i;
70         }
71     params->push_back(pv);
72     pv.value.clear();
73     childNode = childNode->getNextNode();
74     }
75
76 return 0;
77 }
78 //-----------------------------------------------------------------------------
79 int SETTINGS_IMPL::ReadSettings()
80 {
81 const char * requiredOptions[] = {
82     "ModulesPath",
83     "SourceStoreModule",
84     "DestStoreModule",
85     NULL
86     };
87 int sourceStoreModulesCount = 0;
88 int destStoreModulesCount = 0;
89
90 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
91 conf.setRequiredOptionNames(requiredOptions);
92
93 if(conf.setContent(confFile.c_str()) != 0)
94     {
95     strError = "Cannot read file " + confFile + ".";
96     printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
97     return -1;
98     }
99
100 const DOTCONFDocumentNode * node = conf.getFirstNode();
101
102 while (node)
103     {
104     if (strcasecmp(node->getName(), "ModulesPath") == 0)
105         {
106         modulesPath = node->getValue(0);
107         }
108
109     if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
110         {
111         if (node->getValue(1))
112             {
113             strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
114             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
115             return -1;
116             }
117
118         if (sourceStoreModulesCount)
119             {
120             strError = "Should be only one source StoreModule.";
121             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
122             return -1;
123             }
124         ++sourceStoreModulesCount;
125
126         sourceStoreModuleSettings.moduleName = node->getValue(0);
127         ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
128         }
129
130     if (strcasecmp(node->getName(), "DestStoreModule") == 0)
131         {
132         if (node->getValue(1))
133             {
134             strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
135             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
136             return -1;
137             }
138
139         if (destStoreModulesCount)
140             {
141             strError = "Should be only one dest StoreModule.";
142             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
143             return -1;
144             }
145         ++destStoreModulesCount;
146
147         destStoreModuleSettings.moduleName = node->getValue(0);
148         ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
149         }
150
151     node = node->getNextNode();
152     }
153
154 return 0;
155 }
156 //-----------------------------------------------------------------------------