]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_users.h
User parser refactoring.
[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
38 namespace STG
39 {
40 namespace PARSER
41 {
42
43 class GET_USERS: public BASE_PARSER
44 {
45     public:
46         GET_USERS(const ADMIN & admin, USERS & users)
47             : BASE_PARSER(admin, "GetUsers"), m_users(users),
48               m_lastUserUpdateTime(0) {}
49         int Start(void * data, const char * el, const char ** attr);
50
51     private:
52         USERS & m_users;
53         time_t m_lastUserUpdateTime;
54
55         void CreateAnswer();
56 };
57
58 class GET_USER: public BASE_PARSER
59 {
60     public:
61         GET_USER(const ADMIN & admin, const USERS & users)
62             : BASE_PARSER(admin, "GetUser"), m_users(users) {}
63         int Start(void * data, const char * el, const char ** attr);
64
65     private:
66         const USERS & m_users;
67         std::string m_login;
68
69         void CreateAnswer();
70 };
71
72 class ADD_USER: public BASE_PARSER
73 {
74     public:
75         ADD_USER(const ADMIN & admin, USERS & users)
76             : BASE_PARSER(admin, "AddUser"), m_users(users) {}
77         int Start(void * data, const char * el, const char ** attr);
78         int End(void * data, const char * el);
79
80     private:
81         USERS & m_users;
82         std::string m_login;
83
84         void CreateAnswer();
85 };
86
87 class CHG_USER: public BASE_PARSER
88 {
89     public:
90         CHG_USER(const ADMIN & admin, USERS & users, const TARIFFS & tariffs)
91             : BASE_PARSER(admin, "SetUser"),
92               m_users(users),
93               m_tariffs(tariffs),
94               m_cashMustBeAdded(false),
95               m_res(0) {}
96
97         int Start(void * data, const char * el, const char ** attr);
98         int End(void * data, const char * el);
99
100     private:
101         USERS & m_users;
102         const TARIFFS & m_tariffs;
103         USER_STAT_RES m_usr;
104         USER_CONF_RES m_ucr;
105         RESETABLE<uint64_t> m_upr[DIR_NUM];
106         RESETABLE<uint64_t> m_downr[DIR_NUM];
107         std::string m_cashMsg;
108         std::string m_login;
109         bool m_cashMustBeAdded;
110         int m_res;
111
112         int ApplyChanges();
113         void CreateAnswer();
114 };
115
116 class DEL_USER: public BASE_PARSER
117 {
118     public:
119         DEL_USER(const ADMIN & admin, USERS & users)
120             : BASE_PARSER(admin, "DelUser"), m_users(users), res(0), u(NULL) {}
121         int Start(void * data, const char * el, const char ** attr);
122         int End(void * data, const char * el);
123
124     private:
125         USERS & m_users;
126         int res;
127         USER * u;
128
129         void CreateAnswer();
130 };
131
132 class CHECK_USER: public BASE_PARSER
133 {
134     public:
135         CHECK_USER(const ADMIN & admin, const USERS & users)
136             : BASE_PARSER(admin, "CheckUser"), m_users(users) {}
137         int Start(void * data, const char * el, const char ** attr);
138         int End(void * data, const char * el);
139
140     private:
141         const USERS & m_users;
142
143         void CreateAnswer(const char * error);
144 };
145
146 }
147 }
148
149 #endif