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: 2010/10/04 20:24:14 $
34 #include "configproto.h"
36 //-----------------------------------------------------------------------------
37 void ParseXMLStart(void *data, const char *el, const char **attr)
39 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
43 cp->currParser->SetAnswerList(&cp->answerList);
44 cp->currParser->SetCurrAdmin(cp->currAdmin);
45 cp->currParser->ParseStart(data, el, attr);
49 for (unsigned int i = 0; i < cp->dataParser.size(); i++)
51 cp->dataParser[i]->SetAnswerList(&cp->answerList);
52 //cp->currAdmin->SetAdminIP(cp->GetAdminIP());
53 cp->dataParser[i]->SetCurrAdmin(cp->currAdmin);
54 cp->dataParser[i]->Reset();
55 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
57 cp->currParser = cp->dataParser[i];
62 cp->dataParser[i]->Reset();
67 //-----------------------------------------------------------------------------
68 void ParseXMLEnd(void *data, const char *el)
70 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
73 if (cp->currParser->ParseEnd(data, el) == 0)
75 cp->currParser = NULL;
80 for (unsigned int i = 0; i < cp->dataParser.size(); i++)
82 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
89 //-----------------------------------------------------------------------------
90 CONFIGPROTO::CONFIGPROTO()
96 WriteServLog(GetStgLogger()),
106 dataParser.push_back(&parserGetServInfo);
108 dataParser.push_back(&parserGetUsers);
109 dataParser.push_back(&parserGetUser);
110 dataParser.push_back(&parserChgUser);
111 dataParser.push_back(&parserAddUser);
112 dataParser.push_back(&parserDelUser);
113 dataParser.push_back(&parserCheckUser);
114 dataParser.push_back(&parserSendMessage);
116 dataParser.push_back(&parserGetTariffs);
117 dataParser.push_back(&parserAddTariff);
118 dataParser.push_back(&parserDelTariff);
119 dataParser.push_back(&parserChgTariff);
121 dataParser.push_back(&parserGetAdmins);
122 dataParser.push_back(&parserChgAdmin);
123 dataParser.push_back(&parserDelAdmin);
124 dataParser.push_back(&parserAddAdmin);
126 xmlParser = XML_ParserCreate(NULL);
130 WriteServLog("Couldn't allocate memory for parser.");
134 //XML_SetElementHandler(parser, ParseXMLStart, ParseXMLEnd);
136 //-----------------------------------------------------------------------------
137 CONFIGPROTO::~CONFIGPROTO()
139 XML_ParserFree(xmlParser);
141 //-----------------------------------------------------------------------------
142 int CONFIGPROTO::ParseCommand()
144 list<string>::iterator n;
149 if (requestList.empty())
152 n = requestList.begin();
154 strncpy(str, (*n).c_str(), 8);
157 XML_ParserReset(xmlParser, NULL);
158 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
159 XML_SetUserData(xmlParser, this);
163 strncpy(str, (*n).c_str(), 8);
168 if (n == requestList.end())
172 if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR)
174 WriteServLog("Invalid configuration request");
175 printfd(__FILE__, "Parse error at line %d:\n%s\n",
176 XML_GetCurrentLineNumber(xmlParser),
177 XML_ErrorString(XML_GetErrorCode(xmlParser)));
180 printfd(__FILE__, "Parser reset\n");
196 //-----------------------------------------------------------------------------
197 void CONFIGPROTO::SetPort(uint16_t p)
201 //-----------------------------------------------------------------------------
202 /*void CONFIGPROTO::SetHostAllow(HOSTALLOW *)
206 //-----------------------------------------------------------------------------
207 void CONFIGPROTO::SetAdmins(ADMINS * a)
210 for (unsigned int i = 0; i < dataParser.size(); i++)
212 dataParser[i]->SetAdmins(a);
216 //-----------------------------------------------------------------------------
217 void CONFIGPROTO::SetUsers(USERS * u)
220 for (unsigned int i = 0; i < dataParser.size(); i++)
222 dataParser[i]->SetUsers(u);
226 //-----------------------------------------------------------------------------
227 void CONFIGPROTO::SetTariffs(TARIFFS * t)
230 for (unsigned int i = 0; i < dataParser.size(); i++)
232 dataParser[i]->SetTariffs(t);
235 //-----------------------------------------------------------------------------
236 void CONFIGPROTO::SetStore(BASE_STORE * s)
239 for (unsigned int i = 0; i < dataParser.size(); i++)
241 dataParser[i]->SetStore(s);
244 //-----------------------------------------------------------------------------
245 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
248 for (unsigned int i = 0; i < dataParser.size(); i++)
250 dataParser[i]->SetStgSettings(s);
253 //-----------------------------------------------------------------------------
254 /*void CONFIGPROTO::Start()
257 threadExited = false;
260 xmlParser = XML_ParserCreate(NULL);
264 WriteServLog("Couldn't allocate memory for parser.");
267 pthread_create(&thrReciveSendConf, NULL, ReciveSendConf, this);
270 //-----------------------------------------------------------------------------
271 /*int CONFIGPROTO::Stop()
277 //-----------------------------------------------------------------------------
278 /*void CONFIGPROTO::Restart()
283 //-----------------------------------------------------------------------------
284 /*CONF_STATUS CONFIGPROTO::Status()
288 //-----------------------------------------------------------------------------
290 const string & CONFIGPROTO::GetStrError()
294 //-----------------------------------------------------------------------------
295 uint32_t CONFIGPROTO::GetAdminIP()
299 //-----------------------------------------------------------------------------