Index: libfaim/aim.h
===================================================================
--- libfaim/aim.h	(revision 862371bb6a5ff5a6491550028e73824b698508bb)
+++ libfaim/aim.h	(revision e374dee70435f8c596358571092675644a9ba731)
@@ -3,5 +3,5 @@
  *
  * "come on, i turned a chick lesbian; i think this is the hackish equivalent"
- *                                                -- Josh Meyer
+ *                                                -- Josh Myer
  *
  */
@@ -29,4 +29,5 @@
 #include <sys/time.h>
 #include <unistd.h>
+#include <netdb.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
@@ -35,8 +36,12 @@
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* XXX adjust these based on autoconf-detected platform */
 typedef unsigned char fu8_t;
 typedef unsigned short fu16_t;
-typedef unsigned long fu32_t;
+typedef unsigned int fu32_t;
 typedef fu32_t aim_snacid_t;
 typedef fu16_t flap_seqnum_t;
@@ -44,10 +49,4 @@
 #if defined(mach) && defined(__APPLE__)
 #define gethostbyname(x) gethostbyname2(x, AF_INET) 
-#endif
-
-#if defined(_WIN32) || defined(STRICT_ANSI)
-#define faim_shortfunc
-#else
-#define faim_shortfunc inline
 #endif
 
@@ -73,4 +72,12 @@
 #endif
 
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#ifndef TRUE
+#define TRUE (!FALSE)
+#endif
+
 /* 
  * Current Maximum Length for Screen Names (not including NULL) 
@@ -79,5 +86,5 @@
  * however it is aparently legal for them to be larger.
  */
-#define MAXSNLEN 32
+#define MAXSNLEN 97
 
 /*
@@ -114,8 +121,8 @@
 #define MAXCHATMSGLEN 512
 
-/*
- * Standard size of an AIM authorization cookie
- */
-#define AIM_COOKIELEN            0x100
+/**
+ * Maximum length for the password of an ICQ account
+ */
+#define MAXICQPASSLEN 8
 
 #define AIM_MD5_STRING "AOL Instant Messenger (SM)"
@@ -130,118 +137,168 @@
 	const char *clientstring;
 	fu16_t clientid;
-	int major;
-	int minor;
-	int point;
-	int build;
+	fu16_t major;
+	fu16_t minor;
+	fu16_t point;
+	fu16_t build;
+	fu32_t distrib;
 	const char *country; /* two-letter abbrev */
 	const char *lang; /* two-letter abbrev */
 };
 
+/* Needs to be checked */
 #define CLIENTINFO_AIM_3_5_1670 { \
 	"AOL Instant Messenger (SM), version 3.5.1670/WIN32", \
 	0x0004, \
-	0x0003, \
-	0x0005, \
-	0x0000, \
-	0x0686, \
-	"us", \
-	"en", \
+	0x0003, 0x0005, \
+	0x0000, 0x0686, \
+	0x0000002a, \
+	"us", "en", \
 }
 
+/* Needs to be checked */
+/* Latest winaim without ssi */
 #define CLIENTINFO_AIM_4_1_2010 { \
-	  "AOL Instant Messenger (SM), version 4.1.2010/WIN32", \
-	  0x0004, \
-	  0x0004, \
-	  0x0001, \
-	  0x0000, \
-	  0x07da, \
-	  "us", \
-	  "en", \
+	"AOL Instant Messenger (SM), version 4.1.2010/WIN32", \
+	0x0004, \
+	0x0004, 0x0001, \
+	0x0000, 0x07da, \
+	0x0000004b, \
+	"us", "en", \
 }
 
+/* Needs to be checked */
+#define CLIENTINFO_AIM_4_3_2188 { \
+	"AOL Instant Messenger (SM), version 4.3.2188/WIN32", \
+	0x0109, \
+	0x0400, 0x0003, \
+	0x0000, 0x088c, \
+	0x00000086, \
+	"us", "en", \
+}
+
+/* Needs to be checked */
+#define CLIENTINFO_AIM_4_8_2540 { \
+	"AOL Instant Messenger (SM), version 4.8.2540/WIN32", \
+	0x0109, \
+	0x0004, 0x0008, \
+	0x0000, 0x09ec, \
+	0x000000af, \
+	"us", "en", \
+}
+
+/* Needs to be checked */
 #define CLIENTINFO_AIM_5_0_2938 { \
-	  "AOL Instant Messenger, version 5.0.2938/WIN32", \
-	  0x0109, \
-	  0x0005, \
-	  0x0000, \
-	  0x0000, \
-	  0x0b7a, \
-	  "us", \
-	  "en", \
+	"AOL Instant Messenger, version 5.0.2938/WIN32", \
+	0x0109, \
+	0x0005, 0x0000, \
+	0x0000, 0x0b7a, \
+	0x00000000, \
+	"us", "en", \
 }
 
+#define CLIENTINFO_AIM_5_1_3036 { \
+	"AOL Instant Messenger, version 5.1.3036/WIN32", \
+	0x0109, \
+	0x0005, 0x0001, \
+	0x0000, 0x0bdc, \
+	0x000000d2, \
+	"us", "en", \
+}
+
+#define CLIENTINFO_ICHAT_1_0 { \
+	"Apple iChat", \
+	0x311a, \
+	0x0001, 0x0000, \
+	0x0000, 0x003c, \
+	0x000000c6, \
+	"us", "en", \
+}
+
+/* Needs to be checked */
 #define CLIENTINFO_ICQ_4_65_3281 { \
 	"ICQ Inc. - Product of ICQ (TM) 2000b.4.65.1.3281.85", \
 	0x010a, \
-	0x0004, \
-	0x0041, \
-	0x0001, \
-	0x0cd1, \
-	"us", \
-	"en", \
+	0x0004, 0x0041, \
+	0x0001, 0x0cd1, \
+	0x00000055, \
+	"us", "en", \
 }
 
+/* Needs to be checked */
 #define CLIENTINFO_ICQ_5_34_3728 { \
 	"ICQ Inc. - Product of ICQ (TM).2002a.5.34.1.3728.85", \
 	0x010a, \
-	0x0005, \
-	0x0022, \
-	0x0001, \
-	0x0e8f, \
-	"us", \
-	"en", \
+	0x0005, 0x0022, \
+	0x0001, 0x0e8f, \
+	0x00000055, \
+	"us", "en", \
 }
 
-/*
- * I would make 4.1.2010 the default, but they seem to have found
- * an alternate way of breaking that one. 
- *
- * 3.5.1670 should work fine, however, you will be subjected to the
- * memory test, which may require you to have a WinAIM binary lying 
- * around. (see login.c::memrequest())
- */
-#define CLIENTINFO_AIM_KNOWNGOOD CLIENTINFO_AIM_3_5_1670
-#define CLIENTINFO_ICQ_KNOWNGOOD CLIENTINFO_ICQ_4_65_3281
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
+#define CLIENTINFO_ICQ_5_45_3777 { \
+	"ICQ Inc. - Product of ICQ (TM).2003a.5.45.1.3777.85", \
+	0x010a, \
+	0x0005, 0x002d, \
+	0x0001, 0x0ec1, \
+	0x00000055, \
+	"us", "en", \
+}
+
+#define CLIENTINFO_ICQBasic_14_3_1068 { \
+	"ICQBasic", \
+	0x010a, \
+	0x0014, 0x0003, \
+	0x0000, 0x042c, \
+	0x0000043d, \
+	"us", "en", \
+}
+
+#define CLIENTINFO_Netscape_7_0_1 { \
+	"Netscape 2000 an approved user of AOL Instant Messenger (SM)", \
+	0x1d0d, \
+	0x0007, 0x0000, \
+	0x0001, 0x0000, \
+	0x00000058, \
+	"us", "en", \
+}
+
+#define CLIENTINFO_AIM_KNOWNGOOD CLIENTINFO_AIM_5_1_3036
+#define CLIENTINFO_ICQ_KNOWNGOOD CLIENTINFO_ICQ_5_45_3777
 
 /* 
  * These could be arbitrary, but its easier to use the actual AIM values 
  */
-#define AIM_CONN_TYPE_AUTH          0x0007
-#define AIM_CONN_TYPE_ADS           0x0005
-#define AIM_CONN_TYPE_BOS           0x0002
-#define AIM_CONN_TYPE_CHAT          0x000e
-#define AIM_CONN_TYPE_CHATNAV       0x000d
-#define AIM_CONN_TYPE_SEARCH        0x000f
-#define AIM_CONN_TYPE_EMAIL         0x0018
-
-/* they start getting arbitrary in rendezvous stuff =) */
-#define AIM_CONN_TYPE_RENDEZVOUS    0x0101 /* these do not speak FLAP! */
-#define AIM_CONN_TYPE_RENDEZVOUS_OUT 0x0102 /* socket waiting for accept() */
+#define AIM_CONN_TYPE_BOS		0x0002
+#define AIM_CONN_TYPE_ADS		0x0005
+#define AIM_CONN_TYPE_AUTH		0x0007
+#define AIM_CONN_TYPE_CHATNAV		0x000d
+#define AIM_CONN_TYPE_CHAT		0x000e
+#define AIM_CONN_TYPE_SEARCH		0x000f
+#define AIM_CONN_TYPE_ICON		0x0010
+#define AIM_CONN_TYPE_EMAIL		0x0018
+
+/* they start getting arbitrary for rendezvous stuff =) */
+#define AIM_CONN_TYPE_RENDEZVOUS	0xfffe /* these do not speak FLAP! */
+#define AIM_CONN_TYPE_LISTENER		0xffff /* socket waiting for accept() */
 
 /*
  * Subtypes, we need these for OFT stuff.
  */
