]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/store/firebird/firebird_store.h
Добавление исходников
[stg.git] / projects / stargazer / plugins / store / firebird / firebird_store.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 /*
22  *  Firebird storage class definition
23  *
24  *  $Revision: 1.13 $
25  *  $Date: 2010/01/19 11:07:25 $
26  *
27  */
28
29 #ifndef FIREBIRD_STORE_H
30 #define FIREBIRD_STORE_H
31
32 #include <string>
33 #include <vector>
34 #include <map>
35
36 #include "base_store.h"
37 #include "stg_locker.h"
38 #include "ibpp.h"
39 //#include "firebird_database.h"
40
41 struct ToLower
42 {
43 char operator() (char c) const  { return std::tolower(c); }
44 };
45
46 extern "C" BASE_STORE * GetStore();
47
48 class FIREBIRD_STORE : public BASE_STORE {
49 public:
50     FIREBIRD_STORE();
51     virtual ~FIREBIRD_STORE();
52
53     int GetUsersList(std::vector<std::string> * usersList) const;
54     int AddUser(const std::string & login) const;
55     int DelUser(const std::string & login) const;
56     int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
57     int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
58     int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
59     int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
60     int WriteUserChgLog(const std::string & login,
61                         const std::string & admLogin,
62                         uint32_t admIP,
63                         const std::string & paramName,
64                         const std::string & oldValue,
65                         const std::string & newValue,
66                         const std::string & message) const;
67     int WriteUserConnect(const std::string & login, uint32_t ip) const;
68     int WriteUserDisconnect(const std::string & login,
69                             const DIR_TRAFF & up,
70                             const DIR_TRAFF & down,
71                             const DIR_TRAFF & sessionUp,
72                             const DIR_TRAFF & sessionDown,
73                             double cash,
74                             double freeMb,
75                             const std::string & reason) const;
76     int WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> * statTree,
77                           time_t lastStat,
78                           const std::string & login) const;
79
80     int AddMessage(STG_MSG * msg, const std::string & login) const;
81     int EditMessage(const STG_MSG & msg, const std::string & login) const;
82     int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
83     int DelMessage(uint64_t id, const std::string & login) const;
84     int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
85
86     int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string  & login) const;
87
88     int GetAdminsList(std::vector<std::string> * adminsList) const;
89     int SaveAdmin(const ADMIN_CONF & ac) const;
90     int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
91     int AddAdmin(const std::string & login) const;
92     int DelAdmin(const std::string & login) const;
93
94     int GetTariffsList(std::vector<std::string> * tariffsList) const;
95     int AddTariff(const std::string & name) const;
96     int DelTariff(const string & name) const;
97     int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
98     int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
99
100     int GetCorpsList(std::vector<std::string> * corpsList) const;
101     int SaveCorp(const CORP_CONF & cc) const;
102     int RestoreCorp(CORP_CONF * cc, const std::string & name) const;
103     int AddCorp(const std::string & name) const;
104     int DelCorp(const std::string & name) const;
105
106     inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
107     int ParseSettings();
108
109     inline const string & GetStrError() const { return strError; };
110
111     inline const string & GetVersion() const { return version; };
112
113     int GetServicesList(std::vector<std::string> * servicesList) const;
114     int SaveService(const SERVICE_CONF & sc) const;
115     int RestoreService(SERVICE_CONF * sc, const std::string & name) const;
116     int AddService(const std::string & name) const;
117     int DelService(const std::string & name) const;
118 private:
119     std::string version;
120     mutable std::string strError;
121     mutable std::string db_server, db_database, db_user, db_password;
122     MODULE_SETTINGS settings;
123     mutable IBPP::Database db;
124     mutable pthread_mutex_t mutex;
125     mutable IBPP::TIL til;
126     mutable IBPP::TLR tlr;
127
128     int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const;
129
130     time_t ts2time_t(const IBPP::Timestamp & ts) const;
131     void time_t2ts(time_t t, IBPP::Timestamp * ts) const;
132     void ym2date(int year, int month, IBPP::Date * date) const;
133 };
134
135 #endif //FIREBIRD_STORE_H
136