3 #include "stg/admins.h"
4 #include "stg/common.h"
6 #include <strings.h> // strcasecmp
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
11 int PARSER_GET_ADMINS::ParseStart(void *, const char *el, const char **)
13 if (strcasecmp(el, "GetAdmins") == 0)
19 //-----------------------------------------------------------------------------
20 int PARSER_GET_ADMINS::ParseEnd(void *, const char *el)
22 if (strcasecmp(el, "GetAdmins") == 0)
29 //-----------------------------------------------------------------------------
30 void PARSER_GET_ADMINS::CreateAnswer()
32 const PRIV * priv = currAdmin->GetPriv();
35 answer = "<Error Result=\"Error. Access denied.\"/>";
43 int h = admins->OpenSearch();
45 while (admins->SearchNext(h, &ac) == 0)
47 unsigned int p = (ac.priv.userStat << 0) +
48 (ac.priv.userConf << 2) +
49 (ac.priv.userCash << 4) +
50 (ac.priv.userPasswd << 6) +
51 (ac.priv.userAddDel << 8) +
52 (ac.priv.adminChg << 10) +
53 (ac.priv.tariffChg << 12);
54 answer += "<admin login=\"" + ac.login + "\" priv=\"" + x2str(p) + "\"/>";
56 admins->CloseSearch(h);
57 answer += "</Admins>";
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 int PARSER_DEL_ADMIN::ParseStart(void *, const char *el, const char **attr)
67 if (strcasecmp(el, "DelAdmin") == 0)
74 //-----------------------------------------------------------------------------
75 int PARSER_DEL_ADMIN::ParseEnd(void *, const char *el)
77 if (strcasecmp(el, "DelAdmin") == 0)
84 //-----------------------------------------------------------------------------
85 void PARSER_DEL_ADMIN::CreateAnswer()
87 if (admins->Del(adminToDel, currAdmin) == 0)
88 answer = "<DelAdmin Result=\"Ok\"/>";
90 answer = "<DelAdmin Result=\"Error. " + admins->GetStrError() + "\"/>";
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 int PARSER_ADD_ADMIN::ParseStart(void *, const char *el, const char **attr)
97 if (strcasecmp(el, "AddAdmin") == 0)
104 //-----------------------------------------------------------------------------
105 int PARSER_ADD_ADMIN::ParseEnd(void *, const char *el)
107 if (strcasecmp(el, "AddAdmin") == 0)
114 //-----------------------------------------------------------------------------
115 void PARSER_ADD_ADMIN::CreateAnswer()
117 if (admins->Add(adminToAdd, currAdmin) == 0)
118 answer = "<AddAdmin Result=\"Ok\"/>";
120 answer = "<AddAdmin Result=\"Error. " + admins->GetStrError() + "\"/>";
122 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
126 int PARSER_CHG_ADMIN::ParseStart(void *, const char *el, const char **attr)
128 if (strcasecmp(el, "ChgAdmin") == 0)
130 for (int i = 0; i < 6; i+=2)
132 printfd(__FILE__, "PARSER_CHG_ADMIN::attr[%d] = %s\n", i, attr[i]);
136 if (strcasecmp(attr[i], "Login") == 0)
142 if (strcasecmp(attr[i], "Priv") == 0)
144 privAsString = attr[i + 1];
148 if (strcasecmp(attr[i], "Password") == 0)
150 password = attr[i + 1];
159 //-----------------------------------------------------------------------------
160 int PARSER_CHG_ADMIN::ParseEnd(void *, const char *el)
162 if (strcasecmp(el, "ChgAdmin") == 0)
169 //-----------------------------------------------------------------------------
170 void PARSER_CHG_ADMIN::CreateAnswer()
174 ADMIN * origAdmin = NULL;
176 if (admins->Find(login.data(), &origAdmin))
178 answer = "<ChgAdmin Result = \"Admin '" + login.data() + "' is not found.\"/>";
182 ADMIN_CONF conf(origAdmin->GetConf());
184 if (!password.empty())
185 conf.password = password.data();
187 if (!privAsString.empty())
190 if (str2x(privAsString.data().c_str(), p) < 0)
192 answer = "<ChgAdmin Result = \"Incorrect parameter Priv.\"/>";
196 conf.priv.FromInt(p);
199 if (admins->Change(conf, currAdmin) != 0)
200 answer = "<ChgAdmin Result = \"" + admins->GetStrError() + "\"/>";
202 answer = "<ChgAdmin Result = \"Ok\"/>";
205 answer = "<ChgAdmin Result = \"Incorrect parameter login.\"/>";