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/10/20 11:53:40 $
36 #include "configproto.h"
38 //-----------------------------------------------------------------------------
39 void ParseXMLStart(void *data, const char *el, const char **attr)
41 CONFIGPROTO * cp = (CONFIGPROTO*)(data);
45 cp->currParser->SetAnswerList(&cp->answerList);
46 cp->currParser->SetCurrAdmin(cp->currAdmin);
47 cp->currParser->ParseStart(data, el, attr);
51 for (unsigned int i = 0; i < cp->dataParser.size(); i++)
53 cp->dataParser[i]->SetAnswerList(&cp->answerList);
54 cp->currAdmin->SetAdminIP(cp->GetAdminIP());
55 cp->dataParser[i]->SetCurrAdmin(cp->currAdmin);
56 cp->dataParser[i]->Reset();
57 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
59 cp->currParser = cp->dataParser[i];
64 cp->dataParser[i]->Reset();
69 //-----------------------------------------------------------------------------
70 void ParseXMLEnd(void *data, const char *el)
72 CONFIGPROTO * cp = (CONFIGPROTO*)(data);
75 if (cp->currParser->ParseEnd(data, el) == 0)
77 cp->currParser = NULL;
82 for (unsigned int i = 0; i < cp->dataParser.size(); i++)
84 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
91 //-----------------------------------------------------------------------------
92 CONFIGPROTO::CONFIGPROTO()
98 WriteServLog(GetStgLogger()),
108 dataParser.push_back(&parserGetServInfo);
110 dataParser.push_back(&parserGetUsers);
111 dataParser.push_back(&parserGetUser);
112 dataParser.push_back(&parserChgUser);
113 dataParser.push_back(&parserAddUser);
114 dataParser.push_back(&parserDelUser);
115 dataParser.push_back(&parserCheckUser);
116 dataParser.push_back(&parserSendMessage);
118 dataParser.push_back(&parserGetTariffs);
119 dataParser.push_back(&parserAddTariff);
120 dataParser.push_back(&parserDelTariff);
121 dataParser.push_back(&parserChgTariff);
123 dataParser.push_back(&parserGetAdmins);
124 dataParser.push_back(&parserChgAdmin);
125 dataParser.push_back(&parserDelAdmin);
126 dataParser.push_back(&parserAddAdmin);
128 xmlParser = XML_ParserCreate(NULL);
132 WriteServLog("Couldn't allocate memory for parser.");
136 //XML_SetElementHandler(parser, ParseXMLStart, ParseXMLEnd);
138 //-----------------------------------------------------------------------------
139 CONFIGPROTO::~CONFIGPROTO()
141 XML_ParserFree(xmlParser);
143 //-----------------------------------------------------------------------------
144 int CONFIGPROTO::ParseCommand()
146 list<string>::iterator n;
151 if (requestList.empty())
154 n = requestList.begin();
156 strncpy(str, (*n).c_str(), 8);
159 XML_ParserReset(xmlParser, NULL);
160 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
161 XML_SetUserData(xmlParser, this);
165 strncpy(str, (*n).c_str(), 8);
170 if (n == requestList.end())
174 if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR)
176 WriteServLog("Invalid configuration request");
177 printfd(__FILE__, "Parse error at line %d:\n%s\n",
178 XML_GetCurrentLineNumber(xmlParser),
179 XML_ErrorString(XML_GetErrorCode(xmlParser)));
182 printfd(__FILE__, "Parser reset\n");
198 //-----------------------------------------------------------------------------
199 void CONFIGPROTO::SetPort(uint16_t p)
203 //-----------------------------------------------------------------------------
204 /*void CONFIGPROTO::SetHostAllow(HOSTALLOW *)
208 //-----------------------------------------------------------------------------
209 void CONFIGPROTO::SetAdmins(ADMINS * a)
212 for (unsigned int i = 0; i < dataParser.size(); i++)
214 dataParser[i]->SetAdmins(admins);
218 //-----------------------------------------------------------------------------
219 void CONFIGPROTO::SetUsers(USERS * u)
222 for (unsigned int i = 0; i < dataParser.size(); i++)
224 dataParser[i]->SetUsers(users);
228 //-----------------------------------------------------------------------------
229 void CONFIGPROTO::SetTariffs(TARIFFS * t)
232 for (unsigned int i = 0; i < dataParser.size(); i++)
234 dataParser[i]->SetTariffs(tariffs);
237 //-----------------------------------------------------------------------------
238 void CONFIGPROTO::SetStore(STORE * s)
241 for (unsigned int i = 0; i < dataParser.size(); i++)
243 dataParser[i]->SetStore(s);
246 //-----------------------------------------------------------------------------
247 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
250 for (unsigned int i = 0; i < dataParser.size(); i++)
252 dataParser[i]->SetStgSettings(settings);
255 //-----------------------------------------------------------------------------
256 /*void CONFIGPROTO::Start()
259 threadExited = false;
262 xmlParser = XML_ParserCreate(NULL);
266 WriteServLog("Couldn't allocate memory for parser.");
269 pthread_create(&thrReciveSendConf, NULL, ReciveSendConf, this);
272 //-----------------------------------------------------------------------------
273 /*int CONFIGPROTO::Stop()
279 //-----------------------------------------------------------------------------
280 /*void CONFIGPROTO::Restart()
285 //-----------------------------------------------------------------------------
286 /*CONF_STATUS CONFIGPROTO::Status()
290 //-----------------------------------------------------------------------------
292 const string & CONFIGPROTO::GetStrError()
296 //-----------------------------------------------------------------------------
297 uint32_t CONFIGPROTO::GetAdminIP()
301 //-----------------------------------------------------------------------------