]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/parser_auth_by.cpp
63c23a09a4e7b9f554367472b4fb0ff9b6c3589c
[stg.git] / stglibs / srvconf.lib / parser_auth_by.cpp
1 #include "stg/parser_auth_by.h"
2
3 #include <strings.h> // strcasecmp
4
5 PARSER_AUTH_BY::PARSER_AUTH_BY()
6     : callback(NULL),
7       data(NULL),
8       depth(0)
9 {
10 }
11 //-----------------------------------------------------------------------------
12 int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
13 {
14 depth++;
15 if (depth == 1)
16     {
17     if (strcasecmp(el, "AuthorizedBy") != 0)
18         info.clear();
19     }
20 else
21     {
22     if (depth == 2)
23         {
24         if (strcasecmp(el, "Auth") == 0)
25             {
26             if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "name") == 0)
27                 info.push_back(attr[1]);
28             return 0;
29             }
30         }
31     }
32 return 0;
33 }
34 //-----------------------------------------------------------------------------
35 void PARSER_AUTH_BY::ParseEnd(const char * /*el*/)
36 {
37 depth--;
38 if (depth == 0)
39     callback(info, data);
40 }
41 //-----------------------------------------------------------------------------
42 void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * data)
43 {
44 callback = f;
45 data = data;
46 }