-#define AIM_CONN_SUBTYPE_OFT_DIRECTIM  0x0001
-#define AIM_CONN_SUBTYPE_OFT_GETFILE   0x0002
-#define AIM_CONN_SUBTYPE_OFT_SENDFILE  0x0003
-#define AIM_CONN_SUBTYPE_OFT_BUDDYICON 0x0004
-#define AIM_CONN_SUBTYPE_OFT_VOICE     0x0005
+#define AIM_CONN_SUBTYPE_OFT_DIRECTIM	0x0001
+#define AIM_CONN_SUBTYPE_OFT_GETFILE	0x0002
+#define AIM_CONN_SUBTYPE_OFT_SENDFILE	0x0003
+#define AIM_CONN_SUBTYPE_OFT_BUDDYICON	0x0004
+#define AIM_CONN_SUBTYPE_OFT_VOICE	0x0005
 
 /*
  * Status values returned from aim_conn_new().  ORed together.
  */
-#define AIM_CONN_STATUS_READY       0x0001
-#define AIM_CONN_STATUS_INTERNALERR 0x0002
-#define AIM_CONN_STATUS_RESOLVERR   0x0040
-#define AIM_CONN_STATUS_CONNERR     0x0080
-#define AIM_CONN_STATUS_INPROGRESS  0x0100
-
-#define AIM_FRAMETYPE_FLAP 0x0000
-#define AIM_FRAMETYPE_OFT  0x0001
+#define AIM_CONN_STATUS_READY		0x0001
+#define AIM_CONN_STATUS_INTERNALERR	0x0002
+#define AIM_CONN_STATUS_RESOLVERR	0x0040
+#define AIM_CONN_STATUS_CONNERR		0x0080
+#define AIM_CONN_STATUS_INPROGRESS	0x0100
+
+#define AIM_FRAMETYPE_FLAP		0x0000
+#define AIM_FRAMETYPE_OFT		0x0001
 
 typedef struct aim_conn_s {
@@ -289,5 +346,5 @@
 		} flap;
 		struct {
-			fu8_t magic[4]; /* ODC2 OFT2 */
+			fu8_t magic[4]; /* ODC2 or OFT2 */
 			fu16_t hdrlen;
 			fu16_t type;
@@ -297,10 +354,10 @@
 	fu8_t handled;		/* 0 = new, !0 = been handled */
 	fu8_t nofree;		/* 0 = free data on purge, 1 = only unlink */
-	aim_conn_t *conn;  /* the connection it came in on... */
+	aim_conn_t *conn;	/* the connection it came in on... */
 	struct aim_frame_s *next;
 } aim_frame_t;
 
 typedef struct aim_msgcookie_s {
-	unsigned char cookie[8];
+	fu8_t cookie[8];
 	int type;
 	void *data;
@@ -308,4 +365,10 @@
 	struct aim_msgcookie_s *next;
 } aim_msgcookie_t;
+
+/* Values for sess->flags */
+#define AIM_SESS_FLAGS_SNACLOGIN         0x00000001
+#define AIM_SESS_FLAGS_XORLOGIN          0x00000002
+#define AIM_SESS_FLAGS_NONBLOCKCONNECT   0x00000004
+#define AIM_SESS_FLAGS_DONTTIMEOUTONICBM 0x00000008
 
 /*
@@ -331,16 +394,4 @@
 
 	/* ---- Internal Use Only ------------------------ */
-
-	/* Server-stored information (ssi) */
-	struct {
-		int received_data;
-		fu16_t revision;
-		struct aim_ssi_item *items;
-		time_t timestamp;
-		int waiting_for_ack;
-		aim_frame_t *holding_queue;
-	} ssi;
-
-	struct aim_emailinfo *emailinfo;
 
 	/* Connection information */
@@ -368,4 +419,17 @@
 	int (*tx_enqueue)(struct aim_session_s *, aim_frame_t *);
 
+	void *modlistv;
+
+	struct {
+		char server[128];
+		char username[128];
+		char password[128];
+	} socksproxy;
+
+	fu32_t flags; /* AIM_SESS_FLAGS_ */
+
+	int debug;
+	void (*debugcb)(struct aim_session_s *sess, int level, const char *format, va_list va); /* same as faim_debugging_callback_t */
+
 	/*
 	 * Outstanding snac handling 
@@ -376,144 +440,38 @@
 	aim_snacid_t snacid_next;
 
+	aim_msgcookie_t *msgcookies;
+	struct aim_icq_info *icq_info;
+	struct aim_oft_info *oft_info;
+	struct aim_authresp_info *authinfo;
+	struct aim_emailinfo *emailinfo;
+
+	/* Server-stored information (ssi) */
 	struct {
-		char server[128];
-		char username[128];
-		char password[128];
-	} socksproxy;
-
-	fu32_t flags; /* AIM_SESS_FLAGS_ */
-
-	int debug;
-	void (*debugcb)(struct aim_session_s *sess, int level, const char *format, va_list va); /* same as faim_debugging_callback_t */
-
-	aim_msgcookie_t *msgcookies;
-
-	void *modlistv;
+		int received_data;
+		fu16_t numitems;
+		struct aim_ssi_item *official;
+		struct aim_ssi_item *local;
+		struct aim_ssi_tmp *pending;
+		time_t timestamp;
+		int waiting_for_ack;
+	} ssi;
 } aim_session_t;
 
-/* Values for sess->flags */
-#define AIM_SESS_FLAGS_SNACLOGIN         0x00000001
-#define AIM_SESS_FLAGS_XORLOGIN          0x00000002
-#define AIM_SESS_FLAGS_NONBLOCKCONNECT   0x00000004
-#define AIM_SESS_FLAGS_DONTTIMEOUTONICBM 0x00000008
-
 /* Valid for calling aim_icq_setstatus() and for aim_userinfo_t->icqinfo.status */
