From: Maxim Mamontov Date: Fri, 26 Jul 2013 18:22:09 +0000 (+0300) Subject: Added XML RPC method for getting user's authorizers. X-Git-Tag: 2.409~352 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/a94639179750883b1120be2f5d01bbb38eaa0928?ds=sidebyside Added XML RPC method for getting user's authorizers. --- diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index e84e9a0e..dca87fbe 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -473,5 +473,11 @@ xmlrpc_c::methodPtr const methodGetOnlinIPsPtr(new METHOD_GET_ONLINE_IPS( users )); rpcRegistry.addMethod("stargazer.get_online_ips", methodGetOnlinIPsPtr); + +xmlrpc_c::methodPtr const methodGetUserAuthByPtr(new METHOD_GET_USER_AUTH_BY( + this, + users + )); +rpcRegistry.addMethod("stargazer.get_user_auth_by", methodGetUserAuthByPtr); } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 9eabced6..5adbf441 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -509,3 +509,36 @@ ipm.mask = htonl(0xffFFffFF << (32 - ipm.mask)); return false; } + +void METHOD_GET_USER_AUTH_BY::execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalPtr) +{ +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)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +USER_PTR u; + +if (users->FindByName(login, &u)) + { + structVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(structVal); + return; + } + +std::vector list(u->GetAuthorizers()); +std::vector authList; +for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + authList.push_back(xmlrpc_c::value_string(*it)); +*retvalPtr = xmlrpc_c::value_array(authList); +} diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h index 413e9aaf..d1ec33a4 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.h @@ -229,4 +229,24 @@ private: bool ParseNet(const std::string & net, IP_MASK & ipm) const; }; +class METHOD_GET_USER_AUTH_BY : public xmlrpc_c::method { +public: + METHOD_GET_USER_AUTH_BY(RPC_CONFIG * c, + USERS * u) + : config(c), + users(u) + { + } + + void execute(xmlrpc_c::paramList const & paramList, + xmlrpc_c::value * const retvalP); + +private: + METHOD_GET_USER_AUTH_BY(const METHOD_GET_ONLINE_IPS & rvalue); + METHOD_GET_USER_AUTH_BY & operator=(const METHOD_GET_ONLINE_IPS & rvalue); + + RPC_CONFIG * config; + USERS * users; +}; + #endif