-#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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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))
+if (admins->find(adminInfo.admin, &admin))
{
*retvalPtr = xmlrpc_c::value_boolean(false);
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();
- std::string message = currentTariff->TariffChangeIsAllowed(*newTariff, stgTime);
+ const auto currentTariff = u->GetTariff();
+ std::string message = currentTariff->TariffChangeIsAllowed(*newTariff, time(NULL));
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
{
- GetStgLogger()("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))
{