]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp
Optimized sending answers in sgconfig.
[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 USER_PTR u;
32 if (users->FindByName(login, &u))
33     {
34     answer = "<AuthorizedBy result=\"error\" reason=\"User not found.\"/>";
35     return;
36     }
37
38 answer.clear();
39 answer += "<AuthorizedBy result=\"ok\">";
40 std::vector<std::string> list(u->GetAuthorizers());
41 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
42     answer += "<Auth name=\"" + *it + "\"/>";
43 answer += "</AuthorizedBy>";
44 }