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;
209 SERVERINFO serverInfo;
211 //-----------------------------------------------------------------------------
212 class PARSER_SEND_MESSAGE: public PARSER
215 PARSER_SEND_MESSAGE();
216 int ParseStart(const char *el, const char **attr);
217 void ParseEnd(const char *el);
218 void ParseAnswer(const char *el, const char **attr);
219 void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
221 RecvSendMessageCb_t RecvSendMessageCb;
222 void * sendMessageCbData;
226 //-----------------------------------------------------------------------------
231 void SetServer(const char * server);
232 void SetPort(uint16_t port);
234 void SetAdmLogin(const char * login);
235 void SetAdmPassword(const char * password);
237 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
238 void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
239 void SetChgUserCb(RecvChgUserCb_t, void * data);
240 void SetCheckUserCb(RecvCheckUserCb_t, void * data);
241 void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
242 void SetSendMessageCb(RecvSendMessageCb_t, void * data);
245 int GetUser(const char * login);
246 int ChgUser(const char * request);
247 // TODO: Remove this shit!
248 int MsgUser(const char * request);
249 int SendMessage(const char * login, const char * message, int prio);
251 int CheckUser(const char * login, const char * password);
253 const std::string & GetStrError() const;
255 int Start(const char *el, const char **attr);
256 void End(const char *el);
261 PARSER_GET_USERS parserGetUsers;
262 PARSER_GET_USER parserGetUser;
263 PARSER_GET_SERVER_INFO parserServerInfo;
264 PARSER_CHG_USER parserChgUser;
265 PARSER_CHECK_USER parserCheckUser;
266 PARSER_SEND_MESSAGE parserSendMessage;
271 std::string errorMsg;
275 RecvUserDataCb_t RecvUserDataCb;
276 RecvUserDataCb_t RecvGetUserDataCb;
277 RecvServerInfoDataCb_t RecvServerInfoDataCb;
278 RecvChgUserCb_t RecvChgUserCb;
279 RecvCheckUserCb_t RecvCheckUserCb;
280 RecvSendMessageCb_t RecvSendMessageCb;
282 void * getUserDataDataCb;
283 void * getUsersDataDataCb;
284 void * getServerInfoDataCb;
285 void * chgUserDataCb;
286 void * checkUserDataCb;
287 void * sendMessageDataCb;
289 friend int AnsRecv(void * data, std::list<std::string> * list);
291 //-----------------------------------------------------------------------------
293 #endif /* _SERVCONF_H_ */