]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/parser.cpp
139c91bc6dc0a1b775ec11df1977523cda393498
[stg.git] / stglibs / srvconf.lib / parser.cpp
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.18 $
23  $Date: 2010/08/04 00:40:00 $
24  $Author: faust $
25  */
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <string>
35
36 #include "common.h"
37 //#include "srvconf_common.h"
38 #include "stg_const.h"
39 #include "servconf.h"
40
41 using namespace std;
42
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 PARSER_GET_USERS::PARSER_GET_USERS()
47     : RecvUserDataCb(NULL),
48       userDataCb(NULL),
49       depth(0),
50       error(false)
51 {
52 }
53 //-----------------------------------------------------------------------------
54 int PARSER_GET_USERS::ParseStart(const char *el, const char **attr)
55 {
56 depth++;
57 if (depth == 1)
58     {
59     ParseUsers(el, attr);
60     }
61
62 if (depth == 2)
63     {
64     ParseUser(el, attr);
65     }
66
67 if (depth == 3)
68     {
69     ParseUserParams(el, attr);
70     }
71 return 0;
72 }
73 //-----------------------------------------------------------------------------
74 void PARSER_GET_USERS::ParseEnd(const char *)
75 {
76 depth--;
77 if (depth == 1)
78     {
79     if (RecvUserDataCb)
80         {
81         RecvUserDataCb(&user, userDataCb);
82         }
83     }
84 }
85 //-----------------------------------------------------------------------------
86 void PARSER_GET_USERS::ParseUsers(const char * el, const char ** attr)
87 {
88 if (strcasecmp(el, "users") == 0)
89     {
90     if (*attr != NULL)
91         return;
92     return;
93     }
94 }
95 //-----------------------------------------------------------------------------
96 void PARSER_GET_USERS::ParseUser(const char * el, const char ** attr)
97 {
98 if (el && attr[0])
99     {
100     if (strcasecmp(el, "user") != 0)
101         {
102         return;
103         }
104
105     if (strcasecmp(attr[0], "login") != 0)
106         {
107         return;
108         }
109     user.login = attr[1];
110     }
111 }
112 //-----------------------------------------------------------------------------
113 void PARSER_GET_USERS::ParseUserParams(const char * el, const char ** attr)
114 {
115 if (strcasecmp(el, "cash") == 0)
116     {
117     if (strtodouble2(attr[1], user.cash) < 0)
118         {
119         return;
120         }
121     }
122
123 /*if (strcasecmp(el, "LastCash") == 0)
124     {
125     if (strtodouble2(attr[1], user.lastCash) < 0)
126         {
127         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
128         return 0;
129         }
130     }*/
131
132 /*if (strcasecmp(el, "LastActivityTime") == 0)
133     {
134     if (strtol(attr[1], user.lastActivityTime) < 0)
135         {
136         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
137         return 0;
138         }
139     }*/
140
141
142 /*if (strcasecmp(el, "LastTimeCash") == 0)
143     {
144     if (strtol(attr[1], user.lastTimeCash) < 0)
145         {
146         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
147         return 0;
148         }
149     }*/
150
151 /*if (strcasecmp(el, "CashExpire") == 0)
152     {
153     if (strtol(attr[1], user.cashExpire) < 0)
154         {
155         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
156         return 0;
157         }
158     }*/
159
160 if (strcasecmp(el, "credit") == 0)
161     {
162     if (strtodouble2(attr[1], user.credit) < 0)
163         {
164         return;
165         }
166     }
167
168 /*if (strcasecmp(el, "freemb") == 0)
169     {
170     if (strtodouble2(attr[1], user.freeMb) < 0)
171         {
172         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
173         return 0;
174         }
175     }*/
176
177 if (strcasecmp(el, "down") == 0)
178     {
179     if (str2x(attr[1], user.down) < 0)
180         {
181         return;
182         }
183     }
184
185 if (strcasecmp(el, "passive") == 0)
186     {
187     if (str2x(attr[1], user.passive) < 0)
188         {
189         return;
190         }
191     }
192
193 if (strcasecmp(el, "disableDetailStat") == 0)
194     {
195     if (str2x(attr[1], user.disableDetailStat) < 0)
196         {
197         return;
198         }
199     }
200
201
202 if (strcasecmp(el, "status") == 0)
203     {
204     if (str2x(attr[1], user.connected) < 0)
205         {
206         return;
207         }
208     }
209
210 if (strcasecmp(el, "aonline") == 0)
211     {
212     if (str2x(attr[1], user.alwaysOnline) < 0)
213         {
214         return;
215         }
216     }
217
218 if (strcasecmp(el, "currip") == 0)
219     {
220     user.ip = inet_addr(attr[1]);
221     }
222
223 if (strcasecmp(el, "ip") == 0)
224     {
225     user.ips = attr[1];
226     }
227
228
229 if (strcasecmp(el, "tariff") == 0)
230     {
231     //KOIToWin(user.tariff, *(attr+1), TARIFF_LEN);
232     user.tariff = attr[1];
233     return;
234     }
235
236 if (strcasecmp(el, "password") == 0)
237     {
238     user.password = *(attr+1);
239     return;
240     }
241
242 if (strcasecmp(el, "iface") == 0)
243     {
244     user.iface = attr[1];
245     return;
246     }
247
248 /*if (strcasecmp(el, "name") == 0)
249     {
250     / *char nameEnc[REALNM_LEN * 2 + 1];
251     char name[REALNM_LEN];
252     strncpy(nameEnc, attr[1], REALNM_LEN * 2 + 1);
253     Decode21(name, nameEnc);
254     KOIToWin(user.realName, name, REALNM_LEN);* /
255     Decode21str(user.realName, attr[1]);
256     return;
257     }*/
258
259 if (strcasecmp(el, "address") == 0)
260     {
261     /*char addressEnc[ADDR_LEN * 2 + 1];
262     char address[ADDR_LEN];
263     strncpy(addressEnc, attr[1], ADDR_LEN * 2 + 1);
264     Decode21(address, addressEnc);
265     KOIToWin(user.address, address, ADDR_LEN);*/
266     Decode21str(user.address, attr[1]);
267     return;
268     }
269
270 if (strcasecmp(el, "phone") == 0)
271     {
272     /*char phoneEnc[PHONE_LEN * 2 + 1];
273     char phone[PHONE_LEN];
274     strncpy(phoneEnc, attr[1], PHONE_LEN * 2 + 1);
275     Decode21(phone, phoneEnc);
276     KOIToWin(user.phone, phone, PHONE_LEN);*/
277     Decode21str(user.phone, attr[1]);
278     return;
279     }
280
281 if (strcasecmp(el, "note") == 0)
282     {
283     /*char noteEnc[NOTE_LEN * 2 + 1];
284     char note[NOTE_LEN];
285     strncpy(noteEnc, attr[1], NOTE_LEN * 2 + 1);*/
286     //KOIToWin(user.note, note, NOTE_LEN);
287     //user.note = note;
288     Decode21str(user.note, attr[1]);
289     return;
290     }
291
292 if (strcasecmp(el, "email") == 0)
293     {
294     /*char emailEnc[EMAIL_LEN * 2 + 1];
295     char email[EMAIL_LEN];
296     strncpy(emailEnc, attr[1], EMAIL_LEN * 2 + 1);
297     Decode21(email, emailEnc);
298     //KOIToWin(user.email, email, EMAIL_LEN);
299     user.email = email;*/
300     Decode21str(user.email, attr[1]);
301     return;
302     }
303
304 if (strcasecmp(el, "group") == 0)
305     {
306     /*char groupEnc[GROUP_LEN * 2 + 1];
307     char group[GROUP_LEN];
308     strncpy(groupEnc, attr[1], GROUP_LEN * 2 + 1);
309     Decode21(group, groupEnc);
310     //KOIToWin(user.group, group, GROUP_LEN);
311     user.group = group;*/
312     Decode21str(user.group, attr[1]);
313     return;
314     }
315
316 if (strcasecmp(el, "traff") == 0)
317     {
318     ParseUserLoadStat(el, attr);
319     return;
320     }
321
322 }
323 //-----------------------------------------------------------------------------
324 void PARSER_GET_USERS::ParseUserLoadStat(const char *, const char ** attr)
325 {
326 int i = 0;
327 char dir[6];
328 while (attr[i])
329     {
330     for (int j = 0; j < DIR_NUM; j++)
331         {
332         sprintf(dir, "MU%d", j);
333         if (strcasecmp(dir, attr[i]) == 0)
334             {
335             str2x(attr[i+1], user.stat.mu[j]);
336             break;
337             }
338         }
339     for (int j = 0; j < DIR_NUM; j++)
340         {
341         sprintf(dir, "MD%d", j);
342         if (strcasecmp(dir, attr[i]) == 0)
343             {
344             str2x(attr[i+1], user.stat.md[j]);
345             break;
346             }
347         }
348     for (int j = 0; j < DIR_NUM; j++)
349         {
350         sprintf(dir, "SU%d", j);
351         if (strcasecmp(dir, attr[i]) == 0)
352             {
353             str2x(attr[i+1], user.stat.su[j]);
354             break;
355             }
356         }
357     for (int j = 0; j < DIR_NUM; j++)
358         {
359         sprintf(dir, "SD%d", j);
360         if (strcasecmp(dir, attr[i]) == 0)
361             {
362             str2x(attr[i+1], user.stat.sd[j]);
363             break;
364             }
365         }
366     i+=2;
367     }
368 return;
369 }
370 //-----------------------------------------------------------------------------
371 void PARSER_GET_USERS::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
372 {
373 RecvUserDataCb = f;
374 userDataCb = data;
375 }
376 //-----------------------------------------------------------------------------
377 //-----------------------------------------------------------------------------
378 //-----------------------------------------------------------------------------
379 PARSER_GET_USER::PARSER_GET_USER()
380     : RecvUserDataCb(NULL),
381       userDataCb(NULL),
382       depth(0),
383       error(false)
384 {
385 }
386 //-----------------------------------------------------------------------------
387 int PARSER_GET_USER::ParseStart(const char *el, const char **attr)
388 {
389 depth++;
390 if (depth == 1)
391     {
392     ParseUser(el, attr);
393     }
394
395 if (depth == 2)
396     {
397     ParseUserParams(el, attr);
398     }
399 return 0;
400 }
401 //-----------------------------------------------------------------------------
402 void PARSER_GET_USER::ParseEnd(const char *)
403 {
404 depth--;
405 if (depth == 0)
406     {
407     if (RecvUserDataCb)
408         {
409         RecvUserDataCb(&user, userDataCb);
410         }
411     }
412 }
413 //-----------------------------------------------------------------------------
414 void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
415 {
416 if (strcasecmp(el, "user") == 0)
417     {
418     if (strcasecmp(attr[1], "error") == 0)
419         user.login = "";
420     return;
421     }
422 }
423 //-----------------------------------------------------------------------------
424 struct ParsedStringParams
425 {
426 string    * param;
427 string      paramName;
428 };
429 //-----------------------------------------------------------------------------
430 struct ParsedDoubleParams
431 {
432 double    * param;
433 string      paramName;
434 };
435 //-----------------------------------------------------------------------------
436 void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
437 {
438 //printf("PARSER_GET_USER::ParseUserParams el=%s attr[1]=%s\n", el, attr[1]);
439
440 if (strcasecmp(el, "login") == 0)
441     {
442     user.login = attr[1];
443     }
444
445
446 /*if (strcasecmp(el, "LastActivityTime") == 0)
447     {
448     if (strtol(attr[1], user.lastActivityTime) < 0)
449         {
450         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
451         return 0;
452         }
453     }
454
455
456 if (strcasecmp(el, "LastTimeCash") == 0)
457     {
458     if (strtol(attr[1], user.lastTimeCash) < 0)
459         {
460         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
461         return 0;
462         }
463     }
464
465 if (strcasecmp(el, "CashExpire") == 0)
466     {
467     if (strtol(attr[1], user.cashExpire) < 0)
468         {
469         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
470         return 0;
471         }
472     }
473 */
474
475 if (strcasecmp(el, "down") == 0)
476     {
477     if (str2x(attr[1], user.down) < 0)
478         {
479         return;
480         }
481     }
482
483 if (strcasecmp(el, "passive") == 0)
484     {
485     if (str2x(attr[1], user.passive) < 0)
486         {
487         return;
488         }
489     }
490
491 if (strcasecmp(el, "disableDetailStat") == 0)
492     {
493     if (str2x(attr[1], user.disableDetailStat) < 0)
494         {
495         return;
496         }
497     }
498
499
500 if (strcasecmp(el, "status") == 0)
501     {
502     if (str2x(attr[1], user.connected) < 0)
503         {
504         return;
505         }
506     }
507
508 if (strcasecmp(el, "aonline") == 0)
509     {
510     if (str2x(attr[1], user.alwaysOnline) < 0)
511         {
512         return;
513         }
514     }
515
516 if (strcasecmp(el, "currip") == 0)
517     {
518     user.ip = inet_addr(attr[1]);
519     }
520
521 for (int i = 0; i < USERDATA_NUM; i++)
522     {
523     string num;
524     x2str(i, num);
525     string udName = "UserData" + num;
526     if (strcasecmp(el, udName.c_str()) == 0)
527         {
528         Decode21str(user.userData[i], attr[1]);
529         return;
530         }
531     }
532
533 ParsedStringParams psp[] =
534 {
535     {&user.ips,         "ip"},
536     {&user.tariff,      "tariff"},
537     {&user.password,    "password"},
538     {&user.iface,       "iface"},
539 };
540
541 for (unsigned i = 0; i < sizeof(psp)/sizeof(ParsedStringParams); i++)
542     {
543     if (strcasecmp(el, psp[i].paramName.c_str()) == 0)
544         {
545         *psp[i].param = attr[1];
546         return;
547         }
548     }
549
550 ParsedStringParams pspEnc[] =
551 {
552     {&user.note,    "note"},
553     {&user.email,   "email"},
554     {&user.group,   "group"},
555     {&user.name,    "name"},
556     {&user.address, "address"},
557     {&user.phone,   "phone"}
558 };
559
560 for (unsigned i = 0; i < sizeof(pspEnc)/sizeof(ParsedStringParams); i++)
561     {
562     if (strcasecmp(el, pspEnc[i].paramName.c_str()) == 0)
563         {
564         Decode21str(*pspEnc[i].param, attr[1]);
565         return;
566         }
567     }
568
569 ParsedDoubleParams pdp[] =
570 {
571     {&user.cash,            "cash"},
572     {&user.credit,          "credit"},
573     {&user.lastCash,        "lastCash"},
574     {&user.prepaidTraff,    "freemb"},
575 };
576
577 for (unsigned i = 0; i < sizeof(pdp)/sizeof(ParsedDoubleParams); i++)
578     {
579     if (strcasecmp(el, pdp[i].paramName.c_str()) == 0)
580         {
581         strtodouble2(attr[1], *pdp[i].param);
582         return;
583         }
584     }
585
586 if (strcasecmp(el, "traff") == 0)
587     {
588     ParseUserLoadStat(el, attr);
589     return;
590     }
591 }
592 //-----------------------------------------------------------------------------
593 void PARSER_GET_USER::ParseUserLoadStat(const char *, const char ** attr)
594 {
595 int i = 0;
596 char dir[6];
597 while (attr[i])
598     {
599     for (int j = 0; j < DIR_NUM; j++)
600         {
601         sprintf(dir, "MU%d", j);
602         if (strcasecmp(dir, attr[i]) == 0)
603             {
604             str2x(attr[i+1], user.stat.mu[j]);
605             break;
606             }
607         }
608     for (int j = 0; j < DIR_NUM; j++)
609         {
610         sprintf(dir, "MD%d", j);
611         if (strcasecmp(dir, attr[i]) == 0)
612             {
613             str2x(attr[i+1], user.stat.md[j]);
614             break;
615             }
616         }
617     for (int j = 0; j < DIR_NUM; j++)
618         {
619         sprintf(dir, "SU%d", j);
620         if (strcasecmp(dir, attr[i]) == 0)
621             {
622             str2x(attr[i+1], user.stat.su[j]);
623             break;
624             }
625         }
626     for (int j = 0; j < DIR_NUM; j++)
627         {
628         sprintf(dir, "SD%d", j);
629         if (strcasecmp(dir, attr[i]) == 0)
630             {
631             str2x(attr[i+1], user.stat.sd[j]);
632             break;
633             }
634         }
635     i+=2;
636     }
637 return;
638 }
639 //-----------------------------------------------------------------------------
640 void PARSER_GET_USER::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
641 {
642 RecvUserDataCb = f;
643 userDataCb = data;
644 }
645 //-----------------------------------------------------------------------------
646 //-----------------------------------------------------------------------------
647 //-----------------------------------------------------------------------------
648 PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO()
649     : RecvServerInfoDataCb(NULL),
650       serverInfoDataCb(NULL),
651       depth(0),
652       error(false)
653 {
654 }
655 //-----------------------------------------------------------------------------
656 int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr)
657 {
658 depth++;
659 if (depth == 1)
660     {
661     if (strcasecmp(el, "ServerInfo") != 0)
662         {
663         //printf("%s\n", el);
664         }
665     }
666 else
667     {
668     if (depth == 2)
669         {
670         if (strcasecmp(el, "uname") == 0)
671             {
672             ParseUname(attr);
673             return 0;
674             }
675         if (strcasecmp(el, "version") == 0)
676             {
677             ParseServerVersion(attr);
678             return 0;
679             }
680         if (strcasecmp(el, "tariff") == 0)
681             {
682             ParseTariffType(attr);
683             return 0;
684             }
685         if (strcasecmp(el, "dir_num") == 0)
686             {
687             ParseDirNum(attr);
688             return 0;
689             }
690         if (strcasecmp(el, "users_num") == 0)
691             {
692             ParseUsersNum(attr);
693             return 0;
694             }
695         if (strcasecmp(el, "tariff_num") == 0)
696             {
697             ParseTariffsNum(attr);
698             return 0;
699             }
700
701         for (int j = 0; j < DIR_NUM; j++)
702             {
703             char str[16];
704             sprintf(str, "dir_name_%d", j);
705             if (strcasecmp(el, str) == 0)
706                 {
707                 ParseDirName(attr, j);
708                 }
709             }
710
711         }
712     }
713 return 0;
714 }
715 //-----------------------------------------------------------------------------
716 void PARSER_GET_SERVER_INFO::ParseEnd(const char *)
717 {
718 depth--;
719 if (depth == 0)
720     {
721     RecvServerInfoDataCb(&serverInfo, serverInfoDataCb);
722     }
723 }
724 //-----------------------------------------------------------------------------
725 /*void PARSER_GET_SERVER_INFO::ParseServerInfo(const char * el, const char ** attr)
726     {
727     }*/
728 //-----------------------------------------------------------------------------
729 void PARSER_GET_SERVER_INFO::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
730 {
731 RecvServerInfoDataCb = f;
732 serverInfoDataCb = data;
733 }
734 //-----------------------------------------------------------------------------
735 void PARSER_GET_SERVER_INFO::ParseUname(const char ** attr)
736 {
737 if (strcmp(*attr, "value") == 0)
738     serverInfo.uname = attr[1];
739 }
740 //-----------------------------------------------------------------------------
741 void PARSER_GET_SERVER_INFO::ParseServerVersion(const char ** attr)
742 {
743 if (strcmp(*attr, "value") == 0)
744     serverInfo.version = attr[1];
745 }
746 //-----------------------------------------------------------------------------
747 void PARSER_GET_SERVER_INFO::ParseUsersNum(const char ** attr)
748 {
749 if (strcmp(*attr, "value") == 0)
750     {
751     if (str2x(attr[1], serverInfo.usersNum) < 0)
752         {
753         serverInfo.usersNum = -1;
754         return;
755         }
756     }
757 }
758 //-----------------------------------------------------------------------------
759 void PARSER_GET_SERVER_INFO::ParseTariffsNum(const char ** attr)
760 {
761 if (strcmp(*attr, "value") == 0)
762     {
763     if (str2x(attr[1], serverInfo.tariffNum) < 0)
764         {
765         serverInfo.tariffNum = -1;
766         return;
767         }
768     }
769 }
770 //-----------------------------------------------------------------------------
771 void PARSER_GET_SERVER_INFO::ParseTariffType(const char ** attr)
772 {
773 if (strcmp(*attr, "value") == 0)
774     {
775     if (str2x(attr[1], serverInfo.tariffType) < 0)
776         {
777         serverInfo.tariffType = -1;
778         return;
779         }
780     }
781 }
782 //-----------------------------------------------------------------------------
783 void PARSER_GET_SERVER_INFO::ParseDirNum(const char **attr)
784 {
785 if (strcasecmp(*attr, "value") == 0)
786     {
787     if (str2x(attr[1], serverInfo.dirNum) < 0)
788         {
789         serverInfo.dirNum = -1;
790         return;
791         }
792     }
793 }
794 //-----------------------------------------------------------------------------
795 void PARSER_GET_SERVER_INFO::ParseDirName(const char **attr, int d)
796 {
797 if (strcmp(attr[0], "value") == 0)
798     {
799     char str[2*DIRNAME_LEN + 1];
800     Decode21(str, attr[1]);
801     serverInfo.dirName[d] = str;
802     }
803 }
804 //-----------------------------------------------------------------------------
805 //-----------------------------------------------------------------------------
806 //-----------------------------------------------------------------------------
807 PARSER_CHG_USER::PARSER_CHG_USER()
808     : RecvChgUserCb(NULL),
809       chgUserCbData(NULL),
810       depth(0),
811       error(false)
812 {
813 }
814 //-----------------------------------------------------------------------------
815 int PARSER_CHG_USER::ParseStart(const char *el, const char **attr)
816 {
817 depth++;
818 if (depth == 1)
819     {
820     if (strcasecmp(el, "SetUser") == 0)
821         {
822         ParseAnswer(el, attr);
823         }
824     else if (strcasecmp(el, "DelUser") == 0)
825         {
826         ParseAnswer(el, attr);
827         }
828     else if (strcasecmp(el, "AddUser") == 0)
829         {
830         ParseAnswer(el, attr);
831         }
832     }
833 return 0;
834 }
835 //-----------------------------------------------------------------------------
836 void PARSER_CHG_USER::ParseEnd(const char *)
837 {
838 depth--;
839 }
840 //-----------------------------------------------------------------------------
841 void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr)
842 {
843 if (RecvChgUserCb)
844     {
845     RecvChgUserCb(attr[1], chgUserCbData);
846     }
847 }
848 //-----------------------------------------------------------------------------
849 void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data)
850 {
851 RecvChgUserCb = f;
852 chgUserCbData = data;
853 }
854 //-----------------------------------------------------------------------------
855 //-----------------------------------------------------------------------------
856 //-----------------------------------------------------------------------------
857 PARSER_CHECK_USER::PARSER_CHECK_USER()
858     : RecvCheckUserCb(NULL),
859       checkUserCbData(NULL),
860       depth(0),
861       error(false)
862 {
863 }
864 //-----------------------------------------------------------------------------
865 int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr)
866 {
867 depth++;
868 if (depth == 1)
869     {
870     if (strcasecmp(el, "CheckUser") == 0)
871         {
872         //printf("el=%s attr[0]=%s attr[1]=%s\n", el, attr[0], attr[1]);
873         ParseAnswer(el, attr);
874         }
875     }
876 return 0;
877 }
878 //-----------------------------------------------------------------------------
879 void PARSER_CHECK_USER::ParseEnd(const char *)
880 {
881 depth--;
882 }
883 //-----------------------------------------------------------------------------
884 void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr)
885 {
886 if (RecvCheckUserCb)
887     {
888     RecvCheckUserCb(attr[1], checkUserCbData);
889     }
890 }
891 //-----------------------------------------------------------------------------
892 void PARSER_CHECK_USER::SetCheckUserRecvCb(RecvCheckUserCb_t f, void * data)
893 {
894 RecvCheckUserCb = f;
895 checkUserCbData = data;
896 }
897 //-----------------------------------------------------------------------------
898 //-----------------------------------------------------------------------------
899 //-----------------------------------------------------------------------------
900 PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
901     : RecvSendMessageCb(NULL),
902       sendMessageCbData(NULL),
903       depth(0),
904       error(false)
905 {
906 }
907 //-----------------------------------------------------------------------------
908 int  PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr)
909 {
910 depth++;
911 if (depth == 1)
912     {
913     if (strcasecmp(el, "SendMessageResult") == 0)
914         {
915         ParseAnswer(el, attr);
916         }
917     }
918 return 0;
919 }
920 //-----------------------------------------------------------------------------
921 void PARSER_SEND_MESSAGE::ParseEnd(const char *)
922 {
923 depth--;
924 }
925 //-----------------------------------------------------------------------------
926 void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr)
927 {
928 if (RecvSendMessageCb)
929     RecvSendMessageCb(attr[1], sendMessageCbData);
930 }
931 //-----------------------------------------------------------------------------
932 void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data)
933 {
934 RecvSendMessageCb = f;
935 sendMessageCbData = data;
936 }
937 //-----------------------------------------------------------------------------