changeset 1593:ec31e23aadc7

[gaim-migrate @ 1603] libfaim updates and a bug fix for bad password. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 16 Mar 2001 14:29:54 +0000
parents 41cecde078c1
children ac8eddd16e89
files libfaim/Makefile.am libfaim/aim.h libfaim/aim_internal.h libfaim/conn.c libfaim/ft.c libfaim/tlv.c libfaim/txqueue.c src/oscar.c
diffstat 8 files changed, 256 insertions(+), 228 deletions(-) [+]
line wrap: on
line diff
--- a/libfaim/Makefile.am	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/Makefile.am	Fri Mar 16 14:29:54 2001 +0000
@@ -1,6 +1,6 @@
 noinst_LIBRARIES = libfaim.a
 
-EXTRA_DIST = aim.h aim_cbtypes.h faimconfig.h md5.h README \
+EXTRA_DIST = aim.h aim_cbtypes.h aim_internal.h faimconfig.h md5.h README \
 		README.gaim CHANGES CHANGES.gaim COPYING BUGS AUTHORS
 
 libfaim_a_SOURCES = 	adverts.c	\
--- a/libfaim/aim.h	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/aim.h	Fri Mar 16 14:29:54 2001 +0000
@@ -70,8 +70,7 @@
 /* Portability stuff (DMP) */
 
 #ifdef _WIN32
-#define sleep Sleep
-#define socklen_t int /* this must be a POSIXy thing */
+#define sleep(x) Sleep((x)*1000)
 #define snprintf _snprintf /* I'm not sure whats wrong with Microsoft here */
 #define close(x) closesocket(x) /* no comment */
 #endif
@@ -398,28 +397,28 @@
 };
 
 /* TLV-handling functions */
-faim_internal struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen);
+faim_internal struct aim_tlvlist_t *aim_readtlvchain(const unsigned char *buf, const int maxlen);
 faim_internal void aim_freetlvchain(struct aim_tlvlist_t **list);
-faim_internal struct aim_tlv_t *aim_grabtlv(u_char *src);
-faim_internal struct aim_tlv_t *aim_grabtlvstr(u_char *src);
-faim_internal struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, u_short, int);
-faim_internal char *aim_gettlv_str(struct aim_tlvlist_t *, u_short, int);
-faim_internal unsigned char aim_gettlv8(struct aim_tlvlist_t *list, unsigned short type, int num);
-faim_internal unsigned short aim_gettlv16(struct aim_tlvlist_t *list, unsigned short type, int num);
-faim_internal unsigned long aim_gettlv32(struct aim_tlvlist_t *list, unsigned short type, int num);
-faim_internal int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv);
+faim_internal struct aim_tlv_t *aim_grabtlv(const unsigned char *src);
+faim_internal struct aim_tlv_t *aim_grabtlvstr(const unsigned char *src);
+faim_internal struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *, const unsigned short, const int);
+faim_internal char *aim_gettlv_str(struct aim_tlvlist_t *, const unsigned short, const int);
+faim_internal unsigned char aim_gettlv8(struct aim_tlvlist_t *list, const unsigned short type, const int num);
+faim_internal unsigned short aim_gettlv16(struct aim_tlvlist_t *list, const unsigned short type, const int num);
+faim_internal unsigned long aim_gettlv32(struct aim_tlvlist_t *list, const unsigned short type, const int num);
+faim_internal int aim_puttlv (unsigned char *dest, struct aim_tlv_t *newtlv);
 faim_internal struct aim_tlv_t *aim_createtlv(void);
 faim_internal int aim_freetlv(struct aim_tlv_t **oldtlv);
