3 $Date: 2010/10/04 20:26:10 $
10 #include "stg/resetable.h"
11 #include "stg/const.h"
12 #include "stg/store.h"
13 #include "stg/admins.h"
14 #include "stg/admin.h"
15 #include "stg/users.h"
16 #include "stg/message.h"
24 //-----------------------------------------------------------------------------
37 virtual ~BASE_PARSER() {}
38 virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
39 virtual int ParseEnd(void *data, const char *el) = 0;
40 virtual void Reset() { answer.clear(); depth = 0; }
42 void SetUsers(USERS * u) { users = u; }
43 void SetAdmins(ADMINS * a) { admins = a; }
44 void SetTariffs(TARIFFS * t) { tariffs = t; }
45 void SetStore(STORE * s) { store = s; }
46 void SetStgSettings(const SETTINGS * s) { settings = s; }
48 void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
49 const std::string & GetStrError() const { return strError; }
50 const std::string & GetAnswer() const { return answer; }
53 BASE_PARSER(const BASE_PARSER & rvalue);
54 BASE_PARSER & operator=(const BASE_PARSER & rvalue);
61 const SETTINGS * settings;
66 //-----------------------------------------------------------------------------
67 class PARSER_GET_ADMINS: public BASE_PARSER {
69 int ParseStart(void *data, const char *el, const char **attr);
70 int ParseEnd(void *data, const char *el);
75 //-----------------------------------------------------------------------------
76 class PARSER_ADD_ADMIN: public BASE_PARSER {
78 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
79 int ParseStart(void *data, const char *el, const char **attr);
80 int ParseEnd(void *data, const char *el);
83 std::string adminToAdd;
87 //-----------------------------------------------------------------------------
88 class PARSER_DEL_ADMIN: public BASE_PARSER {
90 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
91 int ParseStart(void *data, const char *el, const char **attr);
92 int ParseEnd(void *data, const char *el);
95 std::string adminToDel;
99 //-----------------------------------------------------------------------------
100 class PARSER_CHG_ADMIN: public BASE_PARSER {
102 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
103 int ParseStart(void *data, const char *el, const char **attr);
104 int ParseEnd(void *data, const char *el);
107 RESETABLE<std::string> login;
108 RESETABLE<std::string> password;
109 RESETABLE<std::string> privAsString;
113 //-----------------------------------------------------------------------------
114 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
116 int ParseStart(void *data, const char *el, const char **attr);
117 int ParseEnd(void *data, const char *el);
122 //-----------------------------------------------------------------------------
123 class PARSER_GET_USER: public BASE_PARSER {
125 PARSER_GET_USER() : BASE_PARSER(), login() {}
126 ~PARSER_GET_USER() {}
127 int ParseStart(void *data, const char *el, const char **attr);
128 int ParseEnd(void *data, const char *el);
135 //-----------------------------------------------------------------------------
136 class PARSER_GET_USERS: public BASE_PARSER {
138 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
139 int ParseStart(void *data, const char *el, const char **attr);
140 int ParseEnd(void *data, const char *el);
143 time_t lastUserUpdateTime;
144 bool lastUpdateFound;
148 //-----------------------------------------------------------------------------
149 class PARSER_GET_TARIFFS: public BASE_PARSER {
151 int ParseStart(void *data, const char *el, const char **attr);
152 int ParseEnd(void *data, const char *el);
157 //-----------------------------------------------------------------------------
158 class PARSER_ADD_TARIFF: public BASE_PARSER {
160 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
161 int ParseStart(void *data, const char *el, const char **attr);
162 int ParseEnd(void *data, const char *el);
165 std::string tariffToAdd;
169 //-----------------------------------------------------------------------------
170 class PARSER_DEL_TARIFF: public BASE_PARSER {
172 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
173 int ParseStart(void *data, const char *el, const char **attr);
174 int ParseEnd(void *data, const char *el);
177 std::string tariffToDel;
181 //-----------------------------------------------------------------------------
182 class PARSER_CHG_TARIFF: public BASE_PARSER {
184 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
185 int ParseStart(void *data, const char *el, const char **attr);
186 int ParseEnd(void *data, const char *el);
191 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
192 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
193 int CheckTariffData();
197 //-----------------------------------------------------------------------------/
198 class PARSER_ADD_USER: public BASE_PARSER {
200 PARSER_ADD_USER() : BASE_PARSER(), login() {}
201 ~PARSER_ADD_USER() {}
202 int ParseStart(void *data, const char *el, const char **attr);
203 int ParseEnd(void *data, const char *el);
212 //-----------------------------------------------------------------------------
213 class PARSER_CHG_USER: public BASE_PARSER {
217 int ParseStart(void *data, const char *el, const char **attr);
218 int ParseEnd(void *data, const char *el);
223 RESETABLE<uint64_t> * upr;
224 RESETABLE<uint64_t> * downr;
227 bool cashMustBeAdded;
230 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
231 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
233 std::string EncChar2String(const char *);
238 //-----------------------------------------------------------------------------
239 class PARSER_DEL_USER: public BASE_PARSER {
241 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
242 int ParseStart(void *data, const char *el, const char **attr);
243 int ParseEnd(void *data, const char *el);
249 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
250 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
254 //-----------------------------------------------------------------------------
255 class PARSER_CHECK_USER: public BASE_PARSER {
257 PARSER_CHECK_USER() : BASE_PARSER() {}
258 int ParseStart(void *data, const char *el, const char **attr);
259 int ParseEnd(void *data, const char *el);
262 void CreateAnswer(const char * error);
264 //-----------------------------------------------------------------------------
265 class PARSER_SEND_MESSAGE: public BASE_PARSER {
267 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
268 int ParseStart(void *data, const char *el, const char **attr);
269 int ParseEnd(void *data, const char *el);
272 enum {res_ok, res_params_error, res_unknown};
273 std::vector<std::string> logins;
278 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
279 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
281 int ParseLogins(const char * logins);
284 //-----------------------------------------------------------------------------