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>
24 #include "stg/message.h"
25 #include "stg/tariff_conf.h"
26 #include "stg/resetable.h"
27 #include "stg/const.h"
42 //-----------------------------------------------------------------------------
55 virtual ~BASE_PARSER() {}
56 virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
57 virtual int ParseEnd(void *data, const char *el) = 0;
58 virtual void Reset() { answer.clear(); depth = 0; }
60 void SetUsers(USERS * u) { users = u; }
61 void SetAdmins(ADMINS * a) { admins = a; }
62 void SetTariffs(TARIFFS * t) { tariffs = t; }
63 void SetStore(STORE * s) { store = s; }
64 void SetStgSettings(const SETTINGS * s) { settings = s; }
66 void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
67 const std::string & GetStrError() const { return strError; }
68 const std::string & GetAnswer() const { return answer; }
71 BASE_PARSER(const BASE_PARSER & rvalue);
72 BASE_PARSER & operator=(const BASE_PARSER & rvalue);
79 const SETTINGS * settings;
84 //-----------------------------------------------------------------------------
85 class PARSER_GET_ADMINS: public BASE_PARSER {
87 int ParseStart(void *data, const char *el, const char **attr);
88 int ParseEnd(void *data, const char *el);
93 //-----------------------------------------------------------------------------
94 class PARSER_ADD_ADMIN: public BASE_PARSER {
96 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
97 int ParseStart(void *data, const char *el, const char **attr);
98 int ParseEnd(void *data, const char *el);
101 std::string adminToAdd;
105 //-----------------------------------------------------------------------------
106 class PARSER_DEL_ADMIN: public BASE_PARSER {
108 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
109 int ParseStart(void *data, const char *el, const char **attr);
110 int ParseEnd(void *data, const char *el);
113 std::string adminToDel;
117 //-----------------------------------------------------------------------------
118 class PARSER_CHG_ADMIN: public BASE_PARSER {
120 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
121 int ParseStart(void *data, const char *el, const char **attr);
122 int ParseEnd(void *data, const char *el);
125 RESETABLE<std::string> login;
126 RESETABLE<std::string> password;
127 RESETABLE<std::string> privAsString;
131 //-----------------------------------------------------------------------------
132 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
134 int ParseStart(void *data, const char *el, const char **attr);
135 int ParseEnd(void *data, const char *el);
140 //-----------------------------------------------------------------------------
141 class PARSER_GET_USER: public BASE_PARSER {
143 PARSER_GET_USER() : BASE_PARSER(), login() {}
144 ~PARSER_GET_USER() {}
145 int ParseStart(void *data, const char *el, const char **attr);
146 int ParseEnd(void *data, const char *el);
153 //-----------------------------------------------------------------------------
154 class PARSER_GET_USERS: public BASE_PARSER {
156 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
157 int ParseStart(void *data, const char *el, const char **attr);
158 int ParseEnd(void *data, const char *el);
161 time_t lastUserUpdateTime;
162 bool lastUpdateFound;
166 //-----------------------------------------------------------------------------
167 class PARSER_GET_TARIFFS: public BASE_PARSER {
169 int ParseStart(void *data, const char *el, const char **attr);
170 int ParseEnd(void *data, const char *el);
175 //-----------------------------------------------------------------------------
176 class PARSER_ADD_TARIFF: public BASE_PARSER {
178 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
179 int ParseStart(void *data, const char *el, const char **attr);
180 int ParseEnd(void *data, const char *el);
183 std::string tariffToAdd;
187 //-----------------------------------------------------------------------------
188 class PARSER_DEL_TARIFF: public BASE_PARSER {
190 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
191 int ParseStart(void *data, const char *el, const char **attr);
192 int ParseEnd(void *data, const char *el);
195 std::string tariffToDel;
199 //-----------------------------------------------------------------------------
200 class PARSER_CHG_TARIFF: public BASE_PARSER {
202 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
203 int ParseStart(void *data, const char *el, const char **attr);
204 int ParseEnd(void *data, const char *el);
209 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
210 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
211 int CheckTariffData();
215 //-----------------------------------------------------------------------------/
216 class PARSER_ADD_USER: public BASE_PARSER {
218 PARSER_ADD_USER() : BASE_PARSER(), login() {}
219 ~PARSER_ADD_USER() {}
220 int ParseStart(void *data, const char *el, const char **attr);
221 int ParseEnd(void *data, const char *el);
230 //-----------------------------------------------------------------------------
231 class PARSER_CHG_USER: public BASE_PARSER {
235 int ParseStart(void *data, const char *el, const char **attr);
236 int ParseEnd(void *data, const char *el);
241 RESETABLE<uint64_t> * upr;
242 RESETABLE<uint64_t> * downr;
245 bool cashMustBeAdded;
248 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
249 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
251 std::string EncChar2String(const char *);
256 //-----------------------------------------------------------------------------
257 class PARSER_DEL_USER: public BASE_PARSER {
259 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
260 int ParseStart(void *data, const char *el, const char **attr);
261 int ParseEnd(void *data, const char *el);
267 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
268 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
272 //-----------------------------------------------------------------------------
273 class PARSER_CHECK_USER: public BASE_PARSER {
275 PARSER_CHECK_USER() : BASE_PARSER() {}
276 int ParseStart(void *data, const char *el, const char **attr);
277 int ParseEnd(void *data, const char *el);
280 void CreateAnswer(const char * error);
282 //-----------------------------------------------------------------------------
283 class PARSER_SEND_MESSAGE: public BASE_PARSER {
285 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
286 int ParseStart(void *data, const char *el, const char **attr);
287 int ParseEnd(void *data, const char *el);
290 enum {res_ok, res_params_error, res_unknown};
291 std::vector<std::string> logins;
296 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
297 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
299 int ParseLogins(const char * logins);
302 //-----------------------------------------------------------------------------