]> andersk Git - libfaim.git/blob - faim/aim.h
6f5165e46ab9af60f5fbe77ad0357ca7530ca18d
[libfaim.git] / faim / aim.h
1 /* 
2  * Main libfaim header.  Must be included in client for prototypes/macros.
3  *
4  */
5
6 #ifndef __AIM_H__
7 #define __AIM_H__
8
9 #define FAIM_VERSION_MAJOR 0
10 #define FAIM_VERSION_MINOR 99
11 #define FAIM_VERSION_MINORMINOR 0
12
13 #include <faim/faimconfig.h>
14 #include <faim/aim_cbtypes.h>
15
16 #if !defined(FAIM_USEPTHREADS) && !defined(FAIM_USEFAKELOCKS)
17 #error pthreads or fakelocks are currently required.
18 #endif
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <fcntl.h>
23 #include <sys/types.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <errno.h>
27
28 #ifdef _WIN32
29 #include <windows.h>
30 #include <time.h>
31 #include <io.h>
32 #else
33 #include <netdb.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <sys/time.h>
37 #include <unistd.h>
38 #endif
39
40 #ifdef FAIM_USEPTHREADS
41 #include <pthread.h>
42 #define faim_mutex_t pthread_mutex_t 
43 #define faim_mutex_init(x) pthread_mutex_init(x, NULL)
44 #define faim_mutex_lock(x) pthread_mutex_lock(x)
45 #define faim_mutex_unlock(x) pthread_mutex_unlock(x)
46 #define faim_mutex_destroy(x) pthread_mutex_destroy(x)
47 #elif defined(FAIM_USEFAKELOCKS)
48 /*
49  * For platforms without pthreads, we also assume
50  * we're not linking against a threaded app.  Which
51  * means we don't have to do real locking.  The 
52  * macros below do nothing really.  They're a joke.
53  * But they get it to compile.
54  */
55 #define faim_mutex_t char
56 #define faim_mutex_init(x) *x = 0
57 #define faim_mutex_lock(x) *x = 1;
58 #define faim_mutex_unlock(x) *x = 0;
59 #define faim_mutex_destroy(x) *x = 0;
60 #endif
61
62 /* Portability stuff (DMP) */
63
64 #ifdef _WIN32
65 #define sleep Sleep
66 #define strlen(x) (int)strlen(x)  /* win32 has a unsigned size_t */
67 #endif
68
69 #if defined(mach) && defined(__APPLE__)
70 #define gethostbyname(x) gethostbyname2(x, AF_INET) 
71 #endif
72
73 #if !defined(MSG_WAITALL)
74 #warning FIX YOUR LIBC! MSG_WAITALL is required!
75 #define MSG_WAITALL 0x100
76 #endif
77
78 /* 
79  * Current Maximum Length for Screen Names (not including NULL) 
80  *
81  * Currently only names up to 16 characters can be registered
82  * however it is aparently legal for them to be larger.
83  */
84 #define MAXSNLEN 32
85
86 /*
87  * Current Maximum Length for Instant Messages
88  *
89  * This was found basically by experiment, but not wholly
90  * accurate experiment.  It should not be regarded
91  * as completely correct.  But its a decent approximation.
92  *
93  * Note that although we can send this much, its impossible
94  * for WinAIM clients (up through the latest (4.0.1957)) to
95  * send any more than 1kb.  Amaze all your windows friends
96  * with utterly oversized instant messages!
97  *
98  * XXX: the real limit is the total SNAC size at 8192. Fix this.
99  * 
100  */
101 #define MAXMSGLEN 7987
102
103 /*
104  * Current Maximum Length for Chat Room Messages
105  *
106  * This is actually defined by the protocol to be
107  * dynamic, but I have yet to see due cause to 
108  * define it dynamically here.  Maybe later.
109  *
110  */
111 #define MAXCHATMSGLEN 512
112
113 /*
114  * Standard size of an AIM authorization cookie
115  */
116 #define AIM_COOKIELEN            0x100
117
118 #define AIM_MD5_STRING "AOL Instant Messenger (SM)"
119
120 #if debug > 0
121 #define faimdprintf(l, x...) {if (l >= debug) printf(x); }
122 #else
123 #define faimdprintf(l, x...)
124 #endif
125
126 /*
127  * Login info.  Passes information from the Authorization
128  * stage of login to the service (BOS, etc) connection
129  * phase.
130  *
131  */
132 struct aim_login_struct {
133   char screen_name[MAXSNLEN+1];
134   char *BOSIP;
135   char cookie[AIM_COOKIELEN];
136   char *email;
137   u_short regstatus;
138   char *errorurl;
139   u_short errorcode;
140 };
141
142 /*
143  * Client info.  Filled in by the client and passed
144  * in to aim_login().  The information ends up
145  * getting passed to OSCAR through the initial
146  * login command.
147  *
148  * XXX: Should this be per-session? -mid
149  *
150  */
151 struct client_info_s {
152   char clientstring[100]; /* arbitrary size */
153   int major;
154   int minor;
155   int build;
156   char country[3];
157   char lang[3];
158   int major2;
159   int minor2;
160   long unknown;
161 };
162
163 #ifndef TRUE
164 #define TRUE 1
165 #define FALSE 0
166 #endif
167
168 /* 
169  * These could be arbitrary, but its easier to use the actual AIM values 
170  */
171 #define AIM_CONN_TYPE_AUTH          0x0007
172 #define AIM_CONN_TYPE_ADS           0x0005
173 #define AIM_CONN_TYPE_BOS           0x0002
174 #define AIM_CONN_TYPE_CHAT          0x000e
175 #define AIM_CONN_TYPE_CHATNAV       0x000d
176
177 /* they start getting arbitrary in rendezvous stuff =) */
178 #define AIM_CONN_TYPE_RENDEZVOUS    0x0101 /* these do not speak OSCAR! */
179 #define AIM_CONN_TYPE_RENDEZVOUS_OUT 0x0102 /* socket waiting for accept() */
180
181 /*
182  * Subtypes, we need these for OFT stuff.
183  */
184 #define AIM_CONN_SUBTYPE_OFT_DIRECTIM  0x0001
185 #define AIM_CONN_SUBTYPE_OFT_GETFILE   0x0002
186 #define AIM_CONN_SUBTYPE_OFT_SENDFILE  0x0003
187 #define AIM_CONN_SUBTYPE_OFT_BUDDYICON 0x0004
188 #define AIM_CONN_SUBTYPE_OFT_VOICE     0x0005
189
190 /*
191  * Status values returned from aim_conn_new().  ORed together.
192  */
193 #define AIM_CONN_STATUS_READY       0x0001
194 #define AIM_CONN_STATUS_INTERNALERR 0x0002
195 #define AIM_CONN_STATUS_RESOLVERR   0x0080
196 #define AIM_CONN_STATUS_CONNERR     0x0040
197
198 #define AIM_FRAMETYPE_OSCAR 0x0000
199 #define AIM_FRAMETYPE_OFT 0x0001
200
201 struct aim_conn_t {
202   int fd;
203   unsigned short type;
204   unsigned short subtype;
205   int seqnum;
206   int status;
207   void *priv; /* misc data the client may want to store */
208   time_t lastactivity; /* time of last transmit */
209   int forcedlatency; 
210   struct aim_rxcblist_t *handlerlist;
211   faim_mutex_t active; /* lock around read/writes */
212   faim_mutex_t seqnum_lock; /* lock around ->seqnum changes */
213   struct aim_conn_t *next;
214 };
215
216 /* struct for incoming commands */
217 struct command_rx_struct {
218   unsigned char hdrtype; /* defines which piece of the union to use */
219   union {
220     struct { 
221       char type;
222       unsigned short seqnum;     
223     } oscar;
224     struct {
225       unsigned short type;
226       unsigned char magic[4]; /* ODC2 OFT2 */
227       unsigned short hdr2len;
228       unsigned char *hdr2; /* rest of bloated header */
229     } oft;
230   } hdr;
231   unsigned short commandlen;         /* total payload length */
232   unsigned char *data;             /* packet data (from 7 byte on) */
233   unsigned char lock;               /* 0 = open, !0 = locked */
234   unsigned char handled;            /* 0 = new, !0 = been handled */
235   unsigned char nofree;             /* 0 = free data on purge, 1 = only unlink */
236   struct aim_conn_t *conn;  /* the connection it came in on... */
237   struct command_rx_struct *next; /* ptr to next struct in list */
238 };
239
240 /* struct for outgoing commands */
241 struct command_tx_struct {
242   unsigned char hdrtype; /* defines which piece of the union to use */
243   union {
244     struct {
245       unsigned char type;
246       unsigned short seqnum;
247     } oscar;
248     struct {
249       unsigned short type;
250       unsigned char magic[4]; /* ODC2 OFT2 */
251       unsigned short hdr2len;
252       unsigned char *hdr2;
253     } oft;
254   } hdr;
255   u_int commandlen;         
256   u_char *data;      
257   u_int lock;               /* 0 = open, !0 = locked */
258   u_int sent;               /* 0 = pending, !0 = has been sent */
259   struct aim_conn_t *conn; 
260   struct command_tx_struct *next; /* ptr to next struct in list */
261 };
262
263
264 /*
265  * AIM Session: The main client-data interface.  
266  *
267  */
268 struct aim_session_t {
269
270   /* ---- Client Accessible ------------------------ */
271   /* 
272    * Login information.  See definition above.
273    *
274    */
275   struct aim_login_struct logininfo;
276   
277   /*
278    * Pointer to anything the client wants to 
279    * explicitly associate with this session.
280    */
281   void *aux_data;
282
283
284   /* ---- Internal Use Only ------------------------ */
285   /* 
286    * Connection information
287    */
288   struct aim_conn_t *connlist;
289   faim_mutex_t connlistlock;
290   
291   /* 
292    * TX/RX queues 
293    */
294   struct command_tx_struct *queue_outgoing;   
295   struct command_rx_struct *queue_incoming; 
296   
297   /*
298    * Tx Enqueuing function
299    */
300   int (*tx_enqueue)(struct aim_session_t *, struct command_tx_struct *);
301
302   /*
303    * This is a dreadful solution to the what-room-are-we-joining
304    * problem.  (There's no connection between the service
305    * request and the resulting redirect.)
306    */ 
307   char *pendingjoin;
308
309   /*
310    * Outstanding snac handling 
311    *
312    * XXX: Should these be per-connection? -mid
313    */
314   struct aim_snac_t *snac_hash[FAIM_SNAC_HASH_SIZE];
315   faim_mutex_t snac_hash_locks[FAIM_SNAC_HASH_SIZE];
316   u_long snac_nextid;
317
318   struct aim_msgcookie_t *msgcookies;
319 };
320
321
322 /*
323  * AIM User Info, Standard Form.
324  */
325 struct aim_userinfo_s {
326   char sn[MAXSNLEN+1];
327   u_short warnlevel;
328   u_short idletime;
329   u_short class;
330   u_long membersince;
331   u_long onlinesince;
332   u_long sessionlen;  
333   u_short capabilities;
334 };
335
336 #define AIM_CLASS_TRIAL         0x0001 /* "damned transients" */
337 #define AIM_CLASS_ADMINISTRATOR 0x0002
338 #define AIM_CLASS_AOL           0x0004
339 #define AIM_CLASS_OSCAR_PAY     0x0008
340 #define AIM_CLASS_FREE          0x0010
341 #define AIM_CLASS_AWAY          0x0020
342 #define AIM_CLASS_UNKNOWN40     0x0040
343 #define AIM_CLASS_UNKNOWN80     0x0080
344
345 #define AIM_CLASS_ALLUSERS      0x001f
346
347 /*
348  * TLV handling
349  */
350
351 /* Generic TLV structure. */
352 struct aim_tlv_t {
353   u_short type;
354   u_short length;
355   u_char *value;
356 };
357
358 /* List of above. */
359 struct aim_tlvlist_t {
360   struct aim_tlv_t *tlv;
361   struct aim_tlvlist_t *next;
362 };
363
364 /* TLV-handling functions */
365 struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
366 void aim_freetlvchain(struct aim_tlvlist_t **list);
367 struct aim_tlv_t *aim_grabtlv(u_char *src);
368 struct aim_tlv_t *aim_grabtlvstr(u_char *src);
369 struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
370 char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
371 int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
372 struct aim_tlv_t *aim_createtlv(void);
373 int aim_freetlv(struct aim_tlv_t **oldtlv);
374 int aim_puttlv_16(u_char *, u_short, u_short);
375 int aim_puttlv_32(u_char *, u_short, u_long);
376 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
377 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
378 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
379 int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
380 int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
381 int aim_counttlvchain(struct aim_tlvlist_t **list);
382
383 /*
384  * Get command from connections / Dispatch commands
385  * already in queue.
386  */
387 int aim_get_command(struct aim_session_t *, struct aim_conn_t *);
388 int aim_rxdispatch(struct aim_session_t *);
389
390 u_long aim_debugconn_sendconnect(struct aim_session_t *sess, struct aim_conn_t *conn);
391
392 int aim_logoff(struct aim_session_t *);
393
394 void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn);
395
396 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
397 int aim_register_callbacks(rxcallback_t *);
398
399 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
400 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
401 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
402
403 struct aim_fileheader_t *aim_oft_getfh(char *hdr);
404
405 /* aim_login.c */
406 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
407 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
408 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *, char *key);
409 unsigned long aim_sendauthresp(struct aim_session_t *sess, 
410                                struct aim_conn_t *conn, 
411                                char *sn, char *bosip, 
412                                char *cookie, char *email, 
413                                int regstatus);
414 int aim_gencookie(unsigned char *buf);
415 int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
416 int aim_authkeyparse(struct aim_session_t *sess, struct command_rx_struct *command);
417 unsigned long aim_sendredirect(struct aim_session_t *sess, 
418                                struct aim_conn_t *conn, 
419                                unsigned short servid, 
420                                char *ip,
421                                char *cookie);
422 void aim_purge_rxqueue(struct aim_session_t *);
423 void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn);
424
425 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
426 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
427 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
428 int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn);
429
430 struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen);
431 int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *);
432 int aim_tx_enqueue__immediate(struct aim_session_t *, struct command_tx_struct *);
433 #define aim_tx_enqueue(x, y) ((*(x->tx_enqueue))(x, y))
434 int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx_struct *cur);
435 u_int aim_get_next_txseqnum(struct aim_conn_t *);
436 int aim_tx_flushqueue(struct aim_session_t *);
437 int aim_tx_printqueue(struct aim_session_t *);
438 void aim_tx_purgequeue(struct aim_session_t *);
439
440 struct aim_rxcblist_t {
441   u_short family;
442   u_short type;
443   rxcallback_t handler;
444   u_short flags;
445   struct aim_rxcblist_t *next;
446 };
447
448 int aim_conn_setlatency(struct aim_conn_t *conn, int newval);
449
450 int aim_conn_addhandler(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short type, rxcallback_t newhandler, u_short flags);
451 rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
452 int aim_clearhandlers(struct aim_conn_t *conn);
453
454 /*
455  * Generic SNAC structure.  Rarely if ever used.
456  */
457 struct aim_snac_t {
458   u_long id;
459   u_short family;
460   u_short type;
461   u_short flags;
462   void *data;
463   time_t issuetime;
464   struct aim_snac_t *next;
465 };
466 void aim_initsnachash(struct aim_session_t *sess);
467 u_long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
468 struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
469 int aim_cleansnacs(struct aim_session_t *, int maxage);
470 int aim_putsnac(u_char *, int, int, int, u_long);
471
472
473 void aim_connrst(struct aim_session_t *);
474 struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
475 void aim_conn_close(struct aim_conn_t *deadconn);
476 struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
477 struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
478 int aim_conngetmaxfd(struct aim_session_t *);
479 struct aim_conn_t *aim_select(struct aim_session_t *, struct timeval *, int *);
480 int aim_conn_isready(struct aim_conn_t *);
481 int aim_conn_setstatus(struct aim_conn_t *, int);
482 void aim_session_init(struct aim_session_t *);
483
484 /* aim_misc.c */
485
486 #define AIM_VISIBILITYCHANGE_PERMITADD    0x05
487 #define AIM_VISIBILITYCHANGE_PERMITREMOVE 0x06
488 #define AIM_VISIBILITYCHANGE_DENYADD      0x07
489 #define AIM_VISIBILITYCHANGE_DENYREMOVE   0x08
490
491 #define AIM_PRIVFLAGS_ALLOWIDLE           0x01
492 #define AIM_PRIVFLAGS_ALLOWMEMBERSINCE    0x02
493
494 #define AIM_WARN_ANON                     0x01
495
496 int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn, int anon);
497 u_long aim_bos_nop(struct aim_session_t *, struct aim_conn_t *);
498 u_long aim_bos_setidle(struct aim_session_t *, struct aim_conn_t *, u_long);
499 u_long aim_bos_changevisibility(struct aim_session_t *, struct aim_conn_t *, int, char *);
500 u_long aim_bos_setbuddylist(struct aim_session_t *, struct aim_conn_t *, char *);
501 u_long aim_bos_setprofile(struct aim_session_t *, struct aim_conn_t *, char *, char *, unsigned int);
502 u_long aim_bos_setgroupperm(struct aim_session_t *, struct aim_conn_t *, u_long);
503 u_long aim_bos_clientready(struct aim_session_t *, struct aim_conn_t *);
504 u_long aim_bos_reqrate(struct aim_session_t *, struct aim_conn_t *);
505 u_long aim_bos_ackrateresp(struct aim_session_t *, struct aim_conn_t *);
506 u_long aim_bos_setprivacyflags(struct aim_session_t *, struct aim_conn_t *, u_long);
507 u_long aim_bos_reqpersonalinfo(struct aim_session_t *, struct aim_conn_t *);
508 u_long aim_bos_reqservice(struct aim_session_t *, struct aim_conn_t *, u_short);
509 u_long aim_bos_reqrights(struct aim_session_t *, struct aim_conn_t *);
510 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
511 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
512 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
513 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
514
515 struct aim_fileheader_t *aim_getlisting(struct aim_session_t*);
516 int aim_listenestablish(u_short);
517
518 /* aim_rxhandlers.c */
519 int aim_rxdispatch(struct aim_session_t *);
520 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
521 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
522 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
523 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
524 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
525 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
526 int aim_parse_ratechange_middle(struct aim_session_t *sess, struct command_rx_struct *command);
527 int aim_parse_evilnotify_middle(struct aim_session_t *sess, struct command_rx_struct *command);
528 int aim_parse_msgack_middle(struct aim_session_t *sess, struct command_rx_struct *command);
529
530 /* aim_im.c */
531 struct aim_directim_priv {
532   unsigned char cookie[8];
533   char sn[MAXSNLEN+1];
534   char ip[30];
535 };
536
537 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
538 #define AIM_IMFLAGS_ACK  0x02 /* request a receipt notice */
539
540 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
541 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
542 int aim_parse_outgoing_im_middle(struct aim_session_t *, struct command_rx_struct *);
543 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
544 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
545 int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
546
547 struct aim_conn_t * aim_directim_initiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *);
548 int aim_send_im_direct(struct aim_session_t *, struct aim_conn_t *, char *);
549 struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *);
550
551 /* aim_info.c */
552 #define AIM_CAPS_BUDDYICON 0x01
553 #define AIM_CAPS_VOICE 0x02
554 #define AIM_CAPS_IMIMAGE 0x04
555 #define AIM_CAPS_CHAT 0x08
556 #define AIM_CAPS_GETFILE 0x10
557 #define AIM_CAPS_SENDFILE 0x20
558
559 extern u_char aim_caps[6][16];
560 u_short aim_getcap(unsigned char *capblock, int buflen);
561 int aim_putcap(unsigned char *capblock, int buflen, u_short caps);
562
563 #define AIM_GETINFO_GENERALINFO 0x00001
564 #define AIM_GETINFO_AWAYMESSAGE 0x00003
565
566 struct aim_msgcookie_t {
567   unsigned char cookie[8];
568   int type;
569   void *data;
570   time_t addtime;
571   struct aim_msgcookie_t *next;
572 };
573
574 struct aim_fileheader_t {
575 #if 0
576   char  magic[4];            /* 0 */
577   short hdrlen;           /* 4 */
578   short hdrtype;             /* 6 */
579 #endif
580   char  bcookie[8];       /* 8 */
581   short encrypt;          /* 16 */
582   short compress;         /* 18 */
583   short totfiles;         /* 20 */
584   short filesleft;        /* 22 */
585   short totparts;         /* 24 */
586   short partsleft;        /* 26 */
587   long  totsize;          /* 28 */
588   long  size;             /* 32 */
589   long  modtime;          /* 36 */
590   long  checksum;         /* 40 */
591   long  rfrcsum;          /* 44 */
592   long  rfsize;           /* 48 */
593   long  cretime;          /* 52 */
594   long  rfcsum;           /* 56 */
595   long  nrecvd;           /* 60 */
596   long  recvcsum;         /* 64 */
597   char  idstring[32];     /* 68 */
598   char  flags;            /* 100 */
599   char  lnameoffset;      /* 101 */
600   char  lsizeoffset;      /* 102 */
601   char  dummy[69];        /* 103 */
602   char  macfileinfo[16];  /* 172 */
603   short nencode;          /* 188 */
604   short nlanguage;        /* 190 */
605   char  name[64];         /* 192 */
606                           /* 256 */
607 };
608
609 struct aim_filetransfer_priv {
610   char sn[MAXSNLEN];
611   char cookie[8];
612   char ip[30];
613   int state;
614   struct aim_fileheader_t fh;
615 };
616
617 #define AIM_COOKIETYPE_UNKNOWN  0x00
618 #define AIM_COOKIETYPE_ICBM     0x01
619 #define AIM_COOKIETYPE_ADS      0x02
620 #define AIM_COOKIETYPE_BOS      0x03
621 #define AIM_COOKIETYPE_IM       0x04
622 #define AIM_COOKIETYPE_CHAT     0x05
623 #define AIM_COOKIETYPE_CHATNAV  0x06
624 /* we'll move OFT up a bit to give breathing room.  not like it really
625  * matters. */
626 #define AIM_COOKIETYPE_OFTIM    0x10
627 #define AIM_COOKIETYPE_OFTGET   0x11
628 #define AIM_COOKIETYPE_OFTSEND  0x12
629 #define AIM_COOKIETYPE_OFTVOICE 0x13
630 #define AIM_COOKIETYPE_OFTIMAGE 0x14
631 #define AIM_COOKIETYPE_OFTICON  0x15
632
633 int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
634 int aim_purgecookies(struct aim_session_t *sess, int maxage);
635 struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type);
636 struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *);
637 struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, char *, int);
638 int aim_getcookietype(int);
639
640 int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur);
641
642 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
643 #define AIM_TRANSFER_DENY_DECLINE 0x0001
644 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
645 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
646 u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn,struct aim_conn_t *oftconn, char *sender, char *cookie, unsigned short rendid);
647
648 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
649 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
650 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
651 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
652 int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
653 int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
654 int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info);
655 int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
656
657
658 /* aim_auth.c */
659 int aim_auth_sendcookie(struct aim_session_t *, struct aim_conn_t *, u_char *);
660 u_long aim_auth_clientready(struct aim_session_t *, struct aim_conn_t *);
661 u_long aim_auth_changepasswd(struct aim_session_t *, struct aim_conn_t *, char *, char *);
662
663 /* aim_buddylist.c */
664 u_long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
665 u_long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
666
667 /* aim_search.c */
668 u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
669 /* u_long aim_usersearch_name(struct aim_session_t *, struct aim_conn_t *, char *); */
670
671
672 struct aim_chat_roominfo {
673   u_short exchange;
674   char *name;
675   u_short instance;
676 };
677 int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
678 int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
679 int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
680 int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
681 int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
682 u_long aim_chat_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg);
683 u_long aim_chat_join(struct aim_session_t *sess, struct aim_conn_t *conn, u_short exchange, const char *roomname);
684 u_long aim_chat_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
685 int aim_chat_attachname(struct aim_conn_t *conn, char *roomname);
686 char *aim_chat_getname(struct aim_conn_t *conn);
687 struct aim_conn_t *aim_chat_getconn(struct aim_session_t *, char *name);
688
689 u_long aim_chatnav_reqrights(struct aim_session_t *sess, struct aim_conn_t *conn);
690 u_long aim_chatnav_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
691
692 u_long aim_chat_invite(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn, char *msg, u_short exchange, char *roomname, u_short instance);
693
694 struct aim_chat_exchangeinfo {
695   u_short number;
696   char *name;
697   char *charset1;
698   char *lang1;
699   char *charset2;
700   char *lang2;
701 };
702 int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
703 u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
704 int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
705
706 /* aim_util.c */
707 #ifdef AIMUTIL_USEMACROS
708 /*
709  * These are really ugly.  You'd think this was LISP.  I wish it was.
710  */
711 #define aimutil_put8(buf, data) ((*(buf) = (u_char)(data)&0xff),1)
712 #define aimutil_get8(buf) ((*(buf))&0xff)
713 #define aimutil_put16(buf, data) ( \
714                                   (*(buf) = (u_char)((data)>>8)&0xff), \
715                                   (*((buf)+1) = (u_char)(data)&0xff),  \
716                                   2)
717 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
718 #define aimutil_put32(buf, data) ( \
719                                   (*((buf)) = (u_char)((data)>>24)&0xff), \
720                                   (*((buf)+1) = (u_char)((data)>>16)&0xff), \
721                                   (*((buf)+2) = (u_char)((data)>>8)&0xff), \
722                                   (*((buf)+3) = (u_char)(data)&0xff), \
723                                   4)
724 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
725                             (((*((buf)+1))<<16)&0x00ff0000) + \
726                             (((*((buf)+2))<< 8)&0x0000ff00) + \
727                             (((*((buf)+3)    )&0x000000ff)))
728 #else
729 #warning Not using aimutil macros.  May have performance problems.
730 int aimutil_put8(u_char *, u_char);
731 u_char aimutil_get8(u_char *buf);
732 int aimutil_put16(u_char *, u_short);
733 u_short aimutil_get16(u_char *);
734 int aimutil_put32(u_char *, u_long);
735 u_long aimutil_get32(u_char *);
736 #endif
737
738 int aimutil_putstr(u_char *, const u_char *, int);
739 int aimutil_tokslen(char *toSearch, int index, char dl);
740 int aimutil_itemcnt(char *toSearch, char dl);
741 char *aimutil_itemidx(char *toSearch, int index, char dl);
742
743 int aim_snlen(const char *sn);
744 int aim_sncmp(const char *sn1, const char *sn2);
745
746 /* aim_meta.c */
747 char *aim_getbuilddate(void);
748 char *aim_getbuildtime(void);
749 char *aim_getbuildstring(void);
750
751 #endif /* __AIM_H__ */
752
This page took 0.085905 seconds and 3 git commands to generate.