3 $Date: 2010/10/07 19:45:52 $
10 #include <mysql/mysql.h>
16 #include "stg/module_settings.h"
17 #include "stg/store.h"
18 #include "stg/user_traff.h"
19 #include "stg/logger.h"
21 //-----------------------------------------------------------------------------
22 class MYSQL_STORE_SETTINGS
25 MYSQL_STORE_SETTINGS();
26 virtual ~MYSQL_STORE_SETTINGS() {}
27 virtual int ParseSettings(const MODULE_SETTINGS & s);
28 virtual const std::string & GetStrError() const { return errorStr; }
30 const std::string & GetDBUser() const { return dbUser; }
31 const std::string & GetDBPassword() const { return dbPass; }
32 const std::string & GetDBHost() const { return dbHost; }
33 const std::string & GetDBName() const { return dbName; }
36 MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
37 MYSQL_STORE_SETTINGS & operator=(const MYSQL_STORE_SETTINGS & rvalue);
39 const MODULE_SETTINGS * settings;
41 int ParseParam(const std::vector<PARAM_VALUE> & moduleParams,
42 const std::string & name, std::string & result);
51 //-----------------------------------------------------------------------------
52 class MYSQL_STORE: public STORE
56 virtual ~MYSQL_STORE() {}
57 virtual const std::string & GetStrError() const { return errorStr; }
60 virtual int GetUsersList(std::vector<std::string> * usersList) const;
61 virtual int AddUser(const std::string & login) const;
62 virtual int DelUser(const std::string & login) const;
63 virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
64 virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
65 virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
66 virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
67 virtual int WriteUserChgLog(const std::string & login,
68 const std::string & admLogin,
70 const std::string & paramName,
71 const std::string & oldValue,
72 const std::string & newValue,
73 const std::string & message = "") const;
74 virtual int WriteUserConnect(const std::string & login, uint32_t ip) const;
75 virtual int WriteUserDisconnect(const std::string & login,
77 const DIR_TRAFF & down,
78 const DIR_TRAFF & sessionUp,
79 const DIR_TRAFF & sessionDown,
82 const std::string & reason) const;
84 virtual int WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
86 const std::string & login) const;
88 virtual int AddMessage(STG_MSG * msg, const std::string & login) const;
89 virtual int EditMessage(const STG_MSG & msg, const std::string & login) const;
90 virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
91 virtual int DelMessage(uint64_t id, const std::string & login) const;
92 virtual int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
94 virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
97 virtual int GetAdminsList(std::vector<std::string> * adminsList) const;
98 virtual int AddAdmin(const std::string & login) const;
99 virtual int DelAdmin(const std::string & login) const;
100 virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
101 virtual int SaveAdmin(const ADMIN_CONF & ac) const;
104 virtual int GetTariffsList(std::vector<std::string> * tariffsList) const;
105 virtual int AddTariff(const std::string & name) const;
106 virtual int DelTariff(const std::string & name) const;
107 virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
108 virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
111 virtual int GetCorpsList(std::vector<std::string> *) const {return 0;}
112 virtual int SaveCorp(const CORP_CONF &) const {return 0;}
113 virtual int RestoreCorp(CORP_CONF *, const std::string &) const {return 0;}
114 virtual int AddCorp(const std::string &) const {return 0;}
115 virtual int DelCorp(const std::string &) const {return 0;}
118 virtual int GetServicesList(std::vector<std::string> *) const {return 0;}
119 virtual int SaveService(const SERVICE_CONF &) const {return 0;}
120 virtual int RestoreService(SERVICE_CONF *, const std::string &) const {return 0;}
121 virtual int AddService(const std::string &) const {return 0;}
122 virtual int DelService(const std::string &) const {return 0;}
124 virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
125 virtual int ParseSettings();
126 virtual const std::string & GetVersion() const { return version; }
129 MYSQL_STORE(const MYSQL_STORE & rvalue);
130 MYSQL_STORE & operator=(const MYSQL_STORE & rvalue);
132 virtual int WriteLogString(const std::string & str, const std::string & login) const;
133 int GetAllParams(std::vector<std::string> * ParamList, const std::string & table, const std::string & name) const;
134 int CheckAllTables(MYSQL * sock);
135 bool IsTablePresent(const std::string & str,MYSQL * sock);
136 mutable std::string errorStr;
137 int MysqlQuery(const char* sQuery,MYSQL * sock) const;
138 int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
139 int MysqlSetQuery(const char * Query) const;
140 MYSQL * MysqlConnect() const ;
142 MYSQL_STORE_SETTINGS storeSettings;
143 MODULE_SETTINGS settings;
145 PLUGIN_LOGGER logger;
147 //-----------------------------------------------------------------------------