3 $Date: 2010/10/07 19:45:52 $
10 #include <mysql/mysql.h>
14 #include "stg/module_settings.h"
15 #include "stg/store.h"
16 #include "stg/user_traff.h"
17 #include "stg/logger.h"
20 //-----------------------------------------------------------------------------
21 extern "C" STORE * GetStore();
22 //-----------------------------------------------------------------------------
23 class MYSQL_STORE_SETTINGS
26 MYSQL_STORE_SETTINGS();
27 virtual ~MYSQL_STORE_SETTINGS() {}
28 virtual int ParseSettings(const MODULE_SETTINGS & s);
29 virtual const string & GetStrError() const { return errorStr; }
31 const string & GetDBUser() const { return dbUser; }
32 const string & GetDBPassword() const { return dbPass; }
33 const string & GetDBHost() const { return dbHost; }
34 const string & GetDBName() const { return dbName; }
37 MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue);
38 MYSQL_STORE_SETTINGS & operator=(const MYSQL_STORE_SETTINGS & rvalue);
40 const MODULE_SETTINGS * settings;
42 int ParseParam(const vector<PARAM_VALUE> & moduleParams,
43 const string & name, string & result);
52 //-----------------------------------------------------------------------------
53 class MYSQL_STORE: public STORE
57 virtual ~MYSQL_STORE() {}
58 virtual const string & GetStrError() const { return errorStr; }
61 virtual int GetUsersList(vector<string> * usersList) const;
62 virtual int AddUser(const string & login) const;
63 virtual int DelUser(const string & login) const;
64 virtual int SaveUserStat(const USER_STAT & stat, const string & login) const;
65 virtual int SaveUserConf(const USER_CONF & conf, const string & login) const;
66 virtual int RestoreUserStat(USER_STAT * stat, const string & login) const;
67 virtual int RestoreUserConf(USER_CONF * conf, const string & login) const;
68 virtual int WriteUserChgLog(const string & login,
69 const string & admLogin,
71 const string & paramName,
72 const string & oldValue,
73 const string & newValue,
74 const string & message = "") const;
75 virtual int WriteUserConnect(const string & login, uint32_t ip) const;
76 virtual int WriteUserDisconnect(const string & login,
78 const DIR_TRAFF & down,
79 const DIR_TRAFF & sessionUp,
80 const DIR_TRAFF & sessionDown,
83 const std::string & reason) const;
85 virtual int WriteDetailedStat(const map<IP_DIR_PAIR, STAT_NODE> & statTree,
87 const string & login) const;
89 virtual int AddMessage(STG_MSG * msg, const string & login) const;
90 virtual int EditMessage(const STG_MSG & msg, const string & login) const;
91 virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const;
92 virtual int DelMessage(uint64_t id, const string & login) const;
93 virtual int GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList, const string & login) const;
95 virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const;
98 virtual int GetAdminsList(vector<string> * adminsList) const;
99 virtual int AddAdmin(const string & login) const;
100 virtual int DelAdmin(const string & login) const;
101 virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const;
102 virtual int SaveAdmin(const ADMIN_CONF & ac) const;
105 virtual int GetTariffsList(vector<string> * tariffsList) const;
106 virtual int AddTariff(const string & name) const;
107 virtual int DelTariff(const string & name) const;
108 virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const;
109 virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const;
112 virtual int GetCorpsList(vector<string> *) const {return 0;};
113 virtual int SaveCorp(const CORP_CONF &) const {return 0;};
114 virtual int RestoreCorp(CORP_CONF *, const string &) const {return 0;};
115 virtual int AddCorp(const string &) const {return 0;};
116 virtual int DelCorp(const string &) const {return 0;};
119 virtual int GetServicesList(vector<string> *) const {return 0;};
120 virtual int SaveService(const SERVICE_CONF &) const {return 0;};
121 virtual int RestoreService(SERVICE_CONF *, const string &) const {return 0;};
122 virtual int AddService(const string &) const {return 0;};
123 virtual int DelService(const string &) const {return 0;};
125 virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
126 virtual int ParseSettings();
127 virtual const string & GetVersion() const { return version; }
130 MYSQL_STORE(const MYSQL_STORE & rvalue);
131 MYSQL_STORE & operator=(const MYSQL_STORE & rvalue);
133 virtual int WriteLogString(const string & str, const string & login) const;
134 int GetAllParams(vector<string> * ParamList, const string & table, const string & name) const;
135 int CheckAllTables(MYSQL * sock);
136 bool IsTablePresent(const string & str,MYSQL * sock);
137 mutable string errorStr;
138 int MysqlQuery(const char* sQuery,MYSQL * sock) const;
139 int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
140 int MysqlSetQuery(const char * Query) const;
141 MYSQL * MysqlConnect() const ;
143 MYSQL_STORE_SETTINGS storeSettings;
144 MODULE_SETTINGS settings;
146 PLUGIN_LOGGER logger;
148 //-----------------------------------------------------------------------------