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"
19 //-----------------------------------------------------------------------------
20 extern "C" STORE * GetStore();
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 string & GetStrError() const { return errorStr; }
30 const string & GetDBUser() const { return dbUser; }
31 const string & GetDBPassword() const { return dbPass; }
32 const string & GetDBHost() const { return dbHost; }
33 const 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 vector<PARAM_VALUE> & moduleParams,
42 const string & name, string & result);
51 //-----------------------------------------------------------------------------
52 class MYSQL_STORE: public STORE
56 virtual ~MYSQL_STORE() {}
57 virtual const string & GetStrError() const { return errorStr; }
60 virtual int GetUsersList(vector<string> * usersList) const;
61 virtual int AddUser(const string & login) const;
62 virtual int DelUser(const string & login) const;
63 virtual int SaveUserStat(const USER_STAT & stat, const string & login) const;
64 virtual int SaveUserConf(const USER_CONF & conf, const string & login) const;
65 virtual int RestoreUserStat(USER_STAT * stat, const string & login) const;
66 virtual int RestoreUserConf(USER_CONF * conf, const string & login) const;
67 virtual int WriteUserChgLog(const string & login,
68 const string & admLogin,
70 const string & paramName,
71 const string & oldValue,
72 const string & newValue,
73 const string & message = "") const;
74 virtual int WriteUserConnect(const string & login, uint32_t ip) const;
75 virtual int WriteUserDisconnect(const 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 map<IP_DIR_PAIR, STAT_NODE> & statTree,
86 const string & login) const;
88 virtual int AddMessage(STG_MSG * msg, const string & login) const;
89 virtual int EditMessage(const STG_MSG & msg, const string & login) const;
90 virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const;
91 virtual int DelMessage(uint64_t id, const string & login) const;
92 virtual int GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList, const string & login) const;
94 virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const;
97 virtual int GetAdminsList(vector<string> * adminsList) const;
98 virtual int AddAdmin(const string & login) const;
99 virtual int DelAdmin(const string & login) const;
100 virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const;
101 virtual int SaveAdmin(const ADMIN_CONF & ac) const;
104 virtual int GetTariffsList(vector<string> * tariffsList) const;
105 virtual int AddTariff(const string & name) const;
106 virtual int DelTariff(const string & name) const;
107 virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const;
108 virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const;
111 virtual int GetCorpsList(vector<string> *) const {return 0;};
112 virtual int SaveCorp(const CORP_CONF &) const {return 0;};
113 virtual int RestoreCorp(CORP_CONF *, const string &) const {return 0;};
114 virtual int AddCorp(const string &) const {return 0;};
115 virtual int DelCorp(const string &) const {return 0;};
118 virtual int GetServicesList(vector<string> *) const {return 0;};
119 virtual int SaveService(const SERVICE_CONF &) const {return 0;};
120 virtual int RestoreService(SERVICE_CONF *, const string &) const {return 0;};
121 virtual int AddService(const string &) const {return 0;};
122 virtual int DelService(const string &) const {return 0;};
124 virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
125 virtual int ParseSettings();
126 virtual const 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 string & str, const string & login) const;
133 int GetAllParams(vector<string> * ParamList, const string & table, const string & name) const;
134 int CheckAllTables(MYSQL * sock);
135 bool IsTablePresent(const string & str,MYSQL * sock);
136 mutable 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 //-----------------------------------------------------------------------------