4 #include "stg/module_settings.h"
5 #include "stg/user_traff.h"
6 #include "stg/logger.h"
12 #include <mysql/mysql.h>
14 //-----------------------------------------------------------------------------
15 class MYSQL_STORE_SETTINGS
18 MYSQL_STORE_SETTINGS();
19 virtual ~MYSQL_STORE_SETTINGS() {}
20 virtual int ParseSettings(const STG::ModuleSettings & s);
21 virtual const std::string & GetStrError() const { return errorStr; }
23 const std::string & GetDBUser() const { return dbUser; }
24 const std::string & GetDBPassword() const { return dbPass; }
25 const std::string & GetDBHost() const { return dbHost; }
26 const std::string & GetDBName() const { return dbName; }
27 unsigned int GetDBPort() const { return dbPort; }
30 MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
31 MYSQL_STORE_SETTINGS & operator=(const MYSQL_STORE_SETTINGS & rvalue);
33 const STG::ModuleSettings * settings;
35 int ParseParam(const std::vector<STG::ParamValue> & moduleParams,
36 const std::string & name, std::string & result);
46 //-----------------------------------------------------------------------------
47 class MYSQL_STORE: public STG::Store
51 const std::string & GetStrError() const override { return errorStr; }
54 int GetUsersList(std::vector<std::string> * usersList) const override;
55 int AddUser(const std::string & login) const override;
56 int DelUser(const std::string & login) const override;
57 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
58 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
59 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
60 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
61 int WriteUserChgLog(const std::string & login,
62 const std::string & admLogin,
64 const std::string & paramName,
65 const std::string & oldValue,
66 const std::string & newValue,
67 const std::string & message = "") const override;
68 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
69 int WriteUserDisconnect(const std::string & login,
70 const STG::DirTraff & up,
71 const STG::DirTraff & down,
72 const STG::DirTraff & sessionUp,
73 const STG::DirTraff & sessionDown,
76 const std::string & reason) const override;
78 int WriteDetailedStat(const STG::TraffStat & statTree,
80 const std::string & login) const override;
82 int AddMessage(STG::Message * msg, const std::string & login) const override;
83 int EditMessage(const STG::Message & msg, const std::string & login) const override;
84 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
85 int DelMessage(uint64_t id, const std::string & login) const override;
86 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
88 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
91 int GetAdminsList(std::vector<std::string> * adminsList) const override;
92 int AddAdmin(const std::string & login) const override;
93 int DelAdmin(const std::string & login) const override;
94 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
95 int SaveAdmin(const STG::AdminConf & ac) const override;
98 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
99 int AddTariff(const std::string & name) const override;
100 int DelTariff(const std::string & name) const override;
101 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
102 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
105 int GetCorpsList(std::vector<std::string> *) const override {return 0;}
106 int SaveCorp(const STG::CorpConf &) const override {return 0;}
107 int RestoreCorp(STG::CorpConf *, const std::string &) const override {return 0;}
108 int AddCorp(const std::string &) const override {return 0;}
109 int DelCorp(const std::string &) const override {return 0;}
112 int GetServicesList(std::vector<std::string> *) const override {return 0;}
113 int SaveService(const STG::ServiceConf &) const override {return 0;}
114 int RestoreService(STG::ServiceConf *, const std::string &) const override {return 0;}
115 int AddService(const std::string &) const override {return 0;}
116 int DelService(const std::string &) const override {return 0;}
118 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
119 int ParseSettings() override;
120 const std::string & GetVersion() const override { return version; }
123 MYSQL_STORE(const MYSQL_STORE & rvalue);
124 MYSQL_STORE & operator=(const MYSQL_STORE & rvalue);
126 virtual int WriteLogString(const std::string & str, const std::string & login) const;
127 int GetAllParams(std::vector<std::string> * ParamList, const std::string & table, const std::string & name) const;
128 int CheckAllTables(MYSQL * sock);
129 int MakeUpdates(MYSQL * sock);
130 bool IsTablePresent(const std::string & str,MYSQL * sock);
131 mutable std::string errorStr;
132 int MysqlQuery(const char* sQuery,MYSQL * sock) const;
133 int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
134 int MysqlSetQuery(const char * Query) const;
135 MYSQL * MysqlConnect() const ;
137 MYSQL_STORE_SETTINGS storeSettings;
138 STG::ModuleSettings settings;
141 STG::PluginLogger logger;