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