-#include <ostream> // 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 <ostream> // xmlrpc-c devs have missed something :)
+
//------------------------------------------------------------------------------
void METHOD_ADMIN_GET::execute(xmlrpc_c::paramList const & paramList,
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(login, &admin))
{
structVal["login"] = xmlrpc_c::value_string(admin->GetLogin());
structVal["password"] = xmlrpc_c::value_string(admin->GetPassword());
-const PRIV * priv = admin->GetPriv();
+const auto priv = admin->GetPriv();
structVal["user_stat"] = xmlrpc_c::value_boolean(priv->userStat);
structVal["user_conf"] = xmlrpc_c::value_boolean(priv->userConf);
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-ADMIN * loggedAdmin;
+STG::Admin * loggedAdmin;
if (admins->Find(adminInfo.admin, &loggedAdmin))
{
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(login, &admin))
{
return;
}
-ADMIN_CONF conf;
+STG::AdminConf conf;
conf.priv = *admin->GetPriv();
conf.password = admin->GetPassword();
return;
}
-ADMIN_CONF ac;
+STG::AdminConf ac;
int h = admins->OpenSearch();
while (admins->SearchNext(h, &ac) == 0)
-#ifndef __ADMINS_METHODS_H__
-#define __ADMINS_METHODS_H__
+#pragma once
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
-#include "stg/admins.h"
-#include "stg/admin.h"
+namespace STG
+{
+
+struct Admins;
+
+}
class RPC_CONFIG;
class METHOD_ADMIN_GET : public xmlrpc_c::method {
public:
METHOD_ADMIN_GET(RPC_CONFIG * c,
- ADMINS * a)
+ STG::Admins * a)
: config(c),
admins(a)
{
METHOD_ADMIN_GET & operator=(const METHOD_ADMIN_GET & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
+ STG::Admins * admins;
};
class METHOD_ADMIN_ADD : public xmlrpc_c::method {
public:
METHOD_ADMIN_ADD(RPC_CONFIG * c,
- ADMINS * a)
+ STG::Admins * a)
: config(c),
admins(a)
{
METHOD_ADMIN_ADD & operator=(const METHOD_ADMIN_ADD & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
+ STG::Admins * admins;
};
class METHOD_ADMIN_DEL : public xmlrpc_c::method {
public:
METHOD_ADMIN_DEL(RPC_CONFIG * c,
- ADMINS * a)
+ STG::Admins * a)
: config(c),
admins(a)
{
METHOD_ADMIN_DEL & operator=(const METHOD_ADMIN_DEL & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
+ STG::Admins * admins;
};
class METHOD_ADMIN_CHG : public xmlrpc_c::method {
public:
METHOD_ADMIN_CHG(RPC_CONFIG * c,
- ADMINS * a)
+ STG::Admins * a)
: config(c),
admins(a)
{
METHOD_ADMIN_CHG & operator=(const METHOD_ADMIN_CHG & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
+ STG::Admins * admins;
};
class METHOD_ADMINS_GET : public xmlrpc_c::method {
public:
METHOD_ADMINS_GET(RPC_CONFIG * c,
- ADMINS * a)
+ STG::Admins * a)
: config(c),
admins(a)
{
METHOD_ADMINS_GET & operator=(const METHOD_ADMINS_GET & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
+ STG::Admins * admins;
};
-
-#endif
-#include <sys/utsname.h>
-
-#include <ostream> // xmlrpc-c devs have missed something :)
+#include "info_methods.h"
+#include "rpcconfig.h"
+#include "stg/users.h"
+#include "stg/tariffs.h"
#include "stg/version.h"
#include "stg/common.h"
-#include "info_methods.h"
-#include "rpcconfig.h"
+#include "stg/const.h"
+
+#include <ostream> // xmlrpc-c devs have missed something :)
+
+#include <sys/utsname.h>
void METHOD_INFO::execute(xmlrpc_c::paramList const & paramList,
xmlrpc_c::value * const retvalPtr)
-#ifndef __INFO_METHODS_H__
-#define __INFO_METHODS_H__
+#pragma once
+
+#include <xmlrpc-c/base.hpp>
+#include <xmlrpc-c/registry.hpp>
#include <string>
#include <vector>
-#include <xmlrpc-c/base.hpp>
-#include <xmlrpc-c/registry.hpp>
+namespace STG
+{
-#include "stg/users.h"
-#include "stg/tariffs.h"
+struct Settings;
+struct Users;
+struct Tariffs;
+
+}
// Forward declaration
class RPC_CONFIG;
-class SETTINGS;
class METHOD_INFO : public xmlrpc_c::method
{
public:
- METHOD_INFO(TARIFFS * t,
- USERS * u,
+ METHOD_INFO(STG::Tariffs * t,
+ STG::Users * u,
size_t df,
const std::vector<std::string> & dn)
: tariffs(t),
METHOD_INFO(const METHOD_INFO & rvalue);
METHOD_INFO & operator=(const METHOD_INFO & rvalue);
- TARIFFS * tariffs;
- USERS * users;
+ STG::Tariffs * tariffs;
+ STG::Users * users;
size_t dayFee;
const std::vector<std::string> & dirNames;
};
RPC_CONFIG * config;
};
-
-#endif
-#include <ostream> // xmlrpc-c devs have missed something :)
+#include "messages_methods.h"
+#include "rpcconfig.h"
+#include "stg/users.h"
+#include "stg/user.h"
#include "stg/message.h"
#include "stg/common.h"
-#include "messages_methods.h"
-#include "rpcconfig.h"
+
+#include <ostream> // xmlrpc-c devs have missed something :)
extern volatile time_t stgTime;
return;
}
-STG_MSG message;
+STG::Message message;
std::map<std::string, xmlrpc_c::value>::iterator it;
std::vector<xmlrpc_c::value>::iterator lit;
for (lit = logins.begin(); lit != logins.end(); ++lit)
{
- USER_PTR ui;
+ using UserPtr = STG::User*;
+ UserPtr ui;
if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
{
printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
-#ifndef __MESSAGES_METHODS_H__
-#define __MESSAGES_METHODS_H__
+#pragma once
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
-#include "stg/users.h"
+namespace STG
+{
+
+struct Users;
+
+}
class RPC_CONFIG;
class METHOD_MESSAGE_SEND : public xmlrpc_c::method {
public:
METHOD_MESSAGE_SEND(RPC_CONFIG * c,
- USERS * u)
+ STG::Users * u)
: config(c),
users(u)
{
METHOD_MESSAGE_SEND & operator=(const METHOD_MESSAGE_SEND & rvalue);
RPC_CONFIG * config;
- USERS * users;
+ STG::Users * users;
};
-
-#endif
-
#include "rpcconfig.h"
+
#include "info_methods.h"
#include "users_methods.h"
#include "tariffs_methods.h"
#include "admins_methods.h"
#include "messages_methods.h"
-#include "stg/common.h"
+#include "stg/admins.h"
#include "stg/admin.h"
#include "stg/module_settings.h"
#include "stg/settings.h"
+#include "stg/common.h"
+#include "stg/const.h"
#include <algorithm>
#include <vector>
{
}
-int RPC_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
+int RPC_CONFIG_SETTINGS::ParseSettings(const STG::ModuleSettings & s)
{
-PARAM_VALUE pv;
+STG::ParamValue pv;
pv.param = "Port";
-std::vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<STG::ParamValue>::const_iterator pvi;
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end() || pvi->value.empty())
{
return 0;
}
-extern "C" Plugin* GetPlugin()
+extern "C" STG::Plugin* GetPlugin()
{
static RPC_CONFIG plugin;
return &plugin;
running(false),
stopped(true),
dayFee(0),
- logger(PluginLogger::get("conf_rpc"))
+ logger(STG::PluginLogger::get("conf_rpc"))
{
}
return ret;
}
-void RPC_CONFIG::SetStgSettings(const SETTINGS * s)
+void RPC_CONFIG::SetStgSettings(const STG::Settings * s)
{
dayFee = s->GetDayFee();
dirNames.erase(dirNames.begin(), dirNames.end());
const std::string & password,
std::string * cookie)
{
-ADMIN * admin = NULL;
+STG::Admin * admin = NULL;
if (!admins->Correct(login, password, &admin))
{
-#ifndef __RPC_CONFIG_H__
-#define __RPC_CONFIG_H__
+#pragma once
-#include <pthread.h>
+#include "stg/plugin.h"
+#include "stg/admin_conf.h"
+#include "stg/module_settings.h"
+#include "stg/logger.h"
+
+#include <xmlrpc-c/base.hpp>
+#include <xmlrpc-c/registry.hpp>
+#include <xmlrpc-c/server_abyss.hpp>
#include <ctime>
#include <cstdint>
#include <map>
#include <vector>
-#include <xmlrpc-c/base.hpp>
-#include <xmlrpc-c/registry.hpp>
-#include <xmlrpc-c/server_abyss.hpp>
-
-#include "stg/plugin.h"
-#include "stg/admin_conf.h"
-#include "stg/module_settings.h"
-#include "stg/logger.h"
+#include <pthread.h>
#define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
-class ADMINS;
-class TARIFFS;
-class USERS;
-class STORE;
+namespace STG
+{
+
+struct Admins;
+struct Tariffs;
+struct Users;
+struct Store;
+
+}
class RPC_CONFIG_SETTINGS
{
RPC_CONFIG_SETTINGS();
virtual ~RPC_CONFIG_SETTINGS() {}
const std::string & GetStrError() const { return errorStr; }
- int ParseSettings(const MODULE_SETTINGS & s);
+ int ParseSettings(const STG::ModuleSettings & s);
uint16_t GetPort() const { return port; }
double GetCookieTimeout() const { return cookieTimeout; }
std::string admin;
time_t accessTime;
- PRIV priviledges;
+ STG::Priv priviledges;
};
-class RPC_CONFIG : public PLUGIN
+class RPC_CONFIG : public STG::Plugin
{
public:
RPC_CONFIG();
- virtual ~RPC_CONFIG();
-
- void SetUsers(USERS * u) { users = u; }
- void SetTariffs(TARIFFS * t) { tariffs = t; }
- void SetAdmins(ADMINS * a) { admins = a; }
- void SetStore(STORE * s) { store = s; }
- void SetStgSettings(const SETTINGS * s);
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
- int ParseSettings();
-
- int Start();
- int Stop();
- int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
- bool IsRunning() { return running && !stopped; }
-
- const std::string & GetStrError() const { return errorStr; }
- std::string GetVersion() const { return RPC_CONFIG_VERSION; }
- uint16_t GetStartPosition() const { return 20; }
- uint16_t GetStopPosition() const { return 20; }
+ ~RPC_CONFIG() override;
+
+ void SetUsers(STG::Users * u) override { users = u; }
+ void SetTariffs(STG::Tariffs * t) override { tariffs = t; }
+ void SetAdmins(STG::Admins * a) override { admins = a; }
+ void SetStore(STG::Store * s) override { store = s; }
+ void SetStgSettings(const STG::Settings * s) override;
+ void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+ int ParseSettings() override;
+
+ int Start() override;
+ int Stop() override;
+ int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
+ bool IsRunning() override { return running && !stopped; }
+
+ const std::string & GetStrError() const override { return errorStr; }
+ std::string GetVersion() const override { return RPC_CONFIG_VERSION; }
+ uint16_t GetStartPosition() const override { return 20; }
+ uint16_t GetStopPosition() const override { return 20; }
bool GetAdminInfo(const std::string & cookie,
ADMIN_INFO * info);
mutable std::string errorStr;
RPC_CONFIG_SETTINGS rpcConfigSettings;
- USERS * users;
- ADMINS * admins;
- TARIFFS * tariffs;
- STORE * store;
- MODULE_SETTINGS settings;
+ STG::Users * users;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
+ STG::Store * store;
+ STG::ModuleSettings settings;
int fd;
xmlrpc_c::registry rpcRegistry;
xmlrpc_c::serverAbyss * rpcServer;
ADMIN_INFO> cookies;
size_t dayFee;
std::vector<std::string> dirNames;
- PLUGIN_LOGGER logger;
+ STG::PluginLogger logger;
};
-
-#endif
-#include <ostream> // xmlrpc-c devs have missed something :)
-
#include "tariff_helper.h"
+
+#include "stg/tariff_conf.h"
#include "stg/common.h"
+#include "stg/const.h"
+
+#include <ostream> // xmlrpc-c devs have missed something :)
void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
{
structVal["freemb"] = xmlrpc_c::value_double(data.tariffConf.free);
structVal["passivecost"] = xmlrpc_c::value_double(data.tariffConf.passiveCost);
structVal["traffType"] = xmlrpc_c::value_int(data.tariffConf.traffType);
-structVal["period"] = xmlrpc_c::value_string(TARIFF::PeriodToString(data.tariffConf.period));
-structVal["changePolicy"] = xmlrpc_c::value_string(TARIFF::ChangePolicyToString(data.tariffConf.changePolicy));
+structVal["period"] = xmlrpc_c::value_string(STG::Tariff::toString(data.tariffConf.period));
+structVal["changePolicy"] = xmlrpc_c::value_string(STG::Tariff::toString(data.tariffConf.changePolicy));
structVal["changePolicyTimeout"] = xmlrpc_c::value_string(formatTime(data.tariffConf.changePolicyTimeout));
std::vector<xmlrpc_c::value> prices(DIR_NUM);
if ((it = structVal.find("traffType")) != structVal.end())
{
- data.tariffConf.traffType = static_cast<TARIFF::TRAFF_TYPE>(xmlrpc_c::value_int(it->second).cvalue());
+ data.tariffConf.traffType = static_cast<STG::Tariff::TraffType>(xmlrpc_c::value_int(it->second).cvalue());
}
if ((it = structVal.find("period")) != structVal.end())
{
- data.tariffConf.period = TARIFF::StringToPeriod(xmlrpc_c::value_string(it->second));
+ data.tariffConf.period = STG::Tariff::parsePeriod(xmlrpc_c::value_string(it->second));
}
if ((it = structVal.find("changePolicy")) != structVal.end())
{
- data.tariffConf.changePolicy = TARIFF::StringToChangePolicy(xmlrpc_c::value_string(it->second));
+ data.tariffConf.changePolicy = STG::Tariff::parseChangePolicy(xmlrpc_c::value_string(it->second));
}
if ((it = structVal.find("changePolicyTimeout")) != structVal.end())
-#ifndef __TARIFF_HELPER_H__
-#define __TARIFF_HELPER_H__
+#pragma once
#include <xmlrpc-c/base.hpp>
-#include "stg/tariff_conf.h"
+
+namespace STG
+{
+
+struct TariffData;
+
+}
class TARIFF_HELPER
{
public:
- explicit TARIFF_HELPER(TARIFF_DATA & td)
+ explicit TARIFF_HELPER(STG::TariffData & td)
: data(td)
{}
void GetTariffInfo(xmlrpc_c::value * info) const;
bool SetTariffInfo(const xmlrpc_c::value & info);
private:
- TARIFF_DATA & data;
+ STG::TariffData & data;
};
-
-#endif
-
-
#include "tariffs_methods.h"
#include "rpcconfig.h"
#include "tariff_helper.h"
+
#include "stg/tariffs.h"
+#include "stg/tariff.h"
+#include "stg/tariff_conf.h"
#include "stg/users.h"
#include "stg/admins.h"
#include "stg/admin.h"
return;
}
-const TARIFF * tariff = tariffs->FindByName(name);
+const auto tariff = tariffs->FindByName(name);
if (!tariff)
{
return;
}
-TARIFF_DATA td(tariff->GetTariffData());
+auto td = tariff->GetTariffData();
TARIFF_HELPER helper(td);
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-const TARIFF * tariff = tariffs->FindByName(name);
+const auto tariff = tariffs->FindByName(name);
if (!tariff)
{
return;
}
-TARIFF_DATA td(tariff->GetTariffData());
+auto td = tariff->GetTariffData();
TARIFF_HELPER helper(td);
std::vector<xmlrpc_c::value> tariffsInfo;
-std::vector<TARIFF_DATA> dataList;
+std::vector<STG::TariffData> dataList;
tariffs->GetTariffsData(&dataList);
auto it = dataList.begin();
for (; it != dataList.end(); ++it)
{
xmlrpc_c::value info;
- TARIFF_DATA td(*it); // 'cause TARIFF_HELPER work in both ways and take not const referense
+ auto td = *it; // 'cause TARIFF_HELPER work in both ways and take not const referense
TARIFF_HELPER helper(td);
helper.GetTariffInfo(&info);
tariffsInfo.push_back(info);
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
-#ifndef __TARIFFS_METHODS_H__
-#define __TARIFFS_METHODS_H__
+#pragma once
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
+namespace STG
+{
+
+struct Tariffs;
+struct Users;
+struct Admins;
+
+}
+
class RPC_CONFIG;
-class TARIFFS;
-class USERS;
-class ADMINS;
class METHOD_TARIFF_GET : public xmlrpc_c::method {
public:
METHOD_TARIFF_GET(RPC_CONFIG * c,
- TARIFFS * t)
+ STG::Tariffs * t)
: config(c),
tariffs(t)
{
METHOD_TARIFF_GET & operator=(const METHOD_TARIFF_GET & rvalue);
RPC_CONFIG * config;
- TARIFFS * tariffs;
+ STG::Tariffs * tariffs;
};
class METHOD_TARIFF_CHG : public xmlrpc_c::method {
public:
METHOD_TARIFF_CHG(RPC_CONFIG * c,
- ADMINS * a,
- TARIFFS * t)
+ STG::Admins * a,
+ STG::Tariffs * t)
: config(c),
admins(a),
tariffs(t)
METHOD_TARIFF_CHG & operator=(const METHOD_TARIFF_CHG & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- TARIFFS * tariffs;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
};
class METHOD_TARIFFS_GET : public xmlrpc_c::method {
public:
METHOD_TARIFFS_GET(RPC_CONFIG * c,
- TARIFFS * t)
+ STG::Tariffs * t)
: config(c),
tariffs(t)
{
METHOD_TARIFFS_GET & operator=(const METHOD_TARIFFS_GET & rvalue);
RPC_CONFIG * config;
- TARIFFS * tariffs;
+ STG::Tariffs * tariffs;
};
class METHOD_TARIFF_ADD : public xmlrpc_c::method {
public:
METHOD_TARIFF_ADD(RPC_CONFIG * c,
- ADMINS * a,
- TARIFFS * t)
+ STG::Admins * a,
+ STG::Tariffs * t)
: config(c),
admins(a),
tariffs(t)
METHOD_TARIFF_ADD & operator=(const METHOD_TARIFF_ADD & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- TARIFFS * tariffs;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
};
class METHOD_TARIFF_DEL : public xmlrpc_c::method {
public:
METHOD_TARIFF_DEL(RPC_CONFIG * c,
- ADMINS * a,
- TARIFFS * t,
- USERS * u)
+ STG::Admins * a,
+ STG::Tariffs * t,
+ STG::Users * u)
: config(c),
admins(a),
tariffs(t),
METHOD_TARIFF_DEL & operator=(const METHOD_TARIFF_DEL & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- TARIFFS * tariffs;
- USERS * users;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
+ STG::Users * users;
};
-
-#endif
-#include <cmath>
+#include "user_helper.h"
#include "stg/tariffs.h"
+#include "stg/tariff.h"
#include "stg/admin.h"
#include "stg/store.h"
+#include "stg/users.h"
+#include "stg/user.h"
#include "stg/user_ips.h"
-#include "stg/common.h"
#include "stg/user_property.h"
-#include "user_helper.h"
+#include "stg/common.h"
+#include "stg/const.h"
+
+#include <cmath>
//------------------------------------------------------------------------------
if (!hidePassword)
{
- structVal["password"] = xmlrpc_c::value_string(ptr->GetProperty().password.Get());
+ structVal["password"] = xmlrpc_c::value_string(ptr->GetProperties().password.Get());
}
else
{
structVal["password"] = xmlrpc_c::value_string("++++++++");
}
-structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperty().cash.Get());
-structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperty().freeMb.Get());
-structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperty().credit.Get());
+structVal["cash"] = xmlrpc_c::value_double(ptr->GetProperties().cash.Get());
+structVal["freemb"] = xmlrpc_c::value_double(ptr->GetProperties().freeMb.Get());
+structVal["credit"] = xmlrpc_c::value_double(ptr->GetProperties().credit.Get());
-if (ptr->GetProperty().nextTariff.Get() != "")
+if (ptr->GetProperties().nextTariff.Get() != "")
{
structVal["tariff"] = xmlrpc_c::value_string(
- ptr->GetProperty().tariffName.Get() +
+ ptr->GetProperties().tariffName.Get() +
"/" +
- ptr->GetProperty().nextTariff.Get()
+ ptr->GetProperties().nextTariff.Get()
);
}
else
{
- structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperty().tariffName.Get());
+ structVal["tariff"] = xmlrpc_c::value_string(ptr->GetProperties().tariffName.Get());
}
-structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().note, "KOI8-RU", "UTF-8"));
+structVal["note"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().note, "KOI8-RU", "UTF-8"));
-structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().phone, "KOI8-RU", "UTF-8"));
+structVal["phone"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().phone, "KOI8-RU", "UTF-8"));
-structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().address, "KOI8-RU", "UTF-8"));
+structVal["address"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().address, "KOI8-RU", "UTF-8"));
-structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().email, "KOI8-RU", "UTF-8"));
+structVal["email"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().email, "KOI8-RU", "UTF-8"));
std::vector<xmlrpc_c::value> userdata;
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata0.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata1.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata2.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata3.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata4.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata5.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata6.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata7.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata8.Get(), "KOI8-RU", "UTF-8")));
-userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperty().userdata9.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata0.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata1.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata2.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata3.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata4.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata5.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata6.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata7.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata8.Get(), "KOI8-RU", "UTF-8")));
+userdata.push_back(xmlrpc_c::value_string(IconvString(ptr->GetProperties().userdata9.Get(), "KOI8-RU", "UTF-8")));
structVal["userdata"] = xmlrpc_c::value_array(userdata);
-structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().realName, "KOI8-RU", "UTF-8"));
+structVal["name"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().realName, "KOI8-RU", "UTF-8"));
-structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group, "KOI8-RU", "UTF-8"));
+structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperties().group, "KOI8-RU", "UTF-8"));
structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected());
-structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get());
+structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperties().alwaysOnline.Get());
structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP()));
structVal["pingtime"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetPingTime()));
-structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr());
+structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperties().ips.Get().toString());
std::map<std::string, xmlrpc_c::value> traffInfo;
std::vector<xmlrpc_c::value> mu(DIR_NUM);
std::vector<xmlrpc_c::value> su(DIR_NUM);
std::vector<xmlrpc_c::value> sd(DIR_NUM);
-DIR_TRAFF upload;
-DIR_TRAFF download;
-DIR_TRAFF supload;
-DIR_TRAFF sdownload;
-download = ptr->GetProperty().down.Get();
-upload = ptr->GetProperty().up.Get();
-sdownload = ptr->GetSessionUpload();
-supload = ptr->GetSessionDownload();
+auto upload = ptr->GetProperties().up.Get();
+auto download = ptr->GetProperties().down.Get();
+auto supload = ptr->GetSessionUpload();
+auto sdownload = ptr->GetSessionDownload();
for (int j = 0; j < DIR_NUM; j++)
{
structVal["traff"] = xmlrpc_c::value_struct(traffInfo);
-structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get());
-structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get());
-structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get());
-structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get());
-structVal["lasttimecash"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperty().lastCashAddTime.Get()));
-structVal["lastactivitytime"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperty().lastActivityTime.Get()));
-structVal["creditexpire"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperty().creditExpire.Get()));
+structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperties().disabled.Get());
+structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperties().disabledDetailStat.Get());
+structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperties().passive.Get());
+structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperties().lastCashAdd.Get());
+structVal["lasttimecash"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperties().lastCashAddTime.Get()));
+structVal["lastactivitytime"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperties().lastActivityTime.Get()));
+structVal["creditexpire"] = xmlrpc_c::value_int(static_cast<int>(ptr->GetProperties().creditExpire.Get()));
*info = xmlrpc_c::value_struct(structVal);
}
//------------------------------------------------------------------------------
bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
- const ADMIN * admin,
+ const STG::Admin& admin,
const std::string & login,
- const STORE & store,
- TARIFFS * tariffs)
+ const STG::Store & store,
+ STG::Tariffs * tariffs)
{
std::map<std::string, xmlrpc_c::value> structVal(
static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
std::map<std::string, xmlrpc_c::value>::iterator it;
bool check = false;
-bool alwaysOnline = ptr->GetProperty().alwaysOnline;
+bool alwaysOnline = ptr->GetProperties().alwaysOnline;
if ((it = structVal.find("aonline")) != structVal.end())
{
check = true;
alwaysOnline = xmlrpc_c::value_boolean(it->second);
}
-bool onlyOneIP = ptr->GetProperty().ips.ConstData().OnlyOneIP();
+bool onlyOneIP = ptr->GetProperties().ips.ConstData().onlyOneIP();
if ((it = structVal.find("ips")) != structVal.end())
{
check = true;
- onlyOneIP = StrToIPS(xmlrpc_c::value_string(it->second)).OnlyOneIP();
+ onlyOneIP = STG::UserIPs::parse(xmlrpc_c::value_string(it->second)).onlyOneIP();
}
if (check && alwaysOnline && !onlyOneIP)
if ((it = structVal.find("ips")) != structVal.end())
{
- USER_IPS ips;
- ips = StrToIPS(xmlrpc_c::value_string(it->second));
+ auto ips = STG::UserIPs::parse(xmlrpc_c::value_string(it->second));
- for (size_t i = 0; i < ips.Count(); ++i)
+ for (size_t i = 0; i < ips.count(); ++i)
{
- CONST_USER_PTR user;
+ using ConstUserPtr = const STG::User*;
+ ConstUserPtr user;
uint32_t ip = ips[i].ip;
if (users.IsIPInUse(ip, login, &user))
{
}
}
- if (!ptr->GetProperty().ips.Set(ips,
- admin,
- login,
- &store))
+ if (!ptr->GetProperties().ips.Set(ips, admin, login, store))
return true;
}
if ((it = structVal.find("aonline")) != structVal.end())
{
bool value(xmlrpc_c::value_boolean(it->second));
- if (ptr->GetProperty().alwaysOnline.Get() != value)
- if (!ptr->GetProperty().alwaysOnline.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().alwaysOnline.Get() != value)
+ if (!ptr->GetProperties().alwaysOnline.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("password")) != structVal.end())
{
std::string value(xmlrpc_c::value_string(it->second));
- if (ptr->GetProperty().password.Get() != value)
- if (!ptr->GetProperty().password.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().password.Get() != value)
+ if (!ptr->GetProperties().password.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("address")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().address.Get() != value)
- if (!ptr->GetProperty().address.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().address.Get() != value)
+ if (!ptr->GetProperties().address.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("phone")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().phone.Get() != value)
- if (!ptr->GetProperty().phone.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().phone.Get() != value)
+ if (!ptr->GetProperties().phone.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("email")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().email.Get() != value)
- if (!ptr->GetProperty().email.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().email.Get() != value)
+ if (!ptr->GetProperties().email.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("cash")) != structVal.end())
{
double value(xmlrpc_c::value_double(it->second));
- if (std::fabs(ptr->GetProperty().cash.Get() - value) > 1.0e-3)
- if (!ptr->GetProperty().cash.Set(value,
- admin,
- login,
- &store))
+ if (std::fabs(ptr->GetProperties().cash.Get() - value) > 1.0e-3)
+ if (!ptr->GetProperties().cash.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("creditexpire")) != structVal.end())
{
time_t value(xmlrpc_c::value_int(it->second));
- if (ptr->GetProperty().creditExpire.Get() != value)
- if (!ptr->GetProperty().creditExpire.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().creditExpire.Get() != value)
+ if (!ptr->GetProperties().creditExpire.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("credit")) != structVal.end())
{
double value(xmlrpc_c::value_double(it->second));
- if (std::fabs(ptr->GetProperty().credit.Get() - value) > 1.0e-3)
- if (!ptr->GetProperty().credit.Set(value,
- admin,
- login,
- &store))
+ if (std::fabs(ptr->GetProperties().credit.Get() - value) > 1.0e-3)
+ if (!ptr->GetProperties().credit.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("freemb")) != structVal.end())
{
double value(xmlrpc_c::value_double(it->second));
- if (std::fabs(ptr->GetProperty().freeMb.Get() - value) > 1.0e-3)
- if (!ptr->GetProperty().freeMb.Set(value,
- admin,
- login,
- &store))
+ if (std::fabs(ptr->GetProperties().freeMb.Get() - value) > 1.0e-3)
+ if (!ptr->GetProperties().freeMb.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("down")) != structVal.end())
{
bool value(xmlrpc_c::value_boolean(it->second));
- if (ptr->GetProperty().disabled.Get() != value)
- if (!ptr->GetProperty().disabled.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().disabled.Get() != value)
+ if (!ptr->GetProperties().disabled.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("passive")) != structVal.end())
{
bool value(xmlrpc_c::value_boolean(it->second));
- if (ptr->GetProperty().passive.Get() != value)
- if (!ptr->GetProperty().passive.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().passive.Get() != value)
+ if (!ptr->GetProperties().passive.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("disableddetailstat")) != structVal.end())
{
bool value(xmlrpc_c::value_boolean(it->second));
- if (ptr->GetProperty().disabledDetailStat.Get() != value)
- if (!ptr->GetProperty().disabledDetailStat.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().disabledDetailStat.Get() != value)
+ if (!ptr->GetProperties().disabledDetailStat.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("name")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().realName.Get() != value)
- if (!ptr->GetProperty().realName.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().realName.Get() != value)
+ if (!ptr->GetProperties().realName.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("group")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().group.Get() != value)
- if (!ptr->GetProperty().group.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().group.Get() != value)
+ if (!ptr->GetProperties().group.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("note")) != structVal.end())
{
std::string value(IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "KOI8-RU"));
- if (ptr->GetProperty().note.Get() != value)
- if (!ptr->GetProperty().note.Set(value,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().note.Get() != value)
+ if (!ptr->GetProperties().note.Set(value, admin, login, store))
return true;
}
if ((it = structVal.find("userdata")) != structVal.end())
{
- std::vector<USER_PROPERTY_LOGGED<std::string> *> userdata;
- userdata.push_back(ptr->GetProperty().userdata0.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata1.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata2.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata3.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata4.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata5.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata6.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata7.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata8.GetPointer());
- userdata.push_back(ptr->GetProperty().userdata9.GetPointer());
+ std::vector<STG::UserPropertyLogged<std::string> *> userdata;
+ userdata.push_back(ptr->GetProperties().userdata0.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata1.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata2.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata3.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata4.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata5.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata6.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata7.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata8.GetPointer());
+ userdata.push_back(ptr->GetProperties().userdata9.GetPointer());
std::vector<xmlrpc_c::value> udata(
xmlrpc_c::value_array(it->second).vectorValueValue()
{
std::string value(IconvString(xmlrpc_c::value_string(udata[i]), "UTF-8", "KOI8-RU"));
if (userdata[i]->Get() != value)
- if (!userdata[i]->Set(value,
- admin,
- login,
- &store))
+ if (!userdata[i]->Set(value, admin, login, store))
return true;
}
}
static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(it->second))
);
- DIR_TRAFF dtData;
- dtData = ptr->GetProperty().up.Get();
+ auto dtData = ptr->GetProperties().up.Get();
if ((it = traff.find("mu")) != traff.end())
{
std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
else
dtData[i] = value;
}
- if (!ptr->GetProperty().up.Set(dtData,
- admin,
- login,
- &store))
+ if (!ptr->GetProperties().up.Set(dtData, admin, login, store))
return true;
}
- dtData = ptr->GetProperty().down.Get();
+ dtData = ptr->GetProperties().down.Get();
if ((it = traff.find("md")) != traff.end())
{
std::vector<xmlrpc_c::value> data(xmlrpc_c::value_array(it->second).vectorValueValue());
else
dtData[i] = value;
}
- if (!ptr->GetProperty().down.Set(dtData,
- admin,
- login,
- &store))
+ if (!ptr->GetProperties().down.Set(dtData, admin, login, store))
return true;
}
}
tariff = tariff.substr(0, pos);
}
- const TARIFF * newTariff = tariffs->FindByName(tariff);
+ const auto newTariff = tariffs->FindByName(tariff);
if (newTariff)
{
- const TARIFF * currentTariff = ptr->GetTariff();
+ const auto currentTariff = ptr->GetTariff();
std::string message = currentTariff->TariffChangeIsAllowed(*newTariff, stgTime);
if (message.empty())
{
- if (ptr->GetProperty().tariffName.Get() != tariff)
+ if (ptr->GetProperties().tariffName.Get() != tariff)
{
- if (!ptr->GetProperty().tariffName.Set(tariff,
- admin,
- login,
- &store))
+ if (!ptr->GetProperties().tariffName.Set(tariff, admin, login, store))
return true;
}
}
else
{
- PluginLogger::get("conf_rpc")("Tariff change is prohibited for user %s. %s", ptr->GetLogin().c_str(), message.c_str());
+ STG::PluginLogger::get("conf_rpc")("Tariff change is prohibited for user %s. %s", ptr->GetLogin().c_str(), message.c_str());
}
}
if (nextTariff != "" &&
tariffs->FindByName(nextTariff))
- if (ptr->GetProperty().nextTariff.Get() != nextTariff)
- if (!ptr->GetProperty().nextTariff.Set(tariff,
- admin,
- login,
- &store))
+ if (ptr->GetProperties().nextTariff.Get() != nextTariff)
+ if (!ptr->GetProperties().nextTariff.Set(tariff, admin, login, store))
return true;
}
-#ifndef __USER_HELPER_H__
-#define __USER_HELPER_H__
+#pragma once
#include <string>
#include <xmlrpc-c/base.hpp>
-#include "stg/users.h"
+namespace STG
+{
+
+struct Admin;
+struct Store;
+struct Tariffs;
+struct User;
+struct Users;
-class ADMIN;
-class STORE;
-class TARIFFS;
+}
class USER_HELPER
{
public:
- USER_HELPER(USER_PTR & p, USERS & us)
+ using UserPtr = STG::User*;
+ USER_HELPER(UserPtr & p, STG::Users & us)
: ptr(p),
users(us)
{
void GetUserInfo(xmlrpc_c::value * info,
bool hidePassword = false);
bool SetUserInfo(const xmlrpc_c::value & info,
- const ADMIN * admin,
+ const STG::Admin& admin,
const std::string & login,
- const STORE & store,
- TARIFFS * tariffs);
+ const STG::Store & store,
+ STG::Tariffs * tariffs);
private:
- USER_PTR & ptr;
- USERS & users;
+ UserPtr & ptr;
+ STG::Users & users;
};
-
-#endif
-#include <cerrno>
+#include "users_methods.h"
+#include "rpcconfig.h"
+#include "user_helper.h"
#include "stg/users.h"
#include "stg/admins.h"
#include "stg/tariffs.h"
-#include "stg/user_ips.h"
-#include "stg/common.h"
+#include "stg/tariff.h"
+#include "stg/user.h"
#include "stg/user_property.h"
+#include "stg/common.h"
-#include "users_methods.h"
-#include "rpcconfig.h"
-#include "user_helper.h"
+#include <cerrno>
+
+using UserPtr = STG::User*;
//------------------------------------------------------------------------------
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
return;
}
-ADMIN * admin = NULL;
+STG::Admin * admin = NULL;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
*retvalPtr = xmlrpc_c::value_boolean(true);
return;
}
-
+
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
}
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (!users->FindByName(login, &u))
{
bool hidePassword = !adminInfo.priviledges.userConf ||
!adminInfo.priviledges.userPasswd;
-USER_PTR u;
+UserPtr u;
int h = users->OpenSearch();
if (!h)
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
- uhelper.SetUserInfo(info, admin, login, *store, tariffs);
+ uhelper.SetUserInfo(info, *admin, login, *store, tariffs);
}
else
{
- uhelper.SetUserInfo(info, admin, login, *store, tariffs);
+ uhelper.SetUserInfo(info, *admin, login, *store, tariffs);
}
u->WriteConf();
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
return;
}
-double cash = u->GetProperty().cash.Get();
+double cash = u->GetProperties().cash.Get();
cash += amount;
-if (!u->GetProperty().cash.Set(cash, admin, login, store, comment))
+if (!u->GetProperties().cash.Set(cash, *admin, login, *store, comment))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
return;
}
-if (!u->GetProperty().cash.Set(cash, admin, login, store, comment))
+if (!u->GetProperties().cash.Set(cash, *admin, login, *store, comment))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
return;
return;
}
-ADMIN * admin;
+STG::Admin * admin;
if (admins->Find(adminInfo.admin, &admin))
{
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
{
if (delayed)
{
- if (u->GetProperty().nextTariff.Set(tariff,
- admin,
- login,
- store,
- comment))
+ if (u->GetProperties().nextTariff.Set(tariff, *admin, login, *store, comment))
{
u->WriteConf();
*retvalPtr = xmlrpc_c::value_boolean(true);
}
else
{
- const TARIFF * newTariff = tariffs->FindByName(tariff);
+ const auto newTariff = tariffs->FindByName(tariff);
if (newTariff)
{
- const TARIFF * currentTariff = u->GetTariff();
+ const auto currentTariff = u->GetTariff();
std::string message = currentTariff->TariffChangeIsAllowed(*newTariff, stgTime);
if (message.empty())
{
- if (u->GetProperty().tariffName.Set(tariff,
- admin,
- login,
- store,
- comment))
+ if (u->GetProperties().tariffName.Set(tariff, *admin, login, *store, comment))
{
u->ResetNextTariff();
u->WriteConf();
}
else
{
- PluginLogger::get("conf_rpc")("Tariff change is prohibited for user %s. %s", u->GetLogin().c_str(), message.c_str());
+ STG::PluginLogger::get("conf_rpc")("Tariff change is prohibited for user %s. %s", u->GetLogin().c_str(), message.c_str());
}
}
}
ValueVector subnetsStr = paramList.getArray(1);
paramList.verifyEnd(2);
-std::vector<IP_MASK> subnets;
+std::vector<STG::IPMask> subnets;
for (ValueVector::const_iterator it(subnetsStr.begin()); it != subnetsStr.end(); ++it)
{
- IP_MASK ipm;
+ STG::IPMask ipm;
if (ParseNet(xmlrpc_c::value_string(*it), ipm))
{
printfd(__FILE__, "METHOD_GET_ONLINE_IPS::execute(): Failed to parse subnet ('%s')\n", std::string(xmlrpc_c::value_string(*it)).c_str());
ValueVector ips;
-USER_PTR u;
+UserPtr u;
int handle = users->OpenSearch();
if (!handle)
{
uint32_t ip = u->GetCurrIP();
- for (std::vector<IP_MASK>::const_iterator it(subnets.begin()); it != subnets.end(); ++it)
+ for (std::vector<STG::IPMask>::const_iterator it(subnets.begin()); it != subnets.end(); ++it)
{
if ((it->ip & it->mask) == (ip & it->mask))
{
*retvalPtr = xmlrpc_c::value_struct(structVal);
}
-bool METHOD_GET_ONLINE_IPS::ParseNet(const std::string & net, IP_MASK & ipm) const
+bool METHOD_GET_ONLINE_IPS::ParseNet(const std::string & net, STG::IPMask & ipm) const
{
size_t pos = net.find_first_of('/');
return;
}
-USER_PTR u;
+UserPtr u;
if (users->FindByName(login, &u))
{
-#ifndef __USERS_METHODS_H__
-#define __USERS_METHODS_H__
+#pragma once
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
+namespace STG
+{
+
+struct Admins;
+struct Tariffs;
+struct Users;
+struct Store;
+struct IPMask;
+
+}
+
class RPC_CONFIG;
-class ADMINS;
-class TARIFFS;
-class USERS;
-class STORE;
-struct IP_MASK;
class METHOD_USER_GET : public xmlrpc_c::method {
public:
METHOD_USER_GET(RPC_CONFIG * c,
- USERS * u)
+ STG::Users * u)
: config(c),
users(u)
{
METHOD_USER_GET & operator=(const METHOD_USER_GET & rvalue);
RPC_CONFIG * config;
- USERS * users;
+ STG::Users * users;
};
class METHOD_USER_ADD : public xmlrpc_c::method {
public:
METHOD_USER_ADD(RPC_CONFIG * c,
- ADMINS * a,
- USERS * u)
+ STG::Admins * a,
+ STG::Users * u)
: config(c),
admins(a),
users(u)
METHOD_USER_ADD & operator=(const METHOD_USER_ADD & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- USERS * users;
+ STG::Admins * admins;
+ STG::Users * users;
};
class METHOD_USER_DEL : public xmlrpc_c::method {
public:
METHOD_USER_DEL(RPC_CONFIG * c,
- ADMINS * a,
- USERS * u)
+ STG::Admins * a,
+ STG::Users * u)
: config(c),
admins(a),
users(u)
METHOD_USER_DEL & operator=(const METHOD_USER_DEL & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- USERS * users;
+ STG::Admins * admins;
+ STG::Users * users;
};
class METHOD_USERS_GET : public xmlrpc_c::method {
public:
METHOD_USERS_GET(RPC_CONFIG * c,
- USERS * u)
+ STG::Users * u)
: config(c),
users(u)
{
METHOD_USERS_GET & operator=(const METHOD_USERS_GET & rvalue);
RPC_CONFIG * config;
- USERS * users;
+ STG::Users * users;
};
class METHOD_USER_CHG : public xmlrpc_c::method {
public:
METHOD_USER_CHG(RPC_CONFIG * c,
- ADMINS * a,
- TARIFFS * t,
- STORE * s,
- USERS * u)
+ STG::Admins * a,
+ STG::Tariffs * t,
+ STG::Store * s,
+ STG::Users * u)
: config(c),
admins(a),
tariffs(t),
METHOD_USER_CHG & operator=(const METHOD_USER_CHG & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- TARIFFS * tariffs;
- STORE * store;
- USERS * users;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
+ STG::Store * store;
+ STG::Users * users;
};
class METHOD_USER_CASH_ADD : public xmlrpc_c::method {
public:
METHOD_USER_CASH_ADD(RPC_CONFIG * c,
- ADMINS * a,
- STORE * s,
- USERS * u)
+ STG::Admins * a,
+ STG::Store * s,
+ STG::Users * u)
: config(c),
admins(a),
store(s),
METHOD_USER_CASH_ADD & operator=(const METHOD_USER_CASH_ADD & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- STORE * store;
- USERS * users;
+ STG::Admins * admins;
+ STG::Store * store;
+ STG::Users * users;
};
class METHOD_USER_CASH_SET : public xmlrpc_c::method {
public:
METHOD_USER_CASH_SET(RPC_CONFIG * c,
- ADMINS * a,
- STORE * s,
- USERS * u)
+ STG::Admins * a,
+ STG::Store * s,
+ STG::Users * u)
: config(c),
admins(a),
store(s),
METHOD_USER_CASH_SET & operator=(const METHOD_USER_CASH_SET & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- STORE * store;
- USERS * users;
+ STG::Admins * admins;
+ STG::Store * store;
+ STG::Users * users;
};
class METHOD_USER_TARIFF_CHANGE : public xmlrpc_c::method {
public:
METHOD_USER_TARIFF_CHANGE(RPC_CONFIG * c,
- ADMINS * a,
- TARIFFS * t,
- STORE * s,
- USERS * u)
+ STG::Admins * a,
+ STG::Tariffs * t,
+ STG::Store * s,
+ STG::Users * u)
: config(c),
admins(a),
tariffs(t),
METHOD_USER_TARIFF_CHANGE & operator=(const METHOD_USER_TARIFF_CHANGE & rvalue);
RPC_CONFIG * config;
- ADMINS * admins;
- TARIFFS * tariffs;
- STORE * store;
- USERS * users;
+ STG::Admins * admins;
+ STG::Tariffs * tariffs;
+ STG::Store * store;
+ STG::Users * users;
};
class METHOD_GET_ONLINE_IPS : public xmlrpc_c::method {
public:
METHOD_GET_ONLINE_IPS(RPC_CONFIG * c,
- USERS * u)
+ STG::Users * u)
: config(c),
users(u)
{
METHOD_GET_ONLINE_IPS & operator=(const METHOD_GET_ONLINE_IPS & rvalue);
RPC_CONFIG * config;
- USERS * users;
+ STG::Users * users;
- bool ParseNet(const std::string & net, IP_MASK & ipm) const;
+ bool ParseNet(const std::string & net, STG::IPMask & ipm) const;
};
class METHOD_GET_USER_AUTH_BY : public xmlrpc_c::method {
public:
METHOD_GET_USER_AUTH_BY(RPC_CONFIG * c,
- USERS * u)
+ STG::Users * u)
: config(c),
users(u)
{
METHOD_GET_USER_AUTH_BY & operator=(const METHOD_GET_ONLINE_IPS & rvalue);
RPC_CONFIG * config;
- USERS * users;
+ STG::Users * users;
};
-
-#endif