git.stg.codes
/
stg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Radius. (#8)
[stg.git]
/
projects
/
sgconf
/
admins.cpp
diff --git
a/projects/sgconf/admins.cpp
b/projects/sgconf/admins.cpp
index 6a59fa28b182f6c90e4389fe2743d67be64cef01..c0700e313c2e3da5b6808d9ce8153acb50f52653 100644
(file)
--- a/
projects/sgconf/admins.cpp
+++ b/
projects/sgconf/admins.cpp
@@
-2,16
+2,18
@@
#include "api_action.h"
#include "options.h"
#include "api_action.h"
#include "options.h"
+#include "makeproto.h"
#include "config.h"
#include "utils.h"
#include "stg/servconf.h"
#include "stg/servconf_types.h"
#include "config.h"
#include "utils.h"
#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 <iostream>
#include <string>
#include <map>
+#include <cstdint>
#include <cassert>
namespace
#include <cassert>
namespace
@@
-24,7
+26,7
@@
if (level == 0)
return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
}
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") +
{
return std::string("") +
(priv.corpChg ? "1" : "0") +
@@
-38,7
+40,7
@@
return std::string("") +
(priv.userStat ? "1" : "0");
}
(priv.userStat ? "1" : "0");
}
-void PrintAdmin(const STG::G
ET_ADMIN::INFO
& info, size_t level = 0)
+void PrintAdmin(const STG::G
etAdmin::Info
& info, size_t level = 0)
{
std::cout << Indent(level, true) << "login: " << info.login << "\n"
<< Indent(level) << "priviledges: " << PrivToString(info.priv) << "\n";
{
std::cout << Indent(level, true) << "login: " << info.login << "\n"
<< Indent(level) << "priviledges: " << PrivToString(info.priv) << "\n";
@@
-52,11
+54,11
@@
params.push_back(SGCONF::API_ACTION::PARAM("priv", "<priv>", "priviledges"));
return params;
}
return params;
}
-void ConvPriv(const std::string & value,
RESETABLE<PRIV
> & res)
+void ConvPriv(const std::string & value,
std::optional<STG::Priv
> & res)
{
if (value.length() != 9)
throw SGCONF::ACTION::ERROR("Priviledges value should be a 9-digits length binary number.");
{
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);
priv.corpChg = (value[0] == '0' ? 0 : 1);
priv.serviceChg = (value[1] == '0' ? 0 : 1);
priv.tariffChg = (value[2] == '0' ? 0 : 1);
@@
-83,7
+85,7
@@
std::cout << "Success.\n";
void GetAdminsCallback(bool result,
const std::string & reason,
void GetAdminsCallback(bool result,
const std::string & reason,
- const std::vector<STG::G
ET_ADMIN::INFO
> & info,
+ const std::vector<STG::G
etAdmin::Info
> & info,
void * /*data*/)
{
if (!result)
void * /*data*/)
{
if (!result)
@@
-98,7
+100,7
@@
for (size_t i = 0; i < info.size(); ++i)
void GetAdminCallback(bool result,
const std::string & reason,
void GetAdminCallback(bool result,
const std::string & reason,
- const std::vector<STG::G
ET_ADMIN::INFO
> & info,
+ const std::vector<STG::G
etAdmin::Info
> & info,
void * data)
{
assert(data != NULL && "Expecting pointer to std::string with the admin's login.");
void * data)
{
assert(data != NULL && "Expecting pointer to std::string with the admin's login.");
@@
-118,60
+120,46
@@
bool GetAdminsFunction(const SGCONF::CONFIG & config,
const std::string & /*arg*/,
const std::map<std::string, std::string> & /*options*/)
{
const std::string & /*arg*/,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.GetAdmins(GetAdminsCallback, NULL) == STG::st_ok;
+return makeProto(config).GetAdmins(GetAdminsCallback, NULL) == STG::st_ok;
}
bool GetAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
}
bool GetAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.userName.data(),
- config.userPass.data());
// STG currently doesn't support <GetAdmin login="..."/>.
// So get a list of admins and filter it. 'data' param holds a pointer to 'login'.
std::string login(arg);
// STG currently doesn't support <GetAdmin login="..."/>.
// So get a list of admins and filter it. 'data' param holds a pointer to 'login'.
std::string login(arg);
-return
proto
.GetAdmins(GetAdminCallback, &login) == STG::st_ok;
+return
makeProto(config)
.GetAdmins(GetAdminCallback, &login) == STG::st_ok;
}
bool DelAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
}
bool DelAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & /*options*/)
{
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.DelAdmin(arg, SimpleCallback, NULL) == STG::st_ok;
+return makeProto(config).DelAdmin(arg, SimpleCallback, NULL) == STG::st_ok;
}
bool AddAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
}
bool AddAdminFunction(const SGCONF::CONFIG & config,
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);
conf.login = arg;
SGCONF::MaybeSet(options, "priv", conf.priv, ConvPriv);
-STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.userName.data(),
- config.userPass.data());
-return proto.AddAdmin(arg, conf, SimpleCallback, NULL) == STG::st_ok;
+SGCONF::MaybeSet(options, "password", conf.password);
+return makeProto(config).AddAdmin(arg, conf, SimpleCallback, NULL) == STG::st_ok;
}
bool ChgAdminFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
}
bool ChgAdminFunction(const SGCONF::CONFIG & config,
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);
+return makeProto(config).ChgAdmin(conf, SimpleCallback, NULL) == STG::st_ok;
}
} // namespace anonymous
}
} // namespace anonymous