]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_users.h
c9f72389751aa44aa5b26df1c109d8ce7553ac61
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_users.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  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #ifndef __STG_SGCONFIG_PARSER_USERS_H__
23 #define __STG_SGCONFIG_PARSER_USERS_H__
24
25 #include "parser.h"
26
27 #include "stg/user_conf.h"
28 #include "stg/user_stat.h"
29 #include "stg/common.h"
30 #include "stg/resetable.h"
31
32 #include <string>
33
34 class USERS;
35 class USER;
36 class TARIFFS;
37 class ADMIN;
38 class STORE;
39
40 namespace STG
41 {
42 namespace PARSER
43 {
44
45 class GET_USERS: public BASE_PARSER
46 {
47     public:
48         class FACTORY : public BASE_PARSER::FACTORY
49         {
50             public:
51                 FACTORY(USERS & users) : m_users(users) {}
52                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USERS(admin, m_users); }
53                 static void Register(REGISTRY & registry, USERS & users)
54                 { registry[ToLower(tag)] = new FACTORY(users); }
55             private:
56                 USERS & m_users;
57         };
58
59         static const char * tag;
60
61         GET_USERS(const ADMIN & admin, USERS & users)
62             : BASE_PARSER(admin, tag), m_users(users),
63               m_lastUserUpdateTime(0) {}
64         int Start(void * data, const char * el, const char ** attr);
65
66     private:
67         USERS & m_users;
68         time_t m_lastUserUpdateTime;
69
70         void CreateAnswer();
71 };
72
73 class GET_USER: public BASE_PARSER
74 {
75     public:
76         class FACTORY : public BASE_PARSER::FACTORY
77         {
78             public:
79                 FACTORY(const USERS & users) : m_users(users) {}
80                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USER(admin, m_users); }
81                 static void Register(REGISTRY & registry, const USERS & users)
82                 { registry[ToLower(tag)] = new FACTORY(users); }
83             private:
84                 const USERS & m_users;
85         };
86
87         static const char * tag;
88
89         GET_USER(const ADMIN & admin, const USERS & users)
90             : BASE_PARSER(admin, tag), m_users(users) {}
91         int Start(void * data, const char * el, const char ** attr);
92
93     private:
94         const USERS & m_users;
95         std::string m_login;
96
97         void CreateAnswer();
98 };
99
100 class ADD_USER: public BASE_PARSER
101 {
102     public:
103         class FACTORY : public BASE_PARSER::FACTORY
104         {
105             public:
106                 FACTORY(USERS & users) : m_users(users) {}
107                 virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_USER(admin, m_users); }
108                 static void Register(REGISTRY & registry, USERS & users)
109                 { registry[ToLower(tag)] = new FACTORY(users); }
110             private:
111                 USERS & m_users;
112         };
113
114         static const char * tag;
115
116         ADD_USER(const ADMIN & admin, USERS & users)
117             : BASE_PARSER(admin, tag), m_users(users) {}
118         int Start(void * data, const char * el, const char ** attr);
119
120     private:
121         USERS & m_users;
122         std::string m_login;
123
124         void CreateAnswer();
125 };
126
127 class CHG_USER: public BASE_PARSER
128 {
129     public:
130         class FACTORY : public BASE_PARSER::FACTORY
131         {
132             public:
133                 FACTORY(USERS & users, STORE & store, const TARIFFS & tariffs)
134                     : m_users(users), m_store(store), m_tariffs(tariffs)
135                 {}
136                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_USER(admin, m_users, m_store, m_tariffs); }
137                 static void Register(REGISTRY & registry, USERS & users, STORE & store, const TARIFFS & tariffs)
138                 { registry[ToLower(tag)] = new FACTORY(users, store, tariffs); }
139             private:
140                 USERS & m_users;
141                 STORE & m_store;
142                 const TARIFFS & m_tariffs;
143         };
144
145         static const char * tag;
146
147         CHG_USER(const ADMIN & admin, USERS & users,
148                  STORE & store, const TARIFFS & tariffs)
149             : BASE_PARSER(admin, tag),
150               m_users(users),
151               m_store(store),
152               m_tariffs(tariffs),
153               m_cashMustBeAdded(false) {}
154
155         int Start(void * data, const char * el, const char ** attr);
156
157     private:
158         USERS & m_users;
159         STORE & m_store;
160         const TARIFFS & m_tariffs;
161         USER_STAT_RES m_usr;
162         USER_CONF_RES m_ucr;
163         RESETABLE<uint64_t> m_upr[DIR_NUM];
164         RESETABLE<uint64_t> m_downr[DIR_NUM];
165         std::string m_cashMsg;
166         std::string m_login;
167         bool m_cashMustBeAdded;
168
169         int ApplyChanges();
170         void CreateAnswer();
171 };
172
173 class DEL_USER: public BASE_PARSER
174 {
175     public:
176         class FACTORY : public BASE_PARSER::FACTORY
177         {
178             public:
179                 FACTORY(USERS & users) : m_users(users) {}
180                 virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_USER(admin, m_users); }
181                 static void Register(REGISTRY & registry, USERS & users)
182                 { registry[ToLower(tag)] = new FACTORY(users); }
183             private:
184                 USERS & m_users;
185         };
186
187         static const char * tag;
188
189         DEL_USER(const ADMIN & admin, USERS & users)
190             : BASE_PARSER(admin, tag), m_users(users), res(0), u(NULL) {}
191         int Start(void * data, const char * el, const char ** attr);
192         int End(void * data, const char * el);
193
194     private:
195         USERS & m_users;
196         int res;
197         USER * u;
198
199         void CreateAnswer();
200 };
201
202 class CHECK_USER: public BASE_PARSER
203 {
204     public:
205         class FACTORY : public BASE_PARSER::FACTORY
206         {
207             public:
208                 FACTORY(const USERS & users) : m_users(users) {}
209                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHECK_USER(admin, m_users); }
210                 static void Register(REGISTRY & registry, const USERS & users)
211                 { registry[ToLower(tag)] = new FACTORY(users); }
212             private:
213                 const USERS & m_users;
214         };
215
216         static const char * tag;
217
218         CHECK_USER(const ADMIN & admin, const USERS & users)
219             : BASE_PARSER(admin, tag), m_users(users) {}
220         int Start(void * data, const char * el, const char ** attr);
221         int End(void * data, const char * el);
222
223     private:
224         const USERS & m_users;
225
226         void CreateAnswer(const char * error);
227         void CreateAnswer() {} // dummy
228 };
229
230 } // namespace PARSER
231 } // namespace STG
232
233 #endif