Mercurial > pidgin
comparison src/protocols/oscar/aim.h @ 2270:d82efea341ef
[gaim-migrate @ 2280]
new libfaim. stupid bugs.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 12 Sep 2001 00:39:51 +0000 |
parents | 933346315b9b |
children | 7ec21662ffc2 |
comparison
equal
deleted
inserted
replaced
2269:7ff6170d84a0 | 2270:d82efea341ef |
---|---|
13 #define FAIM_VERSION_MINOR 99 | 13 #define FAIM_VERSION_MINOR 99 |
14 #define FAIM_VERSION_MINORMINOR 1 | 14 #define FAIM_VERSION_MINORMINOR 1 |
15 | 15 |
16 #include <faimconfig.h> | 16 #include <faimconfig.h> |
17 #include <aim_cbtypes.h> | 17 #include <aim_cbtypes.h> |
18 | |
19 #if !defined(FAIM_USEPTHREADS) && !defined(FAIM_USEFAKELOCKS) && !defined(FAIM_USENOPLOCKS) | |
20 #error pthreads, fakelocks, or noplocks are currently required. | |
21 #endif | |
22 | 18 |
23 #include <stdio.h> | 19 #include <stdio.h> |
24 #include <string.h> | 20 #include <string.h> |
25 #include <fcntl.h> | 21 #include <fcntl.h> |
26 #include <sys/types.h> | 22 #include <sys/types.h> |
43 typedef unsigned char fu8_t; | 39 typedef unsigned char fu8_t; |
44 typedef unsigned short fu16_t; | 40 typedef unsigned short fu16_t; |
45 typedef unsigned long fu32_t; | 41 typedef unsigned long fu32_t; |
46 typedef fu32_t aim_snacid_t; | 42 typedef fu32_t aim_snacid_t; |
47 typedef fu16_t flap_seqnum_t; | 43 typedef fu16_t flap_seqnum_t; |
48 | |
49 #ifdef FAIM_USEPTHREADS | |
50 #include <pthread.h> | |
51 #define faim_mutex_t pthread_mutex_t | |
52 #define faim_mutex_init(x) pthread_mutex_init(x, NULL) | |
53 #define faim_mutex_lock(x) pthread_mutex_lock(x) | |
54 #define faim_mutex_unlock(x) pthread_mutex_unlock(x) | |
55 #define faim_mutex_destroy(x) pthread_mutex_destroy(x) | |
56 #elif defined(FAIM_USEFAKELOCKS) | |
57 /* | |
58 * For platforms without pthreads, we also assume | |
59 * we're not linking against a threaded app. Which | |
60 * means we don't have to do real locking. The | |
61 * macros below do nothing really. They're a joke. | |
62 * But they get it to compile. | |
63 * | |
64 * XXX NOTE that locking hasn't really been tested in a long time, | |
65 * and most code written after dec2000 --is not thread safe--. You'll | |
66 * want to audit locking use before you use less-than-library level | |
67 * concurrency. | |
68 * | |
69 */ | |
70 #define faim_mutex_t fu8_t | |
71 #define faim_mutex_init(x) *x = 0 | |
72 #define faim_mutex_lock(x) while(*x != 0) {/* spin */}; *x = 1; | |
73 #define faim_mutex_unlock(x) while(*x != 0) {/* spin spin spin */}; *x = 0; | |
74 #define faim_mutex_destroy(x) while(*x != 0) {/* spiiiinnn */}; *x = 0; | |
75 #elif defined(FAIM_USENOPLOCKS) | |
76 #define faim_mutex_t fu8_t | |
77 #define faim_mutex_init(x) | |
78 #define faim_mutex_lock(x) | |
79 #define faim_mutex_unlock(x) | |
80 #define faim_mutex_destroy(x) | |
81 #endif | |
82 | 44 |
83 /* Portability stuff (DMP) */ | 45 /* Portability stuff (DMP) */ |
84 | 46 |
85 #ifdef _WIN32 | 47 #ifdef _WIN32 |
86 #define sleep(x) Sleep((x)*1000) | 48 #define sleep(x) Sleep((x)*1000) |
270 void *priv; /* misc data the client may want to store */ | 232 void *priv; /* misc data the client may want to store */ |
271 void *internal; /* internal conn-specific libfaim data */ | 233 void *internal; /* internal conn-specific libfaim data */ |
272 time_t lastactivity; /* time of last transmit */ | 234 time_t lastactivity; /* time of last transmit */ |
273 int forcedlatency; | 235 int forcedlatency; |
274 void *handlerlist; | 236 void *handlerlist; |
275 faim_mutex_t active; /* lock around read/writes */ | |
276 faim_mutex_t seqnum_lock; /* lock around ->seqnum changes */ | |
277 void *sessv; /* pointer to parent session */ | 237 void *sessv; /* pointer to parent session */ |
238 void *inside; /* only accessible from inside libfaim */ | |
278 struct aim_conn_s *next; | 239 struct aim_conn_s *next; |
279 } aim_conn_t; | 240 } aim_conn_t; |
280 | 241 |
281 /* | 242 /* |
282 * Byte Stream type. Sort of. | 243 * Byte Stream type. Sort of. |
350 | 311 |
351 /* ---- Internal Use Only ------------------------ */ | 312 /* ---- Internal Use Only ------------------------ */ |
352 | 313 |
353 /* Connection information */ | 314 /* Connection information */ |
354 aim_conn_t *connlist; | 315 aim_conn_t *connlist; |
355 faim_mutex_t connlistlock; | |
356 | 316 |
357 /* | 317 /* |
358 * Transmit/receive queues. | 318 * Transmit/receive queues. |
359 * | 319 * |
360 * These are only used when you don't use your own lowlevel | 320 * These are only used when you don't use your own lowlevel |
387 * Outstanding snac handling | 347 * Outstanding snac handling |
388 * | 348 * |
389 * XXX: Should these be per-connection? -mid | 349 * XXX: Should these be per-connection? -mid |
390 */ | 350 */ |
391 void *snac_hash[FAIM_SNAC_HASH_SIZE]; | 351 void *snac_hash[FAIM_SNAC_HASH_SIZE]; |
392 faim_mutex_t snac_hash_locks[FAIM_SNAC_HASH_SIZE]; | |
393 aim_snacid_t snacid_next; | 352 aim_snacid_t snacid_next; |
394 | 353 |
395 struct { | 354 struct { |
396 char server[128]; | 355 char server[128]; |
397 char username[128]; | 356 char username[128]; |
484 faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v); | 443 faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v); |
485 faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t type, const fu32_t v); | 444 faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t type, const fu32_t v); |
486 faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v); | 445 faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v); |
487 faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu16_t caps); | 446 faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu16_t caps); |
488 faim_internal int aim_addtlvtochain_noval(aim_tlvlist_t **list, const fu16_t type); | 447 faim_internal int aim_addtlvtochain_noval(aim_tlvlist_t **list, const fu16_t type); |
448 faim_internal int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, fu16_t type, struct aim_userinfo_s *ui); | |
489 faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl); | 449 faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl); |
490 faim_internal int aim_counttlvchain(aim_tlvlist_t **list); | 450 faim_internal int aim_counttlvchain(aim_tlvlist_t **list); |
491 faim_export int aim_sizetlvchain(aim_tlvlist_t **list); | 451 faim_internal int aim_sizetlvchain(aim_tlvlist_t **list); |
492 #endif /* FAIM_INTERNAL */ | 452 #endif /* FAIM_INTERNAL */ |
493 | 453 |
494 /* | 454 /* |
495 * Get command from connections | 455 * Get command from connections |
496 * | 456 * |
538 faim_export int aim_conn_setlatency(aim_conn_t *conn, int newval); | 498 faim_export int aim_conn_setlatency(aim_conn_t *conn, int newval); |
539 | 499 |
540 faim_export int aim_conn_addhandler(aim_session_t *, aim_conn_t *conn, u_short family, u_short type, aim_rxcallback_t newhandler, u_short flags); | 500 faim_export int aim_conn_addhandler(aim_session_t *, aim_conn_t *conn, u_short family, u_short type, aim_rxcallback_t newhandler, u_short flags); |
541 faim_export int aim_clearhandlers(aim_conn_t *conn); | 501 faim_export int aim_clearhandlers(aim_conn_t *conn); |
542 | 502 |
503 faim_export aim_conn_t *aim_conn_findbygroup(aim_session_t *sess, fu16_t group); | |
543 faim_export aim_session_t *aim_conn_getsess(aim_conn_t *conn); | 504 faim_export aim_session_t *aim_conn_getsess(aim_conn_t *conn); |
544 faim_export void aim_conn_close(aim_conn_t *deadconn); | 505 faim_export void aim_conn_close(aim_conn_t *deadconn); |
545 faim_export aim_conn_t *aim_newconn(aim_session_t *, int type, const char *dest); | 506 faim_export aim_conn_t *aim_newconn(aim_session_t *, int type, const char *dest); |
546 faim_export int aim_conngetmaxfd(aim_session_t *); | 507 faim_export int aim_conngetmaxfd(aim_session_t *); |
547 faim_export aim_conn_t *aim_select(aim_session_t *, struct timeval *, int *); | 508 faim_export aim_conn_t *aim_select(aim_session_t *, struct timeval *, int *); |
569 #define AIM_PRIVFLAGS_ALLOWIDLE 0x01 | 530 #define AIM_PRIVFLAGS_ALLOWIDLE 0x01 |
570 #define AIM_PRIVFLAGS_ALLOWMEMBERSINCE 0x02 | 531 #define AIM_PRIVFLAGS_ALLOWMEMBERSINCE 0x02 |
571 | 532 |
572 #define AIM_WARN_ANON 0x01 | 533 #define AIM_WARN_ANON 0x01 |
573 | 534 |
535 faim_export int aim_sendpauseack(aim_session_t *sess, aim_conn_t *conn); | |
574 faim_export int aim_send_warning(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu32_t flags); | 536 faim_export int aim_send_warning(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu32_t flags); |
575 faim_export int aim_bos_nop(aim_session_t *, aim_conn_t *); | 537 faim_export int aim_bos_nop(aim_session_t *, aim_conn_t *); |
576 faim_export int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn); | 538 faim_export int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn); |
577 faim_export int aim_bos_setidle(aim_session_t *, aim_conn_t *, fu32_t); | 539 faim_export int aim_bos_setidle(aim_session_t *, aim_conn_t *, fu32_t); |
578 faim_export int aim_bos_changevisibility(aim_session_t *, aim_conn_t *, int, const char *); | 540 faim_export int aim_bos_changevisibility(aim_session_t *, aim_conn_t *, int, const char *); |
667 #define AIM_IMFLAGS_BUDDYREQ 0x0010 /* buddy icon requested */ | 629 #define AIM_IMFLAGS_BUDDYREQ 0x0010 /* buddy icon requested */ |
668 #define AIM_IMFLAGS_HASICON 0x0020 /* already has icon */ | 630 #define AIM_IMFLAGS_HASICON 0x0020 /* already has icon */ |
669 #define AIM_IMFLAGS_SUBENC_MACINTOSH 0x0040 /* damn that Steve Jobs! */ | 631 #define AIM_IMFLAGS_SUBENC_MACINTOSH 0x0040 /* damn that Steve Jobs! */ |
670 #define AIM_IMFLAGS_CUSTOMFEATURES 0x0080 /* features field present */ | 632 #define AIM_IMFLAGS_CUSTOMFEATURES 0x0080 /* features field present */ |
671 #define AIM_IMFLAGS_EXTDATA 0x0100 | 633 #define AIM_IMFLAGS_EXTDATA 0x0100 |
672 | 634 #define AIM_IMFLAGS_CUSTOMCHARSET 0x0200 /* charset fields set */ |
635 #define AIM_IMFLAGS_MULTIPART 0x0400 /* ->mpmsg section valid */ | |
636 | |
637 /* | |
638 * Multipart message structures. | |
639 */ | |
640 typedef struct aim_mpmsg_section_s { | |
641 fu16_t charset; | |
642 fu16_t charsubset; | |
643 fu8_t *data; | |
644 fu16_t datalen; | |
645 struct aim_mpmsg_section_s *next; | |
646 } aim_mpmsg_section_t; | |
647 | |
648 typedef struct aim_mpmsg_s { | |
649 int numparts; | |
650 aim_mpmsg_section_t *parts; | |
651 } aim_mpmsg_t; | |
652 | |
653 faim_export int aim_mpmsg_init(aim_session_t *sess, aim_mpmsg_t *mpm); | |
654 faim_export int aim_mpmsg_addraw(aim_session_t *sess, aim_mpmsg_t *mpm, fu16_t charset, fu16_t charsubset, const fu8_t *data, fu16_t datalen); | |
655 faim_export int aim_mpmsg_addascii(aim_session_t *sess, aim_mpmsg_t *mpm, const char *ascii); | |
656 faim_export int aim_mpmsg_addunicode(aim_session_t *sess, aim_mpmsg_t *mpm, const fu16_t *unicode, fu16_t unicodelen); | |
657 faim_export void aim_mpmsg_free(aim_session_t *sess, aim_mpmsg_t *mpm); | |
658 | |
659 /* | |
660 * Arguments to aim_send_im_ext(). | |
661 * | |
662 * This is really complicated. But immensely versatile. | |
663 * | |
664 */ | |
673 struct aim_sendimext_args { | 665 struct aim_sendimext_args { |
674 | 666 |
675 /* These are _required_ */ | 667 /* These are _required_ */ |
676 const char *destsn; | 668 const char *destsn; |
677 fu32_t flags; | 669 fu32_t flags; /* often 0 */ |
670 | |
671 /* Only required if not using multipart messages */ | |
678 const char *msg; | 672 const char *msg; |
679 int msglen; | 673 int msglen; |
674 | |
675 /* Required if ->msg is not provided */ | |
676 aim_mpmsg_t *mpmsg; | |
680 | 677 |
681 /* Only used if AIM_IMFLAGS_HASICON is set */ | 678 /* Only used if AIM_IMFLAGS_HASICON is set */ |
682 fu32_t iconlen; | 679 fu32_t iconlen; |
683 time_t iconstamp; | 680 time_t iconstamp; |
684 fu32_t iconsum; | 681 fu32_t iconsum; |
685 | 682 |
686 /* Only used if AIM_IMFLAGS_CUSTOMFEATURES is set */ | 683 /* Only used if AIM_IMFLAGS_CUSTOMFEATURES is set */ |
687 fu8_t *features; | 684 fu8_t *features; |
688 fu8_t featureslen; | 685 fu8_t featureslen; |
689 }; | 686 |
690 | 687 /* Only used if AIM_IMFLAGS_CUSTOMCHARSET is set and mpmsg not used */ |
688 fu16_t charset; | |
689 fu16_t charsubset; | |
690 }; | |
691 | |
692 /* | |
693 * This information is provided in the Incoming ICBM callback for | |
694 * Channel 1 ICBM's. | |
695 * | |
696 * Note that although CUSTOMFEATURES and CUSTOMCHARSET say they | |
697 * are optional, both are always set by the current libfaim code. | |
698 * That may or may not change in the future. It is mainly for | |
699 * consistency with aim_sendimext_args. | |
700 * | |
701 * Multipart messages require some explanation. If you want to use them, | |
702 * I suggest you read all the comments in im.c. | |
703 * | |
704 */ | |
691 struct aim_incomingim_ch1_args { | 705 struct aim_incomingim_ch1_args { |
692 | 706 |
693 /* Always provided */ | 707 /* Always provided */ |
708 aim_mpmsg_t mpmsg; | |
709 fu32_t icbmflags; /* some flags apply only to ->msg, not all mpmsg */ | |
710 | |
711 /* Only provided if message has a human-readable section */ | |
694 char *msg; | 712 char *msg; |
695 int msglen; | 713 int msglen; |
696 fu32_t icbmflags; | |
697 fu16_t flag1; | |
698 fu16_t flag2; | |
699 | 714 |
700 /* Only provided if AIM_IMFLAGS_HASICON is set */ | 715 /* Only provided if AIM_IMFLAGS_HASICON is set */ |
701 time_t iconstamp; | 716 time_t iconstamp; |
702 fu32_t iconlen; | 717 fu32_t iconlen; |
703 fu32_t iconsum; | 718 fu32_t iconsum; |
707 fu8_t featureslen; | 722 fu8_t featureslen; |
708 | 723 |
709 /* Only provided if AIM_IMFLAGS_EXTDATA is set */ | 724 /* Only provided if AIM_IMFLAGS_EXTDATA is set */ |
710 fu8_t extdatalen; | 725 fu8_t extdatalen; |
711 fu8_t *extdata; | 726 fu8_t *extdata; |
727 | |
728 /* Only used if AIM_IMFLAGS_CUSTOMCHARSET is set */ | |
729 fu16_t charset; | |
730 fu16_t charsubset; | |
712 }; | 731 }; |
713 | 732 |
714 struct aim_incomingim_ch2_args { | 733 struct aim_incomingim_ch2_args { |
715 fu8_t cookie[8]; | 734 fu8_t cookie[8]; |
716 fu16_t reqclass; | 735 fu16_t reqclass; |