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; }
29 MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
30 MYSQL_STORE_SETTINGS & operator=(const MYSQL_STORE_SETTINGS & rvalue);
32 const STG::ModuleSettings * settings;
34 int ParseParam(const std::vector<STG::ParamValue> & moduleParams,
35 const std::string & name, std::string & result);
44 //-----------------------------------------------------------------------------
45 class MYSQL_STORE: public STG::Store
49 const std::string & GetStrError() const override { return errorStr; }
52 int GetUsersList(std::vector<std::string> * usersList) const override;
53 int AddUser(const std::string & login) const override;
54 int DelUser(const std::string & login) const override;
55 int SaveUserStat(const STG::UserStat & stat, const std::string & login) const override;
56 int SaveUserConf(const STG::UserConf & conf, const std::string & login) const override;
57 int RestoreUserStat(STG::UserStat * stat, const std::string & login) const override;
58 int RestoreUserConf(STG::UserConf * conf, const std::string & login) const override;
59 int WriteUserChgLog(const std::string & login,
60 const std::string & admLogin,
62 const std::string & paramName,
63 const std::string & oldValue,
64 const std::string & newValue,
65 const std::string & message = "") const override;
66 int WriteUserConnect(const std::string & login, uint32_t ip) const override;
67 int WriteUserDisconnect(const std::string & login,
68 const STG::DirTraff & up,
69 const STG::DirTraff & down,
70 const STG::DirTraff & sessionUp,
71 const STG::DirTraff & sessionDown,
74 const std::string & reason) const override;
76 int WriteDetailedStat(const STG::TraffStat & statTree,
78 const std::string & login) const override;
80 int AddMessage(STG::Message * msg, const std::string & login) const override;
81 int EditMessage(const STG::Message & msg, const std::string & login) const override;
82 int GetMessage(uint64_t id, STG::Message * msg, const std::string & login) const override;
83 int DelMessage(uint64_t id, const std::string & login) const override;
84 int GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList, const std::string & login) const override;
86 int SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const override;
89 int GetAdminsList(std::vector<std::string> * adminsList) const override;
90 int AddAdmin(const std::string & login) const override;
91 int DelAdmin(const std::string & login) const override;
92 int RestoreAdmin(STG::AdminConf * ac, const std::string & login) const override;
93 int SaveAdmin(const STG::AdminConf & ac) const override;
96 int GetTariffsList(std::vector<std::string> * tariffsList) const override;
97 int AddTariff(const std::string & name) const override;
98 int DelTariff(const std::string & name) const override;
99 int SaveTariff(const STG::TariffData & td, const std::string & tariffName) const override;
100 int RestoreTariff(STG::TariffData * td, const std::string & tariffName) const override;
103 int GetCorpsList(std::vector<std::string> *) const override {return 0;}
104 int SaveCorp(const STG::CorpConf &) const override {return 0;}
105 int RestoreCorp(STG::CorpConf *, const std::string &) const override {return 0;}
106 int AddCorp(const std::string &) const override {return 0;}
107 int DelCorp(const std::string &) const override {return 0;}
110 int GetServicesList(std::vector<std::string> *) const override {return 0;}
111 int SaveService(const STG::ServiceConf &) const override {return 0;}
112 int RestoreService(STG::ServiceConf *, const std::string &) const override {return 0;}
113 int AddService(const std::string &) const override {return 0;}
114 int DelService(const std::string &) const override {return 0;}
116 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
117 int ParseSettings() override;
118 const std::string & GetVersion() const override { return version; }
121 MYSQL_STORE(const MYSQL_STORE & rvalue);
122 MYSQL_STORE & operator=(const MYSQL_STORE & rvalue);
124 virtual int WriteLogString(const std::string & str, const std::string & login) const;
125 int GetAllParams(std::vector<std::string> * ParamList, const std::string & table, const std::string & name) const;
126 int CheckAllTables(MYSQL * sock);
127 int MakeUpdates(MYSQL * sock);
128 bool IsTablePresent(const std::string & str,MYSQL * sock);
129 mutable std::string errorStr;
130 int MysqlQuery(const char* sQuery,MYSQL * sock) const;
131 int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
132 int MysqlSetQuery(const char * Query) const;
133 MYSQL * MysqlConnect() const ;
135 MYSQL_STORE_SETTINGS storeSettings;
136 STG::ModuleSettings settings;
139 STG::PluginLogger logger;