//#define CAP_DEBUG 1
-extern "C" Plugin* GetPlugin()
+extern "C" STG::Plugin* GetPlugin()
{
-static ETHER_CAP plugin;
-return &plugin;
+ static ETHER_CAP plugin;
+ return &plugin;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
isRunning(false),
capSock(-1),
traffCnt(NULL),
- logger(PluginLogger::get("cap_ether"))
+ logger(STG::PluginLogger::get("cap_ether"))
{
}
//-----------------------------------------------------------------------------
struct ETH_IP
{
uint16_t ethHdr[8];
-RAW_PACKET rp;
+STG::RawPacket rp;
char padding[4];
char padding1[8];
};
if (ethIP->ethHdr[7] != 0x8)
continue;
- dc->traffCnt->Process(ethIP->rp);
+ dc->traffCnt->process(ethIP->rp);
}
dc->isRunning = false;
* Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
*/
-#ifndef ETHER_CAP_H
-#define ETHER_CAP_H
+#pragma once
#include <pthread.h>
#include "stg/module_settings.h"
#include "stg/logger.h"
-class USERS;
-class TARIFFS;
-class ADMINS;
-class TRAFFCOUNTER;
-class SETTINGS;
+namespace STG
+{
-class TRAFFCOUNTER;
+struct Users;
+struct Tariffs;
+struct Admins;
+struct TraffCounter;
+struct Settings;
+
+}
//-----------------------------------------------------------------------------
-class ETHER_CAP : public PLUGIN {
+class ETHER_CAP : public STG::Plugin {
public:
ETHER_CAP();
- virtual ~ETHER_CAP() {}
- void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; }
+ void SetTraffcounter(STG::TraffCounter * tc) { traffCnt = tc; }
int Start();
int Stop();
- int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
+ int Reload(const STG::ModuleSettings & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
int ParseSettings() { return 0; }
bool isRunning;
int capSock;
- TRAFFCOUNTER * traffCnt;
+ STG::TraffCounter * traffCnt;
- PLUGIN_LOGGER logger;
+ STG::PluginLogger logger;
};
-//-----------------------------------------------------------------------------
-
-#endif
-#include <sys/time.h>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
-#include <algorithm>
-
-#include <mysql/errmsg.h>
+#include "mysql_store.h"
#include "stg/common.h"
#include "stg/user_ips.h"
#include "stg/user_conf.h"
#include "stg/user_stat.h"
+#include "stg/admin_conf.h"
+#include "stg/tariff_conf.h"
#include "stg/blowfish.h"
-#include "stg/plugin_creator.h"
#include "stg/logger.h"
-#include "mysql_store.h"
+
+#include <algorithm>
+#include <sys/time.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+
+#include <mysql/errmsg.h>
#define adm_enc_passwd "cjeifY8m3"
return 0;
}
-PLUGIN_CREATOR<MYSQL_STORE> msc;
}
-extern "C" STORE * GetStore();
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-STORE * GetStore()
+extern "C" STG::Store* GetStore()
{
-return msc.GetPlugin();
+ static MYSQL_STORE plugin;
+ return &plugin;
}
//-----------------------------------------------------------------------------
MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS()
{
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE_SETTINGS::ParseParam(const std::vector<PARAM_VALUE> & moduleParams,
+int MYSQL_STORE_SETTINGS::ParseParam(const std::vector<STG::ParamValue> & moduleParams,
const std::string & name, std::string & result)
{
-PARAM_VALUE pv;
+STG::ParamValue pv;
pv.param = name;
-std::vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<STG::ParamValue>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
if (pvi == moduleParams.end() || pvi->value.empty())
{
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
+int MYSQL_STORE_SETTINGS::ParseSettings(const STG::ModuleSettings & s)
{
if (ParseParam(s.moduleParams, "user", dbUser) < 0 &&
ParseParam(s.moduleParams, "dbuser", dbUser) < 0)
MYSQL_STORE::MYSQL_STORE()
: version("mysql_store v.0.67"),
schemaVersion(0),
- logger(PluginLogger::get("store_mysql"))
+ logger(STG::PluginLogger::get("store_mysql"))
{
}
//-----------------------------------------------------------------------------
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login) const
+int MYSQL_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const
{
MYSQL_RES *res;
MYSQL_ROW row;
GetTime(row[15+USERDATA_NUM], &conf->creditExpire, 0);
std::string ipStr = row[16+USERDATA_NUM];
-USER_IPS i;
+STG::UserIPs i;
try
{
- i = StrToIPS(ipStr);
+ i = STG::UserIPs::parse(ipStr);
}
catch (const std::string & s)
{
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login) const
+int MYSQL_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const
{
MYSQL_RES *res;
MYSQL_ROW row;
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::SaveUserConf(const USER_CONF & conf, const std::string & login) const
+int MYSQL_STORE::SaveUserConf(const STG::UserConf & conf, const std::string & login) const
{
std::string param;
std::string res;
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const
+int MYSQL_STORE::SaveUserStat(const STG::UserStat & stat, const std::string & login) const
{
std::string param;
std::string res;
}
//-----------------------------------------------------------------------------
int MYSQL_STORE::WriteUserDisconnect(const std::string & login,
- const DIR_TRAFF & up,
- const DIR_TRAFF & down,
- const DIR_TRAFF & sessionUp,
- const DIR_TRAFF & sessionDown,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
double cash,
double /*freeMb*/,
const std::string & /*reason*/) const
return WriteLogString(logStr, login);
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year,
+int MYSQL_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year,
const std::string & login) const
{
std::string param, res;
return 0;
}
//-----------------------------------------------------------------------------*/
-int MYSQL_STORE::SaveAdmin(const ADMIN_CONF & ac) const
+int MYSQL_STORE::SaveAdmin(const STG::AdminConf & ac) const
{
char passwordE[2 * ADM_PASSWD_LEN + 2];
char pass[ADM_PASSWD_LEN + 1];
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const
+int MYSQL_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
{
char pass[ADM_PASSWD_LEN + 1];
char password[ADM_PASSWD_LEN + 1];
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const
+int MYSQL_STORE::RestoreTariff(STG::TariffData * td, const std::string & tariffName) const
{
MYSQL_RES *res;
MYSQL_ROW row;
return -1;
}
-td->tariffConf.traffType = TARIFF::StringToTraffType(str);
+td->tariffConf.traffType = STG::Tariff::parseTraffType(str);
if (schemaVersion > 0)
{
return -1;
}
- td->tariffConf.period = TARIFF::StringToPeriod(str);
+ td->tariffConf.period = STG::Tariff::parsePeriod(str);
}
else
{
- td->tariffConf.period = TARIFF::MONTH;
+ td->tariffConf.period = STG::Tariff::MONTH;
}
if (schemaVersion > 1)
return -1;
}
- td->tariffConf.changePolicy = TARIFF::StringToChangePolicy(str);
+ td->tariffConf.changePolicy = STG::Tariff::parseChangePolicy(str);
str = row[7+8*DIR_NUM];
param = "ChangePolicyTimeout";
}
else
{
- td->tariffConf.changePolicy = TARIFF::ALLOW;
+ td->tariffConf.changePolicy = STG::Tariff::ALLOW;
td->tariffConf.changePolicyTimeout = 0;
}
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const
+int MYSQL_STORE::SaveTariff(const STG::TariffData & td, const std::string & tariffName) const
{
std::string param;
strprintf(¶m, " Free=%f,", td.tariffConf.free);
res += param;
-res += " TraffType='" + TARIFF::TraffTypeToString(td.tariffConf.traffType) + "'";
+res += " TraffType='" + STG::Tariff::toString(td.tariffConf.traffType) + "'";
if (schemaVersion > 0)
- res += ", Period='" + TARIFF::PeriodToString(td.tariffConf.period) + "'";
+ res += ", Period='" + STG::Tariff::toString(td.tariffConf.period) + "'";
if (schemaVersion > 1)
- res += ", change_policy='" + TARIFF::ChangePolicyToString(td.tariffConf.changePolicy) + "'"\
+ res += ", change_policy='" + STG::Tariff::toString(td.tariffConf.changePolicy) + "'"\
", change_policy_timeout='" + formatTime(td.tariffConf.changePolicy) + "'";
strprintf(¶m, " WHERE name='%s' LIMIT 1", tariffName.c_str());
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
+int MYSQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree,
time_t lastStat,
const std::string & login) const
{
endTime.c_str()
);
-std::map<IP_DIR_PAIR, STAT_NODE>::const_iterator stIter;
+STG::TraffStat::const_iterator stIter;
stIter = statTree.begin();
while (stIter != statTree.end())
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const
+int MYSQL_STORE::AddMessage(STG::Message * msg, const std::string & login) const
{
struct timeval tv;
return EditMessage(*msg, login);
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::EditMessage(const STG_MSG & msg, const std::string & login) const
+int MYSQL_STORE::EditMessage(const STG::Message & msg, const std::string & login) const
{
std::string res;
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const
+int MYSQL_STORE::GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const
{
MYSQL_RES *res;
MYSQL_ROW row;
return 0;
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE::GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const
+int MYSQL_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const
{
MYSQL_RES *res;
MYSQL_ROW row;
if (str2x(row[1], id))
continue;
- STG_MSG_HDR hdr;
+ STG::Message::Header hdr;
if (row[2])
if(str2x(row[2], hdr.type))
continue;
- /*
- $Revision: 1.5 $
- $Date: 2010/10/07 19:45:52 $
- */
+#pragma once
-
-#ifndef MYSQL_STORE_H
-#define MYSQL_STORE_H
-
-#include <mysql/mysql.h>
+#include "stg/store.h"
+#include "stg/module_settings.h"
+#include "stg/user_traff.h"
+#include "stg/logger.h"
#include <string>
#include <vector>
#include <map>
-#include "stg/module_settings.h"
-#include "stg/store.h"
-#include "stg/user_traff.h"
-#include "stg/logger.h"
+#include <mysql/mysql.h>
//-----------------------------------------------------------------------------
class MYSQL_STORE_SETTINGS
public:
MYSQL_STORE_SETTINGS();
virtual ~MYSQL_STORE_SETTINGS() {}
- virtual int ParseSettings(const MODULE_SETTINGS & s);
+ virtual int ParseSettings(const STG::ModuleSettings & s);
virtual const std::string & GetStrError() const { return errorStr; }
const std::string & GetDBUser() const { return dbUser; }
MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
MYSQL_STORE_SETTINGS & operator=(const MYSQL_STORE_SETTINGS & rvalue);
- const MODULE_SETTINGS * settings;
+ const STG::ModuleSettings * settings;
- int ParseParam(const std::vector<PARAM_VALUE> & moduleParams,
+ int ParseParam(const std::vector<STG::ParamValue> & moduleParams,
const std::string & name, std::string & result);
std::string errorStr;
std::string dbHost;
};
//-----------------------------------------------------------------------------
-class MYSQL_STORE: public STORE
+class MYSQL_STORE: public STG::Store
{
public:
MYSQL_STORE();
- virtual ~MYSQL_STORE() {}
- virtual const std::string & GetStrError() const { return errorStr; }
+ const std::string & GetStrError() const override { return errorStr; }
//User
- virtual int GetUsersList(std::vector<std::string> * usersList) const;
- virtual int AddUser(const std::string & login) const;
- virtual int DelUser(const std::string & login) const;
- virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
- virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
- virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
- virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
- virtual int WriteUserChgLog(const std::string & login,
- const std::string & admLogin,
- uint32_t admIP,
- const std::string & paramName,
- const std::string & oldValue,
- const std::string & newValue,
- const std::string & message = "") const;
- virtual int WriteUserConnect(const std::string & login, uint32_t ip) const;
- virtual int WriteUserDisconnect(const std::string & login,
- const DIR_TRAFF & up,
- const DIR_TRAFF & down,
- const DIR_TRAFF & sessionUp,
- const DIR_TRAFF & sessionDown,
- double cash,
- double freeMb,
- const std::string & reason) const;
-
- virtual int WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
- time_t lastStat,
- const std::string & login) const;
-
- virtual int AddMessage(STG_MSG * msg, const std::string & login) const;
- virtual int EditMessage(const STG_MSG & msg, const std::string & login) const;
- virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
- virtual int DelMessage(uint64_t id, const std::string & login) const;
- virtual int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
-
- virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
+ int GetUsersList(std::vector<std::string> * usersList) const override;
+ int AddUser(const std::string & login) const override;
+ int DelUser(const std::string & login) const override;
+ int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
+ int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
+ int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message = "") const override;
+ int WriteUserConnect(const std::string & login, uint32_t ip) const override;
+ int WriteUserDisconnect(const std::string & login,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
+ double cash,
+ double freeMb,
+ const std::string & reason) const override;
+
+ int WriteDetailedStat(const STG::TraffStat & statTree,
+ time_t lastStat,
+ const std::string & login) const override;
+
+ int AddMessage(STG::Message * msg, const std::string & login) const override;
+ int EditMessage(const STG::Message & msg, const std::string & login) const override;
+ int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
+ int DelMessage(uint64_t id, const std::string & login) const override;
+ int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
+
+ int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
//Admin
- virtual int GetAdminsList(std::vector<std::string> * adminsList) const;
- virtual int AddAdmin(const std::string & login) const;
- virtual int DelAdmin(const std::string & login) const;
- virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
- virtual int SaveAdmin(const ADMIN_CONF & ac) const;
+ int GetAdminsList(std::vector<std::string> * adminsList) const override;
+ int AddAdmin(const std::string & login) const override;
+ int DelAdmin(const std::string & login) const override;
+ int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
+ int SaveAdmin(const STG::AdminConf & ac) const override;
//Tariff
- virtual int GetTariffsList(std::vector<std::string> * tariffsList) const;
- virtual int AddTariff(const std::string & name) const;
- virtual int DelTariff(const std::string & name) const;
- virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
- virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
+ int GetTariffsList(std::vector<std::string> * tariffsList) const override;
+ int AddTariff(const std::string & name) const override;
+ int DelTariff(const std::string & name) const override;
+ int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
+ int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
//Corparation
- virtual int GetCorpsList(std::vector<std::string> *) const {return 0;}
- virtual int SaveCorp(const CORP_CONF &) const {return 0;}
- virtual int RestoreCorp(CORP_CONF *, const std::string &) const {return 0;}
- virtual int AddCorp(const std::string &) const {return 0;}
- virtual int DelCorp(const std::string &) const {return 0;}
+ int GetCorpsList(std::vector<std::string> *) const override {return 0;}
+ int SaveCorp(const STG::CorpConf &) const override {return 0;}
+ int RestoreCorp(STG::CorpConf *, const std::string &) const override {return 0;}
+ int AddCorp(const std::string &) const override {return 0;}
+ int DelCorp(const std::string &) const override {return 0;}
// Services
- virtual int GetServicesList(std::vector<std::string> *) const {return 0;}
- virtual int SaveService(const SERVICE_CONF &) const {return 0;}
- virtual int RestoreService(SERVICE_CONF *, const std::string &) const {return 0;}
- virtual int AddService(const std::string &) const {return 0;}
- virtual int DelService(const std::string &) const {return 0;}
+ int GetServicesList(std::vector<std::string> *) const override {return 0;}
+ int SaveService(const STG::ServiceConf &) const override {return 0;}
+ int RestoreService(STG::ServiceConf *, const std::string &) const override {return 0;}
+ int AddService(const std::string &) const override {return 0;}
+ int DelService(const std::string &) const override {return 0;}
- virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
- virtual int ParseSettings();
- virtual const std::string & GetVersion() const { return version; }
+ void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+ int ParseSettings() override;
+ const std::string & GetVersion() const override { return version; }
private:
MYSQL_STORE(const MYSQL_STORE & rvalue);
MYSQL * MysqlConnect() const ;
std::string version;
MYSQL_STORE_SETTINGS storeSettings;
- MODULE_SETTINGS settings;
+ STG::ModuleSettings settings;
int schemaVersion;
- PLUGIN_LOGGER logger;
+ STG::PluginLogger logger;
};
-//-----------------------------------------------------------------------------
-
-#endif
#include "postgresql_store_utils.h"
#include "postgresql_store.h"
-#include "stg/module_settings.h"
-#include "stg/plugin_creator.h"
+#include "stg/common.h" // str2x, printfd
#include <string>
#include <vector>
#include <libpq-fe.h>
-namespace
+extern "C" STG::Store* GetStore()
{
-PLUGIN_CREATOR<POSTGRESQL_STORE> pgsc;
-}
-
-extern "C" STORE * GetStore();
-
-//-----------------------------------------------------------------------------
-STORE * GetStore()
-{
-return pgsc.GetPlugin();
+ static POSTGRESQL_STORE plugin;
+ return &plugin;
}
//-----------------------------------------------------------------------------
version(0),
retries(3),
connection(NULL),
- logger(PluginLogger::get("store_postgresql"))
+ logger(STG::PluginLogger::get("store_postgresql"))
{
pthread_mutex_init(&mutex, NULL);
}
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::ParseSettings()
{
-std::vector<PARAM_VALUE>::iterator i;
+std::vector<STG::ParamValue>::iterator i;
for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
{
* Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
-/*
- * PostgreSQL storage class definition
- *
- * $Revision: 1.8 $
- * $Date: 2010/01/19 11:06:53 $
- *
- */
+#pragma once
-#ifndef POSTGRESQL_STORE_H
-#define POSTGRESQL_STORE_H
-
-#include <libpq-fe.h>
+#include "stg/store.h"
+#include "stg/module_settings.h"
+#include "stg/logger.h"
#include <string>
#include <vector>
-#include "stg/store.h"
-#include "stg/logger.h"
+#include <libpq-fe.h>
// Minimal DB version is 5
// Recommended DB version is 6 (support FreeMb logging on disconnects)
#define DB_MIN_VERSION 5
-class POSTGRESQL_STORE : public STORE {
+namespace STG
+{
+
+class UserIPs;
+
+}
+
+class POSTGRESQL_STORE : public STG::Store {
public:
POSTGRESQL_STORE();
- virtual ~POSTGRESQL_STORE();
+ ~POSTGRESQL_STORE() override;
// Users
- int GetUsersList(std::vector<std::string> * usersList) const;
- int AddUser(const std::string & login) const;
- int DelUser(const std::string & login) const;
- int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
- int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
- int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
- int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
+ int GetUsersList(std::vector<std::string> * usersList) const override;
+ int AddUser(const std::string & login) const override;
+ int DelUser(const std::string & login) const override;
+ int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
+ int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
+ int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
+ int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
int WriteUserChgLog(const std::string & login,
const std::string & admLogin,
uint32_t admIP,
const std::string & paramName,
const std::string & oldValue,
const std::string & newValue,
- const std::string & message) const;
- int WriteUserConnect(const std::string & login, uint32_t ip) const;
+ const std::string & message) const override;
+ int WriteUserConnect(const std::string & login, uint32_t ip) const override;
int WriteUserDisconnect(const std::string & login,
- const DIR_TRAFF & up,
- const DIR_TRAFF & down,
- const DIR_TRAFF & sessionUp,
- const DIR_TRAFF & sessionDown,
+ const STG::DirTraff & up,
+ const STG::DirTraff & down,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
double cash,
double freeMb,
- const std::string & reason) const;
- int WriteDetailedStat(const TRAFF_STAT & statTree,
+ const std::string & reason) const override;
+ int WriteDetailedStat(const STG::TraffStat & statTree,
time_t lastStat,
- const std::string & login) const;
+ const std::string & login) const override;
// Messages
- int AddMessage(STG_MSG * msg, const std::string & login) const;
- int EditMessage(const STG_MSG & msg, const std::string & login) const;
- int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
- int DelMessage(uint64_t id, const std::string & login) const;
- int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
+ int AddMessage(STG::Message * msg, const std::string & login) const override;
+ int EditMessage(const STG::Message & msg, const std::string & login) const override;
+ int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
+ int DelMessage(uint64_t id, const std::string & login) const override;
+ int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
// Stats
- int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
+ int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
// Admins
- int GetAdminsList(std::vector<std::string> * adminsList) const;
- int SaveAdmin(const ADMIN_CONF & ac) const;
- int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
- int AddAdmin(const std::string & login) const;
- int DelAdmin(const std::string & login) const;
+ int GetAdminsList(std::vector<std::string> * adminsList) const override;
+ int SaveAdmin(const STG::AdminConf & ac) const override;
+ int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
+ int AddAdmin(const std::string & login) const override;
+ int DelAdmin(const std::string & login) const override;
// Tariffs
- int GetTariffsList(std::vector<std::string> * tariffsList) const;
- int AddTariff(const std::string & name) const;
- int DelTariff(const std::string & name) const;
- int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
- int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
+ int GetTariffsList(std::vector<std::string> * tariffsList) const override;
+ int AddTariff(const std::string & name) const override;
+ int DelTariff(const std::string & name) const override;
+ int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
+ int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
// Corporations
- int GetCorpsList(std::vector<std::string> * corpsList) const;
- int SaveCorp(const CORP_CONF & cc) const;
- int RestoreCorp(CORP_CONF * cc, const std::string & name) const;
- int AddCorp(const std::string & name) const;
- int DelCorp(const std::string & name) const;
+ int GetCorpsList(std::vector<std::string> * corpsList) const override;
+ int SaveCorp(const STG::CorpConf & cc) const override;
+ int RestoreCorp(STG::CorpConf * cc, const std::string & name) const override;
+ int AddCorp(const std::string & name) const override;
+ int DelCorp(const std::string & name) const override;
// Services
- int GetServicesList(std::vector<std::string> * servicesList) const;
- int SaveService(const SERVICE_CONF & sc) const;
- int RestoreService(SERVICE_CONF * sc, const std::string & name) const;
- int AddService(const std::string & name) const;
- int DelService(const std::string & name) const;
+ int GetServicesList(std::vector<std::string> * servicesList) const override;
+ int SaveService(const STG::ServiceConf & sc) const override;
+ int RestoreService(STG::ServiceConf * sc, const std::string & name) const override;
+ int AddService(const std::string & name) const override;
+ int DelService(const std::string & name) const override;
// Settings
- inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
- int ParseSettings();
+ void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+ int ParseSettings() override;
- inline const std::string & GetStrError() const { return strError; }
- inline const std::string & GetVersion() const { return versionString; }
+ const std::string & GetStrError() const override { return strError; }
+ const std::string & GetVersion() const override { return versionString; }
private:
POSTGRESQL_STORE(const POSTGRESQL_STORE & rvalue);
POSTGRESQL_STORE & operator=(const POSTGRESQL_STORE & rvalue);
int EscapeString(std::string & value) const;
- int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const;
+ int SaveStat(const STG::UserStat & stat, const std::string & login, int year = 0, int month = 0) const;
int SaveUserServices(uint32_t uid, const std::vector<std::string> & services) const;
int SaveUserData(uint32_t uid, const std::vector<std::string> & data) const;
- int SaveUserIPs(uint32_t uid, const USER_IPS & ips) const;
+ int SaveUserIPs(uint32_t uid, const STG::UserIPs & ips) const;
void MakeDate(std::string & date, int year = 0, int month = 0) const;
std::string user;
std::string password;
std::string clientEncoding;
- MODULE_SETTINGS settings;
+ STG::ModuleSettings settings;
mutable pthread_mutex_t mutex;
mutable int version;
int retries;
PGconn * connection;
- PLUGIN_LOGGER logger;
+ STG::PluginLogger logger;
};
-
-#endif //POSTGRESQL_STORE_H
*
*/
+#include "postgresql_store.h"
+
+#include "stg/locker.h"
+#include "stg/common.h"
+#include "stg/admin_conf.h"
+#include "stg/blowfish.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "stg/locker.h"
-#include "stg/admin_conf.h"
-#include "stg/blowfish.h"
-#include "postgresql_store.h"
-
#define adm_enc_passwd "cjeifY8m3"
//-----------------------------------------------------------------------------
PQclear(result);
printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): '%s'\n", strError.c_str());
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveAdmin(const ADMIN_CONF & ac) const
+int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape password'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
PQclear(result);
printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): '%s'\n", strError.c_str());
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const
+int POSTGRESQL_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): '%s'\n", strError.c_str());
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
PQclear(result);
printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): '%s'\n", strError.c_str());
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
PQclear(result);
printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): '%s'\n", strError.c_str());
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
*
*/
+#include "postgresql_store.h"
+
+#include "stg/corp_conf.h"
+#include "stg/locker.h"
+#include "stg/common.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "postgresql_store.h"
-#include "stg/locker.h"
-
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
{
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveCorp(const CORP_CONF & cc) const
+int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveCorp(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreCorp(CORP_CONF * cc, const std::string & name) const
+int POSTGRESQL_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreCorp(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddCorp(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::DelCorp(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
*
*/
+#include "postgresql_store.h"
+
+#include "stg/common.h"
+#include "stg/locker.h"
+#include "stg/message.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "stg/common.h"
-#include "postgresql_store.h"
-#include "stg/locker.h"
-#include "stg/message.h"
-
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const
+int POSTGRESQL_STORE::AddMessage(STG::Message * msg, const std::string & login) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to escape message text'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::EditMessage(const STG_MSG & msg,
+int POSTGRESQL_STORE::EditMessage(const STG::Message & msg,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to escape message text'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::EditMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetMessage(uint64_t id,
- STG_MSG * msg,
- const std::string &) const
+ STG::Message * msg,
+ const std::string &) const
{
STG_LOCKER lock(&mutex);
printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList,
+int POSTGRESQL_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to escape login'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::GetMessageHdrs(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
for (int i = 0; i < tuples; ++i)
{
std::stringstream tuple;
- STG_MSG_HDR header;
+ STG::Message::Header header;
tuple << PQgetvalue(result, i, 0) << " ";
tuple << PQgetvalue(result, i, 1) << " ";
tuple << PQgetvalue(result, i, 2) << " ";
*
*/
+#include "postgresql_store.h"
+
+#include "stg/service_conf.h"
+#include "stg/common.h"
+#include "stg/locker.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "postgresql_store.h"
-#include "stg/locker.h"
-
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetServicesList(std::vector<std::string> * servicesList) const
{
PQclear(result);
printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): '%s'\n", strError.c_str());
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::GetServicesList(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveService(const SERVICE_CONF & sc) const
+int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to escape comment'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::SaveService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreService(SERVICE_CONF * sc,
- const std::string & name) const
+int POSTGRESQL_STORE::RestoreService(STG::ServiceConf * sc,
+ const std::string & name) const
{
STG_LOCKER lock(&mutex);
{
printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples);
PQclear(result);
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::RestoreService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::AddService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
{
printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to escape name'\n");
if (RollbackTransaction())
- {
- printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n");
- }
+ {
+ printfd(__FILE__, "POSTGRESQL_STORE::DelService(): 'Failed to rollback transaction'\n");
+ }
return -1;
}
*
*/
+#include "postgresql_store.h"
+
+#include "stg/tariff_conf.h"
+#include "stg/common.h"
+#include "stg/locker.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "stg/common.h"
-#include "postgresql_store.h"
-#include "stg/locker.h"
-
namespace
{
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveTariff(const TARIFF_DATA & td,
+int POSTGRESQL_STORE::SaveTariff(const STG::TariffData & td,
const std::string & tariffName) const
{
STG_LOCKER lock(&mutex);
traff_type = " << td.tariffConf.traffType;
if (version > 6)
- query << ", period = '" << TARIFF::PeriodToString(td.tariffConf.period) << "'";
+ query << ", period = '" << STG::Tariff::toString(td.tariffConf.period) << "'";
if (version > 7)
- query << ", change_policy = '" << TARIFF::ChangePolicyToString(td.tariffConf.changePolicy) << "', \
+ query << ", change_policy = '" << STG::Tariff::toString(td.tariffConf.changePolicy) << "', \
change_policy_timeout = CAST('" << formatTime(td.tariffConf.changePolicyTimeout) << "' AS TIMESTAMP)";
query << " WHERE pk_tariff = " << id;
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreTariff(TARIFF_DATA * td,
- const std::string & tariffName) const
+int POSTGRESQL_STORE::RestoreTariff(STG::TariffData * td,
+ const std::string & tariffName) const
{
STG_LOCKER lock(&mutex);
tuple >> td->tariffConf.fee;
tuple >> td->tariffConf.free;
tuple >> td->tariffConf.passiveCost;
- tuple >> td->tariffConf.traffType;
+ unsigned traffType;
+ tuple >> traffType;
+ td->tariffConf.traffType = static_cast<STG::Tariff::TraffType>(traffType);
}
if (version > 6)
- td->tariffConf.period = TARIFF::StringToPeriod(PQgetvalue(result, 0, 5));
+ td->tariffConf.period = STG::Tariff::parsePeriod(PQgetvalue(result, 0, 5));
if (version > 7)
{
- td->tariffConf.changePolicy = TARIFF::StringToChangePolicy(PQgetvalue(result, 0, 6));
+ td->tariffConf.changePolicy = STG::Tariff::parseChangePolicy(PQgetvalue(result, 0, 6));
td->tariffConf.changePolicyTimeout = readTime(PQgetvalue(result, 0, 7));
}
*
*/
+#include "postgresql_store.h"
+
+#include "stg/user_conf.h"
+#include "stg/user_stat.h"
+#include "stg/user_ips.h"
+#include "stg/user_traff.h"
+#include "stg/common.h"
+#include "stg/const.h"
+#include "stg/locker.h"
+#include "../../../stg_timer.h"
+
#include <string>
#include <vector>
#include <sstream>
#include <libpq-fe.h>
-#include "stg/common.h"
-#include "stg/const.h"
-#include "stg/locker.h"
-#include "../../../stg_timer.h"
-#include "postgresql_store.h"
-
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetUsersList(std::vector<std::string> * usersList) const
{
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveUserStat(const USER_STAT & stat,
+int POSTGRESQL_STORE::SaveUserStat(const STG::UserStat & stat,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
return SaveStat(stat, login);
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveStat(const USER_STAT & stat,
+int POSTGRESQL_STORE::SaveStat(const STG::UserStat & stat,
const std::string & login,
int year,
int month) const
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveUserConf(const USER_CONF & conf,
+int POSTGRESQL_STORE::SaveUserConf(const STG::UserConf & conf,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreUserStat(USER_STAT * stat,
+int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreUserConf(USER_CONF * conf,
+int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf,
const std::string & login) const
{
STG_LOCKER lock(&mutex);
tuples = PQntuples(result);
-USER_IPS ips;
+STG::UserIPs ips;
for (int i = 0; i < tuples; ++i)
{
- IP_MASK im;
+ STG::IPMask im;
im.ip = inet_strington(PQgetvalue(result, i, 0));
continue;
}
- ips.Add(im);
+ ips.add(im);
}
conf->ips = ips;
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::WriteUserDisconnect(const std::string & login,
- const DIR_TRAFF & monthUp,
- const DIR_TRAFF & monthDown,
- const DIR_TRAFF & sessionUp,
- const DIR_TRAFF & sessionDown,
+ const STG::DirTraff & monthUp,
+ const STG::DirTraff & monthDown,
+ const STG::DirTraff & sessionUp,
+ const STG::DirTraff & sessionDown,
double cash,
double freeMb,
const std::string & reason) const
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
+int POSTGRESQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree,
time_t lastStat,
const std::string & login) const
{
return -1;
}
-std::map<IP_DIR_PAIR, STAT_NODE>::const_iterator it;
+STG::TraffStat::const_iterator it;
time_t currTime = time(NULL);
for (it = statTree.begin(); it != statTree.end(); ++it)
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const
+int POSTGRESQL_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
{
STG_LOCKER lock(&mutex);
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::SaveUserIPs(uint32_t uid,
- const USER_IPS & ips) const
+ const STG::UserIPs & ips) const
{
PGresult * result;
PQclear(result);
-for (size_t i = 0; i < ips.Count(); ++i)
+for (size_t i = 0; i < ips.count(); ++i)
{
std::ostringstream query;
query << "INSERT INTO tb_allowed_ip "