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;
134 //-----------------------------------------------------------------------------
135 class PARSER_CHECK_USER: public PARSER
139 int ParseStart(const char *el, const char **attr);
140 void ParseEnd(const char *el);
141 void ParseAnswer(const char *el, const char **attr);
142 void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
144 RecvCheckUserCb_t RecvCheckUserCb;
145 void * checkUserCbData;
148 //-----------------------------------------------------------------------------
149 class PARSER_GET_USERS: public PARSER
153 int ParseStart(const char *el, const char **attr);
154 void ParseEnd(const char *el);
155 void ParseUsers(const char *el, const char **attr);
156 void ParseUser(const char *el, const char **attr);
157 void ParseUserParams(const char *el, const char **attr);
158 void ParseUserLoadStat(const char * el, const char ** attr);
159 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
161 RecvUserDataCb_t RecvUserDataCb;
166 //-----------------------------------------------------------------------------
167 class PARSER_GET_USER: public PARSER
171 int ParseStart(const char *el, const char **attr);
172 void ParseEnd(const char *el);
173 void ParseUsers(const char *el, const char **attr);
174 void ParseUser(const char *el, const char **attr);
175 void ParseUserParams(const char *el, const char **attr);
176 void ParseUserLoadStat(const char * el, const char ** attr);
177 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
179 RecvUserDataCb_t RecvUserDataCb;
185 //-----------------------------------------------------------------------------
186 class PARSER_GET_SERVER_INFO: public PARSER
189 PARSER_GET_SERVER_INFO();
190 int ParseStart(const char *el, const char **attr);
191 void ParseEnd(const char *el);
192 void ParseServerInfo(const char *el, const char **attr);
194 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
196 void ParseUname(const char ** attr);
197 void ParseServerVersion(const char ** attr);
198 void ParseUsersNum(const char ** attr);
199 void ParseTariffsNum(const char ** attr);
200 void ParseTariffType(const char ** attr);
201 void ParseDirNum(const char **attr);
202 void ParseDirName(const char **attr, int d);
204 RecvServerInfoDataCb_t RecvServerInfoDataCb;
205 void * serverInfoDataCb;
208 SERVERINFO serverInfo;
210 //-----------------------------------------------------------------------------
211 class PARSER_SEND_MESSAGE: public PARSER
214 PARSER_SEND_MESSAGE();
215 int ParseStart(const char *el, const char **attr);
216 void ParseEnd(const char *el);
217 void ParseAnswer(const char *el, const char **attr);
218 void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
220 RecvSendMessageCb_t RecvSendMessageCb;
221 void * sendMessageCbData;
224 //-----------------------------------------------------------------------------
225 class PARSER_AUTH_BY: public PARSER
229 int ParseStart(const char *el, const char **attr);
230 void ParseEnd(const char *el);
231 void ParseServerInfo(const char *el, const char **attr);
233 void SetRecvCb(RecvAuthByDataCb_t, void * data);
235 RecvAuthByDataCb_t RecvAuthByDataCb;
239 std::vector<std::string> list;
241 //-----------------------------------------------------------------------------
246 void SetServer(const char * server);
247 void SetPort(uint16_t port);
249 void SetAdmLogin(const char * login);
250 void SetAdmPassword(const char * password);
252 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
253 void SetGetUserAuthByRecvCb(RecvAuthByDataCb_t, void * data);
254 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
255 void SetChgUserCb(RecvChgUserCb_t, void * data);
256 void SetCheckUserCb(RecvCheckUserCb_t, void * data);
257 void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
258 void SetSendMessageCb(RecvSendMessageCb_t, void * data);
261 int GetUser(const char * login);
262 int ChgUser(const char * request);
263 int GetUserAuthBy(const char * login);
264 // TODO: Remove this shit!
265 int MsgUser(const char * request);
266 int SendMessage(const char * login, const char * message, int prio);
268 int CheckUser(const char * login, const char * password);
270 const std::string & GetStrError() const;
272 int Start(const char *el, const char **attr);
273 void End(const char *el);
278 PARSER_GET_USERS parserGetUsers;
279 PARSER_GET_USER parserGetUser;
280 PARSER_AUTH_BY parserAuthBy;
281 PARSER_GET_SERVER_INFO parserServerInfo;
282 PARSER_CHG_USER parserChgUser;
283 PARSER_CHECK_USER parserCheckUser;
284 PARSER_SEND_MESSAGE parserSendMessage;
288 std::string errorMsg;
292 RecvUserDataCb_t RecvUserDataCb;
293 RecvUserDataCb_t RecvGetUserDataCb;
294 RecvAuthByDataCb_t RecvAuthByCb;
295 RecvServerInfoDataCb_t RecvServerInfoDataCb;
296 RecvChgUserCb_t RecvChgUserCb;
297 RecvCheckUserCb_t RecvCheckUserCb;
298 RecvSendMessageCb_t RecvSendMessageCb;
300 void * getUserDataDataCb;
301 void * getUserAuthByDataCb;
302 void * getUsersDataDataCb;
303 void * getServerInfoDataCb;
304 void * chgUserDataCb;
305 void * checkUserDataCb;
306 void * sendMessageDataCb;
308 friend int AnsRecv(void * data, std::list<std::string> * list);
310 //-----------------------------------------------------------------------------
312 #endif /* _SERVCONF_H_ */