-#define AIM_ICQ_STATE_NORMAL    0x00000000
-#define AIM_ICQ_STATE_AWAY      0x00000001
-#define AIM_ICQ_STATE_DND       0x00000002
-#define AIM_ICQ_STATE_OUT       0x00000004
-#define AIM_ICQ_STATE_BUSY      0x00000010
-#define AIM_ICQ_STATE_CHAT      0x00000020
-#define AIM_ICQ_STATE_INVISIBLE 0x00000100
-#define AIM_ICQ_STATE_WEBAWARE  0x00010000
-
-/*
- * AIM User Info, Standard Form.
- */
-typedef struct {
-	char sn[MAXSNLEN+1];
-	fu16_t warnlevel; /* evil percent * 10 (999 = 99.9%) */
-	fu16_t idletime; /* in seconds */
-	fu16_t flags;
-	fu32_t createtime; /* time_t */
-	fu32_t membersince; /* time_t */
-	fu32_t onlinesince; /* time_t */
-	fu32_t sessionlen;  /* in seconds */
-	fu32_t capabilities;
-	struct {
-		fu32_t status;
-		fu32_t ipaddr;
-		fu8_t crap[0x25]; /* until we figure it out... */
-	} icqinfo;
-	fu32_t present;
-} aim_userinfo_t;
-
-#define AIM_USERINFO_PRESENT_FLAGS        0x00000001
-#define AIM_USERINFO_PRESENT_MEMBERSINCE  0x00000002
-#define AIM_USERINFO_PRESENT_ONLINESINCE  0x00000004
-#define AIM_USERINFO_PRESENT_IDLE         0x00000008
-#define AIM_USERINFO_PRESENT_ICQEXTSTATUS 0x00000010
-#define AIM_USERINFO_PRESENT_ICQIPADDR    0x00000020
-#define AIM_USERINFO_PRESENT_ICQDATA      0x00000040
-#define AIM_USERINFO_PRESENT_CAPABILITIES 0x00000080
-#define AIM_USERINFO_PRESENT_SESSIONLEN   0x00000100
-#define AIM_USERINFO_PRESENT_CREATETIME   0x00000200
-
-faim_export const char *aim_userinfo_sn(aim_userinfo_t *ui);
-faim_export fu16_t aim_userinfo_flags(aim_userinfo_t *ui);
-faim_export fu16_t aim_userinfo_idle(aim_userinfo_t *ui);
-faim_export float aim_userinfo_warnlevel(aim_userinfo_t *ui);
-faim_export time_t aim_userinfo_createtime(aim_userinfo_t *ui);
-faim_export time_t aim_userinfo_membersince(aim_userinfo_t *ui);
-faim_export time_t aim_userinfo_onlinesince(aim_userinfo_t *ui);
-faim_export fu32_t aim_userinfo_sessionlen(aim_userinfo_t *ui);
-faim_export int aim_userinfo_hascap(aim_userinfo_t *ui, fu32_t cap);
-
-#define AIM_FLAG_UNCONFIRMED 	0x0001 /* "damned transients" */
-#define AIM_FLAG_ADMINISTRATOR	0x0002
-#define AIM_FLAG_AOL		0x0004
-#define AIM_FLAG_OSCAR_PAY	0x0008
-#define AIM_FLAG_FREE 		0x0010
-#define AIM_FLAG_AWAY		0x0020
-#define AIM_FLAG_ICQ		0x0040
-#define AIM_FLAG_WIRELESS	0x0080
-#define AIM_FLAG_UNKNOWN100	0x0100
-#define AIM_FLAG_UNKNOWN200	0x0200
-#define AIM_FLAG_ACTIVEBUDDY    0x0400
-#define AIM_FLAG_UNKNOWN800	0x0800
-#define AIM_FLAG_ABINTERNAL     0x1000
-
-#define AIM_FLAG_ALLUSERS	0x001f
-
-
-#if defined(FAIM_INTERNAL) || defined(FAIM_NEED_TLV)
-/*
- * TLV handling
- */
-
-/* Generic TLV structure. */
-typedef struct aim_tlv_s {
-	fu16_t type;
-	fu16_t length;
-	fu8_t *value;
-} aim_tlv_t;
-
-/* List of above. */
-typedef struct aim_tlvlist_s {
-	aim_tlv_t *tlv;
-	struct aim_tlvlist_s *next;
-} aim_tlvlist_t;
-
-/* TLV-handling functions */
-
-#if 0
-/* Very, very raw TLV handling. */
-faim_internal int aim_puttlv_8(fu8_t *buf, const fu16_t t, const fu8_t v);
-faim_internal int aim_puttlv_16(fu8_t *buf, const fu16_t t, const fu16_t v);
-faim_internal int aim_puttlv_32(fu8_t *buf, const fu16_t t, const fu32_t v);
-faim_internal int aim_puttlv_raw(fu8_t *buf, const fu16_t t, const fu16_t l, const fu8_t *v);
-#endif
-
-/* TLV list handling. */
-faim_internal aim_tlvlist_t *aim_readtlvchain(aim_bstream_t *bs);
-faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num);
-faim_internal void aim_freetlvchain(aim_tlvlist_t **list);
-faim_internal aim_tlv_t *aim_gettlv(aim_tlvlist_t *, fu16_t t, const int n);
-faim_internal char *aim_gettlv_str(aim_tlvlist_t *, const fu16_t t, const int n);
-faim_internal fu8_t aim_gettlv8(aim_tlvlist_t *list, const fu16_t type, const int num);
-faim_internal fu16_t aim_gettlv16(aim_tlvlist_t *list, const fu16_t t, const int n);
-faim_internal fu32_t aim_gettlv32(aim_tlvlist_t *list, const fu16_t t, const int n);
-faim_internal int aim_writetlvchain(aim_bstream_t *bs, aim_tlvlist_t **list);
-faim_internal int aim_addtlvtochain8(aim_tlvlist_t **list, const fu16_t t, const fu8_t v);
-faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v);
-faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t type, const fu32_t v);
-faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v);
-faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu32_t caps);
-faim_internal int aim_addtlvtochain_noval(aim_tlvlist_t **list, const fu16_t type);
-faim_internal int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, fu16_t type, aim_userinfo_t *ui);
-faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl);
-faim_internal int aim_counttlvchain(aim_tlvlist_t **list);
-faim_internal int aim_sizetlvchain(aim_tlvlist_t **list);
-#endif /* FAIM_INTERNAL */
+#define AIM_ICQ_STATE_NORMAL		0x00000000
+#define AIM_ICQ_STATE_AWAY		0x00000001
+#define AIM_ICQ_STATE_DND		0x00000002
+#define AIM_ICQ_STATE_OUT		0x00000004
+#define AIM_ICQ_STATE_BUSY		0x00000010
+#define AIM_ICQ_STATE_CHAT		0x00000020
+#define AIM_ICQ_STATE_INVISIBLE		0x00000100
+#define AIM_ICQ_STATE_WEBAWARE		0x00010000
+#define AIM_ICQ_STATE_HIDEIP		0x00020000
+#define AIM_ICQ_STATE_BIRTHDAY		0x00080000
+#define AIM_ICQ_STATE_DIRECTDISABLED	0x00100000
+#define AIM_ICQ_STATE_ICQHOMEPAGE	0x00200000
+#define AIM_ICQ_STATE_DIRECTREQUIREAUTH	0x10000000
+#define AIM_ICQ_STATE_DIRECTCONTACTLIST	0x20000000
+
 
 /*
@@ -542,4 +500,6 @@
 typedef int (*aim_rxcallback_t)(aim_session_t *, aim_frame_t *, ...);
 
+
+/* auth.c */
 struct aim_clientrelease {
 	char *name;
@@ -556,4 +516,5 @@
 	char *email;
 	char *bosip;
+	fu16_t cookielen;
 	fu8_t *cookie;
 	char *chpassurl;
@@ -566,4 +527,5 @@
 	fu16_t group;
 	const char *ip;
+	fu16_t cookielen;
 	const fu8_t *cookie;
 	struct { /* group == AIM_CONN_TYPE_CHAT */
@@ -578,6 +540,7 @@
 faim_export int aim_request_login(aim_session_t *sess, aim_conn_t *conn, const char *sn);
 faim_export int aim_send_login(aim_session_t *, aim_conn_t *, const char *, const char *, struct client_info_s *, const char *key);
-faim_export int aim_encode_password_md5(const char *password, const char *key, unsigned char *digest);
+faim_export int aim_encode_password_md5(const char *password, const char *key, fu8_t *digest);
 faim_export void aim_purge_rxqueue(aim_session_t *);
+faim_export void aim_cleansnacs(aim_session_t *, int maxage);
 
 #define AIM_TX_QUEUED    0 /* default */
@@ -591,5 +554,5 @@
 faim_export int aim_conn_setlatency(aim_conn_t *conn, int newval);
 
-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);
+faim_export int aim_conn_addhandler(aim_session_t *, aim_conn_t *conn, fu16_t family, fu16_t type, aim_rxcallback_t newhandler, fu16_t flags);
 faim_export int aim_clearhandlers(aim_conn_t *conn);
 
@@ -600,4 +563,5 @@
 faim_export int aim_conngetmaxfd(aim_session_t *);
 faim_export aim_conn_t *aim_select(aim_session_t *, struct timeval *, int *);
+faim_export int aim_conn_in_sess(aim_session_t *sess, aim_conn_t *conn);
 faim_export int aim_conn_isready(aim_conn_t *);
 faim_export int aim_conn_setstatus(aim_conn_t *, int);
@@ -607,5 +571,5 @@
 typedef void (*faim_debugging_callback_t)(aim_session_t *sess, int level, const char *format, va_list va);
 faim_export int aim_setdebuggingcb(aim_session_t *sess, faim_debugging_callback_t);
-faim_export void aim_session_init(aim_session_t *, unsigned long flags, int debuglevel);
+faim_export void aim_session_init(aim_session_t *, fu32_t flags, int debuglevel);
 faim_export void aim_session_kill(aim_session_t *);
 faim_export void aim_setupproxy(aim_session_t *sess, const char *server, const char *username, const char *password);
@@ -614,4 +578,11 @@
 faim_export aim_conn_t *aim_getconn_fd(aim_session_t *, int fd);
 
+
+
+/* service.c */
+faim_export int aim_srv_setavailmsg(aim_session_t *sess, char *msg);
+
+
+
 /* misc.c */
 
@@ -627,5 +598,4 @@
 
 faim_export int aim_sendpauseack(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_send_warning(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu32_t flags);
 faim_export int aim_nop(aim_session_t *, aim_conn_t *);
 faim_export int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn);
@@ -633,5 +603,5 @@
 faim_export int aim_bos_changevisibility(aim_session_t *, aim_conn_t *, int, const char *);
 faim_export int aim_bos_setbuddylist(aim_session_t *, aim_conn_t *, const char *);
-faim_export int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile, const char *awaymsg, fu32_t caps);
+faim_export int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile_encoding, const char *profile, const int profile_len, const char *awaymsg_encoding, const char *awaymsg, const int awaymsg_len, fu32_t caps);
 faim_export int aim_bos_setgroupperm(aim_session_t *, aim_conn_t *, fu32_t mask);
 faim_export int aim_bos_setprivacyflags(aim_session_t *, aim_conn_t *, fu32_t);
@@ -643,7 +613,5 @@
 faim_export int aim_setdirectoryinfo(aim_session_t *sess, aim_conn_t *conn, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, fu16_t privacy);
 faim_export int aim_setuserinterests(aim_session_t *sess, aim_conn_t *conn, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, fu16_t privacy);
-faim_export int aim_setextstatus(aim_session_t *sess, aim_conn_t *conn, fu32_t status);
-
-faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *);
+faim_export int aim_setextstatus(aim_session_t *sess, fu32_t status);
 
 #define AIM_CLIENTTYPE_UNKNOWN  0x0000
@@ -652,5 +620,5 @@
 #define AIM_CLIENTTYPE_WINAIM41 0x0003
 #define AIM_CLIENTTYPE_AOL_TOC  0x0004
-faim_export unsigned short aim_fingerprintclient(unsigned char *msghdr, int len);
+faim_export fu16_t aim_im_fingerprint(const fu8_t *msghdr, int len);
 
 #define AIM_RATE_CODE_CHANGE     0x0001
