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"
25 //-----------------------------------------------------------------------------
39 virtual ~BASE_PARSER() {}
40 virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
41 virtual int ParseEnd(void *data, const char *el) = 0;
42 virtual void Reset() { answerList->clear(); depth = 0; }
44 void SetAnswerList(std::list<std::string> * ansList) { answerList = ansList; }
46 void SetUsers(USERS * u) { users = u; }
47 void SetAdmins(ADMINS * a) { admins = a; }
48 void SetTariffs(TARIFFS * t) { tariffs = t; }
49 void SetStore(STORE * s) { store = s; }
50 void SetStgSettings(const SETTINGS * s) { settings = s; }
52 void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
53 std::string & GetStrError() { return strError; }
56 BASE_PARSER(const BASE_PARSER & rvalue);
57 BASE_PARSER & operator=(const BASE_PARSER & rvalue);
64 const SETTINGS * settings;
67 std::list<std::string> * answerList;
69 //-----------------------------------------------------------------------------
70 class PARSER_GET_ADMINS: public BASE_PARSER {
72 int ParseStart(void *data, const char *el, const char **attr);
73 int ParseEnd(void *data, const char *el);
78 //-----------------------------------------------------------------------------
79 class PARSER_ADD_ADMIN: public BASE_PARSER {
81 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
82 int ParseStart(void *data, const char *el, const char **attr);
83 int ParseEnd(void *data, const char *el);
86 std::string adminToAdd;
90 //-----------------------------------------------------------------------------
91 class PARSER_DEL_ADMIN: public BASE_PARSER {
93 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
94 int ParseStart(void *data, const char *el, const char **attr);
95 int ParseEnd(void *data, const char *el);
98 std::string adminToDel;
102 //-----------------------------------------------------------------------------
103 class PARSER_CHG_ADMIN: public BASE_PARSER {
105 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
106 int ParseStart(void *data, const char *el, const char **attr);
107 int ParseEnd(void *data, const char *el);
110 RESETABLE<std::string> login;
111 RESETABLE<std::string> password;
112 RESETABLE<std::string> privAsString;
116 //-----------------------------------------------------------------------------
117 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
119 int ParseStart(void *data, const char *el, const char **attr);
120 int ParseEnd(void *data, const char *el);
125 //-----------------------------------------------------------------------------
126 class PARSER_GET_USER: public BASE_PARSER {
128 PARSER_GET_USER() : BASE_PARSER(), login() {}
129 ~PARSER_GET_USER() {}
130 int ParseStart(void *data, const char *el, const char **attr);
131 int ParseEnd(void *data, const char *el);
138 //-----------------------------------------------------------------------------
139 class PARSER_GET_USERS: public BASE_PARSER {
141 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
142 int ParseStart(void *data, const char *el, const char **attr);
143 int ParseEnd(void *data, const char *el);
146 time_t lastUserUpdateTime;
147 bool lastUpdateFound;
151 //-----------------------------------------------------------------------------
152 class PARSER_GET_TARIFFS: public BASE_PARSER {
154 int ParseStart(void *data, const char *el, const char **attr);
155 int ParseEnd(void *data, const char *el);
160 //-----------------------------------------------------------------------------
161 class PARSER_ADD_TARIFF: public BASE_PARSER {
163 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
164 int ParseStart(void *data, const char *el, const char **attr);
165 int ParseEnd(void *data, const char *el);
168 std::string tariffToAdd;
172 //-----------------------------------------------------------------------------
173 class PARSER_DEL_TARIFF: public BASE_PARSER {
175 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
176 int ParseStart(void *data, const char *el, const char **attr);
177 int ParseEnd(void *data, const char *el);
180 std::string tariffToDel;
184 //-----------------------------------------------------------------------------
185 class PARSER_CHG_TARIFF: public BASE_PARSER {
187 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
188 int ParseStart(void *data, const char *el, const char **attr);
189 int ParseEnd(void *data, const char *el);
194 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
195 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
196 int CheckTariffData();
200 //-----------------------------------------------------------------------------/
201 class PARSER_ADD_USER: public BASE_PARSER {
203 PARSER_ADD_USER() : BASE_PARSER(), login() {}
204 ~PARSER_ADD_USER() {}
205 int ParseStart(void *data, const char *el, const char **attr);
206 int ParseEnd(void *data, const char *el);
215 //-----------------------------------------------------------------------------
216 class PARSER_CHG_USER: public BASE_PARSER {
220 int ParseStart(void *data, const char *el, const char **attr);
221 int ParseEnd(void *data, const char *el);
226 RESETABLE<uint64_t> * upr;
227 RESETABLE<uint64_t> * downr;
230 bool cashMustBeAdded;
233 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
234 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
236 std::string EncChar2String(const char *);
241 //-----------------------------------------------------------------------------
242 class PARSER_DEL_USER: public BASE_PARSER {
244 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
245 int ParseStart(void *data, const char *el, const char **attr);
246 int ParseEnd(void *data, const char *el);
252 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
253 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
257 //-----------------------------------------------------------------------------
258 class PARSER_CHECK_USER: public BASE_PARSER {
260 PARSER_CHECK_USER() : BASE_PARSER() {}
261 int ParseStart(void *data, const char *el, const char **attr);
262 int ParseEnd(void *data, const char *el);
265 void CreateAnswer(const char * error);
267 //-----------------------------------------------------------------------------
268 class PARSER_SEND_MESSAGE: public BASE_PARSER {
270 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
271 int ParseStart(void *data, const char *el, const char **attr);
272 int ParseEnd(void *data, const char *el);
275 enum {res_ok, res_params_error, res_unknown};
276 std::vector<std::string> logins;
281 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
282 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
284 int ParseLogins(const char * logins);
287 //-----------------------------------------------------------------------------