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.
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.
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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
26 #include "stg/user_conf.h"
27 #include "stg/user_stat.h"
28 #include "stg/common.h"
45 class GET_USERS: public BASE_PARSER
48 class FACTORY : public BASE_PARSER::FACTORY
51 explicit FACTORY(Users & users) : m_users(users) {}
52 BASE_PARSER * create(const Admin & admin) override { return new GET_USERS(admin, m_users); }
53 static void Register(REGISTRY & registry, Users & users)
54 { registry[ToLower(tag)] = new FACTORY(users); }
59 static const char * tag;
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) override;
68 time_t m_lastUserUpdateTime;
70 void CreateAnswer() override;
73 class GET_USER: public BASE_PARSER
76 class FACTORY : public BASE_PARSER::FACTORY
79 explicit FACTORY(const Users & users) : m_users(users) {}
80 BASE_PARSER * create(const Admin & admin) override { return new GET_USER(admin, m_users); }
81 static void Register(REGISTRY & registry, const Users & users)
82 { registry[ToLower(tag)] = new FACTORY(users); }
84 const Users & m_users;
87 static const char * tag;
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) override;
94 const Users & m_users;
97 void CreateAnswer() override;
100 class ADD_USER: public BASE_PARSER
103 class FACTORY : public BASE_PARSER::FACTORY
106 explicit FACTORY(Users & users) : m_users(users) {}
107 BASE_PARSER * create(const Admin & admin) override { return new ADD_USER(admin, m_users); }
108 static void Register(REGISTRY & registry, Users & users)
109 { registry[ToLower(tag)] = new FACTORY(users); }
114 static const char * tag;
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) override;
124 void CreateAnswer() override;
127 class CHG_USER: public BASE_PARSER
130 class FACTORY : public BASE_PARSER::FACTORY
133 FACTORY(Users & users, Store & store, const Tariffs & tariffs)
134 : m_users(users), m_store(store), m_tariffs(tariffs)
136 BASE_PARSER * create(const Admin & admin) override { 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); }
142 const Tariffs & m_tariffs;
145 static const char * tag;
147 CHG_USER(const Admin & admin, Users & users,
148 Store & store, const Tariffs & tariffs)
149 : BASE_PARSER(admin, tag),
153 m_cashMustBeAdded(false) {}
155 int Start(void * data, const char * el, const char ** attr) override;
160 const Tariffs & m_tariffs;
163 std::optional<uint64_t> m_upr[DIR_NUM];
164 std::optional<uint64_t> m_downr[DIR_NUM];
165 std::string m_cashMsg;
167 bool m_cashMustBeAdded;
170 void CreateAnswer() override;
173 class DEL_USER: public BASE_PARSER
176 class FACTORY : public BASE_PARSER::FACTORY
179 explicit FACTORY(Users & users) : m_users(users) {}
180 BASE_PARSER * create(const Admin & admin) override { return new DEL_USER(admin, m_users); }
181 static void Register(REGISTRY & registry, Users & users)
182 { registry[ToLower(tag)] = new FACTORY(users); }
187 static const char * tag;
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) override;
192 int End(void * data, const char * el) override;
199 void CreateAnswer() override;
202 class CHECK_USER: public BASE_PARSER
205 class FACTORY : public BASE_PARSER::FACTORY
208 explicit FACTORY(const Users & users) : m_users(users) {}
209 BASE_PARSER * create(const Admin & admin) override { return new CHECK_USER(admin, m_users); }
210 static void Register(REGISTRY & registry, const Users & users)
211 { registry[ToLower(tag)] = new FACTORY(users); }
213 const Users & m_users;
216 static const char * tag;
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) override;
221 int End(void * data, const char * el) override;
224 const Users & m_users;
226 void CreateAnswer(const char * error);
227 void CreateAnswer() override {} // dummy
230 } // namespace PARSER