-faim_internal int aim_puttlv_8(unsigned char *buf, unsigned short t, unsigned char  v);
-faim_internal int aim_puttlv_16(u_char *, u_short, u_short);
-faim_internal int aim_puttlv_32(u_char *, u_short, u_long);
-faim_internal int aim_puttlv_str(u_char *buf, u_short t, int l, char *v);
-faim_internal int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
-faim_internal int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
-faim_internal int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
-faim_internal int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
-faim_internal int aim_addtlvtochain_caps(struct aim_tlvlist_t **list, unsigned short type, unsigned short caps);
-faim_internal int aim_addtlvtochain_noval(struct aim_tlvlist_t **list, unsigned short type);
+faim_internal int aim_puttlv_8(unsigned char *buf, const unsigned short t, const unsigned char  v);
+faim_internal int aim_puttlv_16(unsigned char *, const unsigned short, const unsigned short);
+faim_internal int aim_puttlv_32(unsigned char *, const unsigned short, const unsigned long);
+faim_internal int aim_puttlv_str(u_char *buf, const unsigned short t, const int l, const char *v);
+faim_internal int aim_writetlvchain(unsigned char *buf, const int buflen, struct aim_tlvlist_t **list);
+faim_internal int aim_addtlvtochain16(struct aim_tlvlist_t **list, const unsigned short type, const unsigned short val);
+faim_internal int aim_addtlvtochain32(struct aim_tlvlist_t **list, const unsigned short type, const unsigned long val);
+faim_internal int aim_addtlvtochain_str(struct aim_tlvlist_t **list, const unsigned short type, const char *str, const int len);
+faim_internal int aim_addtlvtochain_caps(struct aim_tlvlist_t **list, const unsigned short type, const unsigned short caps);
+faim_internal int aim_addtlvtochain_noval(struct aim_tlvlist_t **list, const unsigned short type);
 faim_internal int aim_counttlvchain(struct aim_tlvlist_t **list);
 #endif /* FAIM_INTERNAL */
 
@@ -441,12 +440,6 @@
 
 typedef int (*rxcallback_t)(struct aim_session_t *, struct command_rx_struct *, ...);
 
-#ifdef FAIM_INTERNAL
-faim_internal unsigned long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
-faim_internal unsigned long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
-faim_internal unsigned long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
-#endif
-
 /* aim_login.c */
 faim_export int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
 faim_export int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
@@ -457,25 +450,6 @@
 faim_export unsigned long aim_sendredirect(struct aim_session_t *sess, struct aim_conn_t *conn, unsigned short servid, char *ip, char *cookie);
 faim_export void aim_purge_rxqueue(struct aim_session_t *);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_authkeyparse(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn);
-faim_internal int aim_recv(int fd, void *buf, size_t count);
-
-faim_internal int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
-faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn);
-
-faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx_struct *cur);
-faim_internal unsigned int aim_get_next_txseqnum(struct aim_conn_t *);
-faim_internal struct command_tx_struct *aim_tx_new(struct aim_session_t *sess, struct aim_conn_t *conn, unsigned char framing, int chan, int datalen);
-faim_internal int aim_tx_enqueue(struct aim_session_t *, struct command_tx_struct *);
-faim_internal int aim_tx_printqueue(struct aim_session_t *);
-faim_internal int aim_parse_hostonline(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-faim_internal int aim_parse_hostversions(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-faim_internal int aim_parse_accountconfirm(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_parse_infochange(struct aim_session_t *sess, struct command_rx_struct *command);
-#endif /* FAIM_INTERNAL */
-
 #define AIM_TX_QUEUED    0 /* default */
 #define AIM_TX_IMMEDIATE 1
 #define AIM_TX_USER      2
@@ -497,37 +471,6 @@
 faim_export 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);
 faim_export int aim_clearhandlers(struct aim_conn_t *conn);
 
-#ifdef FAIM_INTERNAL
-faim_internal rxcallback_t aim_callhandler(struct aim_session_t *sess, struct aim_conn_t *conn, u_short family, u_short type);
-#endif
-
-#ifdef FAIM_INTERNAL
-/*
- * Generic SNAC structure.  Rarely if ever used.
- */
-struct aim_snac_t {
-  u_long id;
-  u_short family;
-  u_short type;
-  u_short flags;
-  void *data;
-  time_t issuetime;
-  struct aim_snac_t *next;
-};
-faim_internal void aim_initsnachash(struct aim_session_t *sess);
-faim_internal unsigned long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
-faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess, const unsigned short family, const unsigned short type, const unsigned short flags, const void *data, const int datalen);
-faim_internal struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
-faim_internal int aim_cleansnacs(struct aim_session_t *, int maxage);
-faim_internal int aim_putsnac(u_char *, int, int, int, u_long);
-#endif /* FAIM_INTERNAL */
-
-#ifdef FAIM_INTERNAL
-faim_internal void aim_connrst(struct aim_session_t *);
-faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
-faim_internal struct aim_conn_t *aim_cloneconn(struct aim_session_t *sess, struct aim_conn_t *src);
-#endif /* FAIM_INTERNAL */
-
 faim_export void aim_conn_close(struct aim_conn_t *deadconn);
 faim_export struct aim_conn_t *aim_newconn(struct aim_session_t *, int type, char *dest);
 faim_export int aim_conngetmaxfd(struct aim_session_t *);
@@ -585,39 +528,9 @@
 
 faim_export struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess, FILE *);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_oft_buildheader(unsigned char *,struct aim_fileheader_t *);
