#include "stg/servconf.h"
#include "stg/servconf_types.h"
-#include "stg/os_int.h"
+#include "stg/admin_conf.h"
#include <iostream>
#include <string>
#include <map>
+#include <cstdint>
#include <cassert>
namespace
return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
}
-std::string PrivToString(const PRIV& priv)
+std::string PrivToString(const STG::Priv& priv)
{
return std::string("") +
(priv.corpChg ? "1" : "0") +
(priv.userStat ? "1" : "0");
}
-void PrintAdmin(const STG::GET_ADMIN::INFO & info, size_t level = 0)
+void PrintAdmin(const STG::GetAdmin::Info & info, size_t level = 0)
{
std::cout << Indent(level, true) << "login: " << info.login << "\n"
<< Indent(level) << "priviledges: " << PrivToString(info.priv) << "\n";
return params;
}
-void ConvPriv(const std::string & value, RESETABLE<PRIV> & res)
+void ConvPriv(const std::string & value, STG::Optional<STG::Priv> & res)
{
if (value.length() != 9)
throw SGCONF::ACTION::ERROR("Priviledges value should be a 9-digits length binary number.");
-PRIV priv;
+STG::Priv priv;
priv.corpChg = (value[0] == '0' ? 0 : 1);
priv.serviceChg = (value[1] == '0' ? 0 : 1);
priv.tariffChg = (value[2] == '0' ? 0 : 1);
void GetAdminsCallback(bool result,
const std::string & reason,
- const std::vector<STG::GET_ADMIN::INFO> & info,
+ const std::vector<STG::GetAdmin::Info> & info,
void * /*data*/)
{
if (!result)
void GetAdminCallback(bool result,
const std::string & reason,
- const std::vector<STG::GET_ADMIN::INFO> & info,
+ const std::vector<STG::GetAdmin::Info> & info,
void * data)
{
assert(data != NULL && "Expecting pointer to std::string with the admin's login.");
const std::string & /*arg*/,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
+STG::ServConf proto(config.server.data(),
config.port.data(),
+ config.localAddress.data(),
+ config.localPort.data(),
config.userName.data(),
config.userPass.data());
return proto.GetAdmins(GetAdminsCallback, NULL) == STG::st_ok;
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
+STG::ServConf proto(config.server.data(),
config.port.data(),
+ config.localAddress.data(),
+ config.localPort.data(),
config.userName.data(),
config.userPass.data());
// STG currently doesn't support <GetAdmin login="..."/>.
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
+STG::ServConf proto(config.server.data(),
config.port.data(),
+ config.localAddress.data(),
+ config.localPort.data(),
config.userName.data(),
config.userPass.data());
return proto.DelAdmin(arg, SimpleCallback, NULL) == STG::st_ok;
const std::string & arg,
const std::map<std::string, std::string> & options)
{
-// TODO
-ADMIN_CONF_RES conf;
+STG::AdminConfOpt conf;
conf.login = arg;
SGCONF::MaybeSet(options, "priv", conf.priv, ConvPriv);
SGCONF::MaybeSet(options, "password", conf.password);
-STG::SERVCONF proto(config.server.data(),
+STG::ServConf proto(config.server.data(),
config.port.data(),
+ config.localAddress.data(),
+ config.localPort.data(),
config.userName.data(),
config.userPass.data());
return proto.AddAdmin(arg, conf, SimpleCallback, NULL) == STG::st_ok;
const std::string & arg,
const std::map<std::string, std::string> & options)
{
-// TODO
-std::cerr << "Unimplemented.\n";
-return false;
+STG::AdminConfOpt conf;
+conf.login = arg;
+SGCONF::MaybeSet(options, "priv", conf.priv, ConvPriv);
+SGCONF::MaybeSet(options, "password", conf.password);
+STG::ServConf proto(config.server.data(),
+ config.port.data(),
+ config.localAddress.data(),
+ config.localPort.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.ChgAdmin(conf, SimpleCallback, NULL) == STG::st_ok;
}
} // namespace anonymous