#include "admins_methods.h"
-
#include "rpcconfig.h"
+#include "stg/common.h"
+
+#include "stg/admins.h"
+#include "stg/admin.h"
+#include "stg/admin_conf.h"
+
+#include <ostream> // xmlrpc-c devs have missed something :)
+
//------------------------------------------------------------------------------
void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
return;
}
-ADMIN admin;
+STG::Admin * admin;
-if (admins->FindAdmin(login, &admin))
+if (admins->find(login, &admin))
{
structVal["result"] = xmlrpc_c::value_boolean(false);
*retvalPtr = xmlrpc_c::value_struct(structVal);
}
structVal["result"] = xmlrpc_c::value_boolean(true);
-structVal["login"] = xmlrpc_c::value_string(admin.GetLogin());
-structVal["password"] = xmlrpc_c::value_string(admin.GetPassword());
+structVal["login"] = xmlrpc_c::value_string(admin->login());
+structVal["password"] = xmlrpc_c::value_string(admin->password());
-const PRIV * priv = admin.GetPriv();
+const auto priv = admin->priv();
-structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
-structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
-structVal["user_cash"] = xmlrpc_c::value_boolean(priv->userCash);
-structVal["user_passwd"] = xmlrpc_c::value_boolean(priv->userPasswd);
-structVal["user_add_del"] = xmlrpc_c::value_boolean(priv->userAddDel);
-structVal["admin_chg"] = xmlrpc_c::value_boolean(priv->adminChg);
-structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv->tariffChg);
+structVal["user_stat"] = xmlrpc_c::value_boolean(priv.userStat);
+structVal["user_conf"] = xmlrpc_c::value_boolean(priv.userConf);
+structVal["user_cash"] = xmlrpc_c::value_boolean(priv.userCash);
+structVal["user_passwd"] = xmlrpc_c::value_boolean(priv.userPasswd);
+structVal["user_add_del"] = xmlrpc_c::value_boolean(priv.userAddDel);
+structVal["admin_chg"] = xmlrpc_c::value_boolean(priv.adminChg);
+structVal["tariff_chg"] = xmlrpc_c::value_boolean(priv.tariffChg);
*retvalPtr = xmlrpc_c::value_struct(structVal);
}
return;
}
-ADMIN admin;
+STG::Admin * admin;
-if (admins->FindAdmin(adminInfo.admin, &admin))
+if (admins->find(adminInfo.admin, &admin))
{
printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Invalid admin (logged)'\n");
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
}
-if (admins->Add(login, admin))
+if (admins->add(login, *admin))
{
printfd(__FILE__, "METHOD_ADMIN_ADD::execute(): 'Failed to add admin'\n");
*retvalPtr = xmlrpc_c::value_boolean(false);
std::string login = paramList.getString(1);
paramList.verifyEnd(2);
-std::map<std::string, xmlrpc_c::value> structVal;
ADMIN_INFO adminInfo;
if (config->GetAdminInfo(cookie, &adminInfo))
return;
}
-ADMIN admin;
+STG::Admin * admin;
-if (admins->FindAdmin(adminInfo.admin, &admin))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
}
-if (admins->Del(login, admin))
+if (admins->del(login, *admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
return;
}
-ADMIN loggedAdmin;
+STG::Admin * loggedAdmin;
-if (admins->FindAdmin(adminInfo.admin, &loggedAdmin))
+if (admins->find(adminInfo.admin, &loggedAdmin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
}
-ADMIN admin;
+STG::Admin * admin;
-if (admins->FindAdmin(login, &admin))
+if (admins->find(login, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
}
-ADMIN_CONF conf;
+STG::AdminConf conf;
-conf.priv = *admin.GetPriv();
-conf.password = admin.GetPassword();
+conf.priv = admin->priv();
+conf.password = admin->password();
conf.login = login;
-std::map<std::string, xmlrpc_c::value> structVal(
- static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
- );
+std::map<std::string, xmlrpc_c::value> structVal = info;
std::map<std::string, xmlrpc_c::value>::iterator it;
conf.priv.tariffChg = xmlrpc_c::value_boolean(it->second);
}
-if (admins->Change(conf, loggedAdmin))
+if (admins->change(conf, *loggedAdmin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
}
std::string cookie = paramList.getString(0);
paramList.verifyEnd(1);
-std::map<std::string, xmlrpc_c::value> structVal;
+std::map<std::string, xmlrpc_c::value> mainStructVal;
std::vector<xmlrpc_c::value> retval;
ADMIN_INFO adminInfo;
if (config->GetAdminInfo(cookie, &adminInfo))
{
- structVal["result"] = xmlrpc_c::value_boolean(false);
- *retvalPtr = xmlrpc_c::value_struct(structVal);
+ mainStructVal["result"] = xmlrpc_c::value_boolean(false);
+ *retvalPtr = xmlrpc_c::value_struct(mainStructVal);
return;
}
-ADMIN_CONF ac;
-int h = admins->OpenSearch();
-
-while (admins->SearchNext(h, &ac) == 0)
+admins->fmap([&retval](const auto& admin)
{
- std::map<std::string, xmlrpc_c::value> structVal;
- structVal["result"] = xmlrpc_c::value_boolean(true);
- structVal["login"] = xmlrpc_c::value_string(ac.login);
- structVal["password"] = xmlrpc_c::value_string(ac.password);
- structVal["user_stat"] = xmlrpc_c::value_boolean(ac.priv.userStat);
- structVal["user_conf"] = xmlrpc_c::value_boolean(ac.priv.userConf);
- structVal["user_cash"] = xmlrpc_c::value_boolean(ac.priv.userCash);
- structVal["user_passwd"] = xmlrpc_c::value_boolean(ac.priv.userPasswd);
- structVal["user_add_del"] = xmlrpc_c::value_boolean(ac.priv.userAddDel);
- structVal["admin_chg"] = xmlrpc_c::value_boolean(ac.priv.adminChg);
- structVal["tariff_chg"] = xmlrpc_c::value_boolean(ac.priv.tariffChg);
-
- retval.push_back(xmlrpc_c::value_struct(structVal));
- }
+ const std::map<std::string, xmlrpc_c::value> structVal{
+ {"result", xmlrpc_c::value_boolean(true)},
+ {"login", xmlrpc_c::value_string(admin.login())},
+ {"password", xmlrpc_c::value_string(admin.password())},
+ {"user_stat", xmlrpc_c::value_boolean(admin.priv().userStat)},
+ {"user_conf", xmlrpc_c::value_boolean(admin.priv().userConf)},
+ {"user_cash", xmlrpc_c::value_boolean(admin.priv().userCash)},
+ {"user_passwd", xmlrpc_c::value_boolean(admin.priv().userPasswd)},
+ {"user_add_del", xmlrpc_c::value_boolean(admin.priv().userAddDel)},
+ {"admin_chg", xmlrpc_c::value_boolean(admin.priv().adminChg)},
+ {"tariff_chg", xmlrpc_c::value_boolean(admin.priv().tariffChg)}
+ };
+ retval.push_back(xmlrpc_c::value_struct(structVal));
+ });
*retvalPtr = xmlrpc_c::value_array(retval);
}