1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2#ifndef _ICQ_H_
3#define _ICQ_H_
4
5#ifdef HAVE_CONFIG_H
6#include <config.h>
7#endif
8
9#define ICQLIBVER   @ICQLIBVER@
10#define ICQLIBMAJOR @ICQLIBMAJOR@
11#define ICQLIBMINOR @ICQLIBMINOR@
12#define ICQLIBMICRO @ICQLIBMICRO@
13
14#include <time.h>
15
16#ifndef _WIN32
17#include <sys/time.h>
18#include <sys/types.h>
19#include <unistd.h>
20#endif
21
22#ifdef _WIN32
23#include <winsock.h>
24#endif
25
26#define ICQ_LOG_OFF     0
27#define ICQ_LOG_FATAL   1
28#define ICQ_LOG_ERROR   2
29#define ICQ_LOG_WARNING 3
30#define ICQ_LOG_MESSAGE 4
31
32#define STATUS_OFFLINE     (-1L)
33#define STATUS_ONLINE      0x0000L
34#define STATUS_AWAY        0x0001L
35#define STATUS_DND         0x0002L /* 0x13L */
36#define STATUS_NA          0x0004L /* 0x05L */
37#define STATUS_OCCUPIED    0x0010L /* 0x11L */
38#define STATUS_FREE_CHAT   0x0020L
39#define STATUS_INVISIBLE   0x0100L
40
41#define ICQ_SEND_THRUSERVER       0
42#define ICQ_SEND_DIRECT           1
43#define ICQ_SEND_BESTWAY          2
44
45#define ICQ_NOTIFY_SUCCESS        0
46#define ICQ_NOTIFY_FAILED         1
47#define ICQ_NOTIFY_CONNECTING     2
48#define ICQ_NOTIFY_CONNECTED      3
49#define ICQ_NOTIFY_SENT           4
50#define ICQ_NOTIFY_ACK            5
51
52#define ICQ_NOTIFY_CHAT           6
53#define ICQ_NOTIFY_CHATDATA       7
54
55#define ICQ_NOTIFY_FILE           10
56#define ICQ_NOTIFY_FILESESSION    11
57#define ICQ_NOTIFY_FILEDATA       12
58
59#ifdef __cplusplus
60extern "C" {
61#endif /* __cplusplus */
62
63typedef struct
64{
65  const char *name;
66  unsigned short code;
67} icq_ArrayType;
68
69typedef struct icq_link
70{
71  /* General */
72  unsigned long icq_Uin;
73  unsigned long icq_OurIP;          /* HOST byteorder */
74  unsigned short icq_OurPort;       /* HOST byteorder */
75  void *icq_ContactList;
76  unsigned long icq_Status;
77  char *icq_Password;
78  char *icq_Nick;
79
80  /* UDP stuff */
81  int icq_UDPSok;
82  unsigned char icq_UDPServMess[8192]; /* 65536 seqs max, 1 bit per seq -> 65536/8 = 8192 */
83  unsigned short icq_UDPSeqNum1, icq_UDPSeqNum2;
84  unsigned long icq_UDPSession;
85  void *icq_UDPQueue;
86  int icq_UDPExpireInterval;
87
88  /* TCP stuff */
89  unsigned short icq_TCPSrvPort;    /* HOST byteorder */
90  int icq_TCPSequence;
91  void *icq_TCPLinks;
92  void *icq_ChatSessions;
93  void *icq_FileSessions;
94  int TCP_maxfd;
95  fd_set TCP_readfds;
96  fd_set TCP_writefds;
97
98  /* SOCKS5 Proxy stuff */
99  unsigned char icq_UseProxy;
100  char *icq_ProxyHost;
101  unsigned long icq_ProxyIP;        /* HOST byteorder */
102  unsigned short icq_ProxyPort;     /* HOST byteorder */
103  int  icq_ProxyAuth;
104  char *icq_ProxyName;
105  char *icq_ProxyPass;
106  int icq_ProxySok;
107  unsigned short icq_ProxyOurPort;  /* HOST byteorder */
108  unsigned long icq_ProxyDestIP;    /* HOST byteorder */
109  unsigned short icq_ProxyDestPort; /* HOST byteorder */
110
111  /*** Callbacks ***/
112  void (*icq_Logged)(struct icq_link *link);
113  void (*icq_Disconnected)(struct icq_link *link);
114  void (*icq_RecvMessage)(struct icq_link *link, unsigned long uin,
115       unsigned char hour, unsigned char minute, unsigned char day,
116       unsigned char month, unsigned short year, const char *msg);
117  void (*icq_RecvURL)(struct icq_link *link, unsigned long uin,
118       unsigned char hour, unsigned char minute, unsigned char day,
119       unsigned char month, unsigned short year, const char *url,
120       const char *descr);
121  void (*icq_RecvWebPager)(struct icq_link *link,unsigned char hour,
122       unsigned char minute, unsigned char day, unsigned char month,
123       unsigned short year, const char *nick, const char *email,
124       const char *msg);
125  void (*icq_RecvMailExpress)(struct icq_link *link,unsigned char hour,
126       unsigned char minute, unsigned char day, unsigned char month,
127       unsigned short year, const char *nick, const char *email,
128       const char *msg);
129  void (*icq_RecvChatReq)(struct icq_link *link, unsigned long uin,
130       unsigned char hour, unsigned char minute, unsigned char day,
131       unsigned char month, unsigned short year, const char *descr,
132       unsigned long seq);
133  void (*icq_RecvFileReq)(struct icq_link *link, unsigned long uin,
134       unsigned char hour, unsigned char minute, unsigned char day,
135       unsigned char month, unsigned short year, const char *descr,
136       const char *filename, unsigned long filesize, unsigned long seq);
137  void (*icq_RecvAdded)(struct icq_link *link, unsigned long uin,
138       unsigned char hour, unsigned char minute, unsigned char day,
139       unsigned char month, unsigned short year, const char *nick,
140       const char *first, const char *last, const char *email);
141  void (*icq_RecvAuthReq)(struct icq_link *link, unsigned long uin,
142       unsigned char hour, unsigned char minute, unsigned char day,
143       unsigned char month, unsigned short year, const char *nick,
144       const char *first, const char *last, const char *email,
145       const char *reason);
146  void (*icq_UserFound)(struct icq_link *link, unsigned long uin,
147       const char *nick, const char *first, const char *last,
148       const char *email, char auth);
149  void (*icq_SearchDone)(struct icq_link *link);
150  void (*icq_UserOnline)(struct icq_link *link, unsigned long uin,
151       unsigned long status, unsigned long ip, unsigned short port,
152       unsigned long real_ip, unsigned char tcp_flag );
153  void (*icq_UserOffline)(struct icq_link *link, unsigned long uin);
154  void (*icq_UserStatusUpdate)(struct icq_link *link, unsigned long uin,
155       unsigned long status);
156  void (*icq_InfoReply)(struct icq_link *link, unsigned long uin,
157       const char *nick, const char *first, const char *last,
158       const char *email, char auth);
159  void (*icq_ExtInfoReply)(struct icq_link *link, unsigned long uin,
160       const char *city, unsigned short country_code, char country_stat,
161       const char *state, unsigned short age, char gender,
162       const char *phone, const char *hp, const char *about);
163  void (*icq_WrongPassword)(struct icq_link *link);
164  void (*icq_InvalidUIN)(struct icq_link *link);
165  void (*icq_Log)(struct icq_link *link, time_t time, unsigned char level,
166       const char *str);
167  void (*icq_SrvAck)(struct icq_link *link, unsigned short seq);
168  void (*icq_RequestNotify)(struct icq_link *link, unsigned long id, int result,
169       unsigned int length, void *data);
170  void (*icq_NewUIN)(struct icq_link *link, unsigned long uin);
171  void (*icq_SetTimeout)(struct icq_link *link, long interval);
172  void (*icq_MetaUserFound)(struct icq_link *link, unsigned short seq2,
173       unsigned long uin, const char *nick, const char *first,
174       const char *last, const char *email, char auth);
175  void (*icq_MetaUserInfo)(struct icq_link *link, unsigned short seq2,
176       const char *nick, const char *first, const char *last,
177       const char *pri_eml, const char *sec_eml, const char *old_eml,
178       const char *city, const char *state, const char *phone, const char *fax,
179       const char *street, const char *cellular, unsigned long zip,
180       unsigned short country, unsigned char timezone, unsigned char auth,
181       unsigned char webaware, unsigned char hideip);
182  void (*icq_MetaUserWork)(struct icq_link *link, unsigned short seq2,
183       const char *wcity, const char *wstate, const char *wphone,
184       const char *wfax, const char *waddress, unsigned long wzip,
185       unsigned short wcountry, const char *company, const char *department,
186       const char *job, unsigned short occupation, const char *whomepage);
187  void (*icq_MetaUserMore)(struct icq_link *link, unsigned short seq2,
188       unsigned short age, unsigned char gender, const char *homepage,
189       unsigned char byear, unsigned char bmonth, unsigned char bday,
190       unsigned char lang1, unsigned char lang2, unsigned char lang3);
191  void (*icq_MetaUserAbout)(struct icq_link *link, unsigned short seq2,
192       const char *about);
193  void (*icq_MetaUserInterests)(struct icq_link *link, unsigned short seq2,
194       unsigned char num, unsigned short icat1, const char *int1,
195       unsigned short icat2, const char *int2, unsigned short icat3,
196       const char *int3, unsigned short icat4, const char *int4);
197  void (*icq_MetaUserAffiliations)(struct icq_link *link, unsigned short seq2,
198       unsigned char anum, unsigned short acat1, const char *aff1,
199       unsigned short acat2, const char *aff2, unsigned short acat3,
200       const char *aff3, unsigned short acat4, const char *aff4,
201       unsigned char bnum, unsigned short bcat1, const char *back1,
202       unsigned short bcat2, const char *back2, unsigned short bcat3,
203       const char *back3, unsigned short bcat4, const char *back4);
204  void (*icq_MetaUserHomePageCategory)(struct icq_link *link,
205       unsigned short seq2, unsigned char num, unsigned short hcat1,
206       const char *htext1);
207} ICQLINK;
208
209extern int icq_Russian;
210extern unsigned char icq_LogLevel;
211extern icq_ArrayType icq_Countries[];
212
213void icq_SetProxy(ICQLINK *link, const char *phost, unsigned short pport,
214     int pauth, const char *pname, const char *ppass);
215void icq_UnsetProxy(ICQLINK *link);
216
217void icq_Init(ICQLINK *link, unsigned long uin, const char *password,
218     const char *nick);
219void icq_Done(ICQLINK *link);
220int icq_Connect(ICQLINK *link, const char *hostname, int port);
221void icq_Disconnect(ICQLINK *link);
222int icq_GetSok(ICQLINK *link);
223int icq_GetProxySok(ICQLINK *link);
224void icq_HandleServerResponse(ICQLINK *link);
225void icq_HandleProxyResponse(ICQLINK *link);
226void icq_HandleTimeout(ICQLINK *link);
227void icq_Main(ICQLINK *link);
228unsigned short icq_KeepAlive(ICQLINK *link);
229void icq_Login(ICQLINK *link, unsigned long status);
230void icq_Logout(ICQLINK *link);
231void icq_SendContactList(ICQLINK *link);
232void icq_SendVisibleList(ICQLINK *link);
233void icq_SendNewUser(ICQLINK * link, unsigned long uin);
234unsigned long icq_SendMessage(ICQLINK *link, unsigned long uin,
235     const char *text, unsigned char thruSrv);
236unsigned long icq_SendURL(ICQLINK *link, unsigned long uin, const char *url,
237     const char *descr, unsigned char thruSrv);
238void icq_ChangeStatus(ICQLINK *link, unsigned long status);
239unsigned short icq_SendInfoReq(ICQLINK *link, unsigned long uin);
240unsigned short icq_SendExtInfoReq(ICQLINK *link, unsigned long uin);
241unsigned short icq_SendAuthMsg(ICQLINK *link, unsigned long uin);
242void icq_SendSearchReq(ICQLINK *link, const char *email, const char *nick,
243     const char* first, const char* last);
244void icq_SendSearchUINReq(ICQLINK *link, unsigned long uin);
245
246const char *icq_GetCountryName(unsigned short code);
247const char *icq_GetMetaOccupationName(unsigned short code);
248const char *icq_GetMetaBackgroundName(unsigned short code);
249const char *icq_GetMetaAffiliationName(unsigned short code);
250const char *icq_GetMetaLanguageName(unsigned short code);
251void icq_RegNewUser(ICQLINK *link, const char *pass);
252unsigned short icq_UpdateUserInfo(ICQLINK *link, const char *nick,
253     const char *first, const char *last, const char *email);
254unsigned short icq_UpdateAuthInfo(ICQLINK *link, unsigned long auth);
255unsigned short icq_UpdateMetaInfoSet(ICQLINK *link, const char *nick,
256     const char *first, const char *last, const char *email,
257     const char *email2, const char *email3, const char *city,
258     const char *state, const char *phone, const char *fax, const char *street,
259     const char *cellular, unsigned long zip, unsigned short cnt_code,
260     unsigned char cnt_stat, unsigned char emailhide);
261unsigned short icq_UpdateMetaInfoHomepage(ICQLINK *link, unsigned char age,
262     const char *homepage, unsigned char year, unsigned char month,
263     unsigned char day, unsigned char lang1, unsigned char lang2,
264     unsigned char lang3);
265unsigned short icq_UpdateMetaInfoAbout(ICQLINK *link, const char *about);
266unsigned short icq_UpdateMetaInfoSecurity(ICQLINK *link, unsigned char reqauth,
267     unsigned char webpresence, unsigned char pubip);
268unsigned short icq_UpdateNewUserInfo(ICQLINK *link, const char *nick,
269     const char *first, const char *last, const char *email);
270unsigned short icq_SendMetaInfoReq(ICQLINK *link, unsigned long uin);
271
272void icq_FmtLog(ICQLINK *link, int level, const char *fmt, ...);
273
274void icq_ContactAdd(ICQLINK *link, unsigned long cuin);
275void icq_ContactRemove(ICQLINK *link, unsigned long cuin);
276void icq_ContactClear(ICQLINK *link );
277void icq_ContactSetVis(ICQLINK *link, unsigned long cuin, unsigned char vu);
278
279/*** TCP ***/
280void icq_TCPMain(ICQLINK *link);
281
282void icq_TCPProcessReceived(ICQLINK *link);
283
284unsigned long icq_TCPSendMessage(ICQLINK *link, unsigned long uin,
285     const char *message);
286unsigned long icq_TCPSendURL(ICQLINK *link, unsigned long uin,
287     const char *message, const char *url);
288unsigned long icq_SendChatRequest(ICQLINK *link, unsigned long uin,
289     const char *message);
290void icq_AcceptChatRequest(ICQLINK *link, unsigned long uin, unsigned long seq);
291
292void icq_TCPSendChatData(ICQLINK *link, unsigned long uin, const char *data);
293void icq_TCPSendChatData_n(ICQLINK *link, unsigned long uin, const char *data, int len);
294void icq_TCPCloseChat(ICQLINK *link, unsigned long uin);
295
296void icq_CancelChatRequest(ICQLINK *link, unsigned long uin,
297     unsigned long sequence);
298void icq_RefuseChatRequest(ICQLINK *link, unsigned long uin,
299     unsigned long sequence, const char *reason);
300
301/*** TCP ***/
302
303/* file session statuses- request receiver */
304#define FILE_STATUS_LISTENING    1
305#define FILE_STATUS_CONNECTED    3
306
307/* file session statuses- request sender */
308#define FILE_STATUS_CONNECTING   2
309
310#define FILE_STATUS_INITIALIZED  4
311#define FILE_STATUS_NEXT_FILE    5
312#define FILE_STATUS_STOP_FILE    6
313#define FILE_STATUS_NEW_SPEED    7
314
315/* once negotiation is complete, file session enters proper state */
316#define FILE_STATUS_READY        8
317#define FILE_STATUS_SENDING      8
318#define FILE_STATUS_RECEIVING    9
319
320struct icq_TCPLink_s;
321
322typedef struct icq_FileSession_s {
323
324  unsigned long id;
325  int status;
326  ICQLINK *icqlink;
327  struct icq_TCPLink_s *tcplink;
328
329  int direction;
330
331  unsigned long remote_uin;
332  char remote_handle[64];
333
334  char **files;
335  int total_files;
336  int current_file_num;
337  unsigned long total_bytes;
338  unsigned long total_transferred_bytes;
339
340  char working_dir[512];
341  char current_file[64];
342  int current_fd;
343  unsigned long current_file_size;
344  unsigned long current_file_progress;
345
346  int current_speed;
347
348} icq_FileSession;
349
350icq_FileSession *icq_AcceptFileRequest(ICQLINK *link, unsigned long uin,
351                 unsigned long sequence);
352unsigned long icq_SendFileRequest(ICQLINK *link, unsigned long uin,
353              const char *message, char **files);
354void icq_CancelFileRequest(ICQLINK *link, unsigned long uin,
355     unsigned long sequence);
356void icq_RefuseFileRequest(ICQLINK *link, unsigned long uin,
357     unsigned long sequence, const char *reason);
358
359void icq_FileSessionSetSpeed(icq_FileSession *p, int speed);
360void icq_FileSessionClose(icq_FileSession *p);
361void icq_FileSessionSetWorkingDir(icq_FileSession *p, const char *dir);
362void icq_FileSessionSetFiles(icq_FileSession *p, char **files);
363
364#ifdef __cplusplus
365}
366#endif /* __cplusplus */
367
368#endif /* _ICQ_H_ */
369