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>
23 $Date: 2009/03/17 09:52:35 $
36 #include "stg/os_int.h"
37 #include "stg/const.h"
40 void Start(void *data, const char *el, const char **attr);
41 void End(void *data, const char *el);
43 #define MAX_ERR_STR_LEN (64)
44 #define IP_STRING_LEN (255)
45 #define UNAME_LEN (256)
46 #define SERV_VER_LEN (64)
47 #define DIRNAME_LEN (16)
49 //-----------------------------------------------------------------------------
52 long long su[DIR_NUM];
53 long long sd[DIR_NUM];
54 long long mu[DIR_NUM];
55 long long md[DIR_NUM];
58 //-----------------------------------------------------------------------------
67 std::string dirName[DIR_NUM];
69 //-----------------------------------------------------------------------------
81 int disableDetailStat;
95 std::string userData[USERDATA_NUM];
97 struct USERDATA * next;
99 //-----------------------------------------------------------------------------
100 typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data);
101 typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
102 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
103 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
104 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
105 typedef void(*RecvAuthByDataCb_t)(const std::vector<std::string> & list, void * data);
106 //-----------------------------------------------------------------------------
109 char login[ADM_LOGIN_LEN];
111 //-----------------------------------------------------------------------------
117 virtual int ParseStart(const char *el, const char **attr) = 0;
118 virtual void ParseEnd(const char *el) = 0;
120 //-----------------------------------------------------------------------------
121 class PARSER_CHG_USER: public PARSER
125 int ParseStart(const char *el, const char **attr);
126 void ParseEnd(const char *el);
127 void ParseAnswer(const char *el, const char **attr);
128 void SetChgUserRecvCb(RecvChgUserCb_t, void * data);
130 RecvChgUserCb_t RecvChgUserCb;
131 void * chgUserCbData;
135 //-----------------------------------------------------------------------------
136 class PARSER_CHECK_USER: public PARSER
140 int ParseStart(const char *el, const char **attr);
141 void ParseEnd(const char *el);
142 void ParseAnswer(const char *el, const char **attr);
143 void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
145 RecvCheckUserCb_t RecvCheckUserCb;
146 void * checkUserCbData;
150 //-----------------------------------------------------------------------------
151 class PARSER_GET_USERS: public PARSER
155 int ParseStart(const char *el, const char **attr);
156 void ParseEnd(const char *el);
157 void ParseUsers(const char *el, const char **attr);
158 void ParseUser(const char *el, const char **attr);
159 void ParseUserParams(const char *el, const char **attr);
160 void ParseUserLoadStat(const char * el, const char ** attr);
161 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
163 RecvUserDataCb_t RecvUserDataCb;
169 //-----------------------------------------------------------------------------
170 class PARSER_GET_USER: public PARSER
174 int ParseStart(const char *el, const char **attr);
175 void ParseEnd(const char *el);
176 void ParseUsers(const char *el, const char **attr);
177 void ParseUser(const char *el, const char **attr);
178 void ParseUserParams(const char *el, const char **attr);
179 void ParseUserLoadStat(const char * el, const char ** attr);
180 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
182 RecvUserDataCb_t RecvUserDataCb;
188 //-----------------------------------------------------------------------------
189 class PARSER_GET_SERVER_INFO: public PARSER
192 PARSER_GET_SERVER_INFO();
193 int ParseStart(const char *el, const char **attr);
194 void ParseEnd(const char *el);
195 void ParseServerInfo(const char *el, const char **attr);
197 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
199 void ParseUname(const char ** attr);
200 void ParseServerVersion(const char ** attr);
201 void ParseUsersNum(const char ** attr);
202 void ParseTariffsNum(const char ** attr);
203 void ParseTariffType(const char ** attr);
204 void ParseDirNum(const char **attr);
205 void ParseDirName(const char **attr, int d);
207 RecvServerInfoDataCb_t RecvServerInfoDataCb;
208 void * serverInfoDataCb;
211 SERVERINFO serverInfo;
213 //-----------------------------------------------------------------------------
214 class PARSER_SEND_MESSAGE: public PARSER
217 PARSER_SEND_MESSAGE();
218 int ParseStart(const char *el, const char **attr);
219 void ParseEnd(const char *el);
220 void ParseAnswer(const char *el, const char **attr);
221 void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
223 RecvSendMessageCb_t RecvSendMessageCb;
224 void * sendMessageCbData;
228 //-----------------------------------------------------------------------------
229 class PARSER_AUTH_BY: public PARSER
233 int ParseStart(const char *el, const char **attr);
234 void ParseEnd(const char *el);
235 void ParseServerInfo(const char *el, const char **attr);
237 void SetRecvCb(RecvAuthByDataCb_t, void * data);
239 RecvAuthByDataCb_t RecvAuthByDataCb;
243 std::vector<std::string> list;
245 //-----------------------------------------------------------------------------
250 void SetServer(const char * server);
251 void SetPort(uint16_t port);
253 void SetAdmLogin(const char * login);
254 void SetAdmPassword(const char * password);
256 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
257 void SetGetUserAuthByRecvCb(RecvAuthByDataCb_t, void * data);
258 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
259 void SetChgUserCb(RecvChgUserCb_t, void * data);
260 void SetCheckUserCb(RecvCheckUserCb_t, void * data);
261 void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
262 void SetSendMessageCb(RecvSendMessageCb_t, void * data);
265 int GetUser(const char * login);
266 int ChgUser(const char * request);
267 int GetUserAuthBy(const char * login);
268 // TODO: Remove this shit!
269 int MsgUser(const char * request);
270 int SendMessage(const char * login, const char * message, int prio);
272 int CheckUser(const char * login, const char * password);
274 const std::string & GetStrError() const;
276 int Start(const char *el, const char **attr);
277 void End(const char *el);
282 PARSER_GET_USERS parserGetUsers;
283 PARSER_GET_USER parserGetUser;
284 PARSER_AUTH_BY parserAuthBy;
285 PARSER_GET_SERVER_INFO parserServerInfo;
286 PARSER_CHG_USER parserChgUser;
287 PARSER_CHECK_USER parserCheckUser;
288 PARSER_SEND_MESSAGE parserSendMessage;
293 std::string errorMsg;
297 RecvUserDataCb_t RecvUserDataCb;
298 RecvUserDataCb_t RecvGetUserDataCb;
299 RecvAuthByDataCb_t RecvAuthByCb;
300 RecvServerInfoDataCb_t RecvServerInfoDataCb;
301 RecvChgUserCb_t RecvChgUserCb;
302 RecvCheckUserCb_t RecvCheckUserCb;
303 RecvSendMessageCb_t RecvSendMessageCb;
305 void * getUserDataDataCb;
306 void * getUserAuthByDataCb;
307 void * getUsersDataDataCb;
308 void * getServerInfoDataCb;
309 void * chgUserDataCb;
310 void * checkUserDataCb;
311 void * sendMessageDataCb;
313 friend int AnsRecv(void * data, std::list<std::string> * list);
315 //-----------------------------------------------------------------------------
317 #endif /* _SERVCONF_H_ */