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 (size_t i = 0; i < cp->dataParser.size(); i++)
51 cp->dataParser[i]->SetAnswerList(&cp->answerList);
52 cp->dataParser[i]->SetCurrAdmin(*cp->currAdmin);
53 cp->dataParser[i]->Reset();
54 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
56 cp->currParser = cp->dataParser[i];
61 cp->dataParser[i]->Reset();
66 //-----------------------------------------------------------------------------
67 void ParseXMLEnd(void *data, const char *el)
69 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
72 if (cp->currParser->ParseEnd(data, el) == 0)
74 cp->currParser = NULL;
79 for (size_t i = 0; i < cp->dataParser.size(); i++)
81 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
88 //-----------------------------------------------------------------------------
89 CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
125 dataParser.push_back(&parserGetServInfo);
127 dataParser.push_back(&parserGetUsers);
128 dataParser.push_back(&parserGetUser);
129 dataParser.push_back(&parserChgUser);
130 dataParser.push_back(&parserAddUser);
131 dataParser.push_back(&parserDelUser);
132 dataParser.push_back(&parserCheckUser);
133 dataParser.push_back(&parserSendMessage);
134 dataParser.push_back(&parserAuthBy);
136 dataParser.push_back(&parserGetTariffs);
137 dataParser.push_back(&parserAddTariff);
138 dataParser.push_back(&parserDelTariff);
139 dataParser.push_back(&parserChgTariff);
141 dataParser.push_back(&parserGetAdmins);
142 dataParser.push_back(&parserChgAdmin);
143 dataParser.push_back(&parserDelAdmin);
144 dataParser.push_back(&parserAddAdmin);
146 xmlParser = XML_ParserCreate(NULL);
150 logger("Couldn't allocate memory for parser.");
155 //-----------------------------------------------------------------------------
156 CONFIGPROTO::~CONFIGPROTO()
158 XML_ParserFree(xmlParser);
160 //-----------------------------------------------------------------------------
161 int CONFIGPROTO::ParseCommand()
163 std::list<std::string>::iterator n;
167 if (requestList.empty())
170 n = requestList.begin();
172 strncpy(str, (*n).c_str(), 8);
175 XML_ParserReset(xmlParser, NULL);
176 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
177 XML_SetUserData(xmlParser, this);
181 strncpy(str, (*n).c_str(), 8);
183 size_t len = strlen(str);
186 if (n == requestList.end())
190 if (XML_Parse(xmlParser, (*n).c_str(), static_cast<int>(len), done) == XML_STATUS_ERROR)
192 logger("Invalid configuration request");
193 printfd(__FILE__, "Parse error at line %d:\n%s\n",
194 XML_GetCurrentLineNumber(xmlParser),
195 XML_ErrorString(XML_GetErrorCode(xmlParser)));
198 printfd(__FILE__, "Parser reset\n");
214 //-----------------------------------------------------------------------------
215 void CONFIGPROTO::SetPort(uint16_t p)
219 //-----------------------------------------------------------------------------
220 void CONFIGPROTO::SetAdmins(ADMINS * a)
223 for (size_t i = 0; i < dataParser.size(); i++)
225 dataParser[i]->SetAdmins(a);
229 //-----------------------------------------------------------------------------
230 void CONFIGPROTO::SetUsers(USERS * u)
232 for (size_t i = 0; i < dataParser.size(); i++)
234 dataParser[i]->SetUsers(u);
238 //-----------------------------------------------------------------------------
239 void CONFIGPROTO::SetTariffs(TARIFFS * t)
241 for (size_t i = 0; i < dataParser.size(); i++)
243 dataParser[i]->SetTariffs(t);
246 //-----------------------------------------------------------------------------
247 void CONFIGPROTO::SetStore(STORE * s)
249 for (size_t i = 0; i < dataParser.size(); i++)
251 dataParser[i]->SetStore(s);
254 //-----------------------------------------------------------------------------
255 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
257 for (size_t i = 0; i < dataParser.size(); i++)
259 dataParser[i]->SetStgSettings(s);
262 //-----------------------------------------------------------------------------