X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/02be813c72c75c61beaef0266bd5adf713e67b42..a5cb4cf37e5dfa9bb9ce5c5e4ccf8d5978d3576f:/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 3607a806..d8fb0123 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp @@ -1,7 +1,14 @@ -#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, @@ -21,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); @@ -31,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); } @@ -65,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); @@ -93,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)) @@ -102,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; @@ -137,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; @@ -205,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); } @@ -221,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); }