From: Maksym Mamontov Date: Thu, 20 Feb 2020 20:49:04 +0000 (+0200) Subject: Public interfaces: part 2 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/c7801cde8b95a9ef8318030e1caaa0be0603fe80?ds=sidebyside Public interfaces: part 2 --- diff --git a/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/stargazer/plugins/capture/ether_linux/ether_cap.cpp index 389f2eb5..7ca6c01f 100644 --- a/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -51,10 +51,10 @@ $Date: 2009/12/13 13:45:13 $ //#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; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -69,7 +69,7 @@ ETHER_CAP::ETHER_CAP() isRunning(false), capSock(-1), traffCnt(NULL), - logger(PluginLogger::get("cap_ether")) + logger(STG::PluginLogger::get("cap_ether")) { } //----------------------------------------------------------------------------- @@ -154,7 +154,7 @@ dc->isRunning = true; struct ETH_IP { uint16_t ethHdr[8]; -RAW_PACKET rp; +STG::RawPacket rp; char padding[4]; char padding1[8]; }; @@ -178,7 +178,7 @@ while (dc->nonstop) if (ethIP->ethHdr[7] != 0x8) continue; - dc->traffCnt->Process(ethIP->rp); + dc->traffCnt->process(ethIP->rp); } dc->isRunning = false; diff --git a/stargazer/plugins/capture/ether_linux/ether_cap.h b/stargazer/plugins/capture/ether_linux/ether_cap.h index 5bb938fe..cf776a45 100644 --- a/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -23,8 +23,7 @@ * Author : Boris Mikhailenko */ -#ifndef ETHER_CAP_H -#define ETHER_CAP_H +#pragma once #include @@ -34,25 +33,27 @@ #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; } @@ -77,10 +78,7 @@ private: bool isRunning; int capSock; - TRAFFCOUNTER * traffCnt; + STG::TraffCounter * traffCnt; - PLUGIN_LOGGER logger; + STG::PluginLogger logger; }; -//----------------------------------------------------------------------------- - -#endif diff --git a/stargazer/plugins/store/mysql/mysql_store.cpp b/stargazer/plugins/store/mysql/mysql_store.cpp index 57461ad4..3ad79b30 100644 --- a/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/stargazer/plugins/store/mysql/mysql_store.cpp @@ -1,19 +1,21 @@ -#include -#include -#include -#include -#include - -#include +#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 +#include +#include +#include +#include + +#include #define adm_enc_passwd "cjeifY8m3" @@ -98,16 +100,12 @@ int GetULongLongInt(const std::string & str, uint64_t * val, uint64_t defaultVal return 0; } -PLUGIN_CREATOR 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() @@ -115,12 +113,12 @@ MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS() { } //----------------------------------------------------------------------------- -int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, +int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, const std::string & name, std::string & result) { -PARAM_VALUE pv; +STG::ParamValue pv; pv.param = name; -std::vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end() || pvi->value.empty()) { @@ -133,7 +131,7 @@ result = pvi->value[0]; 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) @@ -156,7 +154,7 @@ return 0; MYSQL_STORE::MYSQL_STORE() : version("mysql_store v.0.67"), schemaVersion(0), - logger(PluginLogger::get("store_mysql")) + logger(STG::PluginLogger::get("store_mysql")) { } //----------------------------------------------------------------------------- @@ -727,7 +725,7 @@ if(MysqlSetQuery(qbuf)) 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; @@ -851,10 +849,10 @@ for (int i = 0; i < USERDATA_NUM; i++) 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) { @@ -871,7 +869,7 @@ mysql_close(sock); 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; @@ -994,7 +992,7 @@ mysql_close(sock); 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; @@ -1047,7 +1045,7 @@ if(MysqlSetQuery(res.c_str())) 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; @@ -1171,10 +1169,10 @@ return WriteLogString(logStr, login); } //----------------------------------------------------------------------------- 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 @@ -1209,7 +1207,7 @@ logStr += "\'"; 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; @@ -1267,7 +1265,7 @@ if(MysqlSetQuery(qbuf)) 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]; @@ -1314,7 +1312,7 @@ if(MysqlSetQuery(qbuf)) 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]; @@ -1492,7 +1490,7 @@ if(MysqlSetQuery(qbuf)) 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; @@ -1642,7 +1640,7 @@ if (GetDouble(row[1+8*DIR_NUM], &td->tariffConf.passiveCost, 0.0) < 0) return -1; } -td->tariffConf.traffType = TARIFF::StringToTraffType(str); +td->tariffConf.traffType = STG::Tariff::parseTraffType(str); if (schemaVersion > 0) { @@ -1657,11 +1655,11 @@ 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) @@ -1677,7 +1675,7 @@ 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"; @@ -1694,7 +1692,7 @@ if (schemaVersion > 1) } else { - td->tariffConf.changePolicy = TARIFF::ALLOW; + td->tariffConf.changePolicy = STG::Tariff::ALLOW; td->tariffConf.changePolicyTimeout = 0; } @@ -1703,7 +1701,7 @@ mysql_close(sock); 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; @@ -1760,13 +1758,13 @@ res += 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()); @@ -1782,7 +1780,7 @@ if(MysqlSetQuery(res.c_str())) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteDetailedStat(const std::map & statTree, +int MYSQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree, time_t lastStat, const std::string & login) const { @@ -1867,7 +1865,7 @@ strprintf(&res,"INSERT INTO detailstat_%02d_%4d SET login='%s',"\ endTime.c_str() ); -std::map::const_iterator stIter; +STG::TraffStat::const_iterator stIter; stIter = statTree.begin(); while (stIter != statTree.end()) @@ -1898,7 +1896,7 @@ mysql_close(sock); 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; @@ -1921,7 +1919,7 @@ if(MysqlSetQuery(qbuf)) 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; @@ -1949,7 +1947,7 @@ if(MysqlSetQuery(res.c_str())) 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; @@ -2047,7 +2045,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const +int MYSQL_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { MYSQL_RES *res; MYSQL_ROW row; @@ -2080,7 +2078,7 @@ for (i = 0; i < num_rows; i++) if (str2x(row[1], id)) continue; - STG_MSG_HDR hdr; + STG::Message::Header hdr; if (row[2]) if(str2x(row[2], hdr.type)) continue; diff --git a/stargazer/plugins/store/mysql/mysql_store.h b/stargazer/plugins/store/mysql/mysql_store.h index 4a492b38..6d09c476 100644 --- a/stargazer/plugins/store/mysql/mysql_store.h +++ b/stargazer/plugins/store/mysql/mysql_store.h @@ -1,22 +1,15 @@ - /* - $Revision: 1.5 $ - $Date: 2010/10/07 19:45:52 $ - */ +#pragma once - -#ifndef MYSQL_STORE_H -#define MYSQL_STORE_H - -#include +#include "stg/store.h" +#include "stg/module_settings.h" +#include "stg/user_traff.h" +#include "stg/logger.h" #include #include #include -#include "stg/module_settings.h" -#include "stg/store.h" -#include "stg/user_traff.h" -#include "stg/logger.h" +#include //----------------------------------------------------------------------------- class MYSQL_STORE_SETTINGS @@ -24,7 +17,7 @@ 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; } @@ -36,9 +29,9 @@ private: 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 & moduleParams, + int ParseParam(const std::vector & moduleParams, const std::string & name, std::string & result); std::string errorStr; @@ -49,81 +42,80 @@ private: 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 * 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 & 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 *) 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 *) 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 *) 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 *) 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); @@ -141,11 +133,8 @@ private: 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 diff --git a/stargazer/plugins/store/postgresql/postgresql_store.cpp b/stargazer/plugins/store/postgresql/postgresql_store.cpp index f3a599a9..2146d664 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -43,25 +43,17 @@ #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 #include #include -namespace +extern "C" STG::Store* GetStore() { -PLUGIN_CREATOR pgsc; -} - -extern "C" STORE * GetStore(); - -//----------------------------------------------------------------------------- -STORE * GetStore() -{ -return pgsc.GetPlugin(); + static POSTGRESQL_STORE plugin; + return &plugin; } //----------------------------------------------------------------------------- @@ -75,7 +67,7 @@ POSTGRESQL_STORE::POSTGRESQL_STORE() version(0), retries(3), connection(NULL), - logger(PluginLogger::get("store_postgresql")) + logger(STG::PluginLogger::get("store_postgresql")) { pthread_mutex_init(&mutex, NULL); } @@ -91,7 +83,7 @@ pthread_mutex_destroy(&mutex); //----------------------------------------------------------------------------- int POSTGRESQL_STORE::ParseSettings() { -std::vector::iterator i; +std::vector::iterator i; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { diff --git a/stargazer/plugins/store/postgresql/postgresql_store.h b/stargazer/plugins/store/postgresql/postgresql_store.h index 6bcb3cd0..0e8b6391 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store.h +++ b/stargazer/plugins/store/postgresql/postgresql_store.h @@ -18,106 +18,105 @@ * Author : Maxim Mamontov */ -/* - * 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 +#include "stg/store.h" +#include "stg/module_settings.h" +#include "stg/logger.h" #include #include -#include "stg/store.h" -#include "stg/logger.h" +#include // 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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); @@ -128,11 +127,11 @@ private: 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 & services) const; int SaveUserData(uint32_t uid, const std::vector & 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; @@ -147,14 +146,12 @@ private: 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 diff --git a/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp b/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp index b000aa29..b1c1203e 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp @@ -26,17 +26,19 @@ * */ +#include "postgresql_store.h" + +#include "stg/locker.h" +#include "stg/common.h" +#include "stg/admin_conf.h" +#include "stg/blowfish.h" + #include #include #include #include -#include "stg/locker.h" -#include "stg/admin_conf.h" -#include "stg/blowfish.h" -#include "postgresql_store.h" - #define adm_enc_passwd "cjeifY8m3" //----------------------------------------------------------------------------- @@ -71,9 +73,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) 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; } @@ -96,7 +98,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveAdmin(const ADMIN_CONF & ac) const +int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const { STG_LOCKER lock(&mutex); @@ -141,9 +143,9 @@ if (EscapeString(pass)) { 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; } @@ -151,9 +153,9 @@ if (EscapeString(login)) { 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; } @@ -177,9 +179,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) 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; } @@ -195,7 +197,7 @@ return 0; } //----------------------------------------------------------------------------- -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); @@ -228,9 +230,9 @@ if (EscapeString(elogin)) { 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; } @@ -250,9 +252,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) 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; } @@ -264,9 +266,9 @@ if (tuples != 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; } @@ -345,9 +347,9 @@ if (EscapeString(elogin)) { 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; } @@ -369,9 +371,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) 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; } @@ -415,9 +417,9 @@ if (EscapeString(elogin)) { 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; } @@ -432,9 +434,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) 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; } diff --git a/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp b/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp index 84fab02b..1387d418 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp @@ -26,15 +26,18 @@ * */ +#include "postgresql_store.h" + +#include "stg/corp_conf.h" +#include "stg/locker.h" +#include "stg/common.h" + #include #include #include #include -#include "postgresql_store.h" -#include "stg/locker.h" - //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetCorpsList(std::vector * corpsList) const { @@ -92,7 +95,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveCorp(const CORP_CONF & cc) const +int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const { STG_LOCKER lock(&mutex); @@ -121,9 +124,9 @@ if (EscapeString(ename)) { 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; } @@ -158,7 +161,7 @@ return 0; } //----------------------------------------------------------------------------- -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); @@ -187,9 +190,9 @@ if (EscapeString(ename)) { 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; } @@ -218,9 +221,9 @@ if (tuples != 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; } @@ -270,9 +273,9 @@ if (EscapeString(ename)) { 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; } @@ -337,9 +340,9 @@ if (EscapeString(ename)) { 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; } diff --git a/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp b/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp index 42a19073..905b467c 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp @@ -27,19 +27,20 @@ * */ +#include "postgresql_store.h" + +#include "stg/common.h" +#include "stg/locker.h" +#include "stg/message.h" + #include #include #include #include -#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); @@ -69,9 +70,9 @@ if (EscapeString(elogin)) { 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; } @@ -79,9 +80,9 @@ if (EscapeString(etext)) { 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; } @@ -119,9 +120,9 @@ if (tuples != 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; } @@ -141,7 +142,7 @@ if (CommitTransaction()) 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); @@ -172,9 +173,9 @@ if (EscapeString(elogin)) { 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; } @@ -182,9 +183,9 @@ if (EscapeString(etext)) { 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; } @@ -227,8 +228,8 @@ return 0; } //----------------------------------------------------------------------------- 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); @@ -280,9 +281,9 @@ if (tuples != 1) 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; } @@ -357,7 +358,7 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, +int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -387,9 +388,9 @@ if (EscapeString(elogin)) { 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; } @@ -421,7 +422,7 @@ int tuples = PQntuples(result); 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) << " "; diff --git a/stargazer/plugins/store/postgresql/postgresql_store_services.cpp b/stargazer/plugins/store/postgresql/postgresql_store_services.cpp index 70b9c64c..3d098161 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_services.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_services.cpp @@ -27,15 +27,18 @@ * */ +#include "postgresql_store.h" + +#include "stg/service_conf.h" +#include "stg/common.h" +#include "stg/locker.h" + #include #include #include #include -#include "postgresql_store.h" -#include "stg/locker.h" - //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetServicesList(std::vector * servicesList) const { @@ -68,9 +71,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) 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; } @@ -93,7 +96,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveService(const SERVICE_CONF & sc) const +int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const { STG_LOCKER lock(&mutex); @@ -123,9 +126,9 @@ if (EscapeString(ename)) { 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; } @@ -133,9 +136,9 @@ if (EscapeString(ecomment)) { 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; } @@ -172,8 +175,8 @@ return 0; } //----------------------------------------------------------------------------- -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); @@ -202,9 +205,9 @@ if (EscapeString(ename)) { 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; } @@ -233,9 +236,9 @@ if (tuples != 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; } @@ -289,9 +292,9 @@ if (EscapeString(ename)) { 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; } @@ -356,9 +359,9 @@ if (EscapeString(ename)) { 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; } diff --git a/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index fd0b38bc..6a675989 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@ -26,6 +26,12 @@ * */ +#include "postgresql_store.h" + +#include "stg/tariff_conf.h" +#include "stg/common.h" +#include "stg/locker.h" + #include #include #include @@ -33,10 +39,6 @@ #include -#include "stg/common.h" -#include "postgresql_store.h" -#include "stg/locker.h" - namespace { @@ -227,7 +229,7 @@ if (CommitTransaction()) 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); @@ -316,10 +318,10 @@ int32_t id; 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; @@ -412,8 +414,8 @@ if (CommitTransaction()) 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); @@ -508,15 +510,17 @@ int id; 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(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)); } diff --git a/stargazer/plugins/store/postgresql/postgresql_store_users.cpp b/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index b4c449fb..6919ed00 100644 --- a/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@ -26,6 +26,17 @@ * */ +#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 #include #include @@ -33,12 +44,6 @@ #include -#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 * usersList) const { @@ -223,7 +228,7 @@ if (CommitTransaction()) 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); @@ -231,7 +236,7 @@ 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 @@ -334,7 +339,7 @@ return 0; } //----------------------------------------------------------------------------- -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); @@ -605,7 +610,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreUserStat(USER_STAT * stat, +int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -745,7 +750,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreUserConf(USER_CONF * conf, +int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -954,10 +959,10 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) 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)); @@ -967,7 +972,7 @@ for (int i = 0; i < tuples; ++i) continue; } - ips.Add(im); + ips.add(im); } conf->ips = ips; @@ -1186,10 +1191,10 @@ return 0; //----------------------------------------------------------------------------- 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 @@ -1349,7 +1354,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteDetailedStat(const std::map & statTree, +int POSTGRESQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree, time_t lastStat, const std::string & login) const { @@ -1384,7 +1389,7 @@ if (EscapeString(elogin)) return -1; } -std::map::const_iterator it; +STG::TraffStat::const_iterator it; time_t currTime = time(NULL); for (it = statTree.begin(); it != statTree.end(); ++it) @@ -1430,7 +1435,7 @@ return 0; } //----------------------------------------------------------------------------- -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); @@ -1499,7 +1504,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveUserIPs(uint32_t uid, - const USER_IPS & ips) const + const STG::UserIPs & ips) const { PGresult * result; @@ -1520,7 +1525,7 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) 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 "