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);
100 if (config->GetAdminInfo(cookie, &adminInfo))
102 *retvalPtr = xmlrpc_c::value_boolean(false);
108 if (admins->Find(adminInfo.admin, &admin))
110 *retvalPtr = xmlrpc_c::value_boolean(false);
114 if (admins->Del(login, admin))
116 *retvalPtr = xmlrpc_c::value_boolean(false);
120 *retvalPtr = xmlrpc_c::value_boolean(true);
123 //------------------------------------------------------------------------------
125 void METHOD_ADMIN_CHG::execute(xmlrpc_c::paramList const & paramList,
126 xmlrpc_c::value * const retvalPtr)
128 std::string cookie = paramList.getString(0);
129 std::string login = paramList.getString(1);
130 xmlrpc_c::value_struct info(paramList.getStruct(2));
131 paramList.verifyEnd(3);
133 ADMIN_INFO adminInfo;
135 if (config->GetAdminInfo(cookie, &adminInfo))
137 *retvalPtr = xmlrpc_c::value_boolean(false);
143 if (admins->Find(adminInfo.admin, &loggedAdmin))
145 *retvalPtr = xmlrpc_c::value_boolean(false);
151 if (admins->Find(login, &admin))
153 *retvalPtr = xmlrpc_c::value_boolean(false);
159 conf.priv = *admin->GetPriv();
160 conf.password = admin->GetPassword();
163 std::map<std::string, xmlrpc_c::value> structVal(
164 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
167 std::map<std::string, xmlrpc_c::value>::iterator it;
169 if ((it = structVal.find("password")) != structVal.end())
171 conf.password = xmlrpc_c::value_string(it->second);
174 if ((it = structVal.find("user_stat")) != structVal.end())
176 conf.priv.userStat = xmlrpc_c::value_boolean(it->second);
179 if ((it = structVal.find("user_conf")) != structVal.end())
181 conf.priv.userConf = xmlrpc_c::value_boolean(it->second);
184 if ((it = structVal.find("user_cash")) != structVal.end())
186 conf.priv.userCash = xmlrpc_c::value_boolean(it->second);
189 if ((it = structVal.find("user_passwd")) != structVal.end())
191 conf.priv.userPasswd = xmlrpc_c::value_boolean(it->second);
194 if ((it = structVal.find("user_add_del")) != structVal.end())
196 conf.priv.userAddDel = xmlrpc_c::value_boolean(it->second);
199 if ((it = structVal.find("admin_chg")) != structVal.end())
201 conf.priv.adminChg = xmlrpc_c::value_boolean(it->second);
204 if ((it = structVal.find("tariff_chg")) != structVal.end())
206 conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
209 if (admins->Change(conf, loggedAdmin))
211 *retvalPtr = xmlrpc_c::value_boolean(false);
214 *retvalPtr = xmlrpc_c::value_boolean(true);
217 //------------------------------------------------------------------------------
219 void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList,
220 xmlrpc_c::value * const retvalPtr)
222 std::string cookie = paramList.getString(0);
223 paramList.verifyEnd(1);
225 std::map<std::string, xmlrpc_c::value> mainStructVal;
226 std::vector<xmlrpc_c::value> retval;
227 ADMIN_INFO adminInfo;
229 if (config->GetAdminInfo(cookie, &adminInfo))
231 mainStructVal["result"] = xmlrpc_c::value_boolean(false);
232 *retvalPtr = xmlrpc_c::value_struct(mainStructVal);
237 int h = admins->OpenSearch();
239 while (admins->SearchNext(h, &ac) == 0)
241 std::map<std::string, xmlrpc_c::value> structVal;
242 structVal["result"] = xmlrpc_c::value_boolean(true);
243 structVal["login"] = xmlrpc_c::value_string(ac.login);
244 structVal["password"] = xmlrpc_c::value_string(ac.password);
245 structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
246 structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
247 structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
248 structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
249 structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
250 structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
251 structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
253 retval.push_back(xmlrpc_c::value_struct(structVal));
256 *retvalPtr = xmlrpc_c::value_array(retval);