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;
100 int CheckAttr(const char **attr);
103 //-----------------------------------------------------------------------------
104 class PARSER_CHG_ADMIN: public BASE_PARSER {
106 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
107 int ParseStart(void *data, const char *el, const char **attr);
108 int ParseEnd(void *data, const char *el);
111 RESETABLE<std::string> login;
112 RESETABLE<std::string> password;
113 RESETABLE<std::string> privAsString;
117 //-----------------------------------------------------------------------------
118 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
120 int ParseStart(void *data, const char *el, const char **attr);
121 int ParseEnd(void *data, const char *el);
126 //-----------------------------------------------------------------------------
127 class PARSER_GET_USER: public BASE_PARSER {
129 PARSER_GET_USER() : BASE_PARSER(), login() {}
130 ~PARSER_GET_USER() {}
131 int ParseStart(void *data, const char *el, const char **attr);
132 int ParseEnd(void *data, const char *el);
139 //-----------------------------------------------------------------------------
140 class PARSER_GET_USERS: public BASE_PARSER {
142 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
143 int ParseStart(void *data, const char *el, const char **attr);
144 int ParseEnd(void *data, const char *el);
147 time_t lastUserUpdateTime;
148 bool lastUpdateFound;
152 //-----------------------------------------------------------------------------
153 class PARSER_GET_TARIFFS: public BASE_PARSER {
155 int ParseStart(void *data, const char *el, const char **attr);
156 int ParseEnd(void *data, const char *el);
161 //-----------------------------------------------------------------------------
162 class PARSER_ADD_TARIFF: public BASE_PARSER {
164 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
165 int ParseStart(void *data, const char *el, const char **attr);
166 int ParseEnd(void *data, const char *el);
169 std::string tariffToAdd;
173 //-----------------------------------------------------------------------------
174 class PARSER_DEL_TARIFF: public BASE_PARSER {
176 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
177 int ParseStart(void *data, const char *el, const char **attr);
178 int ParseEnd(void *data, const char *el);
181 std::string tariffToDel;
185 //-----------------------------------------------------------------------------
186 class PARSER_CHG_TARIFF: public BASE_PARSER {
188 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
189 int ParseStart(void *data, const char *el, const char **attr);
190 int ParseEnd(void *data, const char *el);
195 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
196 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
197 int CheckTariffData();
201 //-----------------------------------------------------------------------------/
202 class PARSER_ADD_USER: public BASE_PARSER {
204 PARSER_ADD_USER() : BASE_PARSER(), login() {}
205 ~PARSER_ADD_USER() {}
206 int ParseStart(void *data, const char *el, const char **attr);
207 int ParseEnd(void *data, const char *el);
216 //-----------------------------------------------------------------------------
217 class PARSER_CHG_USER: public BASE_PARSER {
221 int ParseStart(void *data, const char *el, const char **attr);
222 int ParseEnd(void *data, const char *el);
227 RESETABLE<uint64_t> * upr;
228 RESETABLE<uint64_t> * downr;
231 bool cashMustBeAdded;
234 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
235 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
237 std::string EncChar2String(const char *);
242 //-----------------------------------------------------------------------------
243 class PARSER_DEL_USER: public BASE_PARSER {
245 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
246 int ParseStart(void *data, const char *el, const char **attr);
247 int ParseEnd(void *data, const char *el);
253 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
254 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
258 //-----------------------------------------------------------------------------
259 class PARSER_CHECK_USER: public BASE_PARSER {
261 PARSER_CHECK_USER() : BASE_PARSER() {}
262 int ParseStart(void *data, const char *el, const char **attr);
263 int ParseEnd(void *data, const char *el);
266 void CreateAnswer(const char * error);
268 //-----------------------------------------------------------------------------
269 class PARSER_SEND_MESSAGE: public BASE_PARSER {
271 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
272 int ParseStart(void *data, const char *el, const char **attr);
273 int ParseEnd(void *data, const char *el);
276 enum {res_ok, res_params_error, res_unknown};
277 std::vector<std::string> logins;
282 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
283 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
285 int ParseLogins(const char * logins);
288 //-----------------------------------------------------------------------------