@@ -660,50 +628,50 @@
 faim_export int aim_ads_requestads(aim_session_t *sess, aim_conn_t *conn);
 
+
+
 /* im.c */
-
-struct aim_fileheader_t {
-#if 0
-	char  magic[4];		/* 0 */
-	short hdrlen; 		/* 4 */
-	short hdrtype;		/* 6 */
-#endif
-	char  bcookie[8];       /* 8 */
-	short encrypt;          /* 16 */
-	short compress;         /* 18 */
-	short totfiles;         /* 20 */
-	short filesleft;        /* 22 */
-	short totparts;         /* 24 */
-	short partsleft;        /* 26 */
-	long  totsize;          /* 28 */
-	long  size;             /* 32 */
-	long  modtime;          /* 36 */
-	long  checksum;         /* 40 */
-	long  rfrcsum;          /* 44 */
-	long  rfsize;           /* 48 */
-	long  cretime;          /* 52 */
-	long  rfcsum;           /* 56 */
-	long  nrecvd;           /* 60 */
-	long  recvcsum;         /* 64 */
-	char  idstring[32];     /* 68 */
-	char  flags;            /* 100 */
-	char  lnameoffset;      /* 101 */
-	char  lsizeoffset;      /* 102 */
-	char  dummy[69];        /* 103 */
-	char  macfileinfo[16];  /* 172 */
-	short nencode;          /* 188 */
-	short nlanguage;        /* 190 */
-	char  name[64];         /* 192 */
-				/* 256 */
-};
-
-#define AIM_OFT_SUBTYPE_SEND_FILE 0x0001
-#define AIM_OFT_SUBTYPE_SEND_DIR 0x0002
-#define AIM_OFT_SUBTYPE_GET_FILE 0x0011
-#define AIM_OPT_SUBTYPE_GET_LIST 0x0012
+#define AIM_OFT_SUBTYPE_SEND_FILE	0x0001
+#define AIM_OFT_SUBTYPE_SEND_DIR	0x0002
+#define AIM_OFT_SUBTYPE_GET_FILE	0x0011
+#define AIM_OPT_SUBTYPE_GET_LIST	0x0012
+
+#define AIM_TRANSFER_DENY_NOTSUPPORTED	0x0000
+#define AIM_TRANSFER_DENY_DECLINE	0x0001
+#define AIM_TRANSFER_DENY_NOTACCEPTING	0x0002
+
+#define AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED	0x00000001
+#define AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED	0x00000002
+
+/* This is what the server will give you if you don't set them yourself. */
+#define AIM_IMPARAM_DEFAULTS { \
+	0, \
+	AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED, \
+	512, /* !! Note how small this is. */ \
+	(99.9)*10, (99.9)*10, \
+	1000 /* !! And how large this is. */ \
+}
+
+/* This is what most AIM versions use. */
+#define AIM_IMPARAM_REASONABLE { \
+	0, \
+	AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED, \
+	8000, \
+	(99.9)*10, (99.9)*10, \
+	0 \
+}
+
+struct aim_icbmparameters {
+	fu16_t maxchan;
+	fu32_t flags; /* AIM_IMPARAM_FLAG_ */
+	fu16_t maxmsglen; /* message size that you will accept */
+	fu16_t maxsenderwarn; /* this and below are *10 (999=99.9%) */
+	fu16_t maxrecverwarn;
+	fu32_t minmsginterval; /* in milliseconds? */
+};
 
 struct aim_chat_roominfo {
-	unsigned short exchange;
+	fu16_t exchange;
 	char *name;
-	unsigned short instance;
+	fu16_t instance;
 };
 
@@ -717,5 +685,5 @@
 #define AIM_IMFLAGS_CUSTOMFEATURES 	0x0080 /* features field present */
 #define AIM_IMFLAGS_EXTDATA		0x0100
-#define AIM_IMFLAGS_CUSTOMCHARSET	0x0200 /* charset fields set */
+#define AIM_IMFLAGS_X			0x0200
 #define AIM_IMFLAGS_MULTIPART		0x0400 /* ->mpmsg section valid */
 #define AIM_IMFLAGS_OFFLINE		0x0800 /* send to offline user */
@@ -829,17 +797,17 @@
 
 /* Valid values for channel 2 args->status */
-#define AIM_RENDEZVOUS_PROPOSE 0x0000
-#define AIM_RENDEZVOUS_CANCEL  0x0001
-#define AIM_RENDEZVOUS_ACCEPT  0x0002
+#define AIM_RENDEZVOUS_PROPOSE	0x0000
+#define AIM_RENDEZVOUS_CANCEL	0x0001
+#define AIM_RENDEZVOUS_ACCEPT	0x0002
 
 struct aim_incomingim_ch2_args {
+	fu16_t status;
 	fu8_t cookie[8];
-	fu16_t reqclass;
-	fu16_t status;
-	fu16_t errorcode;
+	int reqclass;
+	const char *proxyip;
 	const char *clientip;
-	const char *clientip2;
 	const char *verifiedip;
 	fu16_t port;
+	fu16_t errorcode;
 	const char *msg; /* invite message or file description */
 	const char *encoding;
@@ -871,58 +839,187 @@
 
 /* Valid values for channel 4 args->type */
-#define AIM_ICQMSG_AUTHREQUEST 0x0006
-#define AIM_ICQMSG_AUTHDENIED 0x0007
-#define AIM_ICQMSG_AUTHGRANTED 0x0008
+#define AIM_ICQMSG_AUTHREQUEST	0x0006
+#define AIM_ICQMSG_AUTHDENIED	0x0007
+#define AIM_ICQMSG_AUTHGRANTED	0x0008
 
 struct aim_incomingim_ch4_args {
 	fu32_t uin; /* Of the sender of the ICBM */
-	fu16_t type;
+	fu8_t type;
+	fu8_t flags;
 	char *msg; /* Reason for auth request, deny, or accept */
-};
-
-faim_export int aim_send_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args);
-faim_export int aim_send_im_ext(aim_session_t *sess, struct aim_sendimext_args *args);
-faim_export int aim_send_im(aim_session_t *, const char *destsn, unsigned short flags, const char *msg);
-faim_export int aim_send_icon(aim_session_t *sess, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu16_t iconsum);
-faim_export fu16_t aim_iconsum(const fu8_t *buf, int buflen);
-faim_export int aim_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing);
-faim_export int aim_send_im_direct(aim_session_t *, aim_conn_t *, const char *msg, int len, int encoding);
-faim_export const char *aim_directim_getsn(aim_conn_t *conn);
-faim_export aim_conn_t *aim_directim_initiate(aim_session_t *, const char *destsn);
-faim_export aim_conn_t *aim_directim_connect(aim_session_t *, const char *sn, const char *addr, const fu8_t *cookie);
-
-faim_export int aim_send_im_ch2_geticqmessage(aim_session_t *sess, const char *sn, int type);
-faim_export aim_conn_t *aim_sendfile_initiate(aim_session_t *, const char *destsn, const char *filename, fu16_t numfiles, fu32_t totsize, char *cookret);
-faim_export int aim_send_im_ch4(aim_session_t *sess, char *sn, fu16_t type, fu8_t *message);
-
-faim_export int aim_mtn_send(aim_session_t *sess, fu16_t type1, char *sn, fu16_t type2);
-
-faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn);
-faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size);
-faim_export int aim_oft_sendfile_request(aim_session_t *sess, aim_conn_t *conn,
-		const char *name, int filesdone, int numfiles, int size,
-		int totsize);
-faim_export int aim_oft_getfile_ack(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_oft_end(aim_session_t *sess, aim_conn_t *conn);
+	int msglen;
+};
+
+/* SNAC sending functions */
+/* 0x0002 */ faim_export int aim_im_setparams(aim_session_t *sess, struct aim_icbmparameters *params);
+/* 0x0004 */ faim_export int aim_im_reqparams(aim_session_t *sess);
+/* 0x0006 */ faim_export int aim_im_sendch1_ext(aim_session_t *sess, struct aim_sendimext_args *args);
+/* 0x0006 */ faim_export int aim_im_sendch1(aim_session_t *, const char *destsn, fu16_t flags, const char *msg);
+/* 0x0006 */ faim_export int aim_im_sendch2_icon(aim_session_t *sess, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu16_t iconsum);
+/* 0x0006 */ faim_export int aim_im_sendch2_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args);
+/* 0x0006 */ faim_export int aim_im_sendch2_odcrequest(aim_session_t *sess, fu8_t *cookie, const char *sn, const fu8_t *ip, fu16_t port);
+/* 0x0006 */ faim_export int aim_im_sendch2_sendfile_ask(aim_session_t *sess, struct aim_oft_info *oft_info);
+/* 0x0006 */ faim_export int aim_im_sendch2_sendfile_accept(aim_session_t *sess, struct aim_oft_info *info);
+/* 0x0006 */ faim_export int aim_im_sendch2_sendfile_cancel(aim_session_t *sess, struct aim_oft_info *oft_info);
+/* 0x0006 */ faim_export int aim_im_sendch2_geticqaway(aim_session_t *sess, const char *sn, int type);
+/* 0x0006 */ faim_export int aim_im_sendch4(aim_session_t *sess, char *sn, fu16_t type, fu8_t *message);
+/* 0x0008 */ faim_export int aim_im_warn(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu32_t flags);
+/* 0x000b */ faim_export int aim_im_denytransfer(aim_session_t *sess, const char *sender, const char *cookie, fu16_t code);
+/* 0x0014 */ faim_export int aim_im_sendmtn(aim_session_t *sess, fu16_t type1, const char *sn, fu16_t type2);
+
+
+
+/* ft.c */
+struct aim_fileheader_t {
+#if 0
+	char magic[4];		/* 0 */
+	fu16_t hdrlen;		/* 4 */
+	fu16_t hdrtype;		/* 6 */
+#endif
+	char bcookie[8];	/* 8 */
+	fu16_t encrypt;		/* 16 */
+	fu16_t compress;	/* 18 */
+	fu16_t totfiles;	/* 20 */
+	fu16_t filesleft;	/* 22 */
+	fu16_t totparts;	/* 24 */
+	fu16_t partsleft;	/* 26 */
+	fu32_t totsize;		/* 28 */
+	fu32_t size;		/* 32 */
+	fu32_t modtime;		/* 36 */
+	fu32_t checksum;	/* 40 */
+	fu32_t rfrcsum;		/* 44 */
+	fu32_t rfsize;		/* 48 */
+	fu32_t cretime;		/* 52 */
+	fu32_t rfcsum;		/* 56 */
+	fu32_t nrecvd;		/* 60 */
+	fu32_t recvcsum;	/* 64 */
+	fu8_t idstring[32];	/* 68 */
+	fu8_t flags;		/* 100 */
+	fu8_t lnameoffset;	/* 101 */
+	fu8_t lsizeoffset;	/* 102 */
+	char dummy[69];		/* 103 */
+	char macfileinfo[16];	/* 172 */
+	fu16_t nencode;		/* 188 */
+	fu16_t nlanguage;	/* 190 */
+	char name[64];		/* 192 */
+				/* 256 */
+};
+
+struct aim_oft_info {
+	char cookie[8];
+	char *sn;
+	char *proxyip;
+	char *clientip;
+	char *verifiedip;
+	fu16_t port;
+	aim_conn_t *conn;
+	aim_session_t *sess;
+	struct aim_fileheader_t fh;
+	struct aim_oft_info *next;
+};
+
+faim_export fu32_t aim_oft_checksum_chunk(const fu8_t *buffer, int bufferlen, fu32_t prevcheck);
+faim_export fu32_t aim_oft_checksum_file(char *filename);
+faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur);
+faim_export int aim_odc_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing);
+faim_export int aim_odc_send_im(aim_session_t *sess, aim_conn_t *conn, const char *msg, int len, int encoding, int isawaymsg);
+faim_export const char *aim_odc_getsn(aim_conn_t *conn);
+faim_export aim_conn_t *aim_odc_getconn(aim_session_t *sess, const char *sn);
+faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn);
+faim_export aim_conn_t *aim_odc_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie);
+
+faim_export struct aim_oft_info *aim_oft_createinfo(aim_session_t *sess, const fu8_t *cookie, const char *sn, const char *ip, fu16_t port, fu32_t size, fu32_t modtime, char *filename);
+faim_export int aim_oft_destroyinfo(struct aim_oft_info *oft_info);
+faim_export int aim_sendfile_listen(aim_session_t *sess, struct aim_oft_info *oft_info);
+faim_export int aim_oft_sendheader(aim_session_t *sess, fu16_t type, struct aim_oft_info *oft_info);
+
+
 
 /* info.c */
