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 $
33 #include "parser_auth_by.h"
34 #include "parser_user_info.h"
36 #include "stg/users.h"
37 #include "stg/admins.h"
38 #include "stg/tariffs.h"
39 #include "stg/logger.h"
43 #include "configproto.h"
45 //-----------------------------------------------------------------------------
46 void ParseXMLStart(void *data, const char *el, const char **attr)
48 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
52 cp->currParser->SetAnswerList(&cp->answerList);
53 cp->currParser->SetCurrAdmin(*cp->currAdmin);
54 cp->currParser->ParseStart(data, el, attr);
58 for (size_t i = 0; i < cp->dataParser.size(); i++)
60 cp->dataParser[i]->SetAnswerList(&cp->answerList);
61 cp->dataParser[i]->SetCurrAdmin(*cp->currAdmin);
62 cp->dataParser[i]->Reset();
63 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
65 cp->currParser = cp->dataParser[i];
70 cp->dataParser[i]->Reset();
75 //-----------------------------------------------------------------------------
76 void ParseXMLEnd(void *data, const char *el)
78 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
81 if (cp->currParser->ParseEnd(data, el) == 0)
83 cp->currParser = NULL;
88 for (size_t i = 0; i < cp->dataParser.size(); i++)
90 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
97 //-----------------------------------------------------------------------------
98 CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
134 dataParser.push_back(new PARSER_GET_SERVER_INFO);
136 dataParser.push_back(new PARSER_GET_USERS);
137 dataParser.push_back(new PARSER_GET_USER);
138 dataParser.push_back(new PARSER_CHG_USER);
139 dataParser.push_back(new PARSER_ADD_USER);
140 dataParser.push_back(new PARSER_DEL_USER);
141 dataParser.push_back(new PARSER_CHECK_USER);
142 dataParser.push_back(new PARSER_SEND_MESSAGE);
143 dataParser.push_back(new PARSER_AUTH_BY);
144 dataParser.push_back(new PARSER_USER_INFO);
146 dataParser.push_back(new PARSER_GET_TARIFFS);
147 dataParser.push_back(new PARSER_ADD_TARIFF);
148 dataParser.push_back(new PARSER_DEL_TARIFF);
149 dataParser.push_back(new PARSER_CHG_TARIFF);
151 dataParser.push_back(new PARSER_GET_ADMINS);
152 dataParser.push_back(new PARSER_CHG_ADMIN);
153 dataParser.push_back(new PARSER_DEL_ADMIN);
154 dataParser.push_back(new PARSER_ADD_ADMIN);
156 xmlParser = XML_ParserCreate(NULL);
160 logger("Couldn't allocate memory for parser.");
165 //-----------------------------------------------------------------------------
166 CONFIGPROTO::~CONFIGPROTO()
168 for (size_t i = 0; i < dataParser.size(); ++i)
169 delete dataParser[i];
170 XML_ParserFree(xmlParser);
172 //-----------------------------------------------------------------------------
173 int CONFIGPROTO::ParseCommand()
175 std::list<std::string>::iterator n;
179 if (requestList.empty())
182 n = requestList.begin();
184 strncpy(str, (*n).c_str(), 8);
187 XML_ParserReset(xmlParser, NULL);
188 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
189 XML_SetUserData(xmlParser, this);
193 strncpy(str, (*n).c_str(), 8);
195 size_t len = strlen(str);
198 if (n == requestList.end())
202 if (XML_Parse(xmlParser, (*n).c_str(), static_cast<int>(len), done) == XML_STATUS_ERROR)
204 logger("Invalid configuration request");
205 printfd(__FILE__, "Parse error at line %d:\n%s\n",
206 XML_GetCurrentLineNumber(xmlParser),
207 XML_ErrorString(XML_GetErrorCode(xmlParser)));
210 printfd(__FILE__, "Parser reset\n");
226 //-----------------------------------------------------------------------------
227 void CONFIGPROTO::SetPort(uint16_t p)
231 //-----------------------------------------------------------------------------
232 void CONFIGPROTO::SetAdmins(ADMINS * a)
235 for (size_t i = 0; i < dataParser.size(); i++)
237 dataParser[i]->SetAdmins(a);
241 //-----------------------------------------------------------------------------
242 void CONFIGPROTO::SetUsers(USERS * u)
244 for (size_t i = 0; i < dataParser.size(); i++)
246 dataParser[i]->SetUsers(u);
250 //-----------------------------------------------------------------------------
251 void CONFIGPROTO::SetTariffs(TARIFFS * t)
253 for (size_t i = 0; i < dataParser.size(); i++)
255 dataParser[i]->SetTariffs(t);
258 //-----------------------------------------------------------------------------
259 void CONFIGPROTO::SetStore(STORE * s)
261 for (size_t i = 0; i < dataParser.size(); i++)
263 dataParser[i]->SetStore(s);
266 //-----------------------------------------------------------------------------
267 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
269 for (size_t i = 0; i < dataParser.size(); i++)
271 dataParser[i]->SetStgSettings(s);
274 //-----------------------------------------------------------------------------