comparison libfaim/faim/aim.h @ 503:6e318907bcce

[gaim-migrate @ 513] bringing gaim up to latest libfaim committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 18 Jul 2000 05:37:39 +0000
parents 6d78b988b479
children 3133ab511d92
comparison
equal deleted inserted replaced
502:4d1e39112cbd 503:6e318907bcce
22 #include <fcntl.h> 22 #include <fcntl.h>
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <stdlib.h> 24 #include <stdlib.h>
25 #include <stdarg.h> 25 #include <stdarg.h>
26 #include <errno.h> 26 #include <errno.h>
27
28 #ifdef FAIM_USEPTHREADS
29 #include <pthread.h>
30 #define faim_mutex_t pthread_mutex_t
31 #define faim_mutex_init pthread_mutex_init
32 #define faim_mutex_lock pthread_mutex_lock
33 #define faim_mutex_unlock pthread_mutex_unlock
34 #elif defined(FAIM_USEFAKELOCKS)
35 /*
36 * For platforms without pthreads, we also assume
37 * we're not linking against a threaded app. Which
38 * means we don't have to do real locking. The
39 * macros below do nothing really. They're a joke.
40 * But they get it to compile.
41 */
42 #define faim_mutex_t char
43 #define faim_mutex_init(x, y) *x = 0
44 #define faim_mutex_lock(x) *x = 1;
45 #define faim_mutex_unlock(x) *x = 0;
46 #endif
47 27
48 #ifdef _WIN32 28 #ifdef _WIN32
49 #include <windows.h> 29 #include <windows.h>
50 #include <time.h> 30 #include <time.h>
51 #include <io.h> 31 #include <io.h>
55 #include <netinet/in.h> 35 #include <netinet/in.h>
56 #include <sys/time.h> 36 #include <sys/time.h>
57 #include <unistd.h> 37 #include <unistd.h>
58 #endif 38 #endif
59 39
40 #ifdef FAIM_USEPTHREADS
41 #include <pthread.h>
42 #define faim_mutex_t pthread_mutex_t
43 #define faim_mutex_init pthread_mutex_init
44 #define faim_mutex_lock pthread_mutex_lock
45 #define faim_mutex_unlock pthread_mutex_unlock
46 #elif defined(FAIM_USEFAKELOCKS)
47 /*
48 * For platforms without pthreads, we also assume
49 * we're not linking against a threaded app. Which
50 * means we don't have to do real locking. The
51 * macros below do nothing really. They're a joke.
52 * But they get it to compile.
53 */
54 #define faim_mutex_t char
55 #define faim_mutex_init(x, y) *x = 0
56 #define faim_mutex_lock(x) *x = 1;
57 #define faim_mutex_unlock(x) *x = 0;
58 #endif
59
60 /* Portability stuff (DMP) */ 60 /* Portability stuff (DMP) */
61 61
62 #ifdef _WIN32 62 #ifdef _WIN32
63 #define sleep Sleep 63 #define sleep Sleep
64 #define strlen(x) (int)strlen(x) /* win32 has a unsigned size_t */ 64 #define strlen(x) (int)strlen(x) /* win32 has a unsigned size_t */
165 #define AIM_CONN_TYPE_AUTH 0x0007 165 #define AIM_CONN_TYPE_AUTH 0x0007
166 #define AIM_CONN_TYPE_ADS 0x0005 166 #define AIM_CONN_TYPE_ADS 0x0005
167 #define AIM_CONN_TYPE_BOS 0x0002 167 #define AIM_CONN_TYPE_BOS 0x0002
168 #define AIM_CONN_TYPE_CHAT 0x000e 168 #define AIM_CONN_TYPE_CHAT 0x000e
169 #define AIM_CONN_TYPE_CHATNAV 0x000d 169 #define AIM_CONN_TYPE_CHATNAV 0x000d
170
171 /* they start getting arbitrary in rendezvous stuff =) */
170 #define AIM_CONN_TYPE_RENDEZVOUS 0x0101 /* these do not speak OSCAR! */ 172 #define AIM_CONN_TYPE_RENDEZVOUS 0x0101 /* these do not speak OSCAR! */
173 #define AIM_CONN_TYPE_RENDEZVOUS_OUT 0x0102 /* socket waiting for accept() */
174
175 /*
176 * Subtypes, we need these for OFT stuff.
177 */
178 #define AIM_CONN_SUBTYPE_OFT_DIRECTIM 0x0001
179 #define AIM_CONN_SUBTYPE_OFT_GETFILE 0x0002
180 #define AIM_CONN_SUBTYPE_OFT_SENDFILE 0x0003
181 #define AIM_CONN_SUBTYPE_OFT_BUDDYICON 0x0004
182 #define AIM_CONN_SUBTYPE_OFT_VOICE 0x0005
171 183
172 /* 184 /*
173 * Status values returned from aim_conn_new(). ORed together. 185 * Status values returned from aim_conn_new(). ORed together.
174 */ 186 */
175 #define AIM_CONN_STATUS_READY 0x0001 187 #define AIM_CONN_STATUS_READY 0x0001
180 #define AIM_FRAMETYPE_OSCAR 0x0000 192 #define AIM_FRAMETYPE_OSCAR 0x0000
181 #define AIM_FRAMETYPE_OFT 0x0001 193 #define AIM_FRAMETYPE_OFT 0x0001
182 194
183 struct aim_conn_t { 195 struct aim_conn_t {
184 int fd; 196 int fd;
185 int type; 197 unsigned short type;
198 unsigned short subtype;
186 int seqnum; 199 int seqnum;
187 int status; 200 int status;
188 void *priv; /* misc data the client may want to store */ 201 void *priv; /* misc data the client may want to store */
189 time_t lastactivity; /* time of last transmit */ 202 time_t lastactivity; /* time of last transmit */
190 int forcedlatency; 203 int forcedlatency;
197 /* struct for incoming commands */ 210 /* struct for incoming commands */
198 struct command_rx_struct { 211 struct command_rx_struct {
199 unsigned char hdrtype; /* defines which piece of the union to use */ 212 unsigned char hdrtype; /* defines which piece of the union to use */
200 union { 213 union {
201 struct { 214 struct {
202 char type; 215 char type;
203 unsigned short seqnum; 216 unsigned short seqnum;
204 } oscar; 217 } oscar;
205 struct { 218 struct {
206 unsigned short type; 219 unsigned short type;
220 unsigned char magic[4]; /* ODC2 OFT2 */
207 unsigned short hdr2len; 221 unsigned short hdr2len;
208 unsigned char *hdr2; /* rest of bloated header */ 222 unsigned char *hdr2; /* rest of bloated header */
209 } oft; 223 } oft;
210 } hdr; 224 } hdr;
211 unsigned short commandlen; /* total payload length */ 225 unsigned short commandlen; /* total payload length */
225 unsigned char type; 239 unsigned char type;
226 unsigned short seqnum; 240 unsigned short seqnum;
227 } oscar; 241 } oscar;
228 struct { 242 struct {
229 unsigned short type; 243 unsigned short type;
244 unsigned char magic[4]; /* ODC2 OFT2 */
230 unsigned short hdr2len; 245 unsigned short hdr2len;
231 unsigned char *hdr2; 246 unsigned char *hdr2;
232 } oft; 247 } oft;
233 } hdr; 248 } hdr;
234 u_int commandlen; 249 u_int commandlen;
360 * Get command from connections / Dispatch commands 375 * Get command from connections / Dispatch commands
361 * already in queue. 376 * already in queue.
362 */ 377 */
363 int aim_get_command(struct aim_session_t *, struct aim_conn_t *); 378 int aim_get_command(struct aim_session_t *, struct aim_conn_t *);
364 int aim_rxdispatch(struct aim_session_t *); 379 int aim_rxdispatch(struct aim_session_t *);
365 u_long aim_debugconn_sendconnect(struct aim_session_t *sess, 380
366 struct aim_conn_t *conn); 381 u_long aim_debugconn_sendconnect(struct aim_session_t *sess, struct aim_conn_t *conn);
382
367 int aim_logoff(struct aim_session_t *); 383 int aim_logoff(struct aim_session_t *);
368 384
369 void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn); 385 void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn);
370 386
371 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...); 387 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
372 int aim_register_callbacks(rxcallback_t *); 388 int aim_register_callbacks(rxcallback_t *);
373 389
374 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype); 390 u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
375 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *); 391 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
376 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *); 392 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
393
394 struct aim_fileheader_t *aim_oft_getfh(char *hdr);
377 395
378 /* aim_login.c */ 396 /* aim_login.c */
379 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn); 397 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
380 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn); 398 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
381 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *); 399 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
397 void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn); 415 void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn);
398 416
399 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...); 417 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
400 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...); 418 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
401 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...); 419 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
402 420 int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn);
403 421
404 struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen); 422 struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen);
405 int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *); 423 int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *);
406 int aim_tx_enqueue__immediate(struct aim_session_t *, struct command_tx_struct *); 424 int aim_tx_enqueue__immediate(struct aim_session_t *, struct command_tx_struct *);
407 #define aim_tx_enqueue(x, y) ((*(x->tx_enqueue))(x, y)) 425 #define aim_tx_enqueue(x, y) ((*(x->tx_enqueue))(x, y))
477 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *); 495 u_long aim_bos_reqbuddyrights(struct aim_session_t *, struct aim_conn_t *);
478 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *); 496 u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
479 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *); 497 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
480 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn); 498 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
481 499
500 struct aim_fileheader_t *aim_getlisting(struct aim_session_t*);
501 int aim_listenestablish(u_short);
502
482 /* aim_rxhandlers.c */ 503 /* aim_rxhandlers.c */
483 int aim_rxdispatch(struct aim_session_t *); 504 int aim_rxdispatch(struct aim_session_t *);
484 int aim_authparse(struct aim_session_t *, struct command_rx_struct *); 505 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
485 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...); 506 int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
486 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...); 507 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
487 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...); 508 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
488 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...); 509 int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
489 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...); 510 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
490 511
491 /* aim_im.c */ 512 /* aim_im.c */
513 struct aim_directim_priv {
514 unsigned char cookie[8];
515 char sn[MAXSNLEN+1];
516 char ip[30];
517 };
518
492 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */ 519 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
493 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */ 520 #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */
494 521
495 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *); 522 u_long aim_send_im(struct aim_session_t *, struct aim_conn_t *, char *, u_int, char *);
496 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *); 523 int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
497 int aim_parse_outgoing_im_middle(struct aim_session_t *, struct command_rx_struct *); 524 int aim_parse_outgoing_im_middle(struct aim_session_t *, struct command_rx_struct *);
498 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn); 525 u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
499 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *); 526 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
500 int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command); 527 int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
528
529 struct aim_conn_t * aim_directim_intiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *);
530 int aim_send_im_direct(struct aim_session_t *, struct aim_conn_t *, char *);
531 struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *);
501 532
502 /* aim_info.c */ 533 /* aim_info.c */
503 #define AIM_CAPS_BUDDYICON 0x01 534 #define AIM_CAPS_BUDDYICON 0x01
504 #define AIM_CAPS_VOICE 0x02 535 #define AIM_CAPS_VOICE 0x02
505 #define AIM_CAPS_IMIMAGE 0x04 536 #define AIM_CAPS_IMIMAGE 0x04
520 void *data; 551 void *data;
521 time_t addtime; 552 time_t addtime;
522 struct aim_msgcookie_t *next; 553 struct aim_msgcookie_t *next;
523 }; 554 };
524 555
525 struct aim_filetransfer_t { 556 struct aim_fileheader_t {
526 char sender[MAXSNLEN]; 557 #if 0
558 char magic[4]; /* 0 */
559 short hdrlen; /* 4 */
560 short hdrtype; /* 6 */
561 #endif
562 char bcookie[8]; /* 8 */
563 short encrypt; /* 16 */
564 short compress; /* 18 */
565 short totfiles; /* 20 */
566 short filesleft; /* 22 */
567 short totparts; /* 24 */
568 short partsleft; /* 26 */
569 long totsize; /* 28 */
570 long size; /* 32 */
571 long modtime; /* 36 */
572 long checksum; /* 40 */
573 long rfrcsum; /* 44 */
574 long rfsize; /* 48 */
575 long cretime; /* 52 */
576 long rfcsum; /* 56 */
577 long nrecvd; /* 60 */
578 long recvcsum; /* 64 */
579 char idstring[32]; /* 68 */
580 char flags; /* 100 */
581 char lnameoffset; /* 101 */
582 char lsizeoffset; /* 102 */
583 char dummy[69]; /* 103 */
584 char macfileinfo[16]; /* 172 */
585 short nencode; /* 188 */
586 short nlanguage; /* 190 */
587 char name[64]; /* 192 */
588 /* 256 */
589 };
590
591 struct aim_filetransfer_priv {
592 char sn[MAXSNLEN];
593 char cookie[8];
527 char ip[30]; 594 char ip[30];
528 char *filename; 595 int state;
529 }; 596 struct aim_fileheader_t fh;
597 };
598
599 #define AIM_COOKIETYPE_UNKNOWN 0x00
600 #define AIM_COOKIETYPE_ICBM 0x01
601 #define AIM_COOKIETYPE_ADS 0x02
602 #define AIM_COOKIETYPE_BOS 0x03
603 #define AIM_COOKIETYPE_IM 0x04
604 #define AIM_COOKIETYPE_CHAT 0x05
605 #define AIM_COOKIETYPE_CHATNAV 0x06
606 /* we'll move OFT up a bit to give breathing room. not like it really
607 * matters. */
608 #define AIM_COOKIETYPE_OFTIM 0x10
609 #define AIM_COOKIETYPE_OFTGET 0x11
610 #define AIM_COOKIETYPE_OFTSEND 0x12
611 #define AIM_COOKIETYPE_OFTVOICE 0x13
612 #define AIM_COOKIETYPE_OFTIMAGE 0x14
613 #define AIM_COOKIETYPE_OFTICON 0x15
614
530 int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie); 615 int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
531 struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie); 616 int aim_purgecookies(struct aim_session_t *sess, int maxage);
532 int aim_purgecookies(struct aim_session_t *sess); 617 struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type);
618 struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *);
619 struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, char *, int);
620 int aim_getcookietype(int);
621
622 int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur);
533 623
534 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000 624 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
535 #define AIM_TRANSFER_DENY_DECLINE 0x0001 625 #define AIM_TRANSFER_DENY_DECLINE 0x0001
536 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002 626 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
537 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code); 627 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
538 u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short rendid); 628 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);
539 629
540 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short); 630 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
541 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *); 631 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
542 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *); 632 int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
543 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *); 633 int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);