-#define AIM_CAPS_BUDDYICON      0x00000001
-#define AIM_CAPS_VOICE          0x00000002
-#define AIM_CAPS_IMIMAGE        0x00000004
-#define AIM_CAPS_CHAT           0x00000008
-#define AIM_CAPS_GETFILE        0x00000010
-#define AIM_CAPS_SENDFILE       0x00000020
-#define AIM_CAPS_GAMES          0x00000040
-#define AIM_CAPS_SAVESTOCKS     0x00000080
-#define AIM_CAPS_SENDBUDDYLIST  0x00000100
-#define AIM_CAPS_GAMES2         0x00000200
-#define AIM_CAPS_ICQ            0x00000400
-#define AIM_CAPS_APINFO         0x00000800
+/*
+ * AIM User Info, Standard Form.
+ */
+#define AIM_FLAG_UNCONFIRMED 	0x0001 /* "damned transients" */
+#define AIM_FLAG_ADMINISTRATOR	0x0002
+#define AIM_FLAG_AOL		0x0004
+#define AIM_FLAG_OSCAR_PAY	0x0008
+#define AIM_FLAG_FREE 		0x0010
+#define AIM_FLAG_AWAY		0x0020
+#define AIM_FLAG_ICQ		0x0040
+#define AIM_FLAG_WIRELESS	0x0080
+#define AIM_FLAG_UNKNOWN100	0x0100
+#define AIM_FLAG_UNKNOWN200	0x0200
+#define AIM_FLAG_ACTIVEBUDDY    0x0400
+#define AIM_FLAG_UNKNOWN800	0x0800
+#define AIM_FLAG_ABINTERNAL     0x1000
+#define AIM_FLAG_ALLUSERS	0x001f
+
+#define AIM_USERINFO_PRESENT_FLAGS        0x00000001
+#define AIM_USERINFO_PRESENT_MEMBERSINCE  0x00000002
+#define AIM_USERINFO_PRESENT_ONLINESINCE  0x00000004
+#define AIM_USERINFO_PRESENT_IDLE         0x00000008
+#define AIM_USERINFO_PRESENT_ICQEXTSTATUS 0x00000010
+#define AIM_USERINFO_PRESENT_ICQIPADDR    0x00000020
+#define AIM_USERINFO_PRESENT_ICQDATA      0x00000040
+#define AIM_USERINFO_PRESENT_CAPABILITIES 0x00000080
+#define AIM_USERINFO_PRESENT_SESSIONLEN   0x00000100
+#define AIM_USERINFO_PRESENT_CREATETIME   0x00000200
+
+typedef struct {
+	char sn[MAXSNLEN+1];
+	fu16_t warnlevel; /* evil percent * 10 (999 = 99.9%) */
+	fu16_t idletime; /* in seconds */
+	fu16_t flags;
+	fu32_t createtime; /* time_t */
+	fu32_t membersince; /* time_t */
+	fu32_t onlinesince; /* time_t */
+	fu32_t sessionlen;  /* in seconds */
+	fu32_t capabilities;
+	struct {
+		fu32_t status;
+		fu32_t ipaddr;
+		fu8_t crap[0x25]; /* until we figure it out... */
+	} icqinfo;
+	fu32_t present;
+	fu16_t iconcsumlen;
+	fu8_t *iconcsum;
+	char *availmsg_encoding;
+	char *availmsg;
+	int availmsg_len;
+} aim_userinfo_t;
+
+faim_export const char *aim_userinfo_sn(aim_userinfo_t *ui);
+faim_export fu16_t aim_userinfo_flags(aim_userinfo_t *ui);
+faim_export fu16_t aim_userinfo_idle(aim_userinfo_t *ui);
+faim_export float aim_userinfo_warnlevel(aim_userinfo_t *ui);
+faim_export time_t aim_userinfo_createtime(aim_userinfo_t *ui);
+faim_export time_t aim_userinfo_membersince(aim_userinfo_t *ui);
+faim_export time_t aim_userinfo_onlinesince(aim_userinfo_t *ui);
+faim_export fu32_t aim_userinfo_sessionlen(aim_userinfo_t *ui);
+faim_export int aim_userinfo_hascap(aim_userinfo_t *ui, fu32_t cap);
+
+#define AIM_CAPS_BUDDYICON	0x00000001
+#define AIM_CAPS_VOICE		0x00000002
+#define AIM_CAPS_DIRECTIM	0x00000004
+#define AIM_CAPS_CHAT		0x00000008
+#define AIM_CAPS_GETFILE	0x00000010
+#define AIM_CAPS_SENDFILE	0x00000020
+#define AIM_CAPS_GAMES		0x00000040
+#define AIM_CAPS_SAVESTOCKS	0x00000080
+#define AIM_CAPS_SENDBUDDYLIST	0x00000100
+#define AIM_CAPS_GAMES2		0x00000200
+#define AIM_CAPS_ICQ		0x00000400
+#define AIM_CAPS_APINFO		0x00000800
 #define AIM_CAPS_ICQRTF		0x00001000
 #define AIM_CAPS_EMPTY		0x00002000
-#define AIM_CAPS_ICQSERVERRELAY 0x00004000
-#define AIM_CAPS_ICQUNKNOWN     0x00008000
-#define AIM_CAPS_TRILLIANCRYPT  0x00010000
-#define AIM_CAPS_LAST           0x00020000
+#define AIM_CAPS_ICQSERVERRELAY	0x00004000
+#define AIM_CAPS_ICQUTF8OLD	0x00008000
+#define AIM_CAPS_TRILLIANCRYPT	0x00010000
+#define AIM_CAPS_ICQUTF8	0x00020000
+#define AIM_CAPS_INTEROPERATE	0x00040000
+#define AIM_CAPS_ICHAT		0x00080000
+#define AIM_CAPS_HIPTOP		0x00100000
+#define AIM_CAPS_SECUREIM	0x00200000
+#define AIM_CAPS_LAST		0x00400000
 
 faim_export int aim_0002_000b(aim_session_t *sess, aim_conn_t *conn, const char *sn);
