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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/08/04 00:40:38 $
34 //-----------------------------------------------------------------------------
35 int AnsRecv(void * data, list<string> * list1)
39 char ans[ENC_MSG_LEN + 1];
44 XML_ParserReset(sc->parser, NULL);
45 XML_SetElementHandler(sc->parser, Start, End);
46 XML_SetUserData(sc->parser, data);
49 list<string>::iterator node;
50 node = list1->begin();
52 if (node == list1->end())
57 while (node != list1->end())
59 strncpy(ans, node->c_str(), ENC_MSG_LEN);
61 //printf("---> %s\n", ans);
64 if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR)
66 strprintf(&sc->errorMsg, "XML parse error at line %d: %s",
67 static_cast<int>(XML_GetCurrentLineNumber(sc->parser)),
68 XML_ErrorString(XML_GetErrorCode(sc->parser)));
69 return st_xml_parse_error;
77 //-----------------------------------------------------------------------------
78 void Start(void *data, const char *el, const char **attr)
84 //-----------------------------------------------------------------------------
85 void End(void *data, const char *el)
91 //-----------------------------------------------------------------------------
97 RecvGetUserDataCb(NULL),
98 RecvServerInfoDataCb(NULL),
100 RecvCheckUserCb(NULL),
101 RecvSendMessageCb(NULL),
102 getUserDataDataCb(NULL),
103 getUsersDataDataCb(NULL),
104 getServerInfoDataCb(NULL),
106 checkUserDataCb(NULL),
107 sendMessageDataCb(NULL)
109 parser = XML_ParserCreate(NULL);
111 //-----------------------------------------------------------------------------
112 void SERVCONF::SetServer(const char * server)
114 nt.SetServer(server);
116 //-----------------------------------------------------------------------------
117 void SERVCONF::SetPort(uint16_t port)
119 nt.SetServerPort(port);
121 //-----------------------------------------------------------------------------
122 void SERVCONF::SetAdmLogin(const char * login)
126 //-----------------------------------------------------------------------------
127 void SERVCONF::SetAdmPassword(const char * password)
129 nt.SetPassword(password);
131 //-----------------------------------------------------------------------------
132 int SERVCONF::GetUser(const char * l)
135 snprintf(request, 255, "<GetUser login=\"%s\"/>", l);
138 currParser = &parserGetUser;
139 ((PARSER_GET_USER*)currParser)->SetUserDataRecvCb(RecvGetUserDataCb, getUserDataDataCb);
142 nt.SetRxCallback(this, AnsRecv);
144 if ((ret = nt.Connect()) != st_ok)
146 errorMsg = nt.GetError();
149 if ((ret = nt.Transact(request)) != st_ok)
151 errorMsg = nt.GetError();
154 if ((ret = nt.Disconnect()) != st_ok)
156 errorMsg = nt.GetError();
162 //-----------------------------------------------------------------------------
163 int SERVCONF::GetUsers()
165 char request[] = "<GetUsers/>";
168 currParser = &parserGetUsers;
169 ((PARSER_GET_USERS*)currParser)->SetUserDataRecvCb(RecvUserDataCb, getUsersDataDataCb);
172 nt.SetRxCallback(this, AnsRecv);
174 if ((ret = nt.Connect()) != st_ok)
176 errorMsg = nt.GetError();
179 if ((ret = nt.Transact(request)) != st_ok)
181 errorMsg = nt.GetError();
184 if ((ret = nt.Disconnect()) != st_ok)
186 errorMsg = nt.GetError();
192 //-----------------------------------------------------------------------------
193 int SERVCONF::SendMessage(const char * login, const char * message, int prio)
197 Encode12(msg, message, strlen(message));
198 snprintf(request, 1000, "<Message login=\"%s\" priority=\"%d\" text=\"%s\"/>", login, prio, msg);
201 currParser = &parserSendMessage;
202 parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
205 nt.SetRxCallback(this, AnsRecv);
207 if ((ret = nt.Connect()) != st_ok)
209 errorMsg = nt.GetError();
212 if ((ret = nt.Transact(request)) != st_ok)
214 errorMsg = nt.GetError();
217 if ((ret = nt.Disconnect()) != st_ok)
219 errorMsg = nt.GetError();
225 //-----------------------------------------------------------------------------
226 int SERVCONF::GetServerInfo()
228 char request[] = "<GetServerInfo/>";
231 currParser = &parserServerInfo;
232 ((PARSER_GET_SERVER_INFO*)currParser)->SetServerInfoRecvCb(RecvServerInfoDataCb, getServerInfoDataCb);
235 nt.SetRxCallback(this, AnsRecv);
237 if ((ret = nt.Connect()) != st_ok)
239 errorMsg = nt.GetError();
242 if ((ret = nt.Transact(request)) != st_ok)
244 errorMsg = nt.GetError();
247 if ((ret = nt.Disconnect()) != st_ok)
249 errorMsg = nt.GetError();
255 //-----------------------------------------------------------------------------
256 int SERVCONF::ChgUser(const char * request)
260 currParser = &parserChgUser;
261 ((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb);
264 nt.SetRxCallback(this, AnsRecv);
266 if ((ret = nt.Connect()) != st_ok)
268 errorMsg = nt.GetError();
271 if ((ret = nt.Transact(request)) != st_ok)
273 errorMsg = nt.GetError();
276 if ((ret = nt.Disconnect()) != st_ok)
278 errorMsg = nt.GetError();
284 //-----------------------------------------------------------------------------
285 // TODO: remove this shit!
286 //-----------------------------------------------------------------------------
287 int SERVCONF::MsgUser(const char * request)
291 currParser = &parserSendMessage;
292 parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
295 nt.SetRxCallback(this, AnsRecv);
297 if ((ret = nt.Connect()) != st_ok)
299 errorMsg = nt.GetError();
302 if ((ret = nt.Transact(request)) != st_ok)
304 errorMsg = nt.GetError();
307 if ((ret = nt.Disconnect()) != st_ok)
309 errorMsg = nt.GetError();
315 //-----------------------------------------------------------------------------
316 int SERVCONF::CheckUser(const char * login, const char * password)
319 snprintf(request, 255, "<CheckUser login=\"%s\" password=\"%s\"/>", login, password);
322 currParser = &parserCheckUser;
323 ((PARSER_CHECK_USER*)currParser)->SetCheckUserRecvCb(RecvCheckUserCb, checkUserDataCb);
326 nt.SetRxCallback(this, AnsRecv);
328 if ((ret = nt.Connect()) != st_ok)
330 errorMsg = nt.GetError();
333 if ((ret = nt.Transact(request)) != st_ok)
335 errorMsg = nt.GetError();
338 if ((ret = nt.Disconnect()) != st_ok)
340 errorMsg = nt.GetError();
346 //-----------------------------------------------------------------------------
347 int SERVCONF::Start(const char *el, const char **attr)
349 currParser->ParseStart(el, attr);
352 //-----------------------------------------------------------------------------
353 void SERVCONF::End(const char *el)
355 currParser->ParseEnd(el);
357 //-----------------------------------------------------------------------------
358 void SERVCONF::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
361 getUsersDataDataCb = data;
363 //-----------------------------------------------------------------------------
364 void SERVCONF::SetGetUserDataRecvCb(RecvUserDataCb_t f, void * data)
366 RecvGetUserDataCb = f; //GET_USER
367 getUserDataDataCb = data;
369 //-----------------------------------------------------------------------------
370 void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
372 RecvServerInfoDataCb = f;
373 getServerInfoDataCb = data;
375 //-----------------------------------------------------------------------------
376 void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data)
379 chgUserDataCb = data;
381 //-----------------------------------------------------------------------------
382 void SERVCONF::SetCheckUserCb(RecvCheckUserCb_t f, void * data)
385 checkUserDataCb = data;
387 //-----------------------------------------------------------------------------
388 void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data)
390 RecvSendMessageCb = f;
391 sendMessageDataCb = data;
393 //-----------------------------------------------------------------------------
394 const std::string & SERVCONF::GetStrError() const
398 //-----------------------------------------------------------------------------
399 int SERVCONF::GetError()
405 //-----------------------------------------------------------------------------