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"
35 //-----------------------------------------------------------------------------
36 void ParseXMLStart(void *data, const char *el, const char **attr)
38 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
42 cp->currParser->SetAnswerList(&cp->answerList);
43 cp->currParser->SetCurrAdmin(*cp->currAdmin);
44 cp->currParser->ParseStart(data, el, attr);
48 for (size_t i = 0; i < cp->dataParser.size(); i++)
50 cp->dataParser[i]->SetAnswerList(&cp->answerList);
51 cp->dataParser[i]->SetCurrAdmin(*cp->currAdmin);
52 cp->dataParser[i]->Reset();
53 if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
55 cp->currParser = cp->dataParser[i];
60 cp->dataParser[i]->Reset();
65 //-----------------------------------------------------------------------------
66 void ParseXMLEnd(void *data, const char *el)
68 CONFIGPROTO * cp = static_cast<CONFIGPROTO *>(data);
71 if (cp->currParser->ParseEnd(data, el) == 0)
73 cp->currParser = NULL;
78 for (size_t i = 0; i < cp->dataParser.size(); i++)
80 if (cp->dataParser[i]->ParseEnd(data, el) == 0)
87 //-----------------------------------------------------------------------------
88 CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
99 dataParser.push_back(&parserGetServInfo);
101 dataParser.push_back(&parserGetUsers);
102 dataParser.push_back(&parserGetUser);
103 dataParser.push_back(&parserChgUser);
104 dataParser.push_back(&parserAddUser);
105 dataParser.push_back(&parserDelUser);
106 dataParser.push_back(&parserCheckUser);
107 dataParser.push_back(&parserSendMessage);
108 dataParser.push_back(&parserAuthBy);
109 dataParser.push_back(&parserUserInfo);
111 dataParser.push_back(&parserGetTariffs);
112 dataParser.push_back(&parserAddTariff);
113 dataParser.push_back(&parserDelTariff);
114 dataParser.push_back(&parserChgTariff);
116 dataParser.push_back(&parserGetAdmins);
117 dataParser.push_back(&parserChgAdmin);
118 dataParser.push_back(&parserDelAdmin);
119 dataParser.push_back(&parserAddAdmin);
121 xmlParser = XML_ParserCreate(NULL);
125 logger("Couldn't allocate memory for parser.");
130 //-----------------------------------------------------------------------------
131 CONFIGPROTO::~CONFIGPROTO()
133 XML_ParserFree(xmlParser);
135 //-----------------------------------------------------------------------------
136 int CONFIGPROTO::ParseCommand()
138 std::list<std::string>::iterator n;
142 if (requestList.empty())
145 n = requestList.begin();
147 strncpy(str, (*n).c_str(), 8);
150 XML_ParserReset(xmlParser, NULL);
151 XML_SetElementHandler(xmlParser, ParseXMLStart, ParseXMLEnd);
152 XML_SetUserData(xmlParser, this);
156 strncpy(str, (*n).c_str(), 8);
158 size_t len = strlen(str);
161 if (n == requestList.end())
165 if (XML_Parse(xmlParser, (*n).c_str(), static_cast<int>(len), done) == XML_STATUS_ERROR)
167 logger("Invalid configuration request");
168 printfd(__FILE__, "Parse error at line %d:\n%s\n",
169 XML_GetCurrentLineNumber(xmlParser),
170 XML_ErrorString(XML_GetErrorCode(xmlParser)));
173 printfd(__FILE__, "Parser reset\n");
189 //-----------------------------------------------------------------------------
190 void CONFIGPROTO::SetAdmins(ADMINS * a)
193 for (size_t i = 0; i < dataParser.size(); i++)
194 dataParser[i]->SetAdmins(a);
196 //-----------------------------------------------------------------------------
197 void CONFIGPROTO::SetUsers(USERS * u)
199 for (size_t i = 0; i < dataParser.size(); i++)
200 dataParser[i]->SetUsers(u);
202 //-----------------------------------------------------------------------------
203 void CONFIGPROTO::SetTariffs(TARIFFS * t)
205 for (size_t i = 0; i < dataParser.size(); i++)
206 dataParser[i]->SetTariffs(t);
208 //-----------------------------------------------------------------------------
209 void CONFIGPROTO::SetStore(STORE * s)
211 for (size_t i = 0; i < dataParser.size(); i++)
212 dataParser[i]->SetStore(s);
214 //-----------------------------------------------------------------------------
215 void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
217 for (size_t i = 0; i < dataParser.size(); i++)
218 dataParser[i]->SetStgSettings(s);
220 //-----------------------------------------------------------------------------