@@ -931,5 +1028,5 @@
 #define AIM_SENDMEMBLOCK_FLAG_ISHASH     1
 
-faim_export int aim_sendmemblock(aim_session_t *sess, aim_conn_t *conn, unsigned long offset, unsigned long len, const unsigned char *buf, unsigned char flag);
+faim_export int aim_sendmemblock(aim_session_t *sess, aim_conn_t *conn, fu32_t offset, fu32_t len, const fu8_t *buf, fu8_t flag);
 
 #define AIM_GETINFO_GENERALINFO 0x00001
@@ -961,73 +1058,58 @@
 #define AIM_COOKIETYPE_OFTICON  0x15
 
-faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur);
-
-#define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
-#define AIM_TRANSFER_DENY_DECLINE 0x0001
-#define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
-faim_export int aim_denytransfer(aim_session_t *sess, const char *sender, const char *cookie, unsigned short code);
-faim_export aim_conn_t *aim_accepttransfer(aim_session_t *sess, aim_conn_t *conn, const char *sn, const fu8_t *cookie, const fu8_t *ip, fu16_t port, fu16_t rendid, ...);
-faim_export int aim_canceltransfer(aim_session_t *sess, aim_conn_t *conn,
-		                const char *cookie, const char *sn, int rendid);
-faim_export fu32_t aim_update_checksum(aim_session_t *sess, aim_conn_t *conn,
-		                const unsigned char *buffer, int bufferlen);
-
-faim_export int aim_getinfo(aim_session_t *, aim_conn_t *, const char *, unsigned short);
-faim_export int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info);
-faim_export int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn);
-
-#define AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED	0x00000001
-#define AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED	0x00000002
-
-/* This is what the server will give you if you don't set them yourself. */
-#define AIM_IMPARAM_DEFAULTS { \
-	0, \
-	AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED, \
-	512, /* !! Note how small this is. */ \
-	(99.9)*10, (99.9)*10, \
-	1000 /* !! And how large this is. */ \
-}
-
-/* This is what most AIM versions use. */
-#define AIM_IMPARAM_REASONABLE { \
-	0, \
-	AIM_IMPARAM_FLAG_CHANMSGS_ALLOWED | AIM_IMPARAM_FLAG_MISSEDCALLS_ENABLED, \
-	8000, \
-	(99.9)*10, (99.9)*10, \
-	0 \
-}
-
-
-struct aim_icbmparameters {
-	fu16_t maxchan;
-	fu32_t flags; /* AIM_IMPARAM_FLAG_ */
-	fu16_t maxmsglen; /* message size that you will accept */
-	fu16_t maxsenderwarn; /* this and below are *10 (999=99.9%) */
-	fu16_t maxrecverwarn;
-	fu32_t minmsginterval; /* in milliseconds? */
-};
-
-faim_export int aim_reqicbmparams(aim_session_t *sess);
-faim_export int aim_seticbmparam(aim_session_t *sess, struct aim_icbmparameters *params);
-
-
-/* auth.c */
-faim_export int aim_sendcookie(aim_session_t *, aim_conn_t *, const fu8_t *);
-
-faim_export int aim_admin_changepasswd(aim_session_t *, aim_conn_t *, const char *newpw, const char *curpw);
-faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info);
-faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail);
-faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick);
-
-/* buddylist.c */
-faim_export int aim_add_buddy(aim_session_t *, aim_conn_t *, const char *);
-faim_export int aim_remove_buddy(aim_session_t *, aim_conn_t *, const char *);
-
-/* search.c */
-faim_export int aim_usersearch_address(aim_session_t *, aim_conn_t *, const char *);
-
-/* newsearch.c */
-struct aim_usersearch {
+/* 0x0005 */ faim_export int aim_getinfo(aim_session_t *, aim_conn_t *, const char *, fu16_t);
+
+
+
+/* 0x0003 - buddylist.c */
+/* 0x0004 */ faim_export int aim_add_buddy(aim_session_t *, aim_conn_t *, const char *);
+/* 0x0005 */ faim_export int aim_remove_buddy(aim_session_t *, aim_conn_t *, const char *);
+/* 0x000b */ faim_export int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info);
+/* 0x000c */ faim_export int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn);
+
+
+
+/* 0x000a - search.c */
+faim_export int aim_search_address(aim_session_t *, aim_conn_t *, const char *);
+
+
+
+/* 0x000d - chatnav.c */
+/* 0x000e - chat.c */
+/* These apply to exchanges as well. */
+#define AIM_CHATROOM_FLAG_EVILABLE 0x0001
+#define AIM_CHATROOM_FLAG_NAV_ONLY 0x0002
+#define AIM_CHATROOM_FLAG_INSTANCING_ALLOWED 0x0004
+#define AIM_CHATROOM_FLAG_OCCUPANT_PEEK_ALLOWED 0x0008
+
+struct aim_chat_exchangeinfo {
+	fu16_t number;
+	fu16_t flags;
+	char *name;
+	char *charset1;
+	char *lang1;
+	char *charset2;
+	char *lang2;
+};
+
+#define AIM_CHATFLAGS_NOREFLECT 0x0001
+#define AIM_CHATFLAGS_AWAY      0x0002
+faim_export int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, fu16_t flags, const char *msg, int msglen);
+faim_export int aim_chat_join(aim_session_t *sess, aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance);
+faim_export int aim_chat_attachname(aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance);
+faim_export char *aim_chat_getname(aim_conn_t *conn);
+faim_export aim_conn_t *aim_chat_getconn(aim_session_t *, const char *name);
+
+faim_export int aim_chatnav_reqrights(aim_session_t *sess, aim_conn_t *conn);
+
+faim_export int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, fu16_t exchange, const char *roomname, fu16_t instance);
+
+faim_export int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, fu16_t exchange);
+faim_export int aim_chat_leaveroom(aim_session_t *sess, const char *name);
+
+
+
+/* 0x000f - odir.c */
+struct aim_odir {
 	char *first;
 	char *last;
@@ -1044,50 +1126,34 @@
 	char *region;
 	char *address;
-	struct aim_usersearch *next;
-};
-
-faim_export int aim_usersearch_email(aim_session_t *, const char *, const char *);
-faim_export int aim_usersearch_name(aim_session_t *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
-faim_export int aim_usersearch_interest(aim_session_t *, const char *, const char *);
-
-
-/* These apply to exchanges as well. */
-#define AIM_CHATROOM_FLAG_EVILABLE 0x0001
-#define AIM_CHATROOM_FLAG_NAV_ONLY 0x0002
-#define AIM_CHATROOM_FLAG_INSTANCING_ALLOWED 0x0004
-#define AIM_CHATROOM_FLAG_OCCUPANT_PEEK_ALLOWED 0x0008
-
-struct aim_chat_exchangeinfo {
-	fu16_t number;
-	fu16_t flags;
-	char *name;
-	char *charset1;
-	char *lang1;
-	char *charset2;
-	char *lang2;
-};
-
-#define AIM_CHATFLAGS_NOREFLECT 0x0001
-#define AIM_CHATFLAGS_AWAY      0x0002
-faim_export int aim_chat_send_im(aim_session_t *sess, aim_conn_t *conn, fu16_t flags, const char *msg, int msglen);
-faim_export int aim_chat_join(aim_session_t *sess, aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance);
-faim_export int aim_chat_attachname(aim_conn_t *conn, fu16_t exchange, const char *roomname, fu16_t instance);
-faim_export char *aim_chat_getname(aim_conn_t *conn);
-faim_export aim_conn_t *aim_chat_getconn(aim_session_t *, const char *name);
-
-faim_export int aim_chatnav_reqrights(aim_session_t *sess, aim_conn_t *conn);
-
-faim_export int aim_chat_invite(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *msg, fu16_t exchange, const char *roomname, fu16_t instance);
-
-faim_export int aim_chatnav_createroom(aim_session_t *sess, aim_conn_t *conn, const char *name, fu16_t exchange);
-faim_export int aim_chat_leaveroom(aim_session_t *sess, const char *name);
-
-
-#define AIM_SSI_TYPE_BUDDY         0x0000
-#define AIM_SSI_TYPE_GROUP         0x0001
-#define AIM_SSI_TYPE_PERMIT        0x0002
-#define AIM_SSI_TYPE_DENY          0x0003
-#define AIM_SSI_TYPE_PDINFO        0x0004
-#define AIM_SSI_TYPE_PRESENCEPREFS 0x0005
+	struct aim_odir *next;
+};
+
+faim_export int aim_odir_email(aim_session_t *, const char *, const char *);
+faim_export int aim_odir_name(aim_session_t *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
+faim_export int aim_odir_interest(aim_session_t *, const char *, const char *);
+
+
+
+/* 0x0010 - icon.c */
+faim_export int aim_bart_upload(aim_session_t *sess, const fu8_t *icon, fu16_t iconlen);
+faim_export int aim_bart_request(aim_session_t *sess, const char *sn, const fu8_t *iconstr, fu16_t iconstrlen);
+
+
+
+/* 0x0013 - ssi.c */
+#define AIM_SSI_TYPE_BUDDY		0x0000
+#define AIM_SSI_TYPE_GROUP		0x0001
+#define AIM_SSI_TYPE_PERMIT		0x0002
+#define AIM_SSI_TYPE_DENY		0x0003
+#define AIM_SSI_TYPE_PDINFO		0x0004
+#define AIM_SSI_TYPE_PRESENCEPREFS	0x0005
+#define AIM_SSI_TYPE_ICONINFO		0x0014
+
+#define AIM_SSI_ACK_SUCCESS		0x0000
+#define AIM_SSI_ACK_ITEMNOTFOUND	0x0002
+#define AIM_SSI_ACK_IDNUMINUSE		0x000a
+#define AIM_SSI_ACK_ATMAX		0x000c
+#define AIM_SSI_ACK_INVALIDNAME		0x000d
+#define AIM_SSI_ACK_AUTHREQUIRED	0x000e
 
 struct aim_ssi_item {
@@ -1096,36 +1162,67 @@
 	fu16_t bid;
 	fu16_t type;
-	void *data;
+	struct aim_tlvlist_s *data;
 	struct aim_ssi_item *next;
 };
 
+struct aim_ssi_tmp {
+	fu16_t action;
+	fu16_t ack;
+	char *name;
+	struct aim_ssi_item *item;
+	struct aim_ssi_tmp *next;
+};
+
 /* These build the actual SNACs and queue them to be sent */
-faim_export int aim_ssi_reqrights(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_reqdata(aim_session_t *sess, aim_conn_t *conn, time_t localstamp, fu16_t localrev);
-faim_export int aim_ssi_enable(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_addmoddel(aim_session_t *sess, aim_conn_t *conn, struct aim_ssi_item **items, unsigned int num, fu16_t subtype);
-faim_export int aim_ssi_modbegin(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_modend(aim_session_t *sess, aim_conn_t *conn);
-
-/* These handle the local variables */
+/* 0x0002 */ faim_export int aim_ssi_reqrights(aim_session_t *sess);
+/* 0x0004 */ faim_export int aim_ssi_reqdata(aim_session_t *sess);
+/* 0x0005 */ faim_export int aim_ssi_reqifchanged(aim_session_t *sess, time_t localstamp, fu16_t localrev);
+/* 0x0007 */ faim_export int aim_ssi_enable(aim_session_t *sess);
+/* 0x0008 */ faim_export int aim_ssi_addmoddel(aim_session_t *sess);
+/* 0x0011 */ faim_export int aim_ssi_modbegin(aim_session_t *sess);
+/* 0x0012 */ faim_export int aim_ssi_modend(aim_session_t *sess);
+/* 0x0014 */ faim_export int aim_ssi_sendauth(aim_session_t *sess, char *sn, char *msg);
+/* 0x0018 */ faim_export int aim_ssi_sendauthrequest(aim_session_t *sess, char *sn, char *msg);
+/* 0x001a */ faim_export int aim_ssi_sendauthreply(aim_session_t *sess, char *sn, fu8_t reply, char *msg);
+
+/* Client functions for retrieving SSI data */
 faim_export struct aim_ssi_item *aim_ssi_itemlist_find(struct aim_ssi_item *list, fu16_t gid, fu16_t bid);
 faim_export struct aim_ssi_item *aim_ssi_itemlist_finditem(struct aim_ssi_item *list, const char *gn, const char *sn, fu16_t type);
-faim_export struct aim_ssi_item *aim_ssi_itemlist_findparent(struct aim_ssi_item *list, char *sn);
+faim_export struct aim_ssi_item *aim_ssi_itemlist_exists(struct aim_ssi_item *list, const char *sn);
+faim_export char *aim_ssi_itemlist_findparentname(struct aim_ssi_item *list, const char *sn);
 faim_export int aim_ssi_getpermdeny(struct aim_ssi_item *list);
 faim_export fu32_t aim_ssi_getpresence(struct aim_ssi_item *list);
-faim_export int aim_ssi_cleanlist(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_addbuddies(aim_session_t *sess, aim_conn_t *conn, const char *gn, const char **sn, unsigned int num);
-faim_export int aim_ssi_addmastergroup(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_addgroups(aim_session_t *sess, aim_conn_t *conn, const char **gn, unsigned int num);
-faim_export int aim_ssi_addpord(aim_session_t *sess, aim_conn_t *conn, const char **sn, unsigned int num, fu16_t type);
-faim_export int aim_ssi_movebuddy(aim_session_t *sess, aim_conn_t *conn, const char *oldgn, const char *newgn, const char *sn);
-faim_export int aim_ssi_rename_group(aim_session_t *sess, aim_conn_t *conn, const char *oldgn, const char *newgn);
-faim_export int aim_ssi_delbuddies(aim_session_t *sess, aim_conn_t *conn, const char *gn, char **sn, unsigned int num);
-faim_export int aim_ssi_delmastergroup(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_delgroups(aim_session_t *sess, aim_conn_t *conn, char **gn, unsigned int num);
-faim_export int aim_ssi_deletelist(aim_session_t *sess, aim_conn_t *conn);
-faim_export int aim_ssi_delpord(aim_session_t *sess, aim_conn_t *conn, const char **sn, unsigned int num, fu16_t type);
-faim_export int aim_ssi_setpermdeny(aim_session_t *sess, aim_conn_t *conn, fu8_t permdeny, fu32_t vismask);
-faim_export int aim_ssi_setpresence(aim_session_t *sess, aim_conn_t *conn, fu32_t presence);
+faim_export char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *sn);
+faim_export int aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *sn);
+
+/* Client functions for changing SSI data */
+faim_export int aim_ssi_addbuddy(aim_session_t *sess, const char *name, const char *group, const char *alias, const char *comment, const char *smsnum, int needauth);
+faim_export int aim_ssi_addpermit(aim_session_t *sess, const char *name);
+faim_export int aim_ssi_adddeny(aim_session_t *sess, const char *name);
+faim_export int aim_ssi_delbuddy(aim_session_t *sess, const char *name, const char *group);
+faim_export int aim_ssi_delpermit(aim_session_t *sess, const char *name);
+faim_export int aim_ssi_deldeny(aim_session_t *sess, const char *name);
+faim_export int aim_ssi_movebuddy(aim_session_t *sess, const char *oldgn, const char *newgn, const char *sn);
+faim_export int aim_ssi_aliasbuddy(aim_session_t *sess, const char *gn, const char *sn, const char *alias);
+faim_export int aim_ssi_rename_group(aim_session_t *sess, const char *oldgn, const char *newgn);
+faim_export int aim_ssi_cleanlist(aim_session_t *sess);
+faim_export int aim_ssi_deletelist(aim_session_t *sess);
+faim_export int aim_ssi_setpermdeny(aim_session_t *sess, fu8_t permdeny, fu32_t vismask);
+faim_export int aim_ssi_setpresence(aim_session_t *sess, fu32_t presence);
+faim_export int aim_ssi_seticon(aim_session_t *sess, fu8_t *iconsum, fu16_t iconsumlen);
+
+
+
+/* 0x0015 - icq.c */
+#define AIM_ICQ_INFO_SIMPLE	0x001
+#define AIM_ICQ_INFO_SUMMARY	0x002
+#define AIM_ICQ_INFO_EMAIL	0x004
+#define AIM_ICQ_INFO_PERSONAL	0x008
+#define AIM_ICQ_INFO_ADDITIONAL	0x010
+#define AIM_ICQ_INFO_WORK	0x020
+#define AIM_ICQ_INFO_INTERESTS	0x040
+#define AIM_ICQ_INFO_ORGS	0x080
+#define AIM_ICQ_INFO_UNKNOWN	0x100
+#define AIM_ICQ_INFO_HAVEALL	0x1ff
 
 struct aim_icq_offlinemsg {
@@ -1133,21 +1230,89 @@
 	fu16_t year;
 	fu8_t month, day, hour, minute;
-	fu16_t type;
+	fu8_t type;
+	fu8_t flags;
 	char *msg;
-};
-
-struct aim_icq_simpleinfo {
+	int msglen;
+};
+
+struct aim_icq_info {
+	fu16_t reqid;
+
+	/* simple */
 	fu32_t uin;
+
+	/* general and "home" information (0x00c8) */
 	char *nick;
 	char *first;
 	char *last;
 	char *email;
+	char *homecity;
+	char *homestate;
+	char *homephone;
+	char *homefax;
+	char *homeaddr;
+	char *mobile;
+	char *homezip;
+	fu16_t homecountry;
+/*	fu8_t timezone;
+	fu8_t hideemail; */
+
+	/* personal (0x00dc) */
+	fu8_t age;
+	fu8_t unknown;
+	fu8_t gender;
+	char *personalwebpage;
+	fu16_t birthyear;
+	fu8_t birthmonth;
+	fu8_t birthday;
+	fu8_t language1;
+	fu8_t language2;
+	fu8_t language3;
+
+	/* work (0x00d2) */
+	char *workcity;
+	char *workstate;
+	char *workphone;
+	char *workfax;
+	char *workaddr;
+	char *workzip;
+	fu16_t workcountry;
+	char *workcompany;
+	char *workdivision;
+	char *workposition;
+	char *workwebpage;
+
+	/* additional personal information (0x00e6) */
+	char *info;
+
+	/* email (0x00eb) */
+	fu16_t numaddresses;
+	char **email2;
+
+	/* we keep track of these in a linked list because we're 1337 */
+	struct aim_icq_info *next;
 };
 
 faim_export int aim_icq_reqofflinemsgs(aim_session_t *sess);
 faim_export int aim_icq_ackofflinemsgs(aim_session_t *sess);
+faim_export int aim_icq_hideip(aim_session_t *sess);
+faim_export int aim_icq_changepasswd(aim_session_t *sess, const char *passwd);
 faim_export int aim_icq_getsimpleinfo(aim_session_t *sess, const char *uin);
-
-/* email.c */
+faim_export int aim_icq_getalias(aim_session_t *sess, const char *uin);
+faim_export int aim_icq_getallinfo(aim_session_t *sess, const char *uin);
+
+
+
+/* 0x0017 - auth.c */
+faim_export int aim_sendcookie(aim_session_t *, aim_conn_t *, const fu16_t length, const fu8_t *);
+faim_export int aim_admin_changepasswd(aim_session_t *, aim_conn_t *, const char *newpw, const char *curpw);
+faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn);
+faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info);
+faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail);
+faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick);
+
+
+
+/* 0x0018 - email.c */
 struct aim_emailinfo {
 	fu8_t *cookie16;
@@ -1164,4 +1329,58 @@
 faim_export int aim_email_activate(aim_session_t *sess, aim_conn_t *conn);
 
+
+
+/* tlv.c - TLV handling */
+#if defined(FAIM_INTERNAL) || defined(FAIM_NEED_TLV)
+/* Generic TLV structure. */
+typedef struct aim_tlv_s {
+	fu16_t type;
+	fu16_t length;
+	fu8_t *value;
+} aim_tlv_t;
+
+/* List of above. */
+typedef struct aim_tlvlist_s {
+	aim_tlv_t *tlv;
+	struct aim_tlvlist_s *next;
+} aim_tlvlist_t;
+
+/* TLV-handling functions */
+
+#if 0
+/* Very, very raw TLV handling. */
+faim_internal int aim_puttlv_8(fu8_t *buf, const fu16_t t, const fu8_t v);
+faim_internal int aim_puttlv_16(fu8_t *buf, const fu16_t t, const fu16_t v);
+faim_internal int aim_puttlv_32(fu8_t *buf, const fu16_t t, const fu32_t v);
+faim_internal int aim_puttlv_raw(fu8_t *buf, const fu16_t t, const fu16_t l, const fu8_t *v);
+#endif
+
+/* TLV list handling. */
+faim_internal aim_tlvlist_t *aim_readtlvchain(aim_bstream_t *bs);
+faim_internal aim_tlvlist_t *aim_readtlvchain_num(aim_bstream_t *bs, fu16_t num);
+faim_internal aim_tlvlist_t *aim_readtlvchain_len(aim_bstream_t *bs, fu16_t len);
+faim_internal aim_tlvlist_t *aim_tlvlist_copy(aim_tlvlist_t *orig);
+faim_internal int aim_tlvlist_cmp(aim_tlvlist_t *one, aim_tlvlist_t *two);
+faim_internal void aim_freetlvchain(aim_tlvlist_t **list);
+faim_internal aim_tlv_t *aim_gettlv(aim_tlvlist_t *, fu16_t t, const int n);
+faim_internal char *aim_gettlv_str(aim_tlvlist_t *, const fu16_t t, const int n);
+faim_internal fu8_t aim_gettlv8(aim_tlvlist_t *list, const fu16_t type, const int num);
+faim_internal fu16_t aim_gettlv16(aim_tlvlist_t *list, const fu16_t t, const int n);
+faim_internal fu32_t aim_gettlv32(aim_tlvlist_t *list, const fu16_t t, const int n);
+faim_internal int aim_writetlvchain(aim_bstream_t *bs, aim_tlvlist_t **list);
+faim_internal int aim_addtlvtochain8(aim_tlvlist_t **list, const fu16_t t, const fu8_t v);
+faim_internal int aim_addtlvtochain16(aim_tlvlist_t **list, const fu16_t t, const fu16_t v);
+faim_internal int aim_addtlvtochain32(aim_tlvlist_t **list, const fu16_t type, const fu32_t v);
+faim_internal int aim_addtlvtochain_raw(aim_tlvlist_t **list, const fu16_t t, const fu16_t l, const fu8_t *v);
+faim_internal int aim_addtlvtochain_caps(aim_tlvlist_t **list, const fu16_t t, const fu32_t caps);
+faim_internal int aim_addtlvtochain_noval(aim_tlvlist_t **list, const fu16_t type);
+faim_internal int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, fu16_t type, aim_userinfo_t *ui);
+faim_internal int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, fu16_t type, aim_tlvlist_t **tl);
+faim_internal int aim_counttlvchain(aim_tlvlist_t **list);
+faim_internal int aim_sizetlvchain(aim_tlvlist_t **list);
+#endif /* FAIM_INTERNAL */
+
+
+
 /* util.c */
 /*
@@ -1172,16 +1391,16 @@
  *
  */
