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 //-----------------------------------------------------------------------------
79 int disableDetailStat;
93 std::string userData[USERDATA_NUM];
95 struct USERDATA * next;
97 //-----------------------------------------------------------------------------
98 typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data);
99 typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
100 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
101 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
102 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
103 //-----------------------------------------------------------------------------
106 char login[ADM_LOGIN_LEN];
108 //-----------------------------------------------------------------------------
114 virtual int ParseStart(const char *el, const char **attr) = 0;
115 virtual void ParseEnd(const char *el) = 0;
117 //-----------------------------------------------------------------------------
118 class PARSER_CHG_USER: public PARSER
122 int ParseStart(const char *el, const char **attr);
123 void ParseEnd(const char *el);
124 void ParseAnswer(const char *el, const char **attr);
125 void SetChgUserRecvCb(RecvChgUserCb_t, void * data);
127 RecvChgUserCb_t RecvChgUserCb;
128 void * chgUserCbData;
132 //-----------------------------------------------------------------------------
133 class PARSER_CHECK_USER: public PARSER
137 int ParseStart(const char *el, const char **attr);
138 void ParseEnd(const char *el);
139 void ParseAnswer(const char *el, const char **attr);
140 void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
142 RecvCheckUserCb_t RecvCheckUserCb;
143 void * checkUserCbData;
147 //-----------------------------------------------------------------------------
148 class PARSER_GET_USERS: public PARSER
152 int ParseStart(const char *el, const char **attr);
153 void ParseEnd(const char *el);
154 void ParseUsers(const char *el, const char **attr);
155 void ParseUser(const char *el, const char **attr);
156 void ParseUserParams(const char *el, const char **attr);
157 void ParseUserLoadStat(const char * el, const char ** attr);
158 void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
160 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;
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;
272 std::string errorMsg;
276 RecvUserDataCb_t RecvUserDataCb;
277 RecvUserDataCb_t RecvGetUserDataCb;
278 RecvServerInfoDataCb_t RecvServerInfoDataCb;
279 RecvChgUserCb_t RecvChgUserCb;
280 RecvCheckUserCb_t RecvCheckUserCb;
281 RecvSendMessageCb_t RecvSendMessageCb;
283 void * getUserDataDataCb;
284 void * getUsersDataDataCb;
285 void * getServerInfoDataCb;
286 void * chgUserDataCb;
287 void * checkUserDataCb;
288 void * sendMessageDataCb;
290 friend int AnsRecv(void * data, std::list<std::string> * list);
292 //-----------------------------------------------------------------------------
294 #endif /* _SERVCONF_H_ */