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