-#define aimutil_put8(buf, data) ((*(buf) = (u_char)(data)&0xff),1)
+#define aimutil_put8(buf, data) ((*(buf) = (fu8_t)(data)&0xff),1)
 #define aimutil_get8(buf) ((*(buf))&0xff)
 #define aimutil_put16(buf, data) ( \
-		(*(buf) = (u_char)((data)>>8)&0xff), \
-		(*((buf)+1) = (u_char)(data)&0xff),  \
+		(*(buf) = (fu8_t)((data)>>8)&0xff), \
+		(*((buf)+1) = (fu8_t)(data)&0xff),  \
 		2)
 #define aimutil_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
 #define aimutil_put32(buf, data) ( \
-		(*((buf)) = (u_char)((data)>>24)&0xff), \
-		(*((buf)+1) = (u_char)((data)>>16)&0xff), \
-		(*((buf)+2) = (u_char)((data)>>8)&0xff), \
-		(*((buf)+3) = (u_char)(data)&0xff), \
+		(*((buf)) = (fu8_t)((data)>>24)&0xff), \
+		(*((buf)+1) = (fu8_t)((data)>>16)&0xff), \
+		(*((buf)+2) = (fu8_t)((data)>>8)&0xff), \
+		(*((buf)+3) = (fu8_t)(data)&0xff), \
 		4)
 #define aimutil_get32(buf) ((((*(buf))<<24)&0xff000000) + \
