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_const.h"
38 void Start(void *data, const char *el, const char **attr);
39 void End(void *data, const char *el);
41 #define MAX_ERR_STR_LEN (64)
42 #define IP_STRING_LEN (255)
43 #define UNAME_LEN (256)
44 #define SERV_VER_LEN (64)
45 #define DIRNAME_LEN (16)
47 //-----------------------------------------------------------------------------
50 long long su[DIR_NUM];
51 long long sd[DIR_NUM];
52 long long mu[DIR_NUM];
53 long long md[DIR_NUM];
56 //-----------------------------------------------------------------------------
65 std::string dirName[DIR_NUM];
67 //-----------------------------------------------------------------------------
78 int disableDetailStat;
92 std::string userData[USERDATA_NUM];
94 struct USERDATA * next;
96 //-----------------------------------------------------------------------------
97 typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data);
98 typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
99 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
100 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
101 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
102 //-----------------------------------------------------------------------------
105 char login[ADM_LOGIN_LEN];
107 //-----------------------------------------------------------------------------
113 virtual int ParseStart(const char *el, const char **attr) = 0;
114 virtual void ParseEnd(const char *el) = 0;
116 //virtual bool GetError() = 0;
117 //virtual void SetUserDataRecvCb(RecvUserDataCb_t) = 0;
119 //RecvUserDataCb_t RecvUserDataCb;
122 //-----------------------------------------------------------------------------
123 class PARSER_CHG_USER: public PARSER
127 int ParseStart(const char *el, const char **attr);
128 void ParseEnd(const char *el);
130 void ParseAnswer(const char *el, const char **attr);
131 void SetChgUserRecvCb(RecvChgUserCb_t, void * data);
133 RecvChgUserCb_t RecvChgUserCb;
134 void * chgUserCbData;
138 //-----------------------------------------------------------------------------
139 class PARSER_CHECK_USER: public PARSER
143 int ParseStart(const char *el, const char **attr);
144 void ParseEnd(const char *el);
146 void ParseAnswer(const char *el, const char **attr);
147 void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
149 RecvCheckUserCb_t RecvCheckUserCb;
150 void * checkUserCbData;
154 //-----------------------------------------------------------------------------
155 class PARSER_GET_USERS: public PARSER
159 int ParseStart(const char *el, const char **attr);
160 void ParseEnd(const char *el);
162 void ParseUsers(const char *el, const char **attr);
163 void ParseUser(const char *el, const char **attr);
164 void ParseUserParams(const char *el, const char **attr);
165 void ParseUserLoadStat(const char * el, const char ** attr);
167 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
169 RecvUserDataCb_t RecvUserDataCb;
175 //-----------------------------------------------------------------------------
176 class PARSER_GET_USER: public PARSER
180 int ParseStart(const char *el, const char **attr);
181 void ParseEnd(const char *el);
183 void ParseUsers(const char *el, const char **attr);
184 void ParseUser(const char *el, const char **attr);
185 void ParseUserParams(const char *el, const char **attr);
186 void ParseUserLoadStat(const char * el, const char ** attr);
187 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
189 RecvUserDataCb_t RecvUserDataCb;
195 //-----------------------------------------------------------------------------
196 class PARSER_GET_SERVER_INFO: public PARSER
199 PARSER_GET_SERVER_INFO();
200 int ParseStart(const char *el, const char **attr);
201 void ParseEnd(const char *el);
203 void ParseServerInfo(const char *el, const char **attr);
205 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
207 void ParseUname(const char ** attr);
208 void ParseServerVersion(const char ** attr);
209 void ParseUsersNum(const char ** attr);
210 void ParseTariffsNum(const char ** attr);
211 void ParseTariffType(const char ** attr);
212 void ParseDirNum(const char **attr);
213 void ParseDirName(const char **attr, int d);
215 RecvServerInfoDataCb_t RecvServerInfoDataCb;
216 void * serverInfoDataCb;
220 SERVERINFO serverInfo;
222 //-----------------------------------------------------------------------------
223 class PARSER_SEND_MESSAGE: public PARSER
226 PARSER_SEND_MESSAGE();
227 int ParseStart(const char *el, const char **attr);
228 void ParseEnd(const char *el);
230 void ParseAnswer(const char *el, const char **attr);
231 void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
233 RecvSendMessageCb_t RecvSendMessageCb;
234 void * sendMessageCbData;
238 //-----------------------------------------------------------------------------
243 void SetServer(const char * server);
244 void SetPort(uint16_t port);
246 void SetAdmLogin(const char * login);
247 void SetAdmPassword(const char * password);
249 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
250 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
251 void SetChgUserCb(RecvChgUserCb_t, void * data);
252 void SetCheckUserCb(RecvCheckUserCb_t, void * data);
253 void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
254 void SetSendMessageCb(RecvSendMessageCb_t, void * data);
257 int GetUser(const char * login);
258 int ChgUser(const char * request);
259 // TODO: Remove this shit!
260 int MsgUser(const char * request);
261 int SendMessage(const char * login, const char * message, int prio);
263 int CheckUser(const char * login, const char * password);
265 char * GetStrError();
267 int Start(const char *el, const char **attr);
268 void End(const char *el);
273 PARSER_GET_USERS parserGetUsers;
274 PARSER_GET_USER parserGetUser;
275 PARSER_GET_SERVER_INFO parserServerInfo;
276 PARSER_CHG_USER parserChgUser;
277 PARSER_CHECK_USER parserCheckUser;
278 PARSER_SEND_MESSAGE parserSendMessage;
284 char errorMsg[MAX_ERR_STR_LEN];
288 RecvUserDataCb_t RecvUserDataCb;
289 RecvUserDataCb_t RecvGetUserDataCb;
290 RecvServerInfoDataCb_t RecvServerInfoDataCb;
291 RecvChgUserCb_t RecvChgUserCb;
292 RecvCheckUserCb_t RecvCheckUserCb;
293 RecvSendMessageCb_t RecvSendMessageCb;
295 void * getUserDataDataCb;
296 void * getUsersDataDataCb;
297 void * getServerInfoDataCb;
298 void * chgUserDataCb;
299 void * checkUserDataCb;
300 void * sendMessageDataCb;
302 friend int AnsRecv(void * data, std::list<std::string> * list);
304 //-----------------------------------------------------------------------------
306 #endif /* _SERVCONF_H_ */