X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/78c67dad18539233b81cfb16144339dc389d5981..7ef8de40e0bcdd931f5a400fd586fee3a1aaaeea:/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 0016babe..d8fb0123 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp @@ -1,9 +1,14 @@ -#include // xmlrpc-c devs have missed something :) - -#include "stg/common.h" #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 // xmlrpc-c devs have missed something :) + //------------------------------------------------------------------------------ void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList, @@ -23,9 +28,9 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN * admin; +STG::Admin * admin; -if (admins->Find(login, &admin)) +if (admins->find(login, &admin)) { structVal["result"] = xmlrpc_c::value_boolean(false); *retvalPtr = xmlrpc_c::value_struct(structVal); @@ -33,18 +38,18 @@ if (admins->Find(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); } @@ -67,16 +72,16 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN * admin; +STG::Admin * admin; -if (admins->Find(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); @@ -95,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)) @@ -104,15 +108,15 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN * admin; +STG::Admin * admin; -if (admins->Find(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; @@ -139,31 +143,29 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -ADMIN * loggedAdmin; +STG::Admin * loggedAdmin; -if (admins->Find(adminInfo.admin, &loggedAdmin)) +if (admins->find(adminInfo.admin, &loggedAdmin)) { *retvalPtr = xmlrpc_c::value_boolean(false); return; } -ADMIN * admin; +STG::Admin * admin; -if (admins->Find(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; @@ -207,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); } @@ -223,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); }