]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/store/firebird/firebird_store.h
638067f2011516f1228af789cb3769f0757d4278
[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 <ctime>
33 #include <string>
34 #include <vector>
35
36 #include "stg/store.h"
37 #include "stg/locker.h"
38 #include "stg/ibpp.h"
39 #include "stg/logger.h"
40
41 struct ToLower {
42     char operator() (char c) const  { return static_cast<char>(std::tolower(c)); }
43 };
44
45 class FIREBIRD_STORE : public STORE {
46 public:
47     FIREBIRD_STORE();
48     virtual ~FIREBIRD_STORE();
49
50     int GetUsersList(std::vector<std::string> * usersList) const;
51     int AddUser(const std::string & login) const;
52     int DelUser(const std::string & login) const;
53     int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
54     int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
55     int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
56     int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
57     int WriteUserChgLog(const std::string & login,
58                         const std::string & admLogin,
59                         uint32_t admIP,
60                         const std::string & paramName,
61                         const std::string & oldValue,
62                         const std::string & newValue,
63                         const std::string & message) const;
64     int WriteUserConnect(const std::string & login, uint32_t ip) const;
65     int WriteUserDisconnect(const std::string & login,
66                             const DIR_TRAFF & up,
67                             const DIR_TRAFF & down,
68                             const DIR_TRAFF & sessionUp,
69                             const DIR_TRAFF & sessionDown,
70                             double cash,
71                             double freeMb,
72                             const std::string & reason) const;
73     int WriteDetailedStat(const TRAFF_STAT & statTree,
74                           time_t lastStat,
75                           const std::string & login) const;
76
77     int AddMessage(STG_MSG * msg, const std::string & login) const;
78     int EditMessage(const STG_MSG & msg, const std::string & login) const;
79     int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
80     int DelMessage(uint64_t id, const std::string & login) const;
81     int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
82
83     int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string  & login) const;
84
85     int GetAdminsList(std::vector<std::string> * adminsList) const;
86     int SaveAdmin(const ADMIN_CONF & ac) const;
87     int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
88     int AddAdmin(const std::string & login) const;
89     int DelAdmin(const std::string & login) const;
90
91     int GetTariffsList(std::vector<std::string> * tariffsList) const;
92     int AddTariff(const std::string & name) const;
93     int DelTariff(const std::string & name) const;
94     int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
95     int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
96
97     int GetCorpsList(std::vector<std::string> * corpsList) const;
98     int SaveCorp(const CORP_CONF & cc) const;
99     int RestoreCorp(CORP_CONF * cc, const std::string & name) const;
100     int AddCorp(const std::string & name) const;
101     int DelCorp(const std::string & name) const;
102
103     inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
104     int ParseSettings();
105
106     inline const std::string & GetStrError() const { return strError; }
107
108     inline const std::string & GetVersion() const { return version; }
109
110     int GetServicesList(std::vector<std::string> * servicesList) const;
111     int SaveService(const SERVICE_CONF & sc) const;
112     int RestoreService(SERVICE_CONF * sc, const std::string & name) const;
113     int AddService(const std::string & name) const;
114     int DelService(const std::string & name) const;
115
116 private:
117     FIREBIRD_STORE(const FIREBIRD_STORE & rvalue);
118     FIREBIRD_STORE & operator=(const FIREBIRD_STORE & rvalue);
119
120     std::string version;
121     mutable std::string strError;
122     std::string db_server, db_database, db_user, db_password;
123     MODULE_SETTINGS settings;
124     mutable IBPP::Database db;
125     mutable pthread_mutex_t mutex;
126     IBPP::TIL til;
127     IBPP::TLR tlr;
128     PLUGIN_LOGGER logger;
129
130     int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const;
131 };
132
133 time_t ts2time_t(const IBPP::Timestamp & ts);
134 void time_t2ts(time_t t, IBPP::Timestamp * ts);
135 void ym2date(int year, int month, IBPP::Date * date);
136
137 #endif //FIREBIRD_STORE_H