6 //-----------------------------------------------------------------------------
8 //-----------------------------------------------------------------------------
9 int PARSER_GET_ADMINS::ParseStart(void *, const char *el, const char **)
11 if (strcasecmp(el, "GetAdmins") == 0)
17 //-----------------------------------------------------------------------------
18 int PARSER_GET_ADMINS::ParseEnd(void *, const char *el)
20 if (strcasecmp(el, "GetAdmins") == 0)
27 //-----------------------------------------------------------------------------
28 void PARSER_GET_ADMINS::CreateAnswer()
30 const PRIV * priv = currAdmin->GetPriv();
33 //answerList->clear();
34 answerList->erase(answerList->begin(), answerList->end());
36 answerList->push_back("<Error Result=\"Error. Access denied.\"/>");
41 //answerList->clear();
42 answerList->erase(answerList->begin(), answerList->end());
44 answerList->push_back("<Admins>");
46 int h = admins->OpenSearch();
49 while (admins->SearchNext(h, &ac) == 0)
51 //memcpy(&p, &ac.priv, sizeof(unsigned int));
52 p = (ac.priv.userStat << 0) +
53 (ac.priv.userConf << 2) +
54 (ac.priv.userCash << 4) +
55 (ac.priv.userPasswd << 6) +
56 (ac.priv.userAddDel << 8) +
57 (ac.priv.adminChg << 10) +
58 (ac.priv.tariffChg << 12);
59 strprintf(&s, "<admin login=\"%s\" priv=\"%d\"/>", ac.login.c_str(), p);
60 answerList->push_back(s);
62 admins->CloseSearch(h);
63 answerList->push_back("</Admins>");
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
70 int PARSER_DEL_ADMIN::ParseStart(void *, const char *el, const char **attr)
73 if (strcasecmp(el, "DelAdmin") == 0)
80 //-----------------------------------------------------------------------------
81 int PARSER_DEL_ADMIN::ParseEnd(void *, const char *el)
83 if (strcasecmp(el, "DelAdmin") == 0)
90 //-----------------------------------------------------------------------------
91 void PARSER_DEL_ADMIN::CreateAnswer()
93 //answerList->clear();
94 answerList->erase(answerList->begin(), answerList->end());
96 if (admins->Del(adminToDel, currAdmin) == 0)
98 answerList->push_back("<DelAdmin Result=\"Ok\"/>");
103 strprintf(&s, "<DelAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
104 answerList->push_back(s);
107 //-----------------------------------------------------------------------------
108 int PARSER_DEL_ADMIN::CheckAttr(const char **attr)
110 /* <DelAdmin login=\"admin\">
111 * attr[0] = "login" (word login)
112 * attr[1] = login, value of login
115 if (strcasecmp(attr[0], "login") == 0 && attr[1] && !attr[2])
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
124 int PARSER_ADD_ADMIN::ParseStart(void *, const char *el, const char **attr)
126 if (strcasecmp(el, "AddAdmin") == 0)
128 adminToAdd = attr[1];
133 //-----------------------------------------------------------------------------
134 int PARSER_ADD_ADMIN::ParseEnd(void *, const char *el)
136 //answerList->clear();
137 answerList->erase(answerList->begin(), answerList->end());
139 if (strcasecmp(el, "AddAdmin") == 0)
146 //-----------------------------------------------------------------------------
147 void PARSER_ADD_ADMIN::CreateAnswer()
149 //answerList->clear();
150 answerList->erase(answerList->begin(), answerList->end());
152 if (admins->Add(adminToAdd, currAdmin) == 0)
154 answerList->push_back("<AddAdmin Result=\"Ok\"/>");
159 strprintf(&s, "<AddAdmin Result=\"Error. %s\"/>", admins->GetStrError().c_str());
160 answerList->push_back(s);
163 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
167 int PARSER_CHG_ADMIN::ParseStart(void *, const char *el, const char **attr)
169 if (strcasecmp(el, "ChgAdmin") == 0)
171 for (int i = 0; i < 6; i+=2)
173 printfd(__FILE__, "PARSER_CHG_ADMIN::attr[%d] = %s\n", i, attr[i]);
177 if (strcasecmp(attr[i], "Login") == 0)
183 if (strcasecmp(attr[i], "Priv") == 0)
185 privAsString = attr[i + 1];
189 if (strcasecmp(attr[i], "Password") == 0)
191 password = attr[i + 1];
200 //-----------------------------------------------------------------------------
201 int PARSER_CHG_ADMIN::ParseEnd(void *, const char *el)
203 if (strcasecmp(el, "ChgAdmin") == 0)
210 //-----------------------------------------------------------------------------
211 void PARSER_CHG_ADMIN::CreateAnswer()
213 answerList->erase(answerList->begin(), answerList->end());
218 ADMIN * origAdmin = NULL;
220 if (admins->Find(login.data(), &origAdmin))
222 answerList->push_back(std::string("<ChgAdmin Result = \"Admin '") + login.data() + "' is not found.\"/>");
226 ADMIN_CONF conf(origAdmin->GetConf());
228 if (!password.empty())
229 conf.password = password.data();
231 if (!privAsString.empty())
234 if (str2x(privAsString.data().c_str(), p) < 0)
236 answerList->push_back("<ChgAdmin Result = \"Incorrect parameter Priv.\"/>");
240 conf.priv.FromInt(p);
243 if (admins->Change(conf, currAdmin) != 0)
246 strprintf(&s, "<ChgAdmin Result = \"%s\"/>", admins->GetStrError().c_str());
247 answerList->push_back(s);
251 answerList->push_back("<ChgAdmin Result = \"Ok\"/>");
256 answerList->push_back("<ChgAdmin Result = \"Incorrect parameter login.\"/>");
259 //-----------------------------------------------------------------------------*/