X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/91b5ae18ae465d0887785aab6dc0eb7abc0d5488..1c324d5b2380a68f209e65969079677dbaf1c511:/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp diff --git a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp index f36debc4..d8fb0123 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp @@ -1,7 +1,13 @@ #include "admins_methods.h" - #include "rpcconfig.h" -#include "common.h" + +#include "stg/common.h" + +#include "stg/admins.h" +#include "stg/admin.h" +#include "stg/admin_conf.h" + +#include // xmlrpc-c devs have missed something :) //------------------------------------------------------------------------------ @@ -22,9 +28,9 @@ if (config->GetAdminInfo(cookie, &adminInfo)) 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); @@ -32,18 +38,18 @@ if (admins->FindAdmin(login, &admin)) } 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); } @@ -66,16 +72,16 @@ if (config->GetAdminInfo(cookie, &adminInfo)) 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); @@ -94,7 +100,6 @@ std::string cookie = paramList.getString(0); std::string login = paramList.getString(1); paramList.verifyEnd(2); -std::map structVal; ADMIN_INFO adminInfo; if (config->GetAdminInfo(cookie, &adminInfo)) @@ -103,15 +108,15 @@ 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; @@ -138,31 +143,29 @@ if (config->GetAdminInfo(cookie, &adminInfo)) 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 structVal( - static_cast >(xmlrpc_c::value_struct(info)) - ); +std::map structVal = info; std::map::iterator it; @@ -206,7 +209,7 @@ if ((it = structVal.find("tariff_chg")) != structVal.end()) 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); } @@ -222,36 +225,33 @@ void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList, std::string cookie = paramList.getString(0); paramList.verifyEnd(1); -std::map structVal; +std::map mainStructVal; std::vector 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 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 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); }