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 //-----------------------------------------------------------------------------
94 parser = XML_ParserCreate(NULL);
97 //-----------------------------------------------------------------------------
98 void SERVCONF::SetServer(const char * server)
100 nt.SetServer(server);
102 //-----------------------------------------------------------------------------
103 void SERVCONF::SetPort(uint16_t port)
105 nt.SetServerPort(port);
107 //-----------------------------------------------------------------------------
108 void SERVCONF::SetAdmLogin(const char * login)
112 //-----------------------------------------------------------------------------
113 void SERVCONF::SetAdmPassword(const char * password)
115 nt.SetPassword(password);
117 //-----------------------------------------------------------------------------
118 int SERVCONF::GetUser(const char * l)
121 snprintf(request, 255, "<GetUser login=\"%s\"/>", l);
124 currParser = &parserGetUser;
125 ((PARSER_GET_USER*)currParser)->SetUserDataRecvCb(RecvGetUserDataCb, getUserDataDataCb);
128 nt.SetRxCallback(this, AnsRecv);
130 if ((ret = nt.Connect()) != st_ok)
132 errorMsg = nt.GetError();
135 if ((ret = nt.Transact(request)) != st_ok)
137 errorMsg = nt.GetError();
140 if ((ret = nt.Disconnect()) != st_ok)
142 errorMsg = nt.GetError();
148 //-----------------------------------------------------------------------------
149 int SERVCONF::GetUsers()
151 char request[] = "<GetUsers/>";
154 currParser = &parserGetUsers;
155 ((PARSER_GET_USERS*)currParser)->SetUserDataRecvCb(RecvUserDataCb, getUsersDataDataCb);
158 nt.SetRxCallback(this, AnsRecv);
160 if ((ret = nt.Connect()) != st_ok)
162 errorMsg = nt.GetError();
165 if ((ret = nt.Transact(request)) != st_ok)
167 errorMsg = nt.GetError();
170 if ((ret = nt.Disconnect()) != st_ok)
172 errorMsg = nt.GetError();
178 //-----------------------------------------------------------------------------
179 int SERVCONF::SendMessage(const char * login, const char * message, int prio)
183 Encode12(msg, message, strlen(message));
184 snprintf(request, 1000, "<Message login=\"%s\" priority=\"%d\" text=\"%s\"/>", login, prio, msg);
187 currParser = &parserSendMessage;
188 parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
191 nt.SetRxCallback(this, AnsRecv);
193 if ((ret = nt.Connect()) != st_ok)
195 errorMsg = nt.GetError();
198 if ((ret = nt.Transact(request)) != st_ok)
200 errorMsg = nt.GetError();
203 if ((ret = nt.Disconnect()) != st_ok)
205 errorMsg = nt.GetError();
211 //-----------------------------------------------------------------------------
212 int SERVCONF::GetServerInfo()
214 char request[] = "<GetServerInfo/>";
217 currParser = &parserServerInfo;
218 ((PARSER_GET_SERVER_INFO*)currParser)->SetServerInfoRecvCb(RecvServerInfoDataCb, getServerInfoDataCb);
221 nt.SetRxCallback(this, AnsRecv);
223 if ((ret = nt.Connect()) != st_ok)
225 errorMsg = nt.GetError();
228 if ((ret = nt.Transact(request)) != st_ok)
230 errorMsg = nt.GetError();
233 if ((ret = nt.Disconnect()) != st_ok)
235 errorMsg = nt.GetError();
241 //-----------------------------------------------------------------------------
242 int SERVCONF::ChgUser(const char * request)
246 currParser = &parserChgUser;
247 ((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb);
250 nt.SetRxCallback(this, AnsRecv);
252 if ((ret = nt.Connect()) != st_ok)
254 errorMsg = nt.GetError();
257 if ((ret = nt.Transact(request)) != st_ok)
259 errorMsg = nt.GetError();
262 if ((ret = nt.Disconnect()) != st_ok)
264 errorMsg = nt.GetError();
270 //-----------------------------------------------------------------------------
271 // TODO: remove this shit!
272 //-----------------------------------------------------------------------------
273 int SERVCONF::MsgUser(const char * request)
277 currParser = &parserSendMessage;
278 parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
281 nt.SetRxCallback(this, AnsRecv);
283 if ((ret = nt.Connect()) != st_ok)
285 errorMsg = nt.GetError();
288 if ((ret = nt.Transact(request)) != st_ok)
290 errorMsg = nt.GetError();
293 if ((ret = nt.Disconnect()) != st_ok)
295 errorMsg = nt.GetError();
301 //-----------------------------------------------------------------------------
302 int SERVCONF::CheckUser(const char * login, const char * password)
305 snprintf(request, 255, "<CheckUser login=\"%s\" password=\"%s\"/>", login, password);
308 currParser = &parserCheckUser;
309 ((PARSER_CHECK_USER*)currParser)->SetCheckUserRecvCb(RecvCheckUserCb, checkUserDataCb);
312 nt.SetRxCallback(this, AnsRecv);
314 if ((ret = nt.Connect()) != st_ok)
316 errorMsg = nt.GetError();
319 if ((ret = nt.Transact(request)) != st_ok)
321 errorMsg = nt.GetError();
324 if ((ret = nt.Disconnect()) != st_ok)
326 errorMsg = nt.GetError();
332 //-----------------------------------------------------------------------------
333 int SERVCONF::Start(const char *el, const char **attr)
335 currParser->ParseStart(el, attr);
338 //-----------------------------------------------------------------------------
339 void SERVCONF::End(const char *el)
341 currParser->ParseEnd(el);
343 //-----------------------------------------------------------------------------
344 void SERVCONF::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
347 getUsersDataDataCb = data;
349 //-----------------------------------------------------------------------------
350 void SERVCONF::SetGetUserDataRecvCb(RecvUserDataCb_t f, void * data)
352 RecvGetUserDataCb = f; //GET_USER
353 getUserDataDataCb = data;
355 //-----------------------------------------------------------------------------
356 void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
358 RecvServerInfoDataCb = f;
359 getServerInfoDataCb = data;
361 //-----------------------------------------------------------------------------
362 void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data)
365 chgUserDataCb = data;
367 //-----------------------------------------------------------------------------
368 void SERVCONF::SetCheckUserCb(RecvCheckUserCb_t f, void * data)
371 checkUserDataCb = data;
373 //-----------------------------------------------------------------------------
374 void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data)
376 RecvSendMessageCb = f;
377 sendMessageDataCb = data;
379 //-----------------------------------------------------------------------------
380 const std::string & SERVCONF::GetStrError() const
384 //-----------------------------------------------------------------------------
385 int SERVCONF::GetError()
391 //-----------------------------------------------------------------------------