]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/parser.cpp
Added ability to list authorizers for user.
[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 "stg/common.h"
37 #include "stg/const.h"
38 #include "stg/servconf.h"
39
40 using namespace std;
41
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 PARSER_GET_USERS::PARSER_GET_USERS()
46     : RecvUserDataCb(NULL),
47       userDataCb(NULL),
48       user(),
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       user(),
391       depth(0),
392       error(false)
393 {
394 }
395 //-----------------------------------------------------------------------------
396 int PARSER_GET_USER::ParseStart(const char *el, const char **attr)
397 {
398 depth++;
399 if (depth == 1)
400     {
401     ParseUser(el, attr);
402     }
403
404 if (depth == 2)
405     {
406     ParseUserParams(el, attr);
407     }
408 return 0;
409 }
410 //-----------------------------------------------------------------------------
411 void PARSER_GET_USER::ParseEnd(const char *)
412 {
413 depth--;
414 if (depth == 0)
415     {
416     if (RecvUserDataCb)
417         {
418         RecvUserDataCb(&user, userDataCb);
419         }
420     }
421 }
422 //-----------------------------------------------------------------------------
423 void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
424 {
425 if (strcasecmp(el, "user") == 0)
426     {
427     if (strcasecmp(attr[1], "error") == 0)
428         user.login = "";
429     return;
430     }
431 }
432 //-----------------------------------------------------------------------------
433 struct ParsedStringParams
434 {
435 string    * param;
436 string      paramName;
437 };
438 //-----------------------------------------------------------------------------
439 struct ParsedDoubleParams
440 {
441 double    * param;
442 string      paramName;
443 };
444 //-----------------------------------------------------------------------------
445 void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
446 {
447 //printf("PARSER_GET_USER::ParseUserParams el=%s attr[1]=%s\n", el, attr[1]);
448
449 if (strcasecmp(el, "login") == 0)
450     {
451     user.login = attr[1];
452     }
453
454
455 /*if (strcasecmp(el, "LastActivityTime") == 0)
456     {
457     if (strtol(attr[1], user.lastActivityTime) < 0)
458         {
459         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
460         return 0;
461         }
462     }
463
464
465 if (strcasecmp(el, "LastTimeCash") == 0)
466     {
467     if (strtol(attr[1], user.lastTimeCash) < 0)
468         {
469         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
470         return 0;
471         }
472     }
473
474 if (strcasecmp(el, "CashExpire") == 0)
475     {
476     if (strtol(attr[1], user.cashExpire) < 0)
477         {
478         MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
479         return 0;
480         }
481     }
482 */
483
484 if (strcasecmp(el, "down") == 0)
485     {
486     if (str2x(attr[1], user.down) < 0)
487         {
488         return;
489         }
490     }
491
492 if (strcasecmp(el, "passive") == 0)
493     {
494     if (str2x(attr[1], user.passive) < 0)
495         {
496         return;
497         }
498     }
499
500 if (strcasecmp(el, "disableDetailStat") == 0)
501     {
502     if (str2x(attr[1], user.disableDetailStat) < 0)
503         {
504         return;
505         }
506     }
507
508
509 if (strcasecmp(el, "status") == 0)
510     {
511     if (str2x(attr[1], user.connected) < 0)
512         {
513         return;
514         }
515     }
516
517 if (strcasecmp(el, "aonline") == 0)
518     {
519     if (str2x(attr[1], user.alwaysOnline) < 0)
520         {
521         return;
522         }
523     }
524
525 if (strcasecmp(el, "currip") == 0)
526     {
527     user.ip = inet_addr(attr[1]);
528     }
529
530 if (strcasecmp(el, "creditExpire") == 0)
531     {
532     if (str2x(attr[1], user.creditExpire) < 0)
533         {
534         return;
535         }
536     }
537
538 for (int i = 0; i < USERDATA_NUM; i++)
539     {
540     string num;
541     x2str(i, num);
542     string udName = "UserData" + num;
543     if (strcasecmp(el, udName.c_str()) == 0)
544         {
545         Decode21str(user.userData[i], attr[1]);
546         return;
547         }
548     }
549
550 ParsedStringParams psp[] =
551 {
552     {&user.ips,         "ip"},
553     {&user.tariff,      "tariff"},
554     {&user.password,    "password"},
555     {&user.iface,       "iface"},
556 };
557
558 for (unsigned i = 0; i < sizeof(psp)/sizeof(ParsedStringParams); i++)
559     {
560     if (strcasecmp(el, psp[i].paramName.c_str()) == 0)
561         {
562         *psp[i].param = attr[1];
563         return;
564         }
565     }
566
567 ParsedStringParams pspEnc[] =
568 {
569     {&user.note,    "note"},
570     {&user.email,   "email"},
571     {&user.group,   "group"},
572     {&user.name,    "name"},
573     {&user.address, "address"},
574     {&user.phone,   "phone"}
575 };
576
577 for (unsigned i = 0; i < sizeof(pspEnc)/sizeof(ParsedStringParams); i++)
578     {
579     if (strcasecmp(el, pspEnc[i].paramName.c_str()) == 0)
580         {
581         Decode21str(*pspEnc[i].param, attr[1]);
582         return;
583         }
584     }
585
586 ParsedDoubleParams pdp[] =
587 {
588     {&user.cash,            "cash"},
589     {&user.credit,          "credit"},
590     {&user.lastCash,        "lastCash"},
591     {&user.prepaidTraff,    "freemb"},
592 };
593
594 for (unsigned i = 0; i < sizeof(pdp)/sizeof(ParsedDoubleParams); i++)
595     {
596     if (strcasecmp(el, pdp[i].paramName.c_str()) == 0)
597         {
598         strtodouble2(attr[1], *pdp[i].param);
599         return;
600         }
601     }
602
603 if (strcasecmp(el, "traff") == 0)
604     {
605     ParseUserLoadStat(el, attr);
606     return;
607     }
608 }
609 //-----------------------------------------------------------------------------
610 void PARSER_GET_USER::ParseUserLoadStat(const char *, const char ** attr)
611 {
612 int i = 0;
613 char dir[6];
614 while (attr[i])
615     {
616     for (int j = 0; j < DIR_NUM; j++)
617         {
618         sprintf(dir, "MU%d", j);
619         if (strcasecmp(dir, attr[i]) == 0)
620             {
621             str2x(attr[i+1], user.stat.mu[j]);
622             break;
623             }
624         }
625     for (int j = 0; j < DIR_NUM; j++)
626         {
627         sprintf(dir, "MD%d", j);
628         if (strcasecmp(dir, attr[i]) == 0)
629             {
630             str2x(attr[i+1], user.stat.md[j]);
631             break;
632             }
633         }
634     for (int j = 0; j < DIR_NUM; j++)
635         {
636         sprintf(dir, "SU%d", j);
637         if (strcasecmp(dir, attr[i]) == 0)
638             {
639             str2x(attr[i+1], user.stat.su[j]);
640             break;
641             }
642         }
643     for (int j = 0; j < DIR_NUM; j++)
644         {
645         sprintf(dir, "SD%d", j);
646         if (strcasecmp(dir, attr[i]) == 0)
647             {
648             str2x(attr[i+1], user.stat.sd[j]);
649             break;
650             }
651         }
652     i+=2;
653     }
654 return;
655 }
656 //-----------------------------------------------------------------------------
657 void PARSER_GET_USER::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
658 {
659 RecvUserDataCb = f;
660 userDataCb = data;
661 }
662 //-----------------------------------------------------------------------------
663 //-----------------------------------------------------------------------------
664 //-----------------------------------------------------------------------------
665 PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO()
666     : RecvServerInfoDataCb(NULL),
667       serverInfoDataCb(NULL),
668       depth(0),
669       error(false),
670       serverInfo()
671 {
672 }
673 //-----------------------------------------------------------------------------
674 int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr)
675 {
676 depth++;
677 if (depth == 1)
678     {
679     if (strcasecmp(el, "ServerInfo") != 0)
680         {
681         //printf("%s\n", el);
682         }
683     }
684 else
685     {
686     if (depth == 2)
687         {
688         if (strcasecmp(el, "uname") == 0)
689             {
690             ParseUname(attr);
691             return 0;
692             }
693         if (strcasecmp(el, "version") == 0)
694             {
695             ParseServerVersion(attr);
696             return 0;
697             }
698         if (strcasecmp(el, "tariff") == 0)
699             {
700             ParseTariffType(attr);
701             return 0;
702             }
703         if (strcasecmp(el, "dir_num") == 0)
704             {
705             ParseDirNum(attr);
706             return 0;
707             }
708         if (strcasecmp(el, "users_num") == 0)
709             {
710             ParseUsersNum(attr);
711             return 0;
712             }
713         if (strcasecmp(el, "tariff_num") == 0)
714             {
715             ParseTariffsNum(attr);
716             return 0;
717             }
718
719         for (int j = 0; j < DIR_NUM; j++)
720             {
721             char str[16];
722             sprintf(str, "dir_name_%d", j);
723             if (strcasecmp(el, str) == 0)
724                 {
725                 ParseDirName(attr, j);
726                 }
727             }
728
729         }
730     }
731 return 0;
732 }
733 //-----------------------------------------------------------------------------
734 void PARSER_GET_SERVER_INFO::ParseEnd(const char *)
735 {
736 depth--;
737 if (depth == 0)
738     {
739     RecvServerInfoDataCb(&serverInfo, serverInfoDataCb);
740     }
741 }
742 //-----------------------------------------------------------------------------
743 /*void PARSER_GET_SERVER_INFO::ParseServerInfo(const char * el, const char ** attr)
744     {
745     }*/
746 //-----------------------------------------------------------------------------
747 void PARSER_GET_SERVER_INFO::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
748 {
749 RecvServerInfoDataCb = f;
750 serverInfoDataCb = data;
751 }
752 //-----------------------------------------------------------------------------
753 void PARSER_GET_SERVER_INFO::ParseUname(const char ** attr)
754 {
755 if (strcmp(*attr, "value") == 0)
756     serverInfo.uname = attr[1];
757 }
758 //-----------------------------------------------------------------------------
759 void PARSER_GET_SERVER_INFO::ParseServerVersion(const char ** attr)
760 {
761 if (strcmp(*attr, "value") == 0)
762     serverInfo.version = attr[1];
763 }
764 //-----------------------------------------------------------------------------
765 void PARSER_GET_SERVER_INFO::ParseUsersNum(const char ** attr)
766 {
767 if (strcmp(*attr, "value") == 0)
768     {
769     if (str2x(attr[1], serverInfo.usersNum) < 0)
770         {
771         serverInfo.usersNum = -1;
772         return;
773         }
774     }
775 }
776 //-----------------------------------------------------------------------------
777 void PARSER_GET_SERVER_INFO::ParseTariffsNum(const char ** attr)
778 {
779 if (strcmp(*attr, "value") == 0)
780     {
781     if (str2x(attr[1], serverInfo.tariffNum) < 0)
782         {
783         serverInfo.tariffNum = -1;
784         return;
785         }
786     }
787 }
788 //-----------------------------------------------------------------------------
789 void PARSER_GET_SERVER_INFO::ParseTariffType(const char ** attr)
790 {
791 if (strcmp(*attr, "value") == 0)
792     {
793     if (str2x(attr[1], serverInfo.tariffType) < 0)
794         {
795         serverInfo.tariffType = -1;
796         return;
797         }
798     }
799 }
800 //-----------------------------------------------------------------------------
801 void PARSER_GET_SERVER_INFO::ParseDirNum(const char **attr)
802 {
803 if (strcasecmp(*attr, "value") == 0)
804     {
805     if (str2x(attr[1], serverInfo.dirNum) < 0)
806         {
807         serverInfo.dirNum = -1;
808         return;
809         }
810     }
811 }
812 //-----------------------------------------------------------------------------
813 void PARSER_GET_SERVER_INFO::ParseDirName(const char **attr, int d)
814 {
815 if (strcmp(attr[0], "value") == 0)
816     {
817     char str[2*DIRNAME_LEN + 1];
818     Decode21(str, attr[1]);
819     serverInfo.dirName[d] = str;
820     }
821 }
822 //-----------------------------------------------------------------------------
823 //-----------------------------------------------------------------------------
824 //-----------------------------------------------------------------------------
825 PARSER_AUTH_BY::PARSER_AUTH_BY()
826     : RecvAuthByDataCb(NULL),
827       authByDataCb(NULL),
828       depth(0),
829       error(false),
830       list()
831 {
832 }
833 //-----------------------------------------------------------------------------
834 int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
835 {
836 depth++;
837 if (depth == 1)
838     {
839     if (strcasecmp(el, "AuthorizedBy") != 0)
840         {
841         list.erase(list.begin(), list.end());
842         //printf("%s\n", el);
843         }
844     }
845 else
846     {
847     if (depth == 2)
848         {
849         if (strcasecmp(el, "Auth") == 0)
850             {
851             if (attr && attr[0])
852                 list.push_back(attr[0]);
853             return 0;
854             }
855         }
856     }
857 return 0;
858 }
859 //-----------------------------------------------------------------------------
860 void PARSER_AUTH_BY::ParseEnd(const char *)
861 {
862 depth--;
863 if (depth == 0)
864     {
865     RecvAuthByDataCb(list, authByDataCb);
866     }
867 }
868 //-----------------------------------------------------------------------------
869 void PARSER_AUTH_BY::SetRecvCb(RecvAuthByDataCb_t f, void * data)
870 {
871 RecvAuthByDataCb = f;
872 authByDataCb = data;
873 }
874 //-----------------------------------------------------------------------------
875 //-----------------------------------------------------------------------------
876 //-----------------------------------------------------------------------------
877 PARSER_CHG_USER::PARSER_CHG_USER()
878     : RecvChgUserCb(NULL),
879       chgUserCbData(NULL),
880       depth(0),
881       error(false)
882 {
883 }
884 //-----------------------------------------------------------------------------
885 int PARSER_CHG_USER::ParseStart(const char *el, const char **attr)
886 {
887 depth++;
888 if (depth == 1)
889     {
890     if (strcasecmp(el, "SetUser") == 0)
891         {
892         ParseAnswer(el, attr);
893         }
894     else if (strcasecmp(el, "DelUser") == 0)
895         {
896         ParseAnswer(el, attr);
897         }
898     else if (strcasecmp(el, "AddUser") == 0)
899         {
900         ParseAnswer(el, attr);
901         }
902     }
903 return 0;
904 }
905 //-----------------------------------------------------------------------------
906 void PARSER_CHG_USER::ParseEnd(const char *)
907 {
908 depth--;
909 }
910 //-----------------------------------------------------------------------------
911 void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr)
912 {
913 if (RecvChgUserCb)
914     {
915     RecvChgUserCb(attr[1], chgUserCbData);
916     }
917 }
918 //-----------------------------------------------------------------------------
919 void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data)
920 {
921 RecvChgUserCb = f;
922 chgUserCbData = data;
923 }
924 //-----------------------------------------------------------------------------
925 //-----------------------------------------------------------------------------
926 //-----------------------------------------------------------------------------
927 PARSER_CHECK_USER::PARSER_CHECK_USER()
928     : RecvCheckUserCb(NULL),
929       checkUserCbData(NULL),
930       depth(0),
931       error(false)
932 {
933 }
934 //-----------------------------------------------------------------------------
935 int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr)
936 {
937 depth++;
938 if (depth == 1)
939     {
940     if (strcasecmp(el, "CheckUser") == 0)
941         {
942         //printf("el=%s attr[0]=%s attr[1]=%s\n", el, attr[0], attr[1]);
943         ParseAnswer(el, attr);
944         }
945     }
946 return 0;
947 }
948 //-----------------------------------------------------------------------------
949 void PARSER_CHECK_USER::ParseEnd(const char *)
950 {
951 depth--;
952 }
953 //-----------------------------------------------------------------------------
954 void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr)
955 {
956 if (RecvCheckUserCb)
957     {
958     RecvCheckUserCb(attr[1], checkUserCbData);
959     }
960 }
961 //-----------------------------------------------------------------------------
962 void PARSER_CHECK_USER::SetCheckUserRecvCb(RecvCheckUserCb_t f, void * data)
963 {
964 RecvCheckUserCb = f;
965 checkUserCbData = data;
966 }
967 //-----------------------------------------------------------------------------
968 //-----------------------------------------------------------------------------
969 //-----------------------------------------------------------------------------
970 PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
971     : RecvSendMessageCb(NULL),
972       sendMessageCbData(NULL),
973       depth(0),
974       error(false)
975 {
976 }
977 //-----------------------------------------------------------------------------
978 int  PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr)
979 {
980 depth++;
981 if (depth == 1)
982     {
983     if (strcasecmp(el, "SendMessageResult") == 0)
984         {
985         ParseAnswer(el, attr);
986         }
987     }
988 return 0;
989 }
990 //-----------------------------------------------------------------------------
991 void PARSER_SEND_MESSAGE::ParseEnd(const char *)
992 {
993 depth--;
994 }
995 //-----------------------------------------------------------------------------
996 void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr)
997 {
998 if (RecvSendMessageCb)
999     RecvSendMessageCb(attr[1], sendMessageCbData);
1000 }
1001 //-----------------------------------------------------------------------------
1002 void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data)
1003 {
1004 RecvSendMessageCb = f;
1005 sendMessageCbData = data;
1006 }
1007 //-----------------------------------------------------------------------------