]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/store/files/file_store.h
Rename BASE_AUTH and BASE_STORE to AUTH and STORE
[stg.git] / projects / stargazer / plugins / store / files / file_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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21 /*
22  $Revision: 1.22 $
23  $Date: 2010/01/19 11:06:53 $
24  $Author: faust $
25  */
26
27
28 #ifndef FILE_STORE_H
29 #define FILE_STORE_H
30
31 #include <sys/types.h>
32 #include <pthread.h>
33
34 #include <string>
35
36 #include "module_settings.h"
37 #include "store.h"
38 #include "conffiles.h"
39 #include "user_traff.h"
40
41 //-----------------------------------------------------------------------------
42 extern "C" STORE * GetStore();
43 //-----------------------------------------------------------------------------
44 class FILES_STORE_SETTINGS {
45 public:
46     FILES_STORE_SETTINGS();
47     virtual ~FILES_STORE_SETTINGS();
48     virtual int ParseSettings(const MODULE_SETTINGS & s);
49     virtual const std::string & GetStrError() const;
50
51     std::string  GetWorkDir() const;
52     std::string  GetUsersDir() const;
53     std::string  GetAdminsDir() const;
54     std::string  GetTariffsDir() const;
55
56     mode_t  GetStatMode() const;
57     mode_t  GetStatModeDir() const;
58     uid_t   GetStatUID() const;
59     gid_t   GetStatGID() const;
60
61     mode_t  GetConfMode() const;
62     mode_t  GetConfModeDir() const;
63     uid_t   GetConfUID() const;
64     gid_t   GetConfGID() const;
65
66     mode_t  GetLogMode() const;
67     uid_t   GetLogUID() const;
68     gid_t   GetLogGID() const;
69
70     bool    GetRemoveBak() const;
71     bool    GetReadBak() const;
72
73 private:
74     const MODULE_SETTINGS * settings;
75
76     int     User2UID(const char * user, uid_t * uid);
77     int     Group2GID(const char * gr, gid_t * gid);
78     int     Str2Mode(const char * str, mode_t * mode);
79     int     ParseOwner(const std::vector<PARAM_VALUE> & moduleParams, const std::string & owner, uid_t * uid);
80     int     ParseGroup(const std::vector<PARAM_VALUE> & moduleParams, const std::string & group, uid_t * uid);
81     int     ParseMode(const std::vector<PARAM_VALUE> & moduleParams, const std::string & modeStr, mode_t * mode);
82     int     ParseYesNo(const std::string & value, bool * val);
83
84     std::string  errorStr;
85
86     std::string  workDir;
87     std::string  usersDir;
88     std::string  adminsDir;
89     std::string  tariffsDir;
90
91     mode_t  statMode;
92     uid_t   statUID;
93     gid_t   statGID;
94
95     mode_t  confMode;
96     uid_t   confUID;
97     gid_t   confGID;
98
99     mode_t  userLogMode;
100     uid_t   userLogUID;
101     gid_t   userLogGID;
102
103     bool    removeBak;
104     bool    readBak;
105 };
106 //-----------------------------------------------------------------------------
107 class FILES_STORE: public STORE {
108 public:
109     FILES_STORE();
110     virtual ~FILES_STORE();
111     virtual const std::string & GetStrError() const;
112
113     //User
114     virtual int GetUsersList(std::vector<std::string> * usersList) const;
115     virtual int AddUser(const std::string & login) const;
116     virtual int DelUser(const std::string & login) const;
117     virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
118     virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
119
120     virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
121     virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
122
123     virtual int WriteUserChgLog(const std::string & login,
124                                 const std::string & admLogin,
125                                 uint32_t admIP,
126                                 const std::string & paramName,
127                                 const std::string & oldValue,
128                                 const std::string & newValue,
129                                 const std::string & message = "") const;
130     virtual int WriteUserConnect(const std::string & login, uint32_t ip) const;
131     virtual int WriteUserDisconnect(const std::string & login,
132                                     const DIR_TRAFF & up,
133                                     const DIR_TRAFF & down,
134                                     const DIR_TRAFF & sessionUp,
135                                     const DIR_TRAFF & sessionDown,
136                                     double cash,
137                                     double freeMb,
138                                     const std::string & reason) const;
139
140     virtual int WriteDetailedStat(const TRAFF_STAT & statTree,
141                                   time_t lastStat,
142                                   const std::string & login) const;
143
144     virtual int AddMessage(STG_MSG * msg, const std::string & login) const;
145     virtual int EditMessage(const STG_MSG & msg, const std::string & login) const;
146     virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
147     virtual int DelMessage(uint64_t id, const std::string & login) const;
148     virtual int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
149     virtual int ReadMessage(const std::string & fileName,
150                             STG_MSG_HDR * hdr,
151                             std::string * text) const;
152
153     virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
154
155     //Admin
156     virtual int GetAdminsList(std::vector<std::string> * adminsList) const;
157     virtual int AddAdmin(const std::string & login) const;
158     virtual int DelAdmin(const std::string & login) const;
159     virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
160     virtual int SaveAdmin(const ADMIN_CONF & ac) const;
161
162     //Tariff
163     virtual int GetTariffsList(std::vector<std::string> * tariffsList) const;
164     virtual int AddTariff(const std::string & name) const;
165     virtual int DelTariff(const std::string & name) const;
166     virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
167     virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
168
169     //Corparation
170     virtual int GetCorpsList(std::vector<std::string> *) const { return 0; }
171     virtual int SaveCorp(const CORP_CONF &) const { return 0; }
172     virtual int RestoreCorp(CORP_CONF *, const std::string &) const { return 0; }
173     virtual int AddCorp(const std::string &) const { return 0; }
174     virtual int DelCorp(const std::string &) const { return 0; }
175
176     // Services
177     virtual int GetServicesList(std::vector<std::string> *) const { return 0; }
178     virtual int SaveService(const SERVICE_CONF &) const { return 0; }
179     virtual int RestoreService(SERVICE_CONF *, const std::string &) const { return 0; }
180     virtual int AddService(const std::string &) const { return 0; }
181     virtual int DelService(const std::string &) const { return 0; }
182
183     virtual void SetSettings(const MODULE_SETTINGS & s);
184     virtual int ParseSettings();
185     virtual const std::string & GetVersion() const;
186
187 private:
188     virtual int RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const;
189     virtual int RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const;
190
191     virtual int WriteLogString(const std::string & str, const std::string & login) const;
192     virtual int WriteLog2String(const std::string & str, const std::string & login) const;
193     int RemoveDir(const char * path) const;
194     int Touch(const std::string & path) const;
195
196     mutable string errorStr;
197     std::string version;
198     FILES_STORE_SETTINGS storeSettings;
199     MODULE_SETTINGS settings;
200     mutable pthread_mutex_t mutex;
201 };
202 //-----------------------------------------------------------------------------
203
204 #endif