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 $
31 #include "configproto.h"
34 #include "parser_auth_by.h"
35 #include "parser_user_info.h"
37 #include "stg/users.h"
38 #include "stg/admins.h"
39 #include "stg/tariffs.h"
40 #include "stg/logger.h"
44 //-----------------------------------------------------------------------------
45 void ParseXMLStart(void *data, const char *el, const char **attr)
47 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
51 cp->currParser->SetCurrAdmin(*cp->currAdmin);
52 cp->currParser->ParseStart(data, el, attr);
56 for (size_t i = 0; i < cp->dataParser.size(); i++)
58 cp->dataParser[i]->SetCurrAdmin(*cp->currAdmin);
59 cp->dataParser[i]->Reset();
60 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
62 cp->currParser = cp->dataParser[i];
67 cp->dataParser[i]->Reset();
72 //-----------------------------------------------------------------------------
73 void ParseXMLEnd(void *data, const char *el)
75 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
78 if (cp->currParser->ParseEnd(data, el) == 0)
80 cp->currParser = NULL;
85 for (size_t i = 0; i < cp->dataParser.size(); i++)
87 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
94 //-----------------------------------------------------------------------------
95 CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
106 dataParser.push_back(new PARSER_GET_SERVER_INFO);
108 dataParser.push_back(new PARSER_GET_USERS);
109 dataParser.push_back(new PARSER_GET_USER);
110 dataParser.push_back(new PARSER_CHG_USER);
111 dataParser.push_back(new PARSER_ADD_USER);
112 dataParser.push_back(new PARSER_DEL_USER);
113 dataParser.push_back(new PARSER_CHECK_USER);
114 dataParser.push_back(new PARSER_SEND_MESSAGE);
115 dataParser.push_back(new PARSER_AUTH_BY);
116 dataParser.push_back(new PARSER_USER_INFO);
118 dataParser.push_back(new PARSER_GET_TARIFFS);
119 dataParser.push_back(new PARSER_ADD_TARIFF);
120 dataParser.push_back(new PARSER_DEL_TARIFF);
121 dataParser.push_back(new PARSER_CHG_TARIFF);
123 dataParser.push_back(new PARSER_GET_ADMINS);
124 dataParser.push_back(new PARSER_CHG_ADMIN);
125 dataParser.push_back(new PARSER_DEL_ADMIN);
126 dataParser.push_back(new PARSER_ADD_ADMIN);
128 xmlParser = XML_ParserCreate(NULL);
132 logger("Couldn't allocate memory for parser.");
137 //-----------------------------------------------------------------------------
138 CONFIGPROTO::~CONFIGPROTO()
140 for (size_t i = 0; i < dataParser.size(); ++i)
141 delete dataParser[i];
142 XML_ParserFree(xmlParser);
144 //-----------------------------------------------------------------------------
145 int CONFIGPROTO::ParseCommand()
147 std::list<std::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);
167 size_t len = strlen(str);
170 if (n == requestList.end())
174 if (XML_Parse(xmlParser, (*n).c_str(), static_cast<int>(len), done) == XML_STATUS_ERROR)
176 logger("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::SetAdmins(ADMINS * a)
202 for (size_t i = 0; i < dataParser.size(); i++)
203 dataParser[i]->SetAdmins(a);
205 //-----------------------------------------------------------------------------
206 void CONFIGPROTO::SetUsers(USERS * u)
208 for (size_t i = 0; i < dataParser.size(); i++)
209 dataParser[i]->SetUsers(u);
211 //-----------------------------------------------------------------------------
212 void CONFIGPROTO::SetTariffs(TARIFFS * t)
214 for (size_t i = 0; i < dataParser.size(); i++)
215 dataParser[i]->SetTariffs(t);
217 //-----------------------------------------------------------------------------
218 void CONFIGPROTO::SetStore(STORE * s)
220 for (size_t i = 0; i < dataParser.size(); i++)
221 dataParser[i]->SetStore(s);
223 //-----------------------------------------------------------------------------
224 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
226 for (size_t i = 0; i < dataParser.size(); i++)
227 dataParser[i]->SetStgSettings(s);
229 //-----------------------------------------------------------------------------