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