2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
24 #include "stg/message.h"
25 #include "stg/tariff_conf.h"
26 #include "stg/resetable.h"
27 #include "stg/const.h"
42 //-----------------------------------------------------------------------------
55 virtual ~BASE_PARSER() {}
56 virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
57 virtual int ParseEnd(void *data, const char *el) = 0;
58 virtual void Reset() { answer.clear(); depth = 0; }
60 virtual void SetUsers(USERS * u) { users = u; }
61 virtual void SetAdmins(ADMINS * a) { admins = a; }
62 virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
63 virtual void SetStore(STORE * s) { store = s; }
64 virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
66 void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
67 const std::string & GetStrError() const { return strError; }
68 const std::string & GetAnswer() const { return answer; }
71 BASE_PARSER(const BASE_PARSER & rvalue);
72 BASE_PARSER & operator=(const BASE_PARSER & rvalue);
79 const SETTINGS * settings;
84 //-----------------------------------------------------------------------------
85 class PARSER_GET_ADMINS: public BASE_PARSER {
87 int ParseStart(void *data, const char *el, const char **attr);
88 int ParseEnd(void *data, const char *el);
91 //-----------------------------------------------------------------------------
92 class PARSER_ADD_ADMIN: public BASE_PARSER {
94 PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
95 int ParseStart(void *data, const char *el, const char **attr);
96 int ParseEnd(void *data, const char *el);
99 std::string adminToAdd;
101 //-----------------------------------------------------------------------------
102 class PARSER_DEL_ADMIN: public BASE_PARSER {
104 PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
105 int ParseStart(void *data, const char *el, const char **attr);
106 int ParseEnd(void *data, const char *el);
109 int CheckAttr(const char **attr);
110 std::string adminToDel;
112 //-----------------------------------------------------------------------------
113 class PARSER_CHG_ADMIN: public BASE_PARSER {
115 PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
116 int ParseStart(void *data, const char *el, const char **attr);
117 int ParseEnd(void *data, const char *el);
120 RESETABLE<std::string> login;
121 RESETABLE<std::string> password;
122 RESETABLE<std::string> privAsString;
124 //-----------------------------------------------------------------------------
125 class PARSER_GET_SERVER_INFO: public BASE_PARSER {
127 int ParseStart(void *data, const char *el, const char **attr);
128 int ParseEnd(void *data, const char *el);
131 //-----------------------------------------------------------------------------
132 class PARSER_GET_USER: public BASE_PARSER {
134 PARSER_GET_USER() : BASE_PARSER(), login() {}
135 ~PARSER_GET_USER() {}
136 int ParseStart(void *data, const char *el, const char **attr);
137 int ParseEnd(void *data, const char *el);
142 //-----------------------------------------------------------------------------
143 class PARSER_GET_USERS: public BASE_PARSER {
145 PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
146 int ParseStart(void *data, const char *el, const char **attr);
147 int ParseEnd(void *data, const char *el);
150 time_t lastUserUpdateTime;
151 bool lastUpdateFound;
153 //-----------------------------------------------------------------------------
154 class PARSER_GET_TARIFFS: public BASE_PARSER {
156 int ParseStart(void *data, const char *el, const char **attr);
157 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;
170 //-----------------------------------------------------------------------------
171 class PARSER_DEL_TARIFF: public BASE_PARSER {
173 PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
174 int ParseStart(void *data, const char *el, const char **attr);
175 int ParseEnd(void *data, const char *el);
178 std::string tariffToDel;
180 //-----------------------------------------------------------------------------
181 class PARSER_CHG_TARIFF: public BASE_PARSER {
183 PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
184 int ParseStart(void *data, const char *el, const char **attr);
185 int ParseEnd(void *data, const char *el);
188 int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
189 int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
190 int CheckTariffData();
195 //-----------------------------------------------------------------------------/
196 class PARSER_ADD_USER: public BASE_PARSER {
198 PARSER_ADD_USER() : BASE_PARSER(), login() {}
199 ~PARSER_ADD_USER() {}
200 int ParseStart(void *data, const char *el, const char **attr);
201 int ParseEnd(void *data, const char *el);
208 //-----------------------------------------------------------------------------
209 class PARSER_CHG_USER: public BASE_PARSER {
213 int ParseStart(void *data, const char *el, const char **attr);
214 int ParseEnd(void *data, const char *el);
218 PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
219 PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
221 std::string EncChar2String(const char *);
226 RESETABLE<uint64_t> * upr;
227 RESETABLE<uint64_t> * downr;
230 bool cashMustBeAdded;
233 //-----------------------------------------------------------------------------
234 class PARSER_DEL_USER: public BASE_PARSER {
236 PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
237 int ParseStart(void *data, const char *el, const char **attr);
238 int ParseEnd(void *data, const char *el);
242 PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
243 PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
248 //-----------------------------------------------------------------------------
249 class PARSER_CHECK_USER: public BASE_PARSER {
251 PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
252 int ParseStart(void *data, const char *el, const char **attr);
253 int ParseEnd(void *data, const char *el);
258 //-----------------------------------------------------------------------------
259 class PARSER_SEND_MESSAGE: public BASE_PARSER {
261 PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
262 int ParseStart(void *data, const char *el, const char **attr);
263 int ParseEnd(void *data, const char *el);
266 PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
267 PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
269 int ParseLogins(const char * logins);
271 enum {res_ok, res_params_error, res_unknown};
272 std::vector<std::string> logins;
277 //-----------------------------------------------------------------------------