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 $
37 #include "stg_const.h"
39 void Start(void *data, const char *el, const char **attr);
40 void End(void *data, const char *el);
42 #define MAX_ERR_STR_LEN (64)
43 #define IP_STRING_LEN (255)
44 #define UNAME_LEN (256)
45 #define SERV_VER_LEN (64)
46 #define DIRNAME_LEN (16)
48 //-----------------------------------------------------------------------------
51 long long su[DIR_NUM];
52 long long sd[DIR_NUM];
53 long long mu[DIR_NUM];
54 long long md[DIR_NUM];
57 //-----------------------------------------------------------------------------
66 std::string dirName[DIR_NUM];
68 //-----------------------------------------------------------------------------
80 int disableDetailStat;
94 std::string userData[USERDATA_NUM];
96 struct USERDATA * next;
98 //-----------------------------------------------------------------------------
99 typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data);
100 typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
101 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
102 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
103 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
104 //-----------------------------------------------------------------------------
107 char login[ADM_LOGIN_LEN];
109 //-----------------------------------------------------------------------------
115 virtual int ParseStart(const char *el, const char **attr) = 0;
116 virtual void ParseEnd(const char *el) = 0;
118 //-----------------------------------------------------------------------------
119 class PARSER_CHG_USER: public PARSER
123 int ParseStart(const char *el, const char **attr);
124 void ParseEnd(const char *el);
125 void ParseAnswer(const char *el, const char **attr);
126 void SetChgUserRecvCb(RecvChgUserCb_t, void * data);
128 RecvChgUserCb_t RecvChgUserCb;
129 void * chgUserCbData;
133 //-----------------------------------------------------------------------------
134 class PARSER_CHECK_USER: public PARSER
138 int ParseStart(const char *el, const char **attr);
139 void ParseEnd(const char *el);
140 void ParseAnswer(const char *el, const char **attr);
141 void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
143 RecvCheckUserCb_t RecvCheckUserCb;
144 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;
167 //-----------------------------------------------------------------------------
168 class PARSER_GET_USER: public PARSER
172 int ParseStart(const char *el, const char **attr);
173 void ParseEnd(const char *el);
174 void ParseUsers(const char *el, const char **attr);
175 void ParseUser(const char *el, const char **attr);
176 void ParseUserParams(const char *el, const char **attr);
177 void ParseUserLoadStat(const char * el, const char ** attr);
178 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
180 RecvUserDataCb_t RecvUserDataCb;
186 //-----------------------------------------------------------------------------
187 class PARSER_GET_SERVER_INFO: public PARSER
190 PARSER_GET_SERVER_INFO();
191 int ParseStart(const char *el, const char **attr);
192 void ParseEnd(const char *el);
193 void ParseServerInfo(const char *el, const char **attr);
195 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
197 void ParseUname(const char ** attr);
198 void ParseServerVersion(const char ** attr);
199 void ParseUsersNum(const char ** attr);
200 void ParseTariffsNum(const char ** attr);
201 void ParseTariffType(const char ** attr);
202 void ParseDirNum(const char **attr);
203 void ParseDirName(const char **attr, int d);
205 RecvServerInfoDataCb_t RecvServerInfoDataCb;
206 void * serverInfoDataCb;
210 SERVERINFO serverInfo;
212 //-----------------------------------------------------------------------------
213 class PARSER_SEND_MESSAGE: public PARSER
216 PARSER_SEND_MESSAGE();
217 int ParseStart(const char *el, const char **attr);
218 void ParseEnd(const char *el);
219 void ParseAnswer(const char *el, const char **attr);
220 void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
222 RecvSendMessageCb_t RecvSendMessageCb;
223 void * sendMessageCbData;
227 //-----------------------------------------------------------------------------
232 void SetServer(const char * server);
233 void SetPort(uint16_t port);
235 void SetAdmLogin(const char * login);
236 void SetAdmPassword(const char * password);
238 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
239 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
240 void SetChgUserCb(RecvChgUserCb_t, void * data);
241 void SetCheckUserCb(RecvCheckUserCb_t, void * data);
242 void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
243 void SetSendMessageCb(RecvSendMessageCb_t, void * data);
246 int GetUser(const char * login);
247 int ChgUser(const char * request);
248 // TODO: Remove this shit!
249 int MsgUser(const char * request);
250 int SendMessage(const char * login, const char * message, int prio);
252 int CheckUser(const char * login, const char * password);
254 const std::string & GetStrError() const;
256 int Start(const char *el, const char **attr);
257 void End(const char *el);
262 PARSER_GET_USERS parserGetUsers;
263 PARSER_GET_USER parserGetUser;
264 PARSER_GET_SERVER_INFO parserServerInfo;
265 PARSER_CHG_USER parserChgUser;
266 PARSER_CHECK_USER parserCheckUser;
267 PARSER_SEND_MESSAGE parserSendMessage;
273 std::string errorMsg;
277 RecvUserDataCb_t RecvUserDataCb;
278 RecvUserDataCb_t RecvGetUserDataCb;
279 RecvServerInfoDataCb_t RecvServerInfoDataCb;
280 RecvChgUserCb_t RecvChgUserCb;
281 RecvCheckUserCb_t RecvCheckUserCb;
282 RecvSendMessageCb_t RecvSendMessageCb;
284 void * getUserDataDataCb;
285 void * getUsersDataDataCb;
286 void * getServerInfoDataCb;
287 void * chgUserDataCb;
288 void * checkUserDataCb;
289 void * sendMessageDataCb;
291 friend int AnsRecv(void * data, std::list<std::string> * list);
293 //-----------------------------------------------------------------------------
295 #endif /* _SERVCONF_H_ */