1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "stg/common.h"
4 #include "admins_methods.h"
7 //------------------------------------------------------------------------------
9 void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
10 xmlrpc_c::value * const retvalPtr)
12 std::string cookie = paramList.getString(0);
13 std::string login = paramList.getString(1);
14 paramList.verifyEnd(2);
16 std::map<std::string, xmlrpc_c::value> structVal;
19 if (config->GetAdminInfo(cookie, &adminInfo))
21 structVal["result"] = xmlrpc_c::value_boolean(false);
22 *retvalPtr = xmlrpc_c::value_struct(structVal);
28 if (admins->Find(login, &admin))
30 structVal["result"] = xmlrpc_c::value_boolean(false);
31 *retvalPtr = xmlrpc_c::value_struct(structVal);
35 structVal["result"] = xmlrpc_c::value_boolean(true);
36 structVal["login"] = xmlrpc_c::value_string(admin->GetLogin());
37 structVal["password"] = xmlrpc_c::value_string(admin->GetPassword());
39 const PRIV * priv = admin->GetPriv();
41 structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
42 structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
43 structVal["user_cash"] = xmlrpc_c::value_boolean(priv->userCash);
44 structVal["user_passwd"] = xmlrpc_c::value_boolean(priv->userPasswd);
45 structVal["user_add_del"] = xmlrpc_c::value_boolean(priv->userAddDel);
46 structVal["admin_chg"] = xmlrpc_c::value_boolean(priv->adminChg);
47 structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv->tariffChg);
49 *retvalPtr = xmlrpc_c::value_struct(structVal);
52 //------------------------------------------------------------------------------
54 void METHOD_ADMIN_ADD::execute(xmlrpc_c::paramList const & paramList,
55 xmlrpc_c::value * const retvalPtr)
57 std::string cookie = paramList.getString(0);
58 std::string login = paramList.getString(1);
59 paramList.verifyEnd(2);
63 if (config->GetAdminInfo(cookie, &adminInfo))
65 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Not logged or cookie timeout'\n");
66 *retvalPtr = xmlrpc_c::value_boolean(false);
72 if (admins->Find(adminInfo.admin, &admin))
74 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Invalid admin (logged)'\n");
75 *retvalPtr = xmlrpc_c::value_boolean(false);
79 if (admins->Add(login, admin))
81 printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Failed to add admin'\n");
82 *retvalPtr = xmlrpc_c::value_boolean(false);
86 *retvalPtr = xmlrpc_c::value_boolean(true);
89 //------------------------------------------------------------------------------
91 void METHOD_ADMIN_DEL::execute(xmlrpc_c::paramList const & paramList,
92 xmlrpc_c::value * const retvalPtr)
94 std::string cookie = paramList.getString(0);
95 std::string login = paramList.getString(1);
96 paramList.verifyEnd(2);
98 std::map<std::string, xmlrpc_c::value> structVal;
101 if (config->GetAdminInfo(cookie, &adminInfo))
103 *retvalPtr = xmlrpc_c::value_boolean(false);
109 if (admins->Find(adminInfo.admin, &admin))
111 *retvalPtr = xmlrpc_c::value_boolean(false);
115 if (admins->Del(login, admin))
117 *retvalPtr = xmlrpc_c::value_boolean(false);
121 *retvalPtr = xmlrpc_c::value_boolean(true);
124 //------------------------------------------------------------------------------
126 void METHOD_ADMIN_CHG::execute(xmlrpc_c::paramList const & paramList,
127 xmlrpc_c::value * const retvalPtr)
129 std::string cookie = paramList.getString(0);
130 std::string login = paramList.getString(1);
131 xmlrpc_c::value_struct info(paramList.getStruct(2));
132 paramList.verifyEnd(3);
134 ADMIN_INFO adminInfo;
136 if (config->GetAdminInfo(cookie, &adminInfo))
138 *retvalPtr = xmlrpc_c::value_boolean(false);
144 if (admins->Find(adminInfo.admin, &loggedAdmin))
146 *retvalPtr = xmlrpc_c::value_boolean(false);
152 if (admins->Find(login, &admin))
154 *retvalPtr = xmlrpc_c::value_boolean(false);
160 conf.priv = *admin->GetPriv();
161 conf.password = admin->GetPassword();
164 std::map<std::string, xmlrpc_c::value> structVal(
165 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
168 std::map<std::string, xmlrpc_c::value>::iterator it;
170 if ((it = structVal.find("password")) != structVal.end())
172 conf.password = xmlrpc_c::value_string(it->second);
175 if ((it = structVal.find("user_stat")) != structVal.end())
177 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
180 if ((it = structVal.find("user_conf")) != structVal.end())
182 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
185 if ((it = structVal.find("user_cash")) != structVal.end())
187 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
190 if ((it = structVal.find("user_passwd")) != structVal.end())
192 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
195 if ((it = structVal.find("user_add_del")) != structVal.end())
197 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
200 if ((it = structVal.find("admin_chg")) != structVal.end())
202 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
205 if ((it = structVal.find("tariff_chg")) != structVal.end())
207 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
210 if (admins->Change(conf, loggedAdmin))
212 *retvalPtr = xmlrpc_c::value_boolean(false);
215 *retvalPtr = xmlrpc_c::value_boolean(true);
218 //------------------------------------------------------------------------------
220 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
221 xmlrpc_c::value * const retvalPtr)
223 std::string cookie = paramList.getString(0);
224 paramList.verifyEnd(1);
226 std::map<std::string, xmlrpc_c::value> structVal;
227 std::vector<xmlrpc_c::value> retval;
228 ADMIN_INFO adminInfo;
230 if (config->GetAdminInfo(cookie, &adminInfo))
232 structVal["result"] = xmlrpc_c::value_boolean(false);
233 *retvalPtr = xmlrpc_c::value_struct(structVal);
238 int h = admins->OpenSearch();
240 while (admins->SearchNext(h, &ac) == 0)
242 std::map<std::string, xmlrpc_c::value> structVal;
243 structVal["result"] = xmlrpc_c::value_boolean(true);
244 structVal["login"] = xmlrpc_c::value_string(ac.login);
245 structVal["password"] = xmlrpc_c::value_string(ac.password);
246 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
247 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
248 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
249 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
250 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
251 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
252 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
254 retval.push_back(xmlrpc_c::value_struct(structVal));
257 *retvalPtr = xmlrpc_c::value_array(retval);