@@ -1192,5 +1411,5 @@
 /* Little-endian versions (damn ICQ) */
 #define aimutil_putle8(buf, data) ( \
-		(*(buf) = (unsigned char)(data) & 0xff), \
+		(*(buf) = (fu8_t)(data) & 0xff), \
 		1)
 #define aimutil_getle8(buf) ( \
@@ -1198,6 +1417,6 @@
 		)
 #define aimutil_putle16(buf, data) ( \
-		(*((buf)+0) = (unsigned char)((data) >> 0) & 0xff),  \
-		(*((buf)+1) = (unsigned char)((data) >> 8) & 0xff), \
+		(*((buf)+0) = (fu8_t)((data) >> 0) & 0xff),  \
+		(*((buf)+1) = (fu8_t)((data) >> 8) & 0xff), \
 		2)
 #define aimutil_getle16(buf) ( \
@@ -1206,8 +1425,8 @@
 		)
 #define aimutil_putle32(buf, data) ( \
-		(*((buf)+0) = (unsigned char)((data) >>  0) & 0xff), \
-		(*((buf)+1) = (unsigned char)((data) >>  8) & 0xff), \
-		(*((buf)+2) = (unsigned char)((data) >> 16) & 0xff), \
-		(*((buf)+3) = (unsigned char)((data) >> 24) & 0xff), \
+		(*((buf)+0) = (fu8_t)((data) >>  0) & 0xff), \
+		(*((buf)+1) = (fu8_t)((data) >>  8) & 0xff), \
+		(*((buf)+2) = (fu8_t)((data) >> 16) & 0xff), \
+		(*((buf)+3) = (fu8_t)((data) >> 24) & 0xff), \
 		4)
 #define aimutil_getle32(buf) ( \
@@ -1218,22 +1437,19 @@
 
 
-faim_export int aimutil_putstr(u_char *, const char *, int);
-faim_export int aimutil_tokslen(char *toSearch, int index, char dl);
+faim_export int aimutil_putstr(char *, const char *, int);
+faim_export fu16_t aimutil_iconsum(const fu8_t *buf, int buflen);
+faim_export int aim_util_getlocalip(fu8_t *ip);
+faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl);
 faim_export int aimutil_itemcnt(char *toSearch, char dl);
-faim_export char *aimutil_itemidx(char *toSearch, int index, char dl);
+faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl);
 
 faim_export int aim_snlen(const char *sn);
 faim_export int aim_sncmp(const char *sn1, const char *sn2);
 
-/* for libc's that dont have it */
-faim_export char *aim_strsep(char **pp, const char *delim);
-
-/* meta.c */
-faim_export char *aim_getbuilddate(void);
-faim_export char *aim_getbuildtime(void);
-faim_export int aim_getbuildstring(char *buf, int buflen);
-
 #include <aim_internal.h>
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __AIM_H__ */
-
