]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp
e1da75b682f4c25f31e830578909ec1a02ca575b
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_auth_by.cpp
1 #include "parser_auth_by.h"
2
3 int PARSER_AUTH_BY::ParseStart(void * /*data*/, const char *el, const char **attr)
4 {
5 if (strcasecmp(el, "GetUserAuthBy") == 0)
6     {
7     if (attr[0] && attr[1])
8         login = attr[1];
9     else
10         {
11         login.erase(login.begin(), login.end());
12         return -1;
13         }
14     return 0;
15     }
16 return -1;
17 }
18
19 int PARSER_AUTH_BY::ParseEnd(void * /*data*/, const char *el)
20 {
21 if (strcasecmp(el, "GetUserAuthBy") == 0)
22     {
23     CreateAnswer();
24     return 0;
25     }
26 return -1;
27 }
28
29 void PARSER_AUTH_BY::CreateAnswer()
30 {
31 answerList->erase(answerList->begin(), answerList->end());
32
33 USER_PTR u;
34 if (users->FindByName(login, &u))
35     {
36     answerList->push_back("<user result=\"error\"/>");
37     return;
38     }
39
40 std::string s = "<AuthorizedBy>";
41 std::vector<std::string> list(u->GetAuthorizers());
42 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
43     s += "<Auth name=\"" + *it + "\"/>";
44 s += "</AuthorizedBy>";
45 answerList->push_back(s);
46 }