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 virtual void SetUsers(USERS * u) { users = u; }
43 virtual void SetAdmins(ADMINS * a) { admins = a; }
44 virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
45 virtual void SetStore(STORE * s) { store = s; }
46 virtual 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);
73 //-----------------------------------------------------------------------------
74 class PARSER_ADD_ADMIN: public BASE_PARSER {
76 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
77 int ParseStart(void *data, const char *el, const char **attr);
78 int ParseEnd(void *data, const char *el);
81 std::string adminToAdd;
83 //-----------------------------------------------------------------------------
84 class PARSER_DEL_ADMIN: public BASE_PARSER {
86 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
87 int ParseStart(void *data, const char *el, const char **attr);
88 int ParseEnd(void *data, const char *el);
91 int CheckAttr(const char **attr);
92 std::string adminToDel;
94 //-----------------------------------------------------------------------------
95 class PARSER_CHG_ADMIN: public BASE_PARSER {
97 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
98 int ParseStart(void *data, const char *el, const char **attr);
99 int ParseEnd(void *data, const char *el);
102 RESETABLE<std::string> login;
103 RESETABLE<std::string> password;
104 RESETABLE<std::string> privAsString;
106 //-----------------------------------------------------------------------------
107 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
109 int ParseStart(void *data, const char *el, const char **attr);
110 int ParseEnd(void *data, const char *el);
113 //-----------------------------------------------------------------------------
114 class PARSER_GET_USER: public BASE_PARSER {
116 PARSER_GET_USER() : BASE_PARSER(), login() {}
117 ~PARSER_GET_USER() {}
118 int ParseStart(void *data, const char *el, const char **attr);
119 int ParseEnd(void *data, const char *el);
124 //-----------------------------------------------------------------------------
125 class PARSER_GET_USERS: public BASE_PARSER {
127 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
128 int ParseStart(void *data, const char *el, const char **attr);
129 int ParseEnd(void *data, const char *el);
132 time_t lastUserUpdateTime;
133 bool lastUpdateFound;
135 //-----------------------------------------------------------------------------
136 class PARSER_GET_TARIFFS: public BASE_PARSER {
138 int ParseStart(void *data, const char *el, const char **attr);
139 int ParseEnd(void *data, const char *el);
142 //-----------------------------------------------------------------------------
143 class PARSER_ADD_TARIFF: public BASE_PARSER {
145 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
146 int ParseStart(void *data, const char *el, const char **attr);
147 int ParseEnd(void *data, const char *el);
150 std::string tariffToAdd;
152 //-----------------------------------------------------------------------------
153 class PARSER_DEL_TARIFF: public BASE_PARSER {
155 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
156 int ParseStart(void *data, const char *el, const char **attr);
157 int ParseEnd(void *data, const char *el);
160 std::string tariffToDel;
162 //-----------------------------------------------------------------------------
163 class PARSER_CHG_TARIFF: public BASE_PARSER {
165 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
166 int ParseStart(void *data, const char *el, const char **attr);
167 int ParseEnd(void *data, const char *el);
170 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
171 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
172 int CheckTariffData();
177 //-----------------------------------------------------------------------------/
178 class PARSER_ADD_USER: public BASE_PARSER {
180 PARSER_ADD_USER() : BASE_PARSER(), login() {}
181 ~PARSER_ADD_USER() {}
182 int ParseStart(void *data, const char *el, const char **attr);
183 int ParseEnd(void *data, const char *el);
190 //-----------------------------------------------------------------------------
191 class PARSER_CHG_USER: public BASE_PARSER {
195 int ParseStart(void *data, const char *el, const char **attr);
196 int ParseEnd(void *data, const char *el);
200 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
201 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
203 std::string EncChar2String(const char *);
208 RESETABLE<uint64_t> * upr;
209 RESETABLE<uint64_t> * downr;
212 bool cashMustBeAdded;
215 //-----------------------------------------------------------------------------
216 class PARSER_DEL_USER: public BASE_PARSER {
218 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
219 int ParseStart(void *data, const char *el, const char **attr);
220 int ParseEnd(void *data, const char *el);
224 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
225 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
230 //-----------------------------------------------------------------------------
231 class PARSER_CHECK_USER: public BASE_PARSER {
233 PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
234 int ParseStart(void *data, const char *el, const char **attr);
235 int ParseEnd(void *data, const char *el);
240 //-----------------------------------------------------------------------------
241 class PARSER_SEND_MESSAGE: public BASE_PARSER {
243 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
244 int ParseStart(void *data, const char *el, const char **attr);
245 int ParseEnd(void *data, const char *el);
248 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
249 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
251 int ParseLogins(const char * logins);
253 enum {res_ok, res_params_error, res_unknown};
254 std::vector<std::string> logins;
259 //-----------------------------------------------------------------------------