From: Maksym Mamontov Date: Thu, 20 Feb 2020 21:27:02 +0000 (+0200) Subject: Public interfaces: part 3 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/4213664cbb7a96bee57fec935878348cebbc7d40 Public interfaces: part 3 --- diff --git a/stargazer/plugins/capture/nfqueue/nfqueue.cpp b/stargazer/plugins/capture/nfqueue/nfqueue.cpp index d4ac8f8f..3c79c1b1 100644 --- a/stargazer/plugins/capture/nfqueue/nfqueue.cpp +++ b/stargazer/plugins/capture/nfqueue/nfqueue.cpp @@ -60,7 +60,7 @@ unsigned char * payload = NULL; if (nfq_get_payload(nfqData, &payload) < 0 || payload == NULL) return id; -RAW_PACKET packet; +STG::RawPacket packet; memcpy(&packet.rawPacket, payload, sizeof(packet.rawPacket)); @@ -73,7 +73,7 @@ return nfq_set_verdict(queueHandle, id, NF_ACCEPT, 0, NULL); } -extern "C" Plugin* GetPlugin() +extern "C" STG::Plugin* GetPlugin() { static NFQ_CAP plugin; return &plugin; @@ -93,7 +93,7 @@ NFQ_CAP::NFQ_CAP() nfqHandle(NULL), queueHandle(NULL), traffCnt(NULL), - logger(PluginLogger::get("cap_nfqueue")) + logger(STG::PluginLogger::get("cap_nfqueue")) { } //----------------------------------------------------------------------------- @@ -240,7 +240,7 @@ dc->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -void NFQ_CAP::Process(const RAW_PACKET & packet) +void NFQ_CAP::Process(const STG::RawPacket & packet) { -traffCnt->Process(packet); +traffCnt->process(packet); } diff --git a/stargazer/plugins/capture/nfqueue/nfqueue.h b/stargazer/plugins/capture/nfqueue/nfqueue.h index fe40bc50..7d71bcd2 100644 --- a/stargazer/plugins/capture/nfqueue/nfqueue.h +++ b/stargazer/plugins/capture/nfqueue/nfqueue.h @@ -18,8 +18,7 @@ * Author : Maxim Mamontov */ -#ifndef NFQ_CAP_H -#define NFQ_CAP_H +#pragma once #include "stg/plugin.h" #include "stg/module_settings.h" @@ -30,39 +29,41 @@ #include -class USERS; -class TARIFFS; -class ADMINS; -class TRAFFCOUNTER; -class SETTINGS; -struct RAW_PACKET; +namespace STG +{ -class TRAFFCOUNTER; +struct Users; +struct Tariffs; +struct Admins; +struct TraffCounter; +struct Settings; +struct RawPacket; + +} struct nfq_handle; struct nfq_q_handle; -class NFQ_CAP : public PLUGIN { +class NFQ_CAP : public STG::Plugin { public: NFQ_CAP(); - virtual ~NFQ_CAP() {} - void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } + void SetTraffcounter(STG::TraffCounter * tc) override { traffCnt = tc; } - int Start(); - int Stop(); - int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } - bool IsRunning() { return isRunning; } + int Start() override; + int Stop() override; + int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; } + bool IsRunning() override { return isRunning; } - void SetSettings(const MODULE_SETTINGS & s) { settings = s; } - int ParseSettings(); + void SetSettings(const STG::ModuleSettings & s) override { settings = s; } + int ParseSettings() override; - const std::string & GetStrError() const { return errorStr; } - std::string GetVersion() const; - uint16_t GetStartPosition() const { return 40; } - uint16_t GetStopPosition() const { return 40; } + const std::string & GetStrError() const override { return errorStr; } + std::string GetVersion() const override; + uint16_t GetStartPosition() const override { return 40; } + uint16_t GetStopPosition() const override { return 40; } - void Process(const RAW_PACKET & packet); + void Process(const STG::RawPacket & packet); private: NFQ_CAP(const NFQ_CAP & rvalue); @@ -75,17 +76,14 @@ private: pthread_t thread; bool nonstop; bool isRunning; - MODULE_SETTINGS settings; + STG::ModuleSettings settings; size_t queueNumber; struct nfq_handle * nfqHandle; struct nfq_q_handle * queueHandle; - TRAFFCOUNTER * traffCnt; + STG::TraffCounter * traffCnt; - PLUGIN_LOGGER logger; + STG::PluginLogger logger; }; -//----------------------------------------------------------------------------- - -#endif diff --git a/stargazer/plugins/capture/pcap/pcap_cap.cpp b/stargazer/plugins/capture/pcap/pcap_cap.cpp index b3f14047..394487f3 100644 --- a/stargazer/plugins/capture/pcap/pcap_cap.cpp +++ b/stargazer/plugins/capture/pcap/pcap_cap.cpp @@ -47,10 +47,10 @@ u_short ether_type; /* IP? ARP? RARP? etc */ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -extern "C" Plugin* GetPlugin() +extern "C" STG::Plugin* GetPlugin() { -static PCAP_CAP plugin; -return &plugin; + static PCAP_CAP plugin; + return &plugin; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -64,7 +64,7 @@ PCAP_CAP::PCAP_CAP() : nonstop(false), isRunning(false), traffCnt(NULL), - logger(PluginLogger::get("pcap_cap")) + logger(STG::PluginLogger::get("pcap_cap")) { } //----------------------------------------------------------------------------- @@ -290,7 +290,7 @@ const ETH * eth = reinterpret_cast(packet); if (eth->ether_type != 0x8) return; -RAW_PACKET ip; +STG::RawPacket ip; memcpy(&ip.rawPacket, packet + 14, sizeof(ip.rawPacket)); -traffCnt->Process(ip); +traffCnt->process(ip); } diff --git a/stargazer/plugins/capture/pcap/pcap_cap.h b/stargazer/plugins/capture/pcap/pcap_cap.h index 3bdfd55e..f47c6b8d 100644 --- a/stargazer/plugins/capture/pcap/pcap_cap.h +++ b/stargazer/plugins/capture/pcap/pcap_cap.h @@ -18,8 +18,7 @@ * Author : Maxim Mamontov */ -#ifndef PCAP_CAP_H -#define PCAP_CAP_H +#pragma once #include "stg/plugin.h" #include "stg/module_settings.h" @@ -32,13 +31,16 @@ #include #include -class USERS; -class TARIFFS; -class ADMINS; -class TRAFFCOUNTER; -class SETTINGS; +namespace STG +{ + +struct Users; +struct Tariffs; +struct Admins; +struct TraffCounter; +struct Settings; -class TRAFFCOUNTER; +} struct DEV { @@ -56,25 +58,24 @@ struct DEV typedef std::vector DEV_MAP; -class PCAP_CAP : public PLUGIN { +class PCAP_CAP : public STG::Plugin { public: PCAP_CAP(); - virtual ~PCAP_CAP() {} - void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } + void SetTraffcounter(STG::TraffCounter * tc) override { traffCnt = tc; } - int Start(); - int Stop(); - int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; } - bool IsRunning() { return isRunning; } + int Start() override; + int Stop() override; + int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; } + bool IsRunning() override { return isRunning; } - void SetSettings(const MODULE_SETTINGS & s) { settings = s; } - int ParseSettings(); + void SetSettings(const STG::ModuleSettings & s) override { settings = s; } + int ParseSettings() override; - const std::string & GetStrError() const { return errorStr; } - std::string GetVersion() const; - uint16_t GetStartPosition() const { return 40; } - uint16_t GetStopPosition() const { return 40; } + const std::string & GetStrError() const override { return errorStr; } + std::string GetVersion() const override; + uint16_t GetStartPosition() const override { return 40; } + uint16_t GetStopPosition() const override { return 40; } private: PCAP_CAP(const PCAP_CAP & rvalue); @@ -90,13 +91,10 @@ private: pthread_t thread; bool nonstop; bool isRunning; - MODULE_SETTINGS settings; + STG::ModuleSettings settings; DEV_MAP devices; - TRAFFCOUNTER * traffCnt; + STG::TraffCounter * traffCnt; - PLUGIN_LOGGER logger; + STG::PluginLogger logger; }; -//----------------------------------------------------------------------------- - -#endif diff --git a/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp b/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp index cc7be006..7e38a119 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp @@ -23,6 +23,8 @@ #include "stg/users.h" #include "stg/user.h" +#include + using STG::PARSER::AUTH_BY; const char * AUTH_BY::tag = "GetUserAuthBy"; diff --git a/stargazer/plugins/configuration/sgconfig/parser_message.cpp b/stargazer/plugins/configuration/sgconfig/parser_message.cpp index c997c135..b4607996 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_message.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_message.cpp @@ -24,6 +24,8 @@ #include "stg/users.h" #include "stg/user.h" +#include + extern volatile time_t stgTime; // So sad... using STG::PARSER::SEND_MESSAGE; diff --git a/stargazer/plugins/store/firebird/firebird_store.cpp b/stargazer/plugins/store/firebird/firebird_store.cpp index c2b815a3..c11b442b 100644 --- a/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/stargazer/plugins/store/firebird/firebird_store.cpp @@ -28,22 +28,15 @@ #include "firebird_store.h" -#include "stg/ibpp.h" -#include "stg/plugin_creator.h" +#include "stg/common.h" #include #include -namespace +extern "C" STG::Store* GetStore() { -PLUGIN_CREATOR frsc; -} - -extern "C" STORE * GetStore(); -//----------------------------------------------------------------------------- -STORE * GetStore() -{ -return frsc.GetPlugin(); + static FIREBIRD_STORE plugin; + return &plugin; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -57,7 +50,7 @@ FIREBIRD_STORE::FIREBIRD_STORE() til(IBPP::ilConcurrency), tlr(IBPP::lrWait), schemaVersion(0), - logger(PluginLogger::get("store_firebird")) + logger(STG::PluginLogger::get("store_firebird")) { pthread_mutex_init(&mutex, NULL); } @@ -69,7 +62,7 @@ db->Disconnect(); //----------------------------------------------------------------------------- int FIREBIRD_STORE::ParseSettings() { -std::vector::iterator i; +std::vector::iterator i; std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) diff --git a/stargazer/plugins/store/firebird/firebird_store.h b/stargazer/plugins/store/firebird/firebird_store.h index d9c6af24..14f0b269 100644 --- a/stargazer/plugins/store/firebird/firebird_store.h +++ b/stargazer/plugins/store/firebird/firebird_store.h @@ -18,100 +18,92 @@ * Author : Maxim Mamontov */ -/* - * Firebird storage class definition - * - * $Revision: 1.13 $ - * $Date: 2010/01/19 11:07:25 $ - * - */ - -#ifndef FIREBIRD_STORE_H -#define FIREBIRD_STORE_H - -#include -#include -#include +#pragma once #include "stg/store.h" #include "stg/locker.h" #include "stg/ibpp.h" #include "stg/logger.h" +#include "stg/module_settings.h" + +#include +#include +#include struct ToLower { char operator() (char c) const { return static_cast(std::tolower(c)); } }; -class FIREBIRD_STORE : public STORE { +class FIREBIRD_STORE : public STG::Store { public: FIREBIRD_STORE(); - virtual ~FIREBIRD_STORE(); - - 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; + ~FIREBIRD_STORE() override; + + 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; - 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; - 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; - 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; - 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; - 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; - inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; } - int ParseSettings(); + inline void SetSettings(const STG::ModuleSettings & s) override { settings = s; } + int ParseSettings() override; - inline const std::string & GetStrError() const { return strError; } + inline const std::string & GetStrError() const override { return strError; } - inline const std::string & GetVersion() const { return version; } + inline const std::string & GetVersion() const override { return version; } - 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; private: FIREBIRD_STORE(const FIREBIRD_STORE & rvalue); @@ -120,15 +112,15 @@ private: std::string version; mutable std::string strError; std::string db_server, db_database, db_user, db_password; - MODULE_SETTINGS settings; + STG::ModuleSettings settings; mutable IBPP::Database db; mutable pthread_mutex_t mutex; IBPP::TIL til; IBPP::TLR tlr; int schemaVersion; - PLUGIN_LOGGER logger; + STG::PluginLogger logger; - 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 CheckVersion(); }; @@ -144,5 +136,3 @@ T Get(IBPP::Statement st, size_t pos) st->Get(pos, value); return value; } - -#endif //FIREBIRD_STORE_H diff --git a/stargazer/plugins/store/firebird/firebird_store_admins.cpp b/stargazer/plugins/store/firebird/firebird_store_admins.cpp index e794d206..bb0bc0f4 100644 --- a/stargazer/plugins/store/firebird/firebird_store_admins.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_admins.cpp @@ -26,12 +26,15 @@ * */ -#include -#include - #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/admin_conf.h" #include "stg/blowfish.h" +#include "stg/common.h" + +#include +#include #define adm_enc_passwd "cjeifY8m3" @@ -68,7 +71,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveAdmin(const ADMIN_CONF & ac) const +int FIREBIRD_STORE::SaveAdmin(const STG::AdminConf & ac) const { STG_LOCKER lock(&mutex); @@ -126,7 +129,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const +int FIREBIRD_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const { STG_LOCKER lock(&mutex); diff --git a/stargazer/plugins/store/firebird/firebird_store_corporations.cpp b/stargazer/plugins/store/firebird/firebird_store_corporations.cpp index 6c483880..3b9ad785 100644 --- a/stargazer/plugins/store/firebird/firebird_store_corporations.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_corporations.cpp @@ -27,7 +27,10 @@ */ #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/corp_conf.h" +#include "stg/common.h" //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetCorpsList(std::vector * corpsList) const @@ -62,7 +65,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveCorp(const CORP_CONF & cc) const +int FIREBIRD_STORE::SaveCorp(const STG::CorpConf & cc) const { STG_LOCKER lock(&mutex); @@ -90,7 +93,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreCorp(CORP_CONF * cc, const std::string & name) const +int FIREBIRD_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const { STG_LOCKER lock(&mutex); diff --git a/stargazer/plugins/store/firebird/firebird_store_messages.cpp b/stargazer/plugins/store/firebird/firebird_store_messages.cpp index 5f9e62bd..90c3e573 100644 --- a/stargazer/plugins/store/firebird/firebird_store_messages.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_messages.cpp @@ -28,10 +28,13 @@ */ #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/message.h" +#include "stg/common.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddMessage(STG_MSG * msg, const std::string & login) const +int FIREBIRD_STORE::AddMessage(STG::Message * msg, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -67,7 +70,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::EditMessage(const STG_MSG & msg, +int FIREBIRD_STORE::EditMessage(const STG::Message & msg, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -105,7 +108,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetMessage(uint64_t id, - STG_MSG * msg, + STG::Message * msg, const std::string &) const { STG_LOCKER lock(&mutex); @@ -179,7 +182,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetMessageHdrs(std::vector * hdrsList, +int FIREBIRD_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -187,7 +190,7 @@ STG_LOCKER lock(&mutex); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -STG_MSG_HDR header; +STG::Message::Header header; try { diff --git a/stargazer/plugins/store/firebird/firebird_store_services.cpp b/stargazer/plugins/store/firebird/firebird_store_services.cpp index 93b7c745..0056879e 100644 --- a/stargazer/plugins/store/firebird/firebird_store_services.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_services.cpp @@ -28,7 +28,10 @@ */ #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/service_conf.h" +#include "stg/common.h" //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetServicesList(std::vector * servicesList) const @@ -63,7 +66,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveService(const SERVICE_CONF & sc) const +int FIREBIRD_STORE::SaveService(const STG::ServiceConf & sc) const { STG_LOCKER lock(&mutex); @@ -97,7 +100,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreService(SERVICE_CONF * sc, +int FIREBIRD_STORE::RestoreService(STG::ServiceConf * sc, const std::string & name) const { STG_LOCKER lock(&mutex); diff --git a/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index 6f8177ca..10c45ab9 100644 --- a/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -26,10 +26,14 @@ * */ -#include - #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/tariff.h" +#include "stg/tariff_conf.h" +#include "stg/common.h" + +#include namespace { @@ -126,7 +130,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveTariff(const TARIFF_DATA & td, +int FIREBIRD_STORE::SaveTariff(const STG::TariffData & td, const std::string & tariffName) const { STG_LOCKER lock(&mutex); @@ -174,13 +178,13 @@ try if (schemaVersion > 0) { - st->Set(5, TARIFF::PeriodToString(td.tariffConf.period)); + st->Set(5, STG::Tariff::toString(td.tariffConf.period)); ++num; } if (schemaVersion > 1) { - st->Set(6, TARIFF::ChangePolicyToString(td.tariffConf.changePolicy)); + st->Set(6, STG::Tariff::toString(td.tariffConf.changePolicy)); IBPP::Timestamp policyTimeout; time_t2ts(td.tariffConf.changePolicyTimeout, &policyTimeout); st->Set(7, policyTimeout); @@ -261,7 +265,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreTariff(TARIFF_DATA * td, +int FIREBIRD_STORE::RestoreTariff(STG::TariffData * td, const std::string & tariffName) const { STG_LOCKER lock(&mutex); @@ -290,12 +294,12 @@ try st->Get(3, td->tariffConf.fee); st->Get(4, td->tariffConf.free); st->Get(5, td->tariffConf.passiveCost); - td->tariffConf.traffType = TARIFF::IntToTraffType(Get(st, 6)); + td->tariffConf.traffType = STG::Tariff::fromInt(Get(st, 6)); if (schemaVersion > 0) - td->tariffConf.period = TARIFF::StringToPeriod(Get(st, 7)); + td->tariffConf.period = STG::Tariff::parsePeriod(Get(st, 7)); if (schemaVersion > 1) { - td->tariffConf.changePolicy = TARIFF::StringToChangePolicy(Get(st, 8)); + td->tariffConf.changePolicy = STG::Tariff::parseChangePolicy(Get(st, 8)); td->tariffConf.changePolicyTimeout = ts2time_t(Get(st, 9)); } st->Close(); diff --git a/stargazer/plugins/store/firebird/firebird_store_users.cpp b/stargazer/plugins/store/firebird/firebird_store_users.cpp index ab18a40a..ad28af3a 100644 --- a/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -26,9 +26,15 @@ * */ -#include "stg/const.h" #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/user_conf.h" +#include "stg/user_stat.h" +#include "stg/user_traff.h" +#include "stg/user_ips.h" +#include "stg/const.h" +#include "stg/common.h" //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetUsersList(std::vector * usersList) const @@ -118,7 +124,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveUserStat(const USER_STAT & stat, +int FIREBIRD_STORE::SaveUserStat(const STG::UserStat & stat, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -126,7 +132,7 @@ STG_LOCKER lock(&mutex); return SaveStat(stat, login); } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveStat(const USER_STAT & stat, +int FIREBIRD_STORE::SaveStat(const STG::UserStat & stat, const std::string & login, int year, int month) const @@ -223,7 +229,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveUserConf(const USER_CONF & conf, +int FIREBIRD_STORE::SaveUserConf(const STG::UserConf & conf, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -331,7 +337,7 @@ try st->Execute(); st->Prepare("insert into tb_allowed_ip (fk_user, ip, mask) values (?, ?, ?)"); - for(size_t i = 0; i < conf.ips.Count(); i++) + for(size_t i = 0; i < conf.ips.count(); i++) { st->Set(1, uid); st->Set(2, (int32_t)conf.ips[i].ip); @@ -351,7 +357,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreUserStat(USER_STAT * stat, +int FIREBIRD_STORE::RestoreUserStat(STG::UserStat * stat, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -438,7 +444,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreUserConf(USER_CONF * conf, +int FIREBIRD_STORE::RestoreUserConf(STG::UserConf * conf, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -537,13 +543,13 @@ try where fk_user = ?"); st->Set(1, uid); st->Execute(); - USER_IPS ips; + STG::UserIPs ips; while (st->Fetch()) { - IP_MASK im; + STG::IPMask im; st->Get(1, (int32_t &)im.ip); st->Get(2, (int32_t &)im.mask); - ips.Add(im); + ips.add(im); } conf->ips = ips; @@ -657,10 +663,10 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_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 @@ -709,7 +715,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::WriteDetailedStat(const std::map & statTree, +int FIREBIRD_STORE::WriteDetailedStat(const STG::TraffStat & statTree, time_t lastStat, const std::string & login) const { @@ -726,7 +732,7 @@ time_t2ts(lastStat, &statTime); try { tr->Start(); - std::map::const_iterator it; + STG::TraffStat::const_iterator it; it = statTree.begin(); st->Prepare("insert into tb_detail_stats \ (till_time, from_time, fk_user, dir_num, \ @@ -761,7 +767,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const +int FIREBIRD_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const { STG_LOCKER lock(&mutex); diff --git a/stargazer/plugins/store/firebird/firebird_store_utils.cpp b/stargazer/plugins/store/firebird/firebird_store_utils.cpp index bbbc8794..582c5445 100644 --- a/stargazer/plugins/store/firebird/firebird_store_utils.cpp +++ b/stargazer/plugins/store/firebird/firebird_store_utils.cpp @@ -26,10 +26,12 @@ * */ -#include - #include "firebird_store.h" + #include "stg/ibpp.h" +#include "stg/common.h" + +#include //----------------------------------------------------------------------------- time_t ts2time_t(const IBPP::Timestamp & ts)