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 CreateAnswer() = 0;
43 virtual void SetAnswerList(std::list<std::string> * ansList) { answerList = ansList; }
45 virtual void SetUsers(USERS * u) { users = u; }
46 virtual void SetAdmins(ADMINS * a) { admins = a; }
47 virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
48 virtual void SetStore(STORE * s) { store = s; }
49 virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
51 virtual void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
52 virtual std::string & GetStrError() { return strError; }
53 virtual void Reset() { answerList->clear(); depth = 0; }
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);
76 //-----------------------------------------------------------------------------
77 class PARSER_ADD_ADMIN: public BASE_PARSER {
79 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
80 int ParseStart(void *data, const char *el, const char **attr);
81 int ParseEnd(void *data, const char *el);
84 std::string adminToAdd;
86 //-----------------------------------------------------------------------------
87 class PARSER_DEL_ADMIN: public BASE_PARSER {
89 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
90 int ParseStart(void *data, const char *el, const char **attr);
91 int ParseEnd(void *data, const char *el);
94 int CheckAttr(const char **attr);
95 std::string adminToDel;
97 //-----------------------------------------------------------------------------
98 class PARSER_CHG_ADMIN: public BASE_PARSER {
100 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
101 int ParseStart(void *data, const char *el, const char **attr);
102 int ParseEnd(void *data, const char *el);
105 RESETABLE<std::string> login;
106 RESETABLE<std::string> password;
107 RESETABLE<std::string> privAsString;
109 //-----------------------------------------------------------------------------
110 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
112 int ParseStart(void *data, const char *el, const char **attr);
113 int ParseEnd(void *data, const char *el);
116 //-----------------------------------------------------------------------------
117 class PARSER_GET_USER: public BASE_PARSER {
119 PARSER_GET_USER() : BASE_PARSER(), login() {}
120 ~PARSER_GET_USER() {}
121 int ParseStart(void *data, const char *el, const char **attr);
122 int ParseEnd(void *data, const char *el);
127 //-----------------------------------------------------------------------------
128 class PARSER_GET_USERS: public BASE_PARSER {
130 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
131 int ParseStart(void *data, const char *el, const char **attr);
132 int ParseEnd(void *data, const char *el);
135 time_t lastUserUpdateTime;
136 bool lastUpdateFound;
138 //-----------------------------------------------------------------------------
139 class PARSER_GET_TARIFFS: public BASE_PARSER {
141 int ParseStart(void *data, const char *el, const char **attr);
142 int ParseEnd(void *data, const char *el);
145 //-----------------------------------------------------------------------------
146 class PARSER_ADD_TARIFF: public BASE_PARSER {
148 PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
149 int ParseStart(void *data, const char *el, const char **attr);
150 int ParseEnd(void *data, const char *el);
153 std::string tariffToAdd;
155 //-----------------------------------------------------------------------------
156 class PARSER_DEL_TARIFF: public BASE_PARSER {
158 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
159 int ParseStart(void *data, const char *el, const char **attr);
160 int ParseEnd(void *data, const char *el);
163 std::string tariffToDel;
165 //-----------------------------------------------------------------------------
166 class PARSER_CHG_TARIFF: public BASE_PARSER {
168 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
169 int ParseStart(void *data, const char *el, const char **attr);
170 int ParseEnd(void *data, const char *el);
173 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
174 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
175 int CheckTariffData();
180 //-----------------------------------------------------------------------------/
181 class PARSER_ADD_USER: public BASE_PARSER {
183 PARSER_ADD_USER() : BASE_PARSER(), login() {}
184 ~PARSER_ADD_USER() {}
185 int ParseStart(void *data, const char *el, const char **attr);
186 int ParseEnd(void *data, const char *el);
193 //-----------------------------------------------------------------------------
194 class PARSER_CHG_USER: public BASE_PARSER {
198 int ParseStart(void *data, const char *el, const char **attr);
199 int ParseEnd(void *data, const char *el);
203 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
204 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
206 std::string EncChar2String(const char *);
211 RESETABLE<uint64_t> * upr;
212 RESETABLE<uint64_t> * downr;
215 bool cashMustBeAdded;
218 //-----------------------------------------------------------------------------
219 class PARSER_DEL_USER: public BASE_PARSER {
221 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
222 int ParseStart(void *data, const char *el, const char **attr);
223 int ParseEnd(void *data, const char *el);
227 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
228 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
233 //-----------------------------------------------------------------------------
234 class PARSER_CHECK_USER: public BASE_PARSER {
236 PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
237 int ParseStart(void *data, const char *el, const char **attr);
238 int ParseEnd(void *data, const char *el);
239 void CreateAnswer(const char * error);
241 //-----------------------------------------------------------------------------
242 class PARSER_SEND_MESSAGE: public BASE_PARSER {
244 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
245 int ParseStart(void *data, const char *el, const char **attr);
246 int ParseEnd(void *data, const char *el);
249 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
250 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
252 int ParseLogins(const char * logins);
254 enum {res_ok, res_params_error, res_unknown};
255 std::vector<std::string> logins;
260 //-----------------------------------------------------------------------------