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"
40 #include "stg/common.h"
44 #include "configproto.h"
46 //-----------------------------------------------------------------------------
47 void ParseXMLStart(void *data, const char *el, const char **attr)
49 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
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]->SetCurrAdmin(*cp->currAdmin);
61 cp->dataParser[i]->Reset();
62 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
64 cp->currParser = cp->dataParser[i];
69 cp->dataParser[i]->Reset();
74 //-----------------------------------------------------------------------------
75 void ParseXMLEnd(void *data, const char *el)
77 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
80 if (cp->currParser->ParseEnd(data, el) == 0)
82 cp->currParser = NULL;
87 for (size_t i = 0; i < cp->dataParser.size(); i++)
89 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
96 //-----------------------------------------------------------------------------
97 CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
133 dataParser.push_back(new PARSER_GET_SERVER_INFO);
135 dataParser.push_back(new PARSER_GET_USERS);
136 dataParser.push_back(new PARSER_GET_USER);
137 dataParser.push_back(new PARSER_CHG_USER);
138 dataParser.push_back(new PARSER_ADD_USER);
139 dataParser.push_back(new PARSER_DEL_USER);
140 dataParser.push_back(new PARSER_CHECK_USER);
141 dataParser.push_back(new PARSER_SEND_MESSAGE);
142 dataParser.push_back(new PARSER_AUTH_BY);
143 dataParser.push_back(new PARSER_USER_INFO);
145 dataParser.push_back(new PARSER_GET_TARIFFS);
146 dataParser.push_back(new PARSER_ADD_TARIFF);
147 dataParser.push_back(new PARSER_DEL_TARIFF);
148 dataParser.push_back(new PARSER_CHG_TARIFF);
150 dataParser.push_back(new PARSER_GET_ADMINS);
151 dataParser.push_back(new PARSER_CHG_ADMIN);
152 dataParser.push_back(new PARSER_DEL_ADMIN);
153 dataParser.push_back(new PARSER_ADD_ADMIN);
155 xmlParser = XML_ParserCreate(NULL);
159 logger("Couldn't allocate memory for parser.");
164 //-----------------------------------------------------------------------------
165 CONFIGPROTO::~CONFIGPROTO()
167 for (size_t i = 0; i < dataParser.size(); ++i)
168 delete dataParser[i];
169 XML_ParserFree(xmlParser);
171 //-----------------------------------------------------------------------------
172 int CONFIGPROTO::ParseCommand()
174 std::list<std::string>::iterator n;
178 if (requestList.empty())
181 n = requestList.begin();
183 strncpy(str, (*n).c_str(), 8);
186 XML_ParserReset(xmlParser, NULL);
187 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
188 XML_SetUserData(xmlParser, this);
192 strncpy(str, (*n).c_str(), 8);
194 size_t len = strlen(str);
197 if (n == requestList.end())
201 if (XML_Parse(xmlParser, (*n).c_str(), static_cast<int>(len), done) == XML_STATUS_ERROR)
203 logger("Invalid configuration request");
204 printfd(__FILE__, "Parse error at line %d:\n%s\n",
205 XML_GetCurrentLineNumber(xmlParser),
206 XML_ErrorString(XML_GetErrorCode(xmlParser)));
209 printfd(__FILE__, "Parser reset\n");
225 //-----------------------------------------------------------------------------
226 void CONFIGPROTO::SetPort(uint16_t p)
230 //-----------------------------------------------------------------------------
231 void CONFIGPROTO::SetAdmins(ADMINS * a)
234 for (size_t i = 0; i < dataParser.size(); i++)
236 dataParser[i]->SetAdmins(a);
240 //-----------------------------------------------------------------------------
241 void CONFIGPROTO::SetUsers(USERS * u)
243 for (size_t i = 0; i < dataParser.size(); i++)
245 dataParser[i]->SetUsers(u);
249 //-----------------------------------------------------------------------------
250 void CONFIGPROTO::SetTariffs(TARIFFS * t)
252 for (size_t i = 0; i < dataParser.size(); i++)
254 dataParser[i]->SetTariffs(t);
257 //-----------------------------------------------------------------------------
258 void CONFIGPROTO::SetStore(STORE * s)
260 for (size_t i = 0; i < dataParser.size(); i++)
262 dataParser[i]->SetStore(s);
265 //-----------------------------------------------------------------------------
266 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
268 for (size_t i = 0; i < dataParser.size(); i++)
270 dataParser[i]->SetStgSettings(s);
273 //-----------------------------------------------------------------------------