-faim_internal int aim_listenestablish(u_short);
-faim_internal int aim_tx_destroy(struct command_tx_struct *);
-#endif /* FAIM_INTERNAL */
-
 /* aim_rxhandlers.c */
 faim_export int aim_rxdispatch(struct aim_session_t *);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
-faim_internal int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
-faim_internal int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
-faim_internal int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-
-/* these are used by aim_*_clientready */
-#define AIM_TOOL_JAVA   0x0001
-#define AIM_TOOL_MAC    0x0002
-#define AIM_TOOL_WIN16  0x0003
-#define AIM_TOOL_WIN32  0x0004
-#define AIM_TOOL_MAC68K 0x0005
-#define AIM_TOOL_MACPPC 0x0006
-#define AIM_TOOL_NEWWIN 0x0010
-struct aim_tool_version {
-  unsigned short group;
-  unsigned short version;
-  unsigned short tool;
-  unsigned short toolversion;
-};
-
-#endif /* FAIM_INTERNAL */
-
 #define AIM_CLIENTTYPE_UNKNOWN  0x0000
 #define AIM_CLIENTTYPE_MC       0x0001
 #define AIM_CLIENTTYPE_WINAIM   0x0002
@@ -632,13 +545,6 @@
 faim_export unsigned long aim_ads_clientready(struct aim_session_t *sess, struct aim_conn_t *conn);
 faim_export unsigned long aim_ads_requestads(struct aim_session_t *sess, struct aim_conn_t *conn);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_parse_ratechange_middle(struct aim_session_t *sess, struct command_rx_struct *command);
-
-faim_internal int aim_parse_evilnotify_middle(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_parse_msgack_middle(struct aim_session_t *sess, struct command_rx_struct *command);
-#endif /* FAIM_INTERNAL */
-
 /* aim_im.c */
 struct aim_directim_priv {
   unsigned char cookie[8];
@@ -699,15 +605,6 @@
 faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *);
 faim_export unsigned long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_parse_bosrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-faim_internal int aim_parse_missedcall(struct aim_session_t *sess, struct command_rx_struct *command);
-#endif /* FAIM_INTERNAL */
-
 faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn);
 faim_export int aim_oft_getfile_request(struct aim_session_t *sess, struct aim_conn_t *conn, const unsigned char *name, const int size);
 faim_export int aim_oft_getfile_ack(struct aim_session_t *sess, struct aim_conn_t *conn);
@@ -723,13 +620,6 @@
 #define AIM_CAPS_GAMES 0x40
 #define AIM_CAPS_SAVESTOCKS 0x80
 
-#ifdef FAIM_INTERNAL
-extern u_char aim_caps[8][16];
-faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen);
-faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps);
-#endif /* FAIM_INTERNAL */
-
-
 #define AIM_GETINFO_GENERALINFO 0x00001
 #define AIM_GETINFO_AWAYMESSAGE 0x00003
 
@@ -765,16 +655,6 @@
 #define AIM_COOKIETYPE_OFTIMAGE 0x14
 #define AIM_COOKIETYPE_OFTICON  0x15
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
-faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type);
-faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *);
-faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, const unsigned char *, const int);
-faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
-faim_internal int aim_msgcookie_gettype(int reqclass);
-faim_internal int aim_cookie_free(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
-#endif /* FAIM_INTERNAL */
-
 faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur);
 
 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
@@ -783,15 +663,6 @@
 faim_export unsigned long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
 faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn, char *cookie, char *ip, unsigned short listingfiles, unsigned short listingtotsize, unsigned short listingsize, unsigned int listingchecksum, unsigned short rendid);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char *, struct aim_userinfo_s *);
-faim_internal int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
-faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
-faim_internal int aim_parse_locateerr(struct aim_session_t *sess, struct command_rx_struct *command);
-#endif /* FAIM_INTERNAL */
-
 faim_export unsigned long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
 faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info);
 faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
@@ -806,18 +677,9 @@
 faim_export unsigned long aim_add_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
 faim_export unsigned long aim_remove_buddy(struct aim_session_t *, struct aim_conn_t *, char *);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-#endif /* FAIM_INTERNAL */
-
 /* aim_search.c */
 faim_export u_long aim_usersearch_address(struct aim_session_t *, struct aim_conn_t *, char *);
 
-#ifdef FAIM_INTERNAL
-faim_internal unsigned long aim_parse_searcherror(struct aim_session_t *, struct command_rx_struct *);
-faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *, struct command_rx_struct *);
-#endif
-
 struct aim_chat_roominfo {
   u_short exchange;
   char *name;
@@ -848,15 +710,6 @@
 faim_export u_long aim_chatnav_createroom(struct aim_session_t *sess, struct aim_conn_t *conn, char *name, u_short exchange);
 faim_export int aim_chat_leaveroom(struct aim_session_t *sess, char *name);
 
-#ifdef FAIM_INTERNAL
-faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
-faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
-faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
-#endif /* FAIM_INTERNAL */
-
 /* aim_util.c */
 #ifdef AIMUTIL_USEMACROS
 /*
@@ -905,14 +758,7 @@
 faim_export char *aim_getbuildtime(void);
 faim_export char *aim_getbuildstring(void);
 
-#ifdef FAIM_INTERNAL
-faim_internal void faimdprintf(struct aim_session_t *sess, int dlevel, const char *format, ...);
-
-/* why the hell wont cpp let you use #error inside #define's? */
-#define printf() printf called inside libfaim
-#define sprintf() unbounded sprintf used inside libfaim
-
-#endif /* FAIM_INTERNAL */
+#include <aim_internal.h>
 
 #endif /* __AIM_H__ */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libfaim/aim_internal.h	Fri Mar 16 14:29:54 2001 +0000
@@ -0,0 +1,133 @@
+/*
+ * aim_internal.h -- prototypes/structs for the guts of libfaim
+ *
+ */
+
+#ifdef FAIM_INTERNAL
+#ifndef __AIM_INTERNAL_H__
+#define __AIM_INTERNAL_H__ 1
+
+faim_internal unsigned long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype);
+faim_internal unsigned long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
+faim_internal unsigned long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
+
+faim_internal int aim_authkeyparse(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn);
+faim_internal int aim_recv(int fd, void *buf, size_t count);
+
+faim_internal int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
+faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn);
+
+faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx_struct *cur);
+faim_internal unsigned int aim_get_next_txseqnum(struct aim_conn_t *);
+faim_internal struct command_tx_struct *aim_tx_new(struct aim_session_t *sess, struct aim_conn_t *conn, unsigned char framing, int chan, int datalen);
+faim_internal int aim_tx_enqueue(struct aim_session_t *, struct command_tx_struct *);
+faim_internal int aim_tx_printqueue(struct aim_session_t *);
+faim_internal int aim_parse_hostonline(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+faim_internal int aim_parse_hostversions(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+faim_internal int aim_parse_accountconfirm(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_parse_infochange(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_tx_cleanqueue(struct aim_session_t *, struct aim_conn_t *);
+
+faim_internal rxcallback_t aim_callhandler(struct aim_session_t *sess, struct aim_conn_t *conn, u_short family, u_short type);
+
+/*
+ * Generic SNAC structure.  Rarely if ever used.
+ */
+struct aim_snac_t {
+  u_long id;
+  u_short family;
+  u_short type;
+  u_short flags;
+  void *data;
+  time_t issuetime;
+  struct aim_snac_t *next;
+};
+faim_internal void aim_initsnachash(struct aim_session_t *sess);
+faim_internal unsigned long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
+faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess, const unsigned short family, const unsigned short type, const unsigned short flags, const void *data, const int datalen);
+faim_internal struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
+faim_internal int aim_cleansnacs(struct aim_session_t *, int maxage);
+faim_internal int aim_putsnac(u_char *, int, int, int, u_long);
+
+faim_internal void aim_connrst(struct aim_session_t *);
+faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *);
+faim_internal struct aim_conn_t *aim_cloneconn(struct aim_session_t *sess, struct aim_conn_t *src);
+
+faim_internal int aim_oft_buildheader(unsigned char *,struct aim_fileheader_t *);
+faim_internal int aim_listenestablish(u_short);
+faim_internal int aim_tx_destroy(struct command_tx_struct *);
+
+faim_internal int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_handleredirect_middle(struct aim_session_t *, struct command_rx_struct *, ...);
+faim_internal int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *, ...);
+faim_internal int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *command, ...);
+faim_internal int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+
+/* these are used by aim_*_clientready */
+#define AIM_TOOL_JAVA   0x0001
+#define AIM_TOOL_MAC    0x0002
+#define AIM_TOOL_WIN16  0x0003
+#define AIM_TOOL_WIN32  0x0004
+#define AIM_TOOL_MAC68K 0x0005
+#define AIM_TOOL_MACPPC 0x0006
+#define AIM_TOOL_NEWWIN 0x0010
+struct aim_tool_version {
+  unsigned short group;
+  unsigned short version;
+  unsigned short tool;
+  unsigned short toolversion;
+};
+
+faim_internal int aim_parse_ratechange_middle(struct aim_session_t *sess, struct command_rx_struct *command);
+
+faim_internal int aim_parse_evilnotify_middle(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_parse_msgack_middle(struct aim_session_t *sess, struct command_rx_struct *command);
+
+faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_parse_bosrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+faim_internal int aim_parse_missedcall(struct aim_session_t *sess, struct command_rx_struct *command);
+
+extern u_char aim_caps[8][16];
+faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen);
+faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps);
+
+faim_internal int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
+faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type);
+faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *);
+faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, const unsigned char *, const int);
+faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
+faim_internal int aim_msgcookie_gettype(int reqclass);
+faim_internal int aim_cookie_free(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
+
+faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char *, struct aim_userinfo_s *);
+faim_internal int aim_parse_userinfo_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_parse_oncoming_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_parse_offgoing_middle(struct aim_session_t *, struct command_rx_struct *);
+faim_internal int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info);
+faim_internal int aim_parse_locateerr(struct aim_session_t *sess, struct command_rx_struct *command);
+
+faim_internal int aim_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+
+faim_internal unsigned long aim_parse_searcherror(struct aim_session_t *, struct command_rx_struct *);
+faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *, struct command_rx_struct *);
+
+faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo);
+faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_chat_parse_joined(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_chat_parse_leave(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess, struct command_rx_struct *command);
+faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command);
+
+faim_internal void faimdprintf(struct aim_session_t *sess, int dlevel, const char *format, ...);
+
+/* why the hell wont cpp let you use #error inside #define's? */
+/* isn't it single-pass? so the #error would get passed to the compiler --jbm */
+#define printf() printf called inside libfaim
+#define sprintf() unbounded sprintf used inside libfaim
+
+#endif /* __AIM_INTERNAL_H__ */
+#endif /* FAIM_INTERNAL */
--- a/libfaim/conn.c	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/conn.c	Fri Mar 16 14:29:54 2001 +0000
@@ -112,6 +112,8 @@
   if (!deadconn || !*deadconn)	
     return;
 
+  aim_tx_cleanqueue(sess, *deadconn);
+
   faim_mutex_lock(&sess->connlistlock);
   if (sess->connlist == NULL)
     ;
@@ -540,7 +542,8 @@
  *
  */ 
 faim_export struct aim_conn_t *aim_select(struct aim_session_t *sess,
-					  struct timeval *timeout, int *status)
+					  struct timeval *timeout, 
+					  int *status)
 {
   struct aim_conn_t *cur;
   fd_set fds, wfds;
@@ -568,6 +571,7 @@
       return cur;
     } else if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
       FD_SET(cur->fd, &wfds);
+      
       haveconnecting++;
     }
     FD_SET(cur->fd, &fds);
--- a/libfaim/ft.c	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/ft.c	Fri Mar 16 14:29:54 2001 +0000
@@ -998,7 +998,7 @@
    faim_mutex_unlock(&conn->active);
    aim_conn_close(conn);
    return -1;
-   }
+ }
  hdrtype = aimutil_get16(hdr);
 
  switch (hdrtype) {
@@ -1019,7 +1019,7 @@
    snptr = (char *)hdr+38;
    strncpy(priv->sn, snptr, MAXSNLEN);
 
-   faimdprintf(sess, 2, "faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr);
+   faimdprintf(sess, 2, "faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, priv->sn);
 
    free(hdr);
    hdr = NULL;
@@ -1027,7 +1027,7 @@
    if (flags == 0x000e) { 
      faim_mutex_unlock(&conn->active);
      if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
-       return userfunc(sess, NULL, snptr);
+       return userfunc(sess, NULL, conn);
    } else {
 
      if ((flags == 0x0000) && payloadlength) { 
@@ -1049,12 +1049,12 @@
 
        faim_mutex_unlock(&conn->active);
        msg[payloadlength] = 0x00;
-       faimdprintf(sess, 2, "faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+       faimdprintf(sess, 2, "faim: directim: %s/%04x/%04x/%s\n", priv->sn, payloadlength, flags, msg);
 
        if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
-	 i = userfunc(sess, NULL, conn, snptr, msg);
+	 i = userfunc(sess, NULL, conn, msg);
        else {
-	  faimdprintf(sess, 0, "directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+	  faimdprintf(sess, 0, "directim: %s/%04x/%04x/%s\n", priv->sn, payloadlength, flags, msg);
 	 i = 1;
        }
 
@@ -1348,7 +1348,8 @@
    int i;
    struct aim_fileheader_t *fh;
 
-   fh = aim_oft_getfh(hdr);
+   if(!(fh = aim_oft_getfh(hdr)))
+     return -1;
 
    free(hdr);
    hdr = NULL;
@@ -1378,6 +1379,7 @@
    break;
  } 
  } /* switch */
+
  if (hdr) {
     faimdprintf(sess, 0, "hdr wasn't freed by a rendezvous switch case (hdrtype: %0x04x)!\n", hdrtype);
    free(hdr);
--- a/libfaim/tlv.c	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/tlv.c	Fri Mar 16 14:29:54 2001 +0000
@@ -13,14 +13,13 @@
  * be called to free the dynamic substructures.
  *
  */
-faim_export struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
+faim_export struct aim_tlvlist_t *aim_readtlvchain(const unsigned char *buf, const int maxlen)
 {
   int pos;
   struct aim_tlvlist_t *list;
   struct aim_tlvlist_t *cur;
   
-  u_short type;
-  u_short length;
+  unsigned short type, length;
 
   if (!buf)
     return NULL;
@@ -156,7 +155,7 @@
  * to the TLV chain.
  *
  */
-faim_export int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len)
+faim_export int aim_addtlvtochain_str(struct aim_tlvlist_t **list, const unsigned short type, const char *str, const int len)
 {
   struct aim_tlvlist_t *newtlv;
   struct aim_tlvlist_t *cur;
@@ -196,7 +195,7 @@
  * Adds a two-byte unsigned integer to a TLV chain.
  *
  */
-faim_export int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val)
+faim_export int aim_addtlvtochain16(struct aim_tlvlist_t **list, const unsigned short type, const unsigned short val)
 {
   struct aim_tlvlist_t *newtl;
   struct aim_tlvlist_t *cur;
@@ -236,7 +235,7 @@
  * Adds a four-byte unsigned integer to a TLV chain.
  *
  */
-faim_export int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val)
+faim_export int aim_addtlvtochain32(struct aim_tlvlist_t **list, const unsigned short type, const unsigned long val)
 {
   struct aim_tlvlist_t *newtl;
   struct aim_tlvlist_t *cur;
@@ -289,7 +288,7 @@
  *      %AIM_CAPS_SENDFILE    Supports Send File functions
  *
  */
-faim_export int aim_addtlvtochain_caps(struct aim_tlvlist_t **list, unsigned short type, unsigned short caps)
+faim_export int aim_addtlvtochain_caps(struct aim_tlvlist_t **list, const unsigned short type, const unsigned short caps)
 {
   unsigned char buf[128]; /* icky fixed length buffer */
   struct aim_tlvlist_t *newtl;
@@ -330,7 +329,7 @@
  * Adds a TLV with a zero length to a TLV chain.
  *
  */
-faim_internal int aim_addtlvtochain_noval(struct aim_tlvlist_t **list, unsigned short type)
+faim_internal int aim_addtlvtochain_noval(struct aim_tlvlist_t **list, const unsigned short type)
 {
   struct aim_tlvlist_t *newtlv;
   struct aim_tlvlist_t *cur;
@@ -369,7 +368,7 @@
  * by the chain structures.
  *
  */
-faim_export int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list)
+faim_export int aim_writetlvchain(unsigned char *buf, int buflen, struct aim_tlvlist_t **list)
 {
   int goodbuflen = 0;
   int i = 0;
@@ -411,7 +410,7 @@
  * in a chain.
  *
  */
-faim_export struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth)
+faim_export struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, const unsigned short type, const int nth)
 {
   int i;
   struct aim_tlvlist_t *cur;
@@ -441,7 +440,7 @@
  * dynamic buffer and must be freed by the caller.
  *
  */
-faim_export char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth)
+faim_export char *aim_gettlv_str(struct aim_tlvlist_t *list, const unsigned short type, const int nth)
 {
   struct aim_tlv_t *tlv;
   char *newstr;
@@ -466,7 +465,7 @@
  * 8bit integer instead of an aim_tlv_t. 
  *
  */
-faim_internal unsigned char aim_gettlv8(struct aim_tlvlist_t *list, unsigned short type, int num)
+faim_internal unsigned char aim_gettlv8(struct aim_tlvlist_t *list, const unsigned short type, const int num)
 {
   struct aim_tlv_t *tlv;
 
@@ -485,7 +484,7 @@
  * 16bit integer instead of an aim_tlv_t. 
  *
  */
-faim_internal unsigned short aim_gettlv16(struct aim_tlvlist_t *list, unsigned short type, int num)
+faim_internal unsigned short aim_gettlv16(struct aim_tlvlist_t *list, const unsigned short type, const int num)
 {
   struct aim_tlv_t *tlv;
 
@@ -504,7 +503,7 @@
  * 32bit integer instead of an aim_tlv_t. 
  *
  */
-faim_internal unsigned long aim_gettlv32(struct aim_tlvlist_t *list, unsigned short type, int num)
+faim_internal unsigned long aim_gettlv32(struct aim_tlvlist_t *list, const unsigned short type, const int num)
 {
   struct aim_tlv_t *tlv;
 
@@ -525,7 +524,7 @@
  * must be freed by the caller if non-%NULL.
  *
  */
-faim_export struct aim_tlv_t *aim_grabtlv(u_char *src)
+faim_export struct aim_tlv_t *aim_grabtlv(const unsigned char *src)
 {
   struct aim_tlv_t *dest = NULL;
 
@@ -537,10 +536,10 @@
   dest->length = src[2] << 8;
   dest->length += src[3];
 
-  dest->value = (u_char *) malloc(dest->length*sizeof(u_char));
-  memset(dest->value, 0, dest->length*sizeof(u_char));
+  dest->value = (unsigned char *) malloc(dest->length);
+  memset(dest->value, 0, dest->length);
 
-  memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
+  memcpy(dest->value, &(src[4]), dest->length);
   
   return dest;
 }
@@ -558,7 +557,7 @@
  * must be freed by the caller if non-%NULL.
  *
  */
-faim_export struct aim_tlv_t *aim_grabtlvstr(u_char *src)
+faim_export struct aim_tlv_t *aim_grabtlvstr(const unsigned char *src)
 {
   struct aim_tlv_t *dest = NULL;
 
@@ -570,10 +569,10 @@
   dest->length = src[2] << 8;
   dest->length += src[3];
 
-  dest->value = (u_char *) malloc((dest->length+1)*sizeof(u_char));
-  memset(dest->value, 0, (dest->length+1)*sizeof(u_char));
+  dest->value = (unsigned char *) malloc(dest->length+1);
+  memset(dest->value, 0, dest->length+1);
 
-  memcpy(dest->value, &(src[4]), dest->length*sizeof(u_char));
+  memcpy(dest->value, src+4, dest->length);
   dest->value[dest->length] = '\0';
 
   return dest;
@@ -591,7 +590,7 @@
  * still be called by the caller to free the structure.
  *
  */
-faim_export int aim_puttlv(u_char *dest, struct aim_tlv_t *newtlv)
+faim_export int aim_puttlv(unsigned char *dest, struct aim_tlv_t *newtlv)
 {
   int i=0;
 
@@ -651,7 +650,7 @@
  * Writes a TLV with a one-byte integer value portion.
  *
  */
-faim_export int aim_puttlv_8(unsigned char *buf, unsigned short t, unsigned char  v)
+faim_export int aim_puttlv_8(unsigned char *buf, const unsigned short t, const unsigned char  v)
 {
   int curbyte=0;
 
@@ -671,12 +670,12 @@
  * Writes a TLV with a two-byte integer value portion.
  *
  */
-faim_export int aim_puttlv_16(u_char *buf, u_short t, u_short v)
+faim_export int aim_puttlv_16(unsigned char *buf, const unsigned short t, const unsigned short v)
 {
   int curbyte=0;
-  curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
-  curbyte += aimutil_put16(buf+curbyte, (u_short)0x0002);
-  curbyte += aimutil_put16(buf+curbyte, (u_short)(v&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)(t&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)0x0002);
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)(v&0xffff));
   return curbyte;
 }
 
@@ -689,12 +688,12 @@
  * Writes a TLV with a four-byte integer value portion.
  *
  */
-faim_export int aim_puttlv_32(u_char *buf, u_short t, u_long v)
+faim_export int aim_puttlv_32(unsigned char *buf, const unsigned short t, const unsigned long v)
 {
   int curbyte=0;
-  curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
-  curbyte += aimutil_put16(buf+curbyte, (u_short)0x0004);
-  curbyte += aimutil_put32(buf+curbyte, (u_long)(v&0xffffffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)(t&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)0x0004);
+  curbyte += aimutil_put32(buf+curbyte, (unsigned long)(v&0xffffffff));
   return curbyte;
 }
 
@@ -710,13 +709,13 @@
  * include the terminating NULL.)
  *
  */
-faim_export int aim_puttlv_str(u_char *buf, u_short t, int l, char *v)
+faim_export int aim_puttlv_str(unsigned char *buf, const unsigned short t, const int l, const char *v)
 {
   int curbyte;
   
   curbyte  = 0;
-  curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
-  curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)(t&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (unsigned short)(l&0xffff));
   if (v)
     memcpy(buf+curbyte, (unsigned char *)v, l);
   curbyte += l;
--- a/libfaim/txqueue.c	Fri Mar 16 11:54:39 2001 +0000
+++ b/libfaim/txqueue.c	Fri Mar 16 14:29:54 2001 +0000
@@ -24,7 +24,11 @@
  * chan = channel for OSCAR, hdrtype for OFT
  *
  */
-faim_internal struct command_tx_struct *aim_tx_new(struct aim_session_t *sess, struct aim_conn_t *conn, unsigned char framing, int chan, int datalen)
+faim_internal struct command_tx_struct *aim_tx_new(struct aim_session_t *sess, 
+						   struct aim_conn_t *conn, 
+						   unsigned char framing, 
+						   int chan, 
+						   int datalen)
 {
   struct command_tx_struct *newtx;
 
@@ -158,7 +162,9 @@
   return 0;
 }
 
-faim_export int aim_tx_setenqueue(struct aim_session_t *sess, int what,  int (*func)(struct aim_session_t *, struct command_tx_struct *))
+faim_export int aim_tx_setenqueue(struct aim_session_t *sess, 
+				  int what,  
+				  int (*func)(struct aim_session_t *, struct command_tx_struct *))
 {
   if (!sess)
     return -1;
@@ -429,3 +435,31 @@
   }
   return;
 }
+
+/**
+ * aim_tx_cleanqueue - get rid of packets waiting for tx on a dying conn
+ * @sess: session
+ * @conn: connection that's dying
+ *
+ * for now this simply marks all packets as sent and lets them
+ * disappear without warning.
+ *
+ * doesn't respect command_tx_struct locks.
+ */
+
+faim_export int aim_tx_cleanqueue(struct aim_session_t *sess, struct aim_conn_t *conn)
+{
+  struct command_tx_struct *cur = NULL;
+
+  if(!sess || !conn)
+    return -1;
+
+  /* we don't respect locks here */
+  for(cur = sess->queue_outgoing; cur; cur = cur->next)
+    if(cur->conn == conn)
+      cur->sent = 1;
+  
+  return 0;
+}
+    
+      
--- a/src/oscar.c	Fri Mar 16 11:54:39 2001 +0000
+++ b/src/oscar.c	Fri Mar 16 14:29:54 2001 +0000
@@ -532,6 +532,7 @@
 		}
 		debug_printf("Login Error Code 0x%04x\n", errorcode);
 		debug_printf("Error URL: %s\n", errurl);
+		aim_conn_kill(sess, &command->conn);
 		signoff(gc);
 		return 0;
 	}
@@ -2109,19 +2110,23 @@
 
 static int gaim_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
 	va_list ap;
-	char *sn = NULL, *msg = NULL;
+	char *msg = NULL;
 	struct aim_conn_t *conn;
+	struct aim_directim_priv *priv;
 	struct gaim_connection *gc = sess->aux_data;
 
 	va_start(ap, command);
 	conn = va_arg(ap, struct aim_conn_t *);
-	sn = va_arg(ap, char *);
 	msg = va_arg(ap, char *);
 	va_end(ap);
 
-	debug_printf("Got DirectIM message from %s\n", sn);
+	if (!(priv = conn->priv)) {
+		return -1;
+	}
 
-	serv_got_im(gc, sn, msg, 0);
+	debug_printf("Got DirectIM message from %s\n", priv->sn);
+
+	serv_got_im(gc, priv->sn, msg, 0);
 
 	return 1;
 }
@@ -2158,14 +2163,19 @@
 
 static int gaim_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
 	va_list ap;
-	char *sn;
+	struct aim_conn_t *conn;
+	struct aim_directim_priv *priv;
 
 	va_start(ap, command);
-	sn = va_arg(ap, char *);
+	conn = va_arg(ap, struct aim_conn_t *);
 	va_end(ap);
 
+	if (!(priv = conn->priv)) {
+		return -1;
+	}
+
 	/* I had to leave this. It's just too funny. It reminds me of my sister. */
-	debug_printf("ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn);
+	debug_printf("ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", priv->sn);
 
 	return 1;
 }