]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig/parser_users.h
Split sgconfig parsers into seaparate files.
[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/resetable.h"
28
29 #include <string>
30
31 class USERS;
32 class USER;
33 class TARIFFS;
34 class ADMIN;
35
36 namespace STG
37 {
38 namespace PARSER
39 {
40
41 class GET_USERS: public BASE_PARSER
42 {
43     public:
44         GET_USERS(const ADMIN & admin, USERS & users)
45             : BASE_PARSER(admin, "GetUsers"), m_users(users),
46               lastUserUpdateTime(0), lastUpdateFound(false) {}
47         int Start(void * data, const char * el, const char ** attr);
48
49     private:
50         USERS & m_users;
51         time_t lastUserUpdateTime;
52         bool lastUpdateFound;
53
54         void CreateAnswer();
55 };
56
57 class GET_USER: public BASE_PARSER
58 {
59     public:
60         GET_USER(const ADMIN & admin, const USERS & users)
61             : BASE_PARSER(admin, "GetUser"), m_users(users) {}
62         int Start(void * data, const char * el, const char ** attr);
63
64     private:
65         const USERS & m_users;
66         std::string login;
67
68         void CreateAnswer();
69 };
70
71 class ADD_USER: public BASE_PARSER
72 {
73     public:
74         ADD_USER(const ADMIN & admin, USERS & users)
75             : BASE_PARSER(admin, "AddUser"), m_users(users) {}
76         int Start(void * data, const char * el, const char ** attr);
77         int End(void * data, const char * el);
78
79     private:
80         USERS & m_users;
81         std::string login;
82
83         int CheckUserData();
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         ~CHG_USER();
92         int Start(void * data, const char * el, const char ** attr);
93         int End(void * data, const char * el);
94
95     private:
96         USERS & m_users;
97         const TARIFFS & m_tariffs;
98         USER_STAT_RES * usr;
99         USER_CONF_RES * ucr;
100         RESETABLE<uint64_t> * upr;
101         RESETABLE<uint64_t> * downr;
102         std::string cashMsg;
103         std::string login;
104         bool cashMustBeAdded;
105         int res;
106
107         int ApplyChanges();
108         void CreateAnswer();
109 };
110
111 class DEL_USER: public BASE_PARSER
112 {
113     public:
114         DEL_USER(const ADMIN & admin, USERS & users)
115             : BASE_PARSER(admin, "DelUser"), m_users(users), res(0), u(NULL) {}
116         int Start(void * data, const char * el, const char ** attr);
117         int End(void * data, const char * el);
118
119     private:
120         USERS & m_users;
121         int res;
122         USER * u;
123
124         void CreateAnswer();
125 };
126
127 class CHECK_USER: public BASE_PARSER
128 {
129     public:
130         CHECK_USER(const ADMIN & admin, const USERS & users)
131             : BASE_PARSER(admin, "CheckUser"), m_users(users) {}
132         int Start(void * data, const char * el, const char ** attr);
133         int End(void * data, const char * el);
134
135     private:
136         const USERS & m_users;
137
138         void CreateAnswer(const char * error);
139 };
140
141 }
142 }
143
144 #endif