]> andersk Git - libfaim.git/commitdiff
- Mon Mar 5 01:19:48 UTC 2001
authormid <mid>
Mon, 5 Mar 2001 01:28:44 +0000 (01:28 +0000)
committermid <mid>
Mon, 5 Mar 2001 01:28:44 +0000 (01:28 +0000)
  - Fix typo in last CHANGES entry.
  - Add fix from Eric to keep efence from complaining about malloc(0)
  - Add .cvsignore files (also from Eric)
  - Throw in josh's latest OFT/ODC kludges
  - Completly remove all calls to printf and (unbounded) sprintf
  - Add aim_setdebuggingcb()
  - Remove preprocessor-based debug semantics (faimconfig.h)
  - faimdprintf() now calls a user-specified callback to do printing
  - Rearrange aim_tx_new() parameters to be more sensical, add sess
  - Do some sanity checking in aim_tx_new()
  - Add #defines to keep printf from compiling inside libfaim
  - Who knows what else. (in total, this patch is nearly 5k lines)

30 files changed:
.cvsignore [new file with mode: 0644]
CHANGES
configure.in
include/.cvsignore [new file with mode: 0644]
include/aim.h
include/aim_cbtypes.h
include/faimconfig.h
src/.cvsignore [new file with mode: 0644]
src/adverts.c
src/auth.c
src/buddylist.c
src/chat.c
src/chatnav.c
src/conn.c
src/ft.c
src/im.c
src/info.c
src/login.c
src/meta.c
src/misc.c
src/msgcookie.c
src/rxhandlers.c
src/rxqueue.c
src/search.c
src/snac.c
src/tlv.c
src/txqueue.c
utils/.cvsignore [new file with mode: 0644]
utils/faimtest/.cvsignore [new file with mode: 0644]
utils/faimtest/faimtest.c

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..97823ff
--- /dev/null
@@ -0,0 +1,8 @@
+aclocal.m4
+Makefile.in
+configure
+config.log
+config.cache
+libtool
+config.status
+Makefile
diff --git a/CHANGES b/CHANGES
index 023ee3307cba43804bc1b703c0c6270c4c0ad538..a1166ff8add4789a6c00292f21a7100ec67177f6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,8 +1,22 @@
 
 No release numbers
 ------------------
+ - Mon Mar  5 01:19:48 UTC 2001
+  - Fix typo in last CHANGES entry.
+  - Add fix from Eric to keep efence from complaining about malloc(0)
+  - Add .cvsignore files (also from Eric)
+  - Throw in josh's latest OFT/ODC kludges
+  - Completly remove all calls to printf and (unbounded) sprintf
+  - Add aim_setdebuggingcb()
+  - Remove preprocessor-based debug semantics (faimconfig.h)
+  - faimdprintf() now calls a user-specified callback to do printing
+  - Rearrange aim_tx_new() parameters to be more sensical, add sess
+  - Do some sanity checking in aim_tx_new()
+  - Add #defines to keep printf from compiling inside libfaim
+  - Who knows what else. (in total, this patch is nearly 5k lines)
+
  - Fri Mar  2 02:17:22 UTC 2001
-  - Add aim_fingerprintclient(). (AB will, but you shouldn't.)
+  - Add aim_fingerprintclient(). (AB will trust this, but you shouldn't.)
   - Add some EXTRA_DIST to Makefile.am
 
  - Mon Feb 26 01:46:34 UTC 2001
index c9948698ae8cf3886cdc4b0def7c8e3a5040fa23..8a92ae8df5eed260d82e51c4bcacf4c386736ece 100644 (file)
@@ -20,6 +20,14 @@ AC_CHECK_LIB(faim, aim_sessioninit)
 dnl Replace `main' with a function in -lpcap:
 dnl AC_CHECK_LIB(pcap, main)
 
+AC_ARG_ENABLE(debug,    [  --disable-debug         compile without debugging options],enable_debug=no,enable_debug=yes)
+
+if test "$enable_debug" = yes ; then
+        CFLAGS="$CFLAGS -Wall -g"
+fi
+
+AC_SUBST(CFLAGS)
+
 dnl Checks for header files.
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
diff --git a/include/.cvsignore b/include/.cvsignore
new file mode 100644 (file)
index 0000000..95b13fe
--- /dev/null
@@ -0,0 +1,6 @@
+stamp-h.in
+libfaim_config.h.in
+Makefile.in
+Makefile
+libfaim_config.h
+stamp-h
index 11977bb9e50fd58d22083264b9cc02535dc9a06b..0cef2211f1cc30824b0ee3c6a54904cbd5f6b8ba 100644 (file)
 #include <stdlib.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <time.h>
 
 #ifdef _WIN32
 #include <windows.h>
-#include <time.h>
 #include <io.h>
 #else
 #include <sys/time.h>
@@ -271,14 +271,6 @@ struct command_tx_struct {
   struct command_tx_struct *next; /* ptr to next struct in list */
 };
 
-/*
- * OFT session: random oft cruft, per-session.
- *
- */
-struct aim_oft_session_t {
-
-};
-
 /*
  * AIM Session: The main client-data interface.  
  *
@@ -302,11 +294,6 @@ struct aim_session_t {
    */
   void *aux_data;
 
-  /* 
-   * OFT Data 
-   */
-  struct aim_oft_session_t oft;
-
   /* ---- Internal Use Only ------------------------ */
   /* 
    * Connection information
@@ -350,6 +337,9 @@ struct aim_session_t {
 
   unsigned long flags;
 
+  int debug;
+  void (*debugcb)(struct aim_session_t *sess, int level, const char *format, va_list va); /* same as faim_debugging_callback_t */
+
   struct aim_msgcookie_t *msgcookies;
 };
 
@@ -444,8 +434,8 @@ faim_export unsigned long aim_debugconn_sendconnect(struct aim_session_t *sess,
 
 faim_export int aim_logoff(struct aim_session_t *);
 
-#if !defined(FAIM_INTERNAL) || defined(FAIM_INTERNAL_FT)
-/* the library should never call aim_conn_kill except in aim_ft.c */
+#ifndef FAIM_INTERNAL
+/* the library should never call aim_conn_kill */
 faim_export void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn);
 #endif /* ndef FAIM_INTERNAL */
 
@@ -477,7 +467,7 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
 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(unsigned char framing, int chan, struct aim_conn_t *conn, 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);
 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, ...);
@@ -508,7 +498,7 @@ faim_export int aim_conn_addhandler(struct aim_session_t *, struct aim_conn_t *c
 faim_export int aim_clearhandlers(struct aim_conn_t *conn);
 
 #ifdef FAIM_INTERNAL
-faim_internal rxcallback_t aim_callhandler(struct aim_conn_t *conn, u_short family, u_short type);
+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
@@ -546,7 +536,10 @@ faim_export int aim_conn_isready(struct aim_conn_t *);
 faim_export int aim_conn_setstatus(struct aim_conn_t *, int);
 faim_export int aim_conn_completeconnect(struct aim_session_t *sess, struct aim_conn_t *conn);
 faim_export int aim_conn_isconnecting(struct aim_conn_t *conn);
-faim_export void aim_session_init(struct aim_session_t *, unsigned long flags);
+
+typedef void (*faim_debugging_callback_t)(struct aim_session_t *sess, int level, const char *format, va_list va);
+faim_export int aim_setdebuggingcb(struct aim_session_t *sess, faim_debugging_callback_t);
+faim_export void aim_session_init(struct aim_session_t *, unsigned long flags, int debuglevel);
 faim_export void aim_setupproxy(struct aim_session_t *sess, char *server, char *username, char *password);
 faim_export struct aim_conn_t *aim_getconn_type(struct aim_session_t *, int type);
 
@@ -590,7 +583,7 @@ faim_export unsigned long aim_setdirectoryinfo(struct aim_session_t *sess, struc
 faim_export unsigned long aim_setuserinterests(struct aim_session_t *sess, struct aim_conn_t *conn, char *interest1, char *interest2, char *interest3, char *interest4, char *interest5, unsigned short privacy);
 faim_export unsigned long aim_icq_setstatus(struct aim_session_t *sess, struct aim_conn_t *conn, unsigned long status);
 
-faim_export struct aim_fileheader_t *aim_getlisting(FILE *);
+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 *);
@@ -732,7 +725,7 @@ faim_export int aim_oft_getfile_end(struct aim_session_t *sess, struct aim_conn_
 
 #ifdef FAIM_INTERNAL
 extern u_char aim_caps[8][16];
-faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen);
+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 */
 
@@ -744,6 +737,7 @@ struct aim_msgcookie_t {
   unsigned char cookie[8];
   int type;
   void *data;
+  time_t addtime;
   struct aim_msgcookie_t *next;
 };
 
@@ -778,6 +772,7 @@ 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);
@@ -789,7 +784,7 @@ faim_export unsigned long aim_denytransfer(struct aim_session_t *sess, struct ai
 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(u_char *, struct aim_userinfo_s *);
+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 *);
@@ -911,7 +906,12 @@ faim_export char *aim_getbuildtime(void);
 faim_export char *aim_getbuildstring(void);
 
 #ifdef FAIM_INTERNAL
-faim_internal void faimdprintf(int dlevel, const char *format, ...);
+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 */
 
 #endif /* __AIM_H__ */
index 1caa9973772b8be841369be924e7ccaa8d0b0c2b..7330a0eb488b879d1a48ad1f76c9b9a710634e2d 100644 (file)
 #define AIM_CB_OFT_DIRECTIMINITIATE 0x0005
 
 #define AIM_CB_OFT_GETFILECONNECTREQ 0x0006 /* connect request -- actually an OSCAR CAP*/
-#define AIM_CB_OFT_GETFILELISTINGREQ 0x000e /* OFT listing.txt request */
-#define AIM_CB_OFT_GETFILEFILEREQ 0x0007    /* recieved file request */
-#define AIM_CB_OFT_GETFILEFILESEND 0x0008   /* recieved file request confirm -- send data */
-#define AIM_CB_OFT_GETFILECOMPLETE 0x0009   /* recieved file send complete*/
-#define AIM_CB_OFT_GETFILEINITIATE 0x000a   /* request for file get acknowledge */
-#define AIM_CB_OFT_GETFILEDISCONNECT 0x000b   /* OFT connection disconnected.*/
-#define AIM_CB_OFT_GETFILELISTING 0x000c   /* OFT listing.txt recieved.*/
-#define AIM_CB_OFT_GETFILERECIEVE 0x000d   /* OFT file incoming.*/
-
-#define AIM_CB_OFT_SENDFILEDISCONNECT 0x000c   /* OFT connection disconnected.*/
+#define AIM_CB_OFT_GETFILELISTINGREQ 0x0007 /* OFT listing.txt request */
+#define AIM_CB_OFT_GETFILEFILEREQ 0x0008    /* received file request */
+#define AIM_CB_OFT_GETFILEFILESEND 0x0009   /* received file request confirm -- send data */
+#define AIM_CB_OFT_GETFILECOMPLETE 0x000a   /* received file send complete*/
+#define AIM_CB_OFT_GETFILEINITIATE 0x000b   /* request for file get acknowledge */
+#define AIM_CB_OFT_GETFILEDISCONNECT 0x000c   /* OFT connection disconnected.*/
+#define AIM_CB_OFT_GETFILELISTING 0x000d   /* OFT listing.txt received.*/
+#define AIM_CB_OFT_GETFILERECEIVE 0x000e   /* OFT file incoming.*/
+#define AIM_CB_OFT_GETFILELISTINGRXCONFIRM 0x000f
+#define AIM_CB_OFT_GETFILESTATE4 0x0010
+
+#define AIM_CB_OFT_SENDFILEDISCONNECT 0x0020   /* OFT connection disconnected.*/
 
 
 
index f439f1eaad5743c7ee4298cfe03854444b778c65..9fbbdb410f95a3827f00a79db5284bf21d95bb8e 100644 (file)
@@ -2,24 +2,12 @@
  *  faimconfig.h
  *
  * Contains various compile-time options that apply _only_ to libfaim.
- * Note that setting any of these options in a frontend header does not imply
- * that they'll get set here.  Notably, the 'debug' of this file is _not_ 
- * the same as the frontend 'debug'.  They can be different values.
  *
  */
 
 #ifndef __FAIMCONFIG_H__
 #define __FAIMCONFIG_H__
 
-/* 
- * set debug to be > 0 if you want debugging information spewing
- * on the attached tty.  set to 0 for daily use.  this value
- * is _not_ inherited by the frontend, only this backend.
- *
- * Default: 0  
-*/
-#define debug 0
-
 /*
  * USE_SNAC_FOR_IMS is an old feature that allowed better
  * tracking of error messages by caching SNAC IDs of outgoing
diff --git a/src/.cvsignore b/src/.cvsignore
new file mode 100644 (file)
index 0000000..417f3f6
--- /dev/null
@@ -0,0 +1,26 @@
+Makefile.in
+Makefile
+.deps
+adverts.lo
+auth.lo
+buddylist.lo
+chat.lo
+chatnav.lo
+conn.lo
+ft.lo
+im.lo
+info.lo
+login.lo
+meta.lo
+misc.lo
+msgcookie.lo
+rxhandlers.lo
+rxqueue.lo
+search.lo
+snac.lo
+tlv.lo
+txqueue.lo
+util.lo
+md5.lo
+.libs
+libfaim.la
index 790d51e519c017c2c04666afe420c84e568733d8..3f717c6bf78d9583ad9404bc676817e3680c8e64 100644 (file)
@@ -12,7 +12,7 @@ faim_export unsigned long aim_ads_clientready(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 0x1a)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x1a)))
     return -1;
 
   newpacket->lock = 1;
index 723fbb2bd22f24ccc67fbc0bf84358da1db80cbb..621c269c84594264f0dfc7fcd0489a9ab4686c99 100644 (file)
@@ -16,7 +16,7 @@ faim_export int aim_auth_sendcookie(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int curbyte=0;
   
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0001, conn, 4+2+2+AIM_COOKIELEN)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4+2+2+AIM_COOKIELEN)))
     return -1;
 
   newpacket->lock = 1;
@@ -41,7 +41,7 @@ faim_export unsigned long aim_auth_clientready(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int toolcount = sizeof(tools)/sizeof(struct aim_tool_version);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   newpacket->lock = 1;
@@ -71,7 +71,7 @@ faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+4+strlen(current)+4+strlen(new))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+4+strlen(current)+4+strlen(new))))
     return -1;
 
   newpacket->lock = 1;
@@ -96,7 +96,7 @@ faim_export unsigned long aim_auth_setversions(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + (4*2))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*2))))
     return -1;
 
   newpacket->lock = 1;
@@ -144,7 +144,7 @@ faim_export unsigned long aim_auth_getinfo(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + 4)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4)))
     return -1;
 
   newpacket->lock = 1;
@@ -169,7 +169,7 @@ faim_export unsigned long aim_auth_setemail(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+2+2+strlen(newemail))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+2+2+strlen(newemail))))
     return -1;
 
   newpacket->lock = 1;
index 64ea2ea6728e8e32b59a56985db72731c9067ea9..55a3571c0b24a29026c759e98368428d92d0d3a6 100644 (file)
@@ -20,7 +20,7 @@ faim_export unsigned long aim_add_buddy(struct aim_session_t *sess,
    if(!sn)
      return -1;
 
-   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
+   if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
      return -1;
 
    newpacket->lock = 1;
@@ -51,7 +51,7 @@ faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess,
    if(!sn)
      return -1;
 
-   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
+   if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
      return -1;
 
    newpacket->lock = 1;
@@ -97,7 +97,7 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
   if (aim_gettlv(tlvlist, 0x0002, 1))
     maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
   
-  if ((userfunc = aim_callhandler(command->conn, 0x0003, 0x0003)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0003, 0x0003)))
     ret =  userfunc(sess, command, maxbuddies, maxwatchers);
 
   aim_freetlvchain(&tlvlist);
index 5c3f45525fbdab7c72649ea15f086bf7dddd98ee..8eb14395e3729edeaf89e154c3ab952ac99a0564 100644 (file)
@@ -27,7 +27,7 @@ faim_export struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char
     if (cur->type != AIM_CONN_TYPE_CHAT)
       continue;
     if (!cur->priv) {
-      printf("faim: chat: chat connection with no name! (fd = %d)\n", cur->fd);
+      faimdprintf(sess, 0, "faim: chat: chat connection with no name! (fd = %d)\n", cur->fd);
       continue;
     }
     if (strcmp((char *)cur->priv, name) == 0)
@@ -64,7 +64,7 @@ faim_export unsigned long aim_chat_send_im(struct aim_session_t *sess,
   if (!sess || !conn || !msg)
     return 0;
   
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   newpacket->lock = 1; /* lock struct */
@@ -143,7 +143,7 @@ faim_export unsigned long aim_chat_join(struct aim_session_t *sess,
   if (!sess || !conn || !roomname)
     return 0;
   
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+9+strlen(roomname)+2)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+9+strlen(roomname)+2)))
     return -1;
 
   newpacket->lock = 1;
@@ -244,9 +244,9 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
 
   if (detaillevel != 0x02) {
     if (detaillevel == 0x01)
-      printf("faim: chat_roomupdateinfo: detail level 1 not supported\n");
+      faimdprintf(sess, 0, "faim: chat_roomupdateinfo: detail level 1 not supported\n");
     else
-      printf("faim: chat_roomupdateinfo: unknown detail level %d\n", detaillevel);
+      faimdprintf(sess, 0, "faim: chat_roomupdateinfo: unknown detail level %d\n", detaillevel);
     return 1;
   }
   
@@ -284,7 +284,7 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
     
     i = 0;
     while (curoccupant < usercount)
-      i += aim_extractuserinfo(tmptlv->value+i, &userinfo[curoccupant++]);
+      i += aim_extractuserinfo(sess, tmptlv->value+i, &userinfo[curoccupant++]);
   }
   
   /* 
@@ -324,7 +324,7 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
     unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1);
 
 
-  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE))) {
+  if ((userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE))) {
     ret = userfunc(sess,
                   command, 
                   &roominfo,
@@ -357,10 +357,10 @@ faim_internal int aim_chat_parse_joined(struct aim_session_t *sess,
   while (i < command->commandlen) {
     curcount++;
     userinfo = realloc(userinfo, curcount * sizeof(struct aim_userinfo_s));
-    i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]);
+    i += aim_extractuserinfo(sess, command->data+i, &userinfo[curcount-1]);
   }
 
-  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN))) {
+  if ((userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN))) {
     ret = userfunc(sess,
                   command, 
                   curcount,
@@ -383,10 +383,10 @@ faim_internal int aim_chat_parse_leave(struct aim_session_t *sess,
   while (i < command->commandlen) {
     curcount++;
     userinfo = realloc(userinfo, curcount * sizeof(struct aim_userinfo_s));
-    i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]);
+    i += aim_extractuserinfo(sess, command->data+i, &userinfo[curcount-1]);
   }
 
-  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE))) {
+  if ((userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE))) {
     ret = userfunc(sess,
                   command, 
                   curcount,
@@ -462,7 +462,7 @@ faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
   i += 2;
 
   if (channel != 0x0003) {
-    printf("faim: chat_incoming: unknown channel! (0x%04x)\n", channel);
+    faimdprintf(sess, 0, "faim: chat_incoming: unknown channel! (0x%04x)\n", channel);
     return 1;
   }
 
@@ -478,7 +478,7 @@ faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
     struct aim_tlv_t *userinfotlv;
     
     userinfotlv = aim_gettlv(outerlist, 0x0003, 1);
-    aim_extractuserinfo(userinfotlv->value, &userinfo);
+    aim_extractuserinfo(sess, userinfotlv->value, &userinfo);
   }
 
   /*
@@ -507,7 +507,7 @@ faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
       aim_freetlvchain(&innerlist); 
     }
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG);
+  userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG);
   if (userfunc)
     {
       ret = userfunc(sess,
@@ -527,7 +527,7 @@ faim_export unsigned long aim_chat_clientready(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 0x20)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x20)))
     return -1;
 
   newpacket->lock = 1;
@@ -586,7 +586,7 @@ faim_export unsigned long aim_chat_invite(struct aim_session_t *sess,
   if (conn->type != AIM_CONN_TYPE_BOS)
     return -1;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
     return -1;
 
   newpacket->lock = 1;
index ae693634509d85d77df27fb0be12897bdbfae92c..4dff1f05d8669ad563ddc23537d200bb5e2d78db 100644 (file)
@@ -27,7 +27,7 @@ faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess,
   struct command_tx_struct *newpacket; 
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 0x20)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x20)))
     return -1;
 
   newpacket->lock = 1;
@@ -66,17 +66,15 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
   snacid = aimutil_get32(command->data+6);
   snac = aim_remsnac(sess, snacid);
 
-  if (!snac)
-    {
-      printf("faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid);
-      return 1;
-    }
+  if (!snac) {
+    faimdprintf(sess, 0, "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid);
+    return 1;
+  }
   
-  if (snac->family != 0x000d)
-    {
-      printf("faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac->family);
-      return 1;
-    }
+  if (snac->family != 0x000d) {
+    faimdprintf(sess, 0, "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac->family);
+    return 1;
+  }
 
   /*
    * We now know what the original SNAC subtype was.
@@ -138,7 +136,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
 
                classperms = aim_gettlv16(innerlist, 0x0002, 1);
                
-               printf("faim: class permissions %x\n", classperms);
+               faimdprintf(sess, 1, "faim: class permissions %x\n", classperms);
              }
 
              /*
@@ -231,14 +229,8 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
          /*
           * Call client.
           */
-         userfunc = aim_callhandler(command->conn, 0x000d, 0x0009);
-         if (userfunc)
-           ret = userfunc(sess, 
-                          command, 
-                          snac->type,
-                          maxrooms,
-                          curexchange, 
-                          exchanges);
+         if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009)))
+           ret = userfunc(sess, command, snac->type, maxrooms, curexchange, exchanges);
          curexchange--;
          while(curexchange >= 0)
            {
@@ -260,19 +252,19 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
          break;
       }
     case 0x0003: /* request exchange info */
-      printf("faim: chatnav_parse_info: resposne to exchange info\n");
+      faimdprintf(sess, 0, "chatnav_parse_info: resposne to exchange info\n");
       break;
     case 0x0004: /* request room info */
-      printf("faim: chatnav_parse_info: response to room info\n");
+       faimdprintf(sess, 0, "chatnav_parse_info: response to room info\n");
       break;
     case 0x0005: /* request more room info */
-      printf("faim: chatnav_parse_info: response to more room info\n");
+       faimdprintf(sess, 0, "chatnav_parse_info: response to more room info\n");
       break;
     case 0x0006: /* request occupant list */
-      printf("faim: chatnav_parse_info: response to occupant info\n");
+       faimdprintf(sess, 0, "chatnav_parse_info: response to occupant info\n");
       break;
     case 0x0007: /* search for a room */
-      printf("faim: chatnav_parse_info: search results\n");
+       faimdprintf(sess, 0, "chatnav_parse_info: search results\n");
       break;
     case 0x0008: { /* create room */
       /*
@@ -295,20 +287,20 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
        */
       struct aim_tlvlist_t *tlvlist, *innerlist;
       char *ck = NULL, *fqcn = NULL, *name = NULL;
-      unsigned short exchange, instance, unknown, flags, maxmsglen, maxoccupancy;
+      unsigned short exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0;
       unsigned long createtime = 0;
-      unsigned char createperms;
+      unsigned char createperms = 0;
       int i, cklen;
       struct aim_tlv_t *bigblock;
 
       i = 10;
       if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) {
-       printf("faim: unable to read top tlv in create room response\n");
+       faimdprintf(sess, 0, "unable to read top tlv in create room response\n");
        break;
       }
 
       if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) {
-       printf("faim: no bigblock in top tlv in create room response\n");
+       faimdprintf(sess, 0, "no bigblock in top tlv in create room response\n");
        aim_freetlvchain(&tlvlist);
        break;
       }
@@ -329,7 +321,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       i += 2;
 
       if (aimutil_get8(bigblock->value+i) != 0x02) {
-       printf("faim: unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i));
+        faimdprintf(sess, 0, "unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i));
        aim_freetlvchain(&tlvlist);
        free(ck);       
        break;
@@ -340,7 +332,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       i += 2;
 
       if (!(innerlist = aim_readtlvchain(bigblock->value+i, bigblock->length-i))) {
-       printf("faim: unable to read inner tlv chain in create room response\n");
+       faimdprintf(sess, 0, "unable to read inner tlv chain in create room response\n");
        aim_freetlvchain(&tlvlist);
        free(ck);
        break;
@@ -367,7 +359,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       if (aim_gettlv(innerlist, 0x00d5, 1))
        createperms = aim_gettlv8(innerlist, 0x00d5, 1);
 
-      if ((userfunc = aim_callhandler(command->conn, 0x000d, 0x0009))) {
+      if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009))) {
        ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
       }
      
@@ -383,7 +375,7 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       break;
     }
     default: /* unknown */
-      printf("faim: chatnav_parse_info: unknown request subtype (%04x)\n", snac->type);
+      faimdprintf(sess, 0, "chatnav_parse_info: unknown request subtype (%04x)\n", snac->type);
     }
 
   if (snac && snac->data)
@@ -402,7 +394,7 @@ faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess,
   struct command_tx_struct *newpacket; 
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+12+strlen("invite")+strlen(name))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+12+strlen("invite")+strlen(name))))
     return -1;
 
   newpacket->lock = 1;
index a46893d5e9715cb4ba3f50d64769c2889ef2476d..e296f9fb4ce0d92b9349a7e669a2a7fe0456224f 100644 (file)
@@ -101,7 +101,8 @@ faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *sess)
  * @sess: Session for the connection
  * @deadconn: Connection to be freed
  *
- * Close, clear, and free a connection structure.
+ * Close, clear, and free a connection structure. Should never be
+ * called from within libfaim.
  *
  */
 faim_export void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn)
@@ -228,7 +229,7 @@ static int aim_proxyconnect(struct aim_session_t *sess,
     proxy[i] = '\0';
 
     if (!(hp = gethostbyname(proxy))) {
-      printf("proxyconnect: unable to resolve proxy name\n");
+      faimdprintf(sess, 0, "proxyconnect: unable to resolve proxy name\n");
       *statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR);
       return -1;
     }
@@ -241,7 +242,7 @@ static int aim_proxyconnect(struct aim_session_t *sess,
   
     fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
     if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
-      printf("proxyconnect: unable to connect to proxy\n");
+      faimdprintf(sess, 0, "proxyconnect: unable to connect to proxy\n");
       close(fd);
       return -1;
     }
@@ -359,6 +360,19 @@ static int aim_proxyconnect(struct aim_session_t *sess,
   return fd;
 }
 
+/**
+ * aim_cloneconn - clone an aim_conn_t
+ * @sess: session containing parent
+ * @src: connection to clone
+ *
+ * A new connection is allocated, and the values are filled in
+ * appropriately. Note that this function sets the new connnection's
+ * ->priv pointer to be equal to that of its parent: only the pointer
+ * is copied, not the data it points to.
+ *
+ * This function returns a pointer to the new aim_conn_t, or %NULL on
+ * error
+ */
 faim_internal struct aim_conn_t *aim_cloneconn(struct aim_session_t *sess,
                                               struct aim_conn_t *src)
 {
@@ -367,7 +381,6 @@ faim_internal struct aim_conn_t *aim_cloneconn(struct aim_session_t *sess,
 
   if (!(conn = aim_conn_getnext(sess)))
     return NULL;
-  
 
   faim_mutex_lock(&conn->active);
 
@@ -515,7 +528,7 @@ faim_export int aim_conn_in_sess(struct aim_session_t *sess, struct aim_conn_t *
  * @status: Return status
  *
  * Waits for a socket with data or for timeout, whichever comes first.
- * See select().
+ * See select(2).
  * 
  * Return codes in *status:
  *   -1  error in select() (%NULL returned)
@@ -600,6 +613,7 @@ faim_export struct aim_conn_t *aim_select(struct aim_session_t *sess,
     *status = i; /* can be 0 or -1 */
 
   faim_mutex_unlock(&sess->connlistlock);
+
   return NULL;  /* no waiting or error, return */
 }
 
@@ -641,6 +655,7 @@ faim_export int aim_conn_setstatus(struct aim_conn_t *conn, int status)
   faim_mutex_lock(&conn->active);
   val = conn->status ^= status;
   faim_mutex_unlock(&conn->active);
+
   return val;
 }
 
@@ -707,11 +722,12 @@ faim_export void aim_setupproxy(struct aim_session_t *sess, char *server, char *
  * aim_session_init - Initializes a session structure
  * @sess: Session to initialize
  * @flags: Flags to use. Any of %AIM_SESS_FLAGS %OR'd together.
+ * @debuglevel: Level of debugging output (zero is least)
  *
  * Sets up the initial values for a session.
  *
  */
-faim_export void aim_session_init(struct aim_session_t *sess, unsigned long flags)
+faim_export void aim_session_init(struct aim_session_t *sess, unsigned long flags, int debuglevel)
 {
   if (!sess)
     return;
@@ -727,6 +743,8 @@ faim_export void aim_session_init(struct aim_session_t *sess, unsigned long flag
   sess->snac_nextid = 0x00000001;
 
   sess->flags = 0;
+  sess->debug = 0;
+  sess->debugcb = NULL;
 
   /*
    * Default to SNAC login unless XORLOGIN is explicitly set.
@@ -744,6 +762,27 @@ faim_export void aim_session_init(struct aim_session_t *sess, unsigned long flag
   return;
 }
 
+/**
+ * aim_setdebuggingcb - Set the function to call when outputting debugging info
+ * @sess: Session to change
+ * @cb: Function to call
+ *
+ * The function specified is called whenever faimdprintf() is used within
+ * libfaim, and the session's debugging level is greater tha nor equal to
+ * the value faimdprintf was called with.
+ *
+ */
+faim_export int aim_setdebuggingcb(struct aim_session_t *sess, faim_debugging_callback_t cb)
+{
+
+  if (!sess)
+    return -1;
+
+  sess->debugcb = cb;
+
+  return 0;
+}
+
 /**
  * aim_conn_isconnecting - Determine if a connection is connecting
  * @conn: Connection to examine
@@ -786,7 +825,7 @@ faim_export int aim_conn_completeconnect(struct aim_session_t *sess, struct aim_
     errno = error;
     return -1;
   } else if (res == 0) {
-    printf("faim: aim_conn_completeconnect: false alarm on %d\n", conn->fd);
+    faimdprintf(sess, 0, "aim_conn_completeconnect: false alarm on %d\n", conn->fd);
     return 0; /* hasn't really completed yet... */
   } 
 
@@ -807,7 +846,7 @@ faim_export int aim_conn_completeconnect(struct aim_session_t *sess, struct aim_
 
   conn->status &= ~AIM_CONN_STATUS_INPROGRESS;
 
-  if ((userfunc = aim_callhandler(conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE)))
+  if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE)))
     userfunc(sess, NULL, conn);
 
   /* Flush out the queues if there was something waiting for this conn  */
@@ -824,6 +863,7 @@ faim_export int aim_conn_completeconnect(struct aim_session_t *sess, struct aim_
  */
 faim_export int aim_logoff(struct aim_session_t *sess)
 {
+
   aim_connrst(sess);  /* in case we want to connect again */
 
   return 0;
index 23d58ad418100125bfae7faba47dc0baa165a092..958a75c11414bcc35fea299bd680d864d65bbda4 100644 (file)
--- a/src/ft.c
+++ b/src/ft.c
@@ -1,11 +1,12 @@
 /*
- * File transfer (OFT) and DirectIM.
+ * File transfer (OFT) and DirectIM (ODC).
+ * (OSCAR File Transfer, Oscar Direct Connect(ion?)
  */
 
-#define FAIM_INTERNAL_FT
 #define FAIM_INTERNAL
 #include <aim.h>
 
+
 #ifndef _WIN32
 #include <netdb.h>
 #include <sys/socket.h>
 #endif
 
 /* TODO: 
-   o fix misspelling of receive 
-   o double-check mutex states on error returns 
    o look for memory leaks.. there's going to be shitloads, i'm sure. 
-   o change listing FILE to listing filesend callback 
-   o change send_file and send_chunk over to buffers.
 */
 
 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr);
@@ -32,9 +29,10 @@ static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr);
  * @cur: the conn the incoming connection is on
  *
  * call this when you get an outstanding read on a conn with subtype
- * AIM_CONN_SUBTYPE_RENDEZVOUS_OUT, it will close the current fd and
- * call a callback with the new, accept'd fd to the other person. then we
- * get to start the fun that is OFT!
+ * AIM_CONN_SUBTYPE_RENDEZVOUS_OUT, it will clone the current
+ * &aim_conn_t and tweak things as appropriate. the new conn and the
+ * listener conn are both returned to the client in the
+ * %AIM_CB_FAM_OFT, %AIM_CB_OFT_<CLASS>INITIATE callback.
  */
 faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
 { 
@@ -45,7 +43,7 @@ faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_con
   int ret = 0;
   struct aim_conn_t *newconn;
 
-  if( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1)
+  if ( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1)
     return -1;
   if (cliaddr.sa_family != AF_INET) { /* just in case IPv6 really is happening */
     close(acceptfd);
@@ -53,52 +51,57 @@ faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_con
     return -1;
   } 
 
-  /* clone it and then close the original */
-  /* XXX safe? maybe cur->priv should be NULLed after this */
+  /* safe? maybe cur->priv should be NULLed after this. --mid */
+
+  /* That would be bad. very bad. we want cur->priv->sn to make it up
+     to the client-level for conn management and such. even though
+     that is abusing the interface --jbm */
+
   if (!(newconn = aim_cloneconn(sess, cur))) {
     close(acceptfd);
     aim_conn_close(cur);
     return -1;
   }
-  aim_conn_close(cur);
 
   newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
   newconn->fd = acceptfd;
 
-  switch(newconn->subtype) { 
+  switch(newconn->subtype) {
   case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { 
     struct aim_directim_priv *priv;
 
-    if(!newconn->priv)
-      newconn->priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
-    priv = (struct aim_directim_priv *)newconn->priv;
+    priv = cur->priv;
+
+    newconn->priv = cur->priv;
+
+    cur->priv = NULL;
 
     snprintf(priv->ip, sizeof(priv->ip), "%s:%u", 
             inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), 
             ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
 
-    /* should we really do this? seems like the client should decide. maybe clone the connection and keep the listener open. -- mid */
-    if ( (userfunc = aim_callhandler(newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE)))
-      ret = userfunc(sess, NULL, newconn);
+    if ( (userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE)))
+      ret = userfunc(sess, NULL, newconn, cur);
 
     break;
-  } 
+  }
   case AIM_CONN_SUBTYPE_OFT_GETFILE: { 
     struct aim_filetransfer_priv *priv;
 
-    if(!newconn->priv)
-      newconn->priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
+
+    newconn->priv = cur->priv;
+    cur->priv = NULL;
     priv = (struct aim_filetransfer_priv *)newconn->priv;
 
     snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
 
-    if ( (userfunc = aim_callhandler(newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
-      ret = userfunc(sess, NULL, newconn);
+    if ( (userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
+      ret = userfunc(sess, NULL, newconn, cur);
 
     break;
-  } 
+  }
   default: { 
-    faimdprintf(1,"Got a Connection on a listener that's not Rendezvous(??!) Killing conn.\n");
+    faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous(??!) Closing conn.\n");
     aim_conn_close(newconn);
     break;
   }
@@ -107,35 +110,37 @@ faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_con
   return ret;
 }
  
-/*
+/**
  * aim_send_im_direct - send IM client-to-client over established connection
  * @sess: session to conn
  * @conn: directim connection
  * @msg: null-terminated string to send; if this is NULL, it will send a "typing" notice. 
  *
+ * Call this just like you would aim_send_im, to send a directim. You
+ * _must_ have previously established the directim connection.
  */
 faim_export int aim_send_im_direct(struct aim_session_t *sess, struct aim_conn_t *conn, char *msg)
-{ 
-
+{
   struct command_tx_struct *newpacket;
   struct aim_directim_priv *priv = NULL;
   int i;
   if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) { 
-    faimdprintf(2,"faim: directim: invalid arguments\n");
+    faimdprintf(sess, 2,"faim: directim: invalid arguments\n");
     return -1;
   }
 
   priv = (struct aim_directim_priv *)conn->priv;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) { 
-    faimdprintf(2,"faim: directim: tx_new failed\n");
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0001, strlen(msg)))) { 
+    faimdprintf(sess, 2,"faim: directim: tx_new failed\n");
     return -1;
   } 
 
   newpacket->lock = 1;
 
   /* if msg is non-null, we'resending an IM, else a "typing" notice */
-  if(msg) { 
+  if (msg) { 
     if (strlen(msg) >= MAXMSGLEN)
       return -1;
     newpacket->hdr.oft.hdr2len = 0x54;
@@ -164,13 +169,13 @@ faim_export int aim_send_im_direct(struct aim_session_t *sess, struct aim_conn_t
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  i += aimutil_put32(newpacket->hdr.oft.hdr2+i, 0x00000000);
+  i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg));
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
 
   /* flags -- 0x000e for "typing", 0x0000 for message */
-  if(msg)
+  if (msg)
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   else 
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000e);
@@ -191,7 +196,7 @@ faim_export int aim_send_im_direct(struct aim_session_t *sess, struct aim_conn_t
 
   /* end of hdr2 */
 
-  if(msg) { 
+  if (msg) { 
     /* values grabbed from a dump */
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008);
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c);
@@ -201,23 +206,28 @@ faim_export int aim_send_im_direct(struct aim_session_t *sess, struct aim_conn_t
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f);
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e);
     i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8);
-    memcpy(newpacket->data, msg, strlen(msg));
+    if(!(newpacket->data = strdup(msg)))
+      return -1;
   } 
   newpacket->lock = 0;
   aim_tx_enqueue(sess, newpacket);
   return 0;
 } 
 
-/*
+/* XXX: give the client author the responsibility of setting up a
+ * listener, then we no longer have a libfaim problem with broken
+ * solaris *innocent smile* -jbm */
+
+/**
  * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves.
  * @sess: your session,
  * @conn: the BOS conn,
- * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a NULL, we alloc one)
+ * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one)
  * @destsn: the SN to connect to.
  *
  */
 faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess, 
-                                                    struct aim_conn_t *conn, 
+                                                    struct aim_conn_t *conn,
                                                     struct aim_directim_priv *priv, 
                                                     char *destsn)
 { 
@@ -236,24 +246,23 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
  
   /* Open our socket */
 
-  if( (listenfd = aim_listenestablish(port)) == -1)
+  if ( (listenfd = aim_listenestablish(port)) == -1)
     return NULL;
 
   /* get our local IP */
   /* XXX if available, use getaddrinfo() */
   /* XXX allow client to specify which IP to use for multihomed boxes */
-  if(gethostname(localhost, 128) < 0)
+  if (gethostname(localhost, 128) < 0)
     return NULL;
-  if( (hptr = gethostbyname(localhost)) == NULL)
+  if ( (hptr = gethostbyname(localhost)) == NULL)
     return NULL;
   memcpy(&d, hptr->h_addr_list[0], 4);
 
-  /* XXX: this probably isn't quite kosher, but it works */
   aim_putcap(cap, 16, AIM_CAPS_IMIMAGE);
 
   /* create the OSCAR packet */
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x32)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(destsn)+4+4+0x32)))
     return NULL;
   newpacket->lock = 1;
 
@@ -273,7 +282,7 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
   cookie->type = AIM_COOKIETYPE_OFTIM;
   priv = cookie->data;
 
-  if(!priv)
+  if (!priv)
     priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
  
   memcpy(priv->cookie, cookie, 8);
@@ -337,13 +346,13 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
   newconn->priv = priv;
   newconn->lastactivity = time(NULL);
 
-  faimdprintf(2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
+  faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
 
   return newconn;
 } 
 
-/*
- * unsigned long aim_oft_listener_clean - close up old listeners
+/**
+ * unsigned int aim_oft_listener_clean - close up old listeners
  * @sess: session to clean up in
  * @age: maximum age in seconds 
  *
@@ -355,12 +364,12 @@ faim_export unsigned int aim_oft_listener_clean(struct aim_session_t *sess, time
   time_t now;
   unsigned int hit = 0;
   
-  if(!sess)
+  if (!sess)
     return -1;
   now = time(NULL);
   faim_mutex_lock(&sess->connlistlock);
   for(cur = sess->connlist;cur; cur = cur->next)
-    if(cur->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { 
+    if (cur->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { 
       faim_mutex_lock(&cur->active);
       if (cur->lastactivity < (now - age) ) { 
        faim_mutex_unlock(&cur->active);
@@ -373,7 +382,7 @@ faim_export unsigned int aim_oft_listener_clean(struct aim_session_t *sess, time
   return hit;
 } 
 
-/*
+/**
  * aim_directim_connect - connect to buddy for directim
  * @sess: the session to append the conn to,
  * @conn: the BOS connection,
@@ -385,28 +394,25 @@ faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
 { 
   struct aim_conn_t *newconn = NULL;
 
-  if(!sess || !conn || !priv)
+  if (!sess || !conn || !priv)
     return NULL;
   
   /* XXX verify that non-blocking connects actually work */
   newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, priv->ip);
   if (!newconn || (newconn->fd == -1)) { 
-    faimdprintf(2, "could not connect to %s\n", priv->ip);
+    faimdprintf(sess, 2, "could not connect to %s\n", priv->ip);
     perror("aim_newconn");
-    /* Its safe to call conn_kill here since we created the connection */
-    if (newconn)
-      aim_conn_kill(sess, &newconn);
-    return NULL;
+    return newconn;
   }
 
   newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
   newconn->priv = priv;
-  faimdprintf(2, "faim: connected to peer (fd = %d)\n", newconn->fd);
+  faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd);
 
   return newconn;
 } 
 
-/*
+/**
  * aim_directim_getconn - find a directim conn for buddy name
  * @sess: your session,
  * @name: the name to get,  
@@ -419,7 +425,7 @@ faim_export struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess,
   struct aim_conn_t *cur;
   struct aim_directim_priv *priv;
 
-  if(!sess || !name)
+  if (!sess || !name)
     return NULL;
 
   faim_mutex_lock(&sess->connlistlock);
@@ -434,7 +440,7 @@ faim_export struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess,
   return cur;
 } 
 
-/*
+/**
  * aim_accepttransfer - accept a file transfer request
  * @sess: the session,
  * @conn: the BOS conn for the CAP reply
@@ -447,7 +453,7 @@ faim_export struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess,
  * @listingchecksum: checksum of the listing
  * @rendid: capability type (%AIM_CAPS_GETFILE or %AIM_CAPS_SENDFILE)  
  *
- * returns connection or %NULL on error.
+ * Returns new connection or %NULL on error.
  */
 faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess, 
                                                  struct aim_conn_t *conn, 
@@ -466,39 +472,36 @@ faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
   struct aim_msgcookie_t *cachedcook;
   int curbyte, i;
 
-  if(!sess || !conn || !sn || !cookie || !ip)
+  if (!sess || !conn || !sn || !cookie || !ip) {
     return NULL;
+  }
 
-  if(rendid == AIM_CAPS_GETFILE)  {
-    newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
-    newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
+  newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
 
-    if (!newconn || (newconn->fd == -1)) {
-      perror("aim_newconn");
-      faimdprintf(2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0);
-      /* Its safe to call conn_kill here since we created the connection */
-      if (newconn)
-       aim_conn_kill(sess, &newconn);
-      return NULL;
-    } else {
-      priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
-
-      memcpy(priv->cookie, cookie, 8);
-      priv->state = 0;
-      strncpy(priv->sn, sn, MAXSNLEN);
-      strncpy(priv->ip, ip, sizeof(priv->ip));
-      newconn->priv = (void *)priv;
-
-      faimdprintf(2, "faim: connected to peer (fd = %d)\n", newconn->fd);
-    }
+  if (!newconn || (newconn->fd == -1)) {
+    perror("aim_newconn");
+    faimdprintf(sess, 2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0);
+    return newconn;
+  } else {
+    priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
+
+    memcpy(priv->cookie, cookie, 8);
+    priv->state = 0;
+    strncpy(priv->sn, sn, MAXSNLEN);
+    strncpy(priv->ip, ip, sizeof(priv->ip));
+    newconn->priv = (void *)priv;
+
+    faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd);
+  }
+
+  if (rendid == AIM_CAPS_GETFILE)  {
+    newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
 
-    if(rendid == AIM_CAPS_GETFILE) { 
-      faimdprintf(2, "faim: getfile request accept\n");
+      faimdprintf(sess, 2, "faim: getfile request accept\n");
 
-      if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, newconn, 0))) { 
-       faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
-       /* Its safe to call conn_kill here since we created the connection */
-       aim_conn_kill(sess, &newconn);
+      if (!(newoft = aim_tx_new(sess, newconn, AIM_FRAMETYPE_OFT, 0x1108, 0))) { 
+       faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n");
+       /* XXX: conn leak here */
        return NULL;
       } 
 
@@ -506,8 +509,11 @@ faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
       memcpy(newoft->hdr.oft.magic, "OFT2", 4);
       newoft->hdr.oft.hdr2len = 0x100 - 8;
 
-      if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
+      if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) {
+       /* XXX: conn leak here */
+       perror("calloc");
        return NULL;
+      }
 
       fh->encrypt = 0x0000;
       fh->compress = 0x0000;
@@ -542,20 +548,23 @@ faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
       if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { 
        newoft->lock = 0;
        aim_tx_destroy(newoft);
+       /* XXX: conn leak */
+       perror("calloc (1)");
        return NULL;
       } 
 
       memcpy(fh->bcookie, cookie, 8);
 
-      if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh)))
-       printf("eek, bh fail!\n");
+      if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh)))
+       faimdprintf(sess, 1, "eek, bh fail!\n");
 
       newoft->lock = 0;
       aim_tx_enqueue(sess, newoft);
    
-      if(!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) { 
-       faimdprintf(1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n");
-       /* more cleanup */
+      if (!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) { 
+       faimdprintf(sess, 1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n");
+       /* XXX: more cleanup, conn leak */
+       perror("calloc (2)");
        return NULL;
       }
 
@@ -565,53 +574,55 @@ faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
       cachedcook->type = AIM_COOKIETYPE_OFTGET;
       cachedcook->data = (void *)priv;
 
-      if (aim_cachecookie(sess, cachedcook) != 0)
-       faimdprintf(1, "faim: ERROR caching message cookie\n");
+      if (aim_cachecookie(sess, cachedcook) == -1)
+       faimdprintf(sess, 1, "faim: ERROR caching message cookie\n");
 
-      free(fh);
-    } 
+      free(fh);     
  
-    /* OSCAR CAP accept packet */
-    
-    if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16)))
-      return NULL;
-
-    newpacket->lock = 1;
-    curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
+      /* OSCAR CAP accept packet */
+   
+      if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) {
+       return NULL;
+      }
+  } else {
+    return NULL;
+  }
+  
+  newpacket->lock = 1;
+  curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
 
-    for (i = 0;         i < 8;  i++)
-      curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
+  for (i = 0; i < 8; i++)
+    curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
 
-    curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
-    curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn));
-    curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn));
-    curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
-    curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a);
-    curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept*/);
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
+  curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn));
+  curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn));
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a);
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept*/);
 
-    for (i = 0;i < 8; i++) 
-      curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
+  for (i = 0;i < 8; i++) 
+    curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
 
-    curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
-    newpacket->lock = 0;
-    aim_tx_enqueue(sess, newpacket);
+  curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
+  newpacket->lock = 0;
+  aim_tx_enqueue(sess, newpacket);
 
-    return newconn;
-  } return NULL;
+  return newconn;
 }
 
-/*
+/**
  * aim_getlisting(FILE *file) -- get an aim_fileheader_t for a given FILE*
  *  @file is an opened listing file
  * 
  * returns a pointer to the filled-in fileheader_t
  *
- * currently omits checksum. we'll fix this when AOL breaks us, i
+ * Currently omits checksum. we'll fix this when AOL breaks us, i
  * guess.
  *
  */
 
-faim_export struct aim_fileheader_t *aim_getlisting(FILE *file) 
+faim_export struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess, FILE *file) 
 {
   struct aim_fileheader_t *fh;
   u_long totsize = 0, size = 0, checksum = 0xffff0000;
@@ -621,24 +632,24 @@ faim_export struct aim_fileheader_t *aim_getlisting(FILE *file)
   int linelength = 1024;
 
   /* XXX: if we have a line longer than 1024chars, God help us. */
-  if( (linebuf = (char *)calloc(1, linelength)) == NULL ) {
-    faimdprintf(2, "linebuf calloc failed\n");
+  if ( (linebuf = (char *)calloc(1, linelength)) == NULL ) {
+    faimdprintf(sess, 2, "linebuf calloc failed\n");
     return NULL;
   }  
 
-  if(fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */
+  if (fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */
     perror("getlisting END1 fseek:");
-    faimdprintf(2, "getlising fseek END1 error\n");
+    faimdprintf(sess, 2, "getlising fseek END1 error\n");
   }
 
-  if(fgetpos(file, &size) == -1) {
+  if ((size = ftell(file)) == -1) {
     perror("getlisting END1 getpos:");
-    faimdprintf(2, "getlising getpos END1 error\n");
+    faimdprintf(sess, 2, "getlising getpos END1 error\n");
   }
 
-  if(fseek(file, 0, SEEK_SET) != 0) {
+  if (fseek(file, 0, SEEK_SET) != 0) {
     perror("getlesting fseek(SET):");
-    faimdprintf(2, "faim: getlisting: couldn't seek to beginning of listing file\n");
+    faimdprintf(sess, 2, "faim: getlisting: couldn't seek to beginning of listing file\n");
   }
 
   memset(linebuf, 0, linelength);
@@ -651,12 +662,12 @@ faim_export struct aim_fileheader_t *aim_getlisting(FILE *file)
 
     size += strlen(linebuf);
     
-    if(strlen(linebuf) < 23) {
-      faimdprintf(2, "line \"%s\" too short. skipping\n", linebuf);
+    if (strlen(linebuf) < 23) {
+      faimdprintf(sess, 2, "line \"%s\" too short. skipping\n", linebuf);
       continue;
     }
-    if(linebuf[strlen(linebuf)-1] != '\n') {
-      faimdprintf(2, "faim: OFT: getlisting -- hit EOF or line too long!\n");
+    if (linebuf[strlen(linebuf)-1] != '\n') {
+      faimdprintf(sess, 2, "faim: OFT: getlisting -- hit EOF or line too long!\n");
     }
 
     memcpy(sizebuf, linebuf+17, 8);
@@ -665,9 +676,9 @@ faim_export struct aim_fileheader_t *aim_getlisting(FILE *file)
     memset(linebuf, 0, linelength);
   }   
 
-  if(fseek(file, 0, SEEK_SET) == -1) {
+  if (fseek(file, 0, SEEK_SET) == -1) {
     perror("getlisting END2 fseek:");
-    faimdprintf(2, "getlising fseek END2 error\n");
+    faimdprintf(sess, 2, "getlising fseek END2 error\n");
   }  
 
   free(linebuf);
@@ -676,11 +687,9 @@ faim_export struct aim_fileheader_t *aim_getlisting(FILE *file)
    * requires walking the whole listing.txt. it should probably be
    * done at register time and cached, but, eh. */  
 
-  if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
+  if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
     return NULL;
 
-  printf( "faim: OFT: getlisting: totfiles: %u, totsize: %lu, size: %lu\n", totfiles, totsize, size);
-
   fh->encrypt     = 0x0000;
   fh->compress    = 0x0000; 
   fh->totfiles    = totfiles;
@@ -716,18 +725,18 @@ faim_export struct aim_fileheader_t *aim_getlisting(FILE *file)
   memcpy(fh->name, "listing.txt", sizeof(fh->name));
   memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name));
 
-  faimdprintf(2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
+  faimdprintf(sess, 2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
   return fh;
 }
 
-/*
+/**
  * aim_listenestablish - create a listening socket on a port.
  * @portnum: the port number to bind to.  
  *
  * you need to call accept() when it's connected. returns your fd 
  *
  */
-faim_internal int aim_listenestablish(u_short portnum)
+faim_export int aim_listenestablish(u_short portnum)
 {
 #if defined(__linux__)
   /* XXX what other OS's support getaddrinfo? */
@@ -735,7 +744,8 @@ faim_internal int aim_listenestablish(u_short portnum)
   const int on = 1;
   struct addrinfo hints, *res, *ressave;
   char serv[5];
-  sprintf(serv, "%d", portnum);
+
+  snprintf(serv, sizeof(serv), "%d", portnum);
   memset(&hints, 0, sizeof(struct addrinfo));
   hints.ai_flags = AI_PASSIVE;
   hints.ai_family = AF_UNSPEC;
@@ -770,6 +780,7 @@ faim_internal int aim_listenestablish(u_short portnum)
   int listenfd;
   const int on = 1;
   struct sockaddr_in sockin;
+
   if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
     perror("socket(listenfd)");
     return -1;
@@ -798,7 +809,8 @@ faim_internal int aim_listenestablish(u_short portnum)
   return listenfd;
 #endif
 } 
-/*
+
+/**
  * aim_get_command_rendezvous - OFT equivalent of aim_get_command
  * @sess: session to work on
  * @conn: conn to pull data from 
@@ -814,30 +826,33 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
   int flags = 0;
   rxcallback_t userfunc = NULL;
   
+  if (!sess || !conn || !conn->priv)
+    return -1;
+
   memset(hdrbuf1, 0, sizeof(hdrbuf1));
   faim_mutex_lock(&conn->active);
   
  /* gets locked down for the entirety */
 
-  if(conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE ) { 
+  if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE ) { 
     struct aim_filetransfer_priv *ft;
     ft = conn->priv;
-    if(ft->state == 2) { 
+    if (ft->state == 2) {
       /* waiting on listing data */
       int ret = 0;
       char *listing;
       struct command_tx_struct *newoft;
-      if(!(listing = malloc(ft->fh.size))) {
+      if (!(listing = malloc(ft->fh.size))) {
        faim_mutex_unlock(&conn->active);
        return -1;
       }
 
      ft->state = 0;
-     if(aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size)       
-       faimdprintf(2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size);
+     if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size)      
+       faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size);
 
-     if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x120b, conn, 0))) {
-       faimdprintf(2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n");
+     if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) {
+       faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n");
        faim_mutex_unlock(&conn->active);
        free(listing);
        aim_conn_close(conn);
@@ -849,7 +864,9 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
      memcpy(newoft->hdr.oft.magic, "OFT2", 4);
      newoft->hdr.oft.hdr2len = 0x100 - 8;
      
-     /* this is icky. */
+     /* Protocol BS - set nrecvd to size of listing, recvcsum to
+       listing checksum, flags to 0 */
+
      ft->fh.nrecvd = ft->fh.size;
      ft->fh.recvcsum = ft->fh.checksum;
      ft->fh.flags = 0;
@@ -862,70 +879,100 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
        return -1;
      }
      
-     if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh))))
-       printf("eek! bh fail listing\n");
+     if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh))))
+       faimdprintf(sess, 2, "eek! bh fail listing\n");
 
      /* send the 120b  */
      newoft->lock = 0;
      aim_tx_enqueue(sess, newoft);
-     if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) )
+     if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) )
        ret = userfunc(sess, NULL, conn, ft, listing);
      
      faim_mutex_unlock(&conn->active);
      free(listing);
      return ret;
    }
-   if(ft->state == 3) { 
+   if (ft->state == 3) { 
      /* waiting on file data */
-     if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECIEVE)) )  {
+     if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) )  {
        faim_mutex_unlock(&conn->active);
        return userfunc(sess, NULL, conn, ft);
      }
      faim_mutex_unlock(&conn->active);
      return 0;
    }
+   if(ft->state == 4) {
+     if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) ) {
+       faim_mutex_unlock(&conn->active);
+       return userfunc(sess, NULL, conn);
+     }
+     faim_mutex_unlock(&conn->active);
+     aim_conn_close(conn);
+     return 0;
+   }   
  }
  
- if ( (hdrlen = aim_recv(conn->fd, hdrbuf1, 6)) < 6) {
-   faimdprintf(2, "faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", 
 if ( (hdrlen = aim_recv(conn->fd, hdrbuf1, 6)) < 6) {
+    faimdprintf(sess, 2, "faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", 
               conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[2],hdrbuf1[3],hdrbuf1[4],hdrbuf1[5],hdrlen);
    faim_mutex_unlock(&conn->active);
-   if(hdrlen < 0)
+   if (hdrlen < 0)
      perror("read");
    else { /* disconnected */
+     char *screenname = NULL;
+     int ret;
+     struct aim_msgcookie_t *cook;
+
      switch(conn->subtype) { 
      case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { 
-       /* XXX: clean up cookies here ? */
        struct aim_directim_priv *priv = NULL;
-       if(!(priv = (struct aim_directim_priv *)conn->priv) )
+       if (!(priv = (struct aim_directim_priv *)conn->priv) )
         return -1;
-       
-       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTIM);
-       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) ) {
+
+       screenname = strdup(priv->sn);
+
+       cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTIM);
+       aim_cookie_free(sess, cook);
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) ) {
         aim_conn_close(conn);
-        return userfunc(sess, NULL, conn, priv->sn);
+        ret = userfunc(sess, NULL, conn, screenname);
+        free(screenname);
+        return ret;
        }
        break;
      } 
      case AIM_CONN_SUBTYPE_OFT_GETFILE: {
        struct aim_filetransfer_priv *priv;
-       if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
+       if (!(priv = (struct aim_filetransfer_priv *)conn->priv))
         return -1;
-       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
-       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) ) {
+       screenname = strdup(priv->sn);
+
+       cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
+
+       aim_cookie_free(sess, cook);
+
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) ) {
         aim_conn_close(conn);
-        return userfunc(sess, NULL, conn, priv->sn);
+        ret =  userfunc(sess, NULL, conn, screenname);
+        free(screenname);
+        return ret;
        }
        break;
      }
      case AIM_CONN_SUBTYPE_OFT_SENDFILE: {
        struct aim_filetransfer_priv *priv;
-       if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
+       if (!(priv = (struct aim_filetransfer_priv *)conn->priv))
         return -1;
-       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
-       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) ) { 
+
+       screenname = strdup(priv->sn);
+
+       cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
+       aim_cookie_free(sess, cook);
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) ) { 
         aim_conn_close(conn);
-        return userfunc(sess, NULL, conn, priv->sn);
+        ret = userfunc(sess, NULL, conn, screenname);
+        free(screenname);
+        return ret;
        }
        break;
      } 
@@ -946,14 +993,14 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
  if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) {
    perror("read");
-   faimdprintf(2,"faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen);
+   faimdprintf(sess, 2,"faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen);
    free(hdr);
    faim_mutex_unlock(&conn->active);
    aim_conn_close(conn);
    return -1;
    }
  hdrtype = aimutil_get16(hdr);
- printf("\tgot 0x%04x", hdrtype);
+
  switch (hdrtype) {
  case 0x0001: {    /* directim */
    int payloadlength = 0;
@@ -961,8 +1008,9 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_directim_priv *priv;
    int i;
 
-   if(!(priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)))) {
+   if (!(priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)))) {
      faim_mutex_unlock(&conn->active);
+     free(hdr);
      return -1;
    }
    
@@ -971,35 +1019,50 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    snptr = (char *)hdr+38;
    strncpy(priv->sn, snptr, MAXSNLEN);
 
-   faimdprintf(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, snptr);
+
+   free(hdr);
+   hdr = NULL;
 
    if (flags == 0x000e) { 
      faim_mutex_unlock(&conn->active);
-     if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
+     if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
        return userfunc(sess, NULL, snptr);
-   } else
+   } else {
+
      if ((flags == 0x0000) && payloadlength) { 
        unsigned char *msg;
-       if(! (msg = calloc(1, payloadlength+1)) ) {
+
+       if (!(msg = calloc(1, payloadlength+1))) {
         faim_mutex_unlock(&conn->active);
         return -1;
        }
+
        if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) {
         perror("read");
-        printf("faim: rend: read3 error\n");
+        faimdprintf(sess, 2,"faim: rend: read3 error\n");
         free(msg);
         faim_mutex_unlock(&conn->active);
         aim_conn_close(conn);
         return -1;
        }
+
        faim_mutex_unlock(&conn->active);
        msg[payloadlength] = 0x00;
-       faimdprintf(2, "faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
-       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
+       faimdprintf(sess, 2, "faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
         i = userfunc(sess, NULL, conn, snptr, msg);
+       else {
+         faimdprintf(sess, 0, "directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+        i = 1;
+       }
+
        free(msg);
+
        return i;
      }
+   }
    break;
  }
  case 0x1108: { /* getfile listing.txt incoming tx->rx */
@@ -1007,24 +1070,35 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_fileheader_t *fh;
    struct aim_msgcookie_t *cook;
    struct command_tx_struct *newoft;
-   faimdprintf(2,"faim: rend: fileget 0x1108\n");
+
+   faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n");
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
      faim_mutex_unlock(&conn->active);
      free(fh);
      return -1;
    }
+
    ft = cook->data;
-   ft->state = 2;
 
    /* we're waaaaiiiting.. for listing.txt */
+   ft->state = 2;
 
    memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
-   aim_cachecookie(sess, cook);
    free(fh);
 
-   if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1209, conn, 0))) {
+   if(aim_cachecookie(sess, cook) == -1) {
+     faimdprintf(sess, 1, "error caching cookie\n");
+     return -1;
+   }     
+
+   if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) {
      aim_conn_close(conn);
      return -1;
    }
@@ -1038,7 +1112,7 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
      return -1;
    }
 
-   if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
+   if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
      newoft->lock = 0;
      aim_tx_destroy(newoft);
      return -1;
@@ -1053,26 +1127,33 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_filetransfer_priv *ft;
    struct aim_fileheader_t *fh;
    struct aim_msgcookie_t *cook;
-   int ret;
+   int ret = 0;
+
+   if(!(fh = aim_oft_getfh(hdr))) {
+     perror("getfh");
+     free(hdr);
+     return -1;
+   }   
+
+   free(hdr);
+   hdr = NULL;
 
-   fh = aim_oft_getfh(hdr);
    faim_mutex_unlock(&conn->active);
 
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))
-     faimdprintf(2, "shit, no cookie in 0x1209. (%i/%s)going to crash..\n", 
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))
+     faimdprintf(sess, 2, "shit, no cookie in 0x1209. (%i/%s)going to crash..\n", 
                 AIM_COOKIETYPE_OFTGET, fh->bcookie);
 
    ft = cook->data;   
 
-   if(ft->fh.size != fh->size)
-     faimdprintf(2, "hrm. ft->fh.size (%ld) != fh->size (%ld). um. using ft->fh.size\n", 
+   if (ft->fh.size != fh->size)
+     faimdprintf(sess, 2, "hrm. ft->fh.size (%ld) != fh->size (%ld). um. using ft->fh.size\n", 
                 ft->fh.size, fh->size);
-
    
-   if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ)))
-     ret = userfunc(sess, NULL, conn, fh);   
+   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ)))
+     ret = userfunc(sess, NULL, conn, fh);
 
-   faimdprintf(2, "faim: get_command_rendezvous: hit end of 1209\n");
+   faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n");
 
    free(fh);
 
@@ -1086,18 +1167,28 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_fileheader_t *fh;
 
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
 
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))     {
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))     {
      free(fh);
      return -1;
    }
 
-   ft = cook->data;
-   aim_cachecookie(sess, cook);
    free(fh);
 
-   /* XXX: call listing.txt rx confirm */
+   ft = cook->data;
+
+   if (aim_cachecookie(sess, cook) == -1) {
+     return -1;
+   }
+
+   if((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM)))
+     return userfunc(sess, NULL, conn);
+
    break;
  }
  case 0x120c: { /* getfile file request */
@@ -1105,13 +1196,19 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_msgcookie_t *cook;
    struct aim_fileheader_t *fh;
    struct command_tx_struct *newoft;
-   int i;
+   int i = 0;
 
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
 
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+     faimdprintf(sess, 2, "no cookie in 120c\n");
      return -1;
+   }
 
    ft = cook->data;
    memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
@@ -1119,16 +1216,16 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
    aim_cachecookie(sess, cook);
 
-   faimdprintf(2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
+   faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
 
-   if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
+   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
      i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie);
 
-   if(i < 0)
-     return -1;
+   if (i < 0)
+     return i;
 
-   if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0))) {
-     faimdprintf(2, "faim: send_final_transfer: tx_new OFT failed\n");
+   if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) {
+     faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n");
      return -1;
    }
 
@@ -1152,7 +1249,7 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    newoft->lock = 0;
    aim_tx_enqueue(sess, newoft);
 
-   faimdprintf(2, "faim: OFT: OFT file header enqueued.\n");
+   faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n");
 
    return i;
 
@@ -1165,10 +1262,13 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct command_tx_struct *newoft;
 
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
 
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
-     printf("fucking no cookie\n");
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
      free(fh);
      return -1;
    }
@@ -1177,13 +1277,17 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    ft = cook->data;
 
    ft->state = 3;
-   aim_cachecookie(sess, cook);
 
-   faimdprintf(2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name);
+   if (aim_cachecookie(sess, cook) == -1) {
+     perror("aim_cachecookie");
+     return -1;
+   }
+
+   faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name);
 
-   if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0202, conn, 0))) {
+   if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) {
      aim_conn_close(conn);
-     faimdprintf(2, "faim: send_final_transfer: tx_new OFT failed\n");
+     faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n");
      return -1;
    }
 
@@ -1203,32 +1307,36 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    newoft->lock = 0;
    aim_tx_enqueue(sess, newoft);
 
-   faimdprintf(2, "faim: OFT: OFT 0x0202 enqueued.\n");
+   faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n");
 
-   if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
+   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
      return 1;
 
    break;
  }
- case 0x0202: {    /* get file: ready to recieve data */
+ case 0x0202: {    /* get file: ready to receive data */
    struct aim_fileheader_t *fh;
    struct aim_filetransfer_priv *ft;
    struct aim_msgcookie_t *cook;
    int ret = 1;
 
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
 
-   if(!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
      free(fh);
      return -1;
    }
    
    ft = cook->data;
 
-   faimdprintf(2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
+   faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
 
-   if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) )
+   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) )
      ret = userfunc(sess, NULL, conn, fh);
 
    free(fh);
@@ -1241,16 +1349,20 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    struct aim_fileheader_t *fh;
 
    fh = aim_oft_getfh(hdr);
+
+   free(hdr);
+   hdr = NULL;
+
    faim_mutex_unlock(&conn->active);
 
-   faimdprintf(2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
+   faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
 
-   if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
+   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
      i = userfunc(sess, NULL, conn, fh);
    else 
      i = 1;
 
-   if(conn)
+   if (conn)
      aim_conn_close(conn);
 
    free(fh);
@@ -1258,28 +1370,34 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
    return i;
    break;
  }
- default: { 
-       faimdprintf(2,"faim: OFT frame: uknown type %04x\n", hdrtype);
-       faim_mutex_unlock(&conn->active);
-       break;
+ default: {
+   free(hdr);
+   hdr = NULL;
+   faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype);
+   faim_mutex_unlock(&conn->active);
+   break;
  } 
  } /* switch */
- free(hdr);
+ if (hdr) {
+    faimdprintf(sess, 0, "hdr wasn't freed by a rendezvous switch case (hdrtype: %0x04x)!\n", hdrtype);
+   free(hdr);
+   hdr = NULL;
+ }
  return 0;
 }
  
-/*
- * aim_oft_getfh - extracts a aim_fileheader_t from buffer hdr.
+/**
+ * aim_oft_getfh - extracts an &aim_fileheader_t from buffer hdr.
  * @hdr: buffer to extract header from  
  *
- * returns pointer to struct on success; %NULL on error.  
+ * returns pointer to new struct on success; %NULL on error.  
  *
  */
 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) 
 {
   struct aim_fileheader_t *fh;
   int i, j;
-  if(!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
+  if (!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
     return NULL;
   
   /* [0] and [1] are the type. we can ignore those here. */
@@ -1339,69 +1457,74 @@ static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr)
   return fh;
 } 
 
-/*
+/**
  * aim_oft_checksum - calculate oft checksum of buffer
  * @buffer: buffer of data to checksum
  * @bufsize: size of buffer
  * @checksum: pointer to integer to place result in (pointer!) 
  *
- * note that checksum is a pointer. checksum should be filled with
+ *
+ * Note that checksum is a pointer. Checksum should be filled with
  * 0xFFFF0000 for each new file; you can have this checksum chunks of
  * files in series if you just call it repeatedly in a for(; ; ) loop
- * and don't reset the checksum between each call. and you thought we
+ * and don't reset the checksum between each call. And you thought we
  * didn't care about you and your pathetic client's meomry footprint
  * ;^) 
  *
+ *
+ * Also, it's been said that this is incorrect as currently
+ * written. You were warned.
  */
-faim_export int aim_oft_checksum(char *buffer, int bufsize, int *checksum){ short check0, check1;
- int i;
- check0 = ((*checksum & 0xFF000000) >> 16);
- check1 = ((*checksum & 0x00ff0000) >> 16);
- for(i = 0; i < bufsize; i++) {
-   if(i % 2) { /* use check1 -- second byte */
-     if ( (short)buffer[i] > check1 ) { /* wrapping */
-       check1 += 0x100;  /* this is a cheap way to wrap */
-
-       /* if we're wrapping, decrement the other one */
-       /* XXX: check this corner case */
-       if(check0 == 0) 
-        check0 = 0x00ff;
-       else 
-        check0--;
-     } 
-     check1 -= buffer[i];
-   } else { /* use check0 -- first byte  */
-     if ( (short)buffer[i] > check0 ) { /* wrapping */
-       check0 += 0x100;       /* this is a cheap way to wrap */
+faim_export int aim_oft_checksum(struct aim_session_t *sess, char *buffer, int bufsize, int *checksum)
+{
+  short check0, check1;
+  int i;
+  check0 = ((*checksum & 0xFF000000) >> 16);
+  check1 = ((*checksum & 0x00ff0000) >> 16);
+  for(i = 0; i < bufsize; i++) {
+    if (i % 2) { /* use check1 -- second byte */
+      if ( (short)buffer[i] > check1 ) { /* wrapping */
+       check1 += 0x100;  /* this is a cheap way to wrap */
+
+       /* if we're wrapping, decrement the other one */
+       /* XXX: check this corner case */
+       if (check0 == 0) 
+         check0 = 0x00ff;
+       else 
+         check0--;
+      } 
+      check1 -= buffer[i];
+    } else { /* use check0 -- first byte  */
+      if ( (short)buffer[i] > check0 ) { /* wrapping */
+       check0 += 0x100;       /* this is a cheap way to wrap */
   
-       /* if we're wrapping, decrement the other one */
-        /* XXX: check this corner case */
-       if(check1 == 0) 
-        check1 = 0x00ff;
-       else 
-        check1--;
-     } 
-     check0 -= buffer[i];
-     
- }
+       /* if we're wrapping, decrement the other one */
+       /* XXX: check this corner case */
+       if (check1 == 0) 
+         check1 = 0x00ff;
+       else 
+         check1--;
+      
+      check0 -= buffer[i];
+    } 
 }
 
if(check0 > 0xff || check1 > 0xff)  { 
-     /* they shouldn't be able to do this. error! */
-   faimdprintf(2, "check0 or check1 is too high: 0x%04x, 0x%04x\n", check0, check1);
-     return -1;
- } 
 if (check0 > 0xff || check1 > 0xff)  { 
+    /* they shouldn't be able to do this. error! */
+    faimdprintf(sess, 2, "check0 or check1 is too high: 0x%04x, 0x%04x\n", check0, check1);
+    return -1;
 
 
- /* grab just the lowest byte; this should be clean, but just in
-    case */
- check0 &= 0xff;
- check1 &= 0xff;
 /* grab just the lowest byte; this should be clean, but just in
+     case */
 check0 &= 0xff;
 check1 &= 0xff;
 
- *checksum = ((check0 * 0x1000000) + (check1 * 0x10000));
- return *checksum;
 *checksum = ((check0 * 0x1000000) + (check1 * 0x10000));
 return *checksum;
 } 
 
-/*
+/**
  * aim_oft_buildheader - fills a buffer with network-order fh data
  * @dest: buffer to fill -- pre-alloced
  * @fh: fh to get data from  
@@ -1413,7 +1536,7 @@ faim_export int aim_oft_checksum(char *buffer, int bufsize, int *checksum){ shor
 faim_internal int aim_oft_buildheader(unsigned char *dest,struct aim_fileheader_t *fh) 
 { 
   int i, curbyte;
-  if(!dest || !fh)
+  if (!dest || !fh)
     return -1;
   curbyte = 0;
   for(i = 0; i < 8; i++) 
@@ -1452,180 +1575,20 @@ faim_internal int aim_oft_buildheader(unsigned char *dest,struct aim_fileheader_
   curbyte += 64;
   return curbyte;
 }
-#if 0 
-/*
-* aim_getfile_send - send a FULL file down (ie: blocking; that is: DON'T USE IT, use send_chunk below.)
-* @conn: the OFT connection to shove the data down,
-* @tosend: is the FILE
-* for the file to send
-* @fh: the filled-in fh value 
-
-*
-* returns -1 on error, 1 on success. This sends the whold file and
-* blocks, so it will totally mess you up if you use it. use the
-* send_chunk below and work out a schduling setup or some such. 
-
-*
-*/
-faim_export int aim_getfile_send(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh)
-{ 
-  int pos, bufpos, i;
-  const int bufsize = 4096;
-  char *buf;
-  
- /* sanity checks
-  */
-
- if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->subtype != AIM_CONN_SUBTYPE_OFT_GETFILE)
-   { faimdprintf(1, "getfile_send: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
-   return -1;
-   }
- if(!tosend)
-   { faimdprintf(1, "getfile_send: file pointer isn't valid\n");
-   return -1;
-   }
- if(!fh)
-   { faimdprintf(1, "getfile_send: fh isn't valid\n");
-   return -1;
-   } 
- /* real code
-  */
-
- if(!(buf = (char *)calloc(1, bufsize)))
-   { perror("faim: getfile_send: calloc:");
-   faimdprintf(2, "getfile_send calloc error\n");
-   return -1;
-   } pos = 0;
- if( fseek(tosend, 0, SEEK_SET) == -1)
-   { perror("faim: getfile_send: fseek:");
-   faimdprintf(2, "getfile_send fseek error\n");
-   } faimdprintf(2, "faim: getfile_send: using %i byte blocks\n", bufsize);
- for(pos = 0;
-     pos < fh->size;
-     pos++) { bufpos = pos % bufsize;
-     if(bufpos == 0 && pos > 0)
-       { 
-        /* filled our buffer. spit it across the wire
-         */
-
-        if ( (i = send(conn->fd, buf, bufsize, 0)) != bufsize )
-          { perror("faim: getfile_send: write1: ");
-          faimdprintf(1, "faim: getfile_send: whoopsy, didn't write it all...\n");
-          free(buf);
-          return -1;
-          } }
-     if( (buf[bufpos] = fgetc(tosend)) == EOF)
-       {
-        if(pos != fh->size)
-          { printf("faim: getfile_send: hrm... apparent early EOF at pos 0x%x of 0x%lx\n", pos, fh->size);
-          faimdprintf(1, "faim: getfile_send: hrm... apparent early EOF at pos 0x%lx of 0x%lx\n", pos, fh->size);
-          free(buf);
-          return -1;
-          } } }
- if( (i = send(conn->fd, buf, bufpos+1, 0)) != (bufpos+1))
-   { perror("faim: getfile_send: write2: ");
-   faimdprintf(1, "faim: getfile_send cleanup: whoopsy, didn't write it all...\n");
-   free(buf);
-   return -1;
-   } free(buf);
- fclose(tosend);
- return 1;
-}
-/*
-* aim_getfile_send_chunk - send a chunk of a file down a conn
-* @conn: the OFT connection to shove the data down,
-* @tosend: the buffer to send
-* @fh: the filled-in fh value
-* @pos: the position to start at (see below)
-* @bufsize: the size of the chunk to send 
-
-*
-* returns -1 on error, new pos on success.
-* Notes on usage:
-* You don't really have to keep track of pos if you don't want
-* to. just always call with -1 for pos, and it'll use the one
-* contained within the FILE
-*. 
-
-*
-* if (pos + chunksize > fh->size), we only send as much data as we
-* can get (ie: up to fh->size. 
-
-*
-* the value of pos: at beginning should be 0, after 5 bytes are sent
-* should be 5); -1 for "don't seek" 
-
-*
-* GOING TO BE CHANGED TO USE unsigned char
-* BUFFERS!!!
-*/
-faim_export int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
-{
- int bufpos;
- char *buf;
-
- /* sanity checks
-  */
-
- if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->type != AIM_CONN_SUBTYPE_OFT_GETFILE)
-   { faimdprintf(1, "faim: getfile_send_chunk: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
-   return -1;
-   }
- if(!tosend)
-   { faimdprintf(1, "faim: getfile_send_chunk: file pointer isn't valid\n");
-   return -1;
-   }
- if(!fh)
-   { faimdprintf(1, "faim: getfile_send_chunk: fh isn't valid\n");
-   return -1;
-   } 
- /* real code
-  */
-
- if(!(buf = (char *)calloc(1, bufsize)))
-   { perror("faim: getfile_send_chunk: calloc:");
-   faimdprintf(2, "faim: getfile_send_chunk calloc error\n");
-   return -1;
-   }
- if(pos != -1)
-   {
-     if( fseek(tosend, pos, SEEK_SET) == -1)
-       { perror("faim: getfile_send_chunk: fseek:");
-       faimdprintf(2, "faim: getfile_send_chunk fseek error\n");
-       } } faimdprintf(2, "faim: getfile_send_chunk: using %i byte blocks\n", bufsize);
- for(bufpos = 0;
-     pos < fh->size;
-     bufpos++, pos++) {
-   if( (buf[bufpos] = fgetc(tosend)) == EOF)
-     {
-       if(pos != fh->size)
-        { faimdprintf(1, "faim: getfile_send_chunk: hrm... apparent early EOF at pos 0x%x of 0x%x\n", pos, fh->size);
-        free(buf);
-        return -1;
-        } } }
- if( send(conn->fd, buf, bufpos+1, 0) != (bufpos+1))
-   { faimdprintf(1, "faim: getfile_send_chunk cleanup: whoopsy, didn't write it all...\n");
-   free(buf);
-   return -1;
-   } free(buf);
- return (pos + bufpos);
-}
-#endif 
-/*
-* aim_tx_destroy - free's tx_command_t's
-* @command: the command to free 
 
-*
-* if command is locked, doesn't free.
-* returns -1 on error (locked struct); 0 on success. 
 
-*
-*/
+/**
+ * aim_tx_destroy - free's tx_command_t's
+ * @command: the command to free  
+ *
+ * if command is locked, doesn't free.
+ * returns -1 on error (locked struct); 0 on success.  
+ *
+ */
 faim_internal int aim_tx_destroy(struct command_tx_struct *command){
-  if(command->lock)
+  if (command->lock)
     return -1;
-  if(command->data)
+  if (command->data)
     free(command->data);
   if (command->hdrtype == AIM_FRAMETYPE_OFT && command->hdr.oft.hdr2)
     free(command->hdr.oft.hdr2);
@@ -1633,225 +1596,230 @@ faim_internal int aim_tx_destroy(struct command_tx_struct *command){
   return 0;
 } 
 
-/*
- * aim_getfile_intitiate - For those times when we want to open up the getfile dialog ourselves.
+/**
+ * aim_getfile_intitiate - Request an OFT getfile session
  * @sess: your session,
  * @conn: the BOS conn,
  * @destsn is the SN to connect to.
+ * 
+ * returns a new &aim_conn_t on success, %NULL on error
  */
 faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess, struct aim_conn_t *conn, char *destsn)
 { 
   struct command_tx_struct *newpacket;
- struct aim_conn_t *newconn;
- struct aim_filetransfer_priv *priv;
- struct aim_msgcookie_t *cookie;
- int curbyte, i, listenfd;
- short port = 4443;
- struct hostent *hptr;
- struct utsname myname;
- char cap[16];
- char d[4];
 struct aim_conn_t *newconn;
 struct aim_filetransfer_priv *priv;
 struct aim_msgcookie_t *cookie;
 int curbyte, i, listenfd;
 short port = 4443;
 struct hostent *hptr;
 struct utsname myname;
 char cap[16];
 char d[4];
  
- /* Open our socket */
 /* Open our socket */
 
if( (listenfd = aim_listenestablish(port)) == -1)
-   return NULL;
 if ( (listenfd = aim_listenestablish(port)) == -1)
+    return NULL;
 
- /* get our local IP */
 /* get our local IP */
 
if(uname(&myname) < 0)
-   return NULL;
if( (hptr = gethostbyname(myname.nodename)) == NULL)
-   return NULL;
- memcpy(&d, hptr->h_addr_list[0], 4);
 if (uname(&myname) < 0)
+    return NULL;
 if ( (hptr = gethostbyname(myname.nodename)) == NULL)
+    return NULL;
 memcpy(&d, hptr->h_addr_list[0], 4);
 
- /* XXX: this probably isn't quite kosher, but it works */
- aim_putcap(cap, 16, AIM_CAPS_GETFILE);
+  aim_putcap(cap, 16, AIM_CAPS_GETFILE);
 
- /* create the OSCAR packet */
 /* create the OSCAR packet */
 
if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x42)))
-   return NULL;
- newpacket->lock = 1;
 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(destsn)+4+4+0x42)))
+    return NULL;
 newpacket->lock = 1;
 
- /* lock struct */
- curbyte = 0;
- curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
 /* lock struct */
 curbyte = 0;
 curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
 
- /* XXX: check the cookie before commiting to using it */
 /* XXX: check the cookie before commiting to using it */
 
- /* Generate a random message cookie
-  * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. */
- for (i=0; i<7; i++) 
-   curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 10));
 /* Generate a random message cookie
+   * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. */
 for (i=0; i<7; i++) 
+    curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 10));
 
- curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 
- /* grab all the data for cookie caching. */
+  /* grab all the data for cookie caching. */
+  if (!(cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t))))
+    return NULL;
+  memcpy(cookie->cookie, newpacket->data+curbyte-8, 8);
+  cookie->type = AIM_COOKIETYPE_OFTGET;
 
- cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t));
- memcpy(cookie->cookie, newpacket->data+curbyte-8, 8);
- cookie->type = AIM_COOKIETYPE_OFTGET;
+  if (!(priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv))))
+    return NULL;
+  memcpy(priv->cookie, cookie, 8);
+  memcpy(priv->sn, destsn, sizeof(priv->sn));
+  memcpy(priv->fh.name, "listing.txt", strlen("listing.txt"));
+  priv->state = 1;
 
- priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
- memcpy(priv->cookie, cookie, 8);
- memcpy(priv->sn, destsn, sizeof(priv->sn));
- memcpy(priv->fh.name, "listing.txt", strlen("listing.txt"));
- priv->state = 1;
- cookie->data = priv;
- conn->priv = priv;
- aim_cachecookie(sess, cookie);
+  cookie->data = priv;
 
- /* cache da cookie */
- /* Channel ID */
- curbyte += aimutil_put16(newpacket->data+curbyte,0x0002);
+  aim_cachecookie(sess, cookie);
+
 /* Channel ID */
 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002);
 
- /* Destination SN (prepended with byte length) */
- curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
- curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
 /* Destination SN (prepended with byte length) */
 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
 
- /* enTLV start */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0042);
 /* enTLV start */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0042);
 
- /* Flag data / ICBM Parameters? */
- curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
- curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 /* Flag data / ICBM Parameters? */
 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 
- /* Cookie */
- curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8);
 /* Cookie */
 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8);
 
- /* Capability String */
- curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10);
 /* Capability String */
 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10);
 
- /* 000a/0002 : 0001 */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
 /* 000a/0002 : 0001 */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
 
- /* 0003/0004: IP address */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
- for(i = 0; i < 4; i++)
-   curbyte += aimutil_put8(newpacket->data+curbyte, d[i]);
 /* 0003/0004: IP address */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
 for(i = 0; i < 4; i++)
+    curbyte += aimutil_put8(newpacket->data+curbyte, d[i]);
 
- /* already in network byte order  */
 /* already in network byte order  */
  
- /* 0005/0002: Port */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
- curbyte += aimutil_put16(newpacket->data+curbyte, port);
 /* 0005/0002: Port */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
 curbyte += aimutil_put16(newpacket->data+curbyte, port);
 
- /* 000f/0000: ?? */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
 /* 000f/0000: ?? */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
 
- /* 2711/000c: ?? */
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c);
- curbyte += aimutil_put32(newpacket->data+curbyte, 0x00120001);
 /* 2711/000c: ?? */
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711);
 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c);
 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00120001);
 
- for(i = 0; i < 0x000c - 4; i++)
-   curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 for(i = 0; i < 0x000c - 4; i++)
+    curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
 
- newpacket->commandlen = curbyte;
- newpacket->lock = 0;
- aim_tx_enqueue(sess, newpacket);
 newpacket->commandlen = curbyte;
 newpacket->lock = 0;
 aim_tx_enqueue(sess, newpacket);
 
- /* allocate and set up our connection */
 /* allocate and set up our connection */
 
- i = fcntl(listenfd, F_GETFL, 0);
- fcntl(listenfd, F_SETFL, i | O_NONBLOCK);
- newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL);
 i = fcntl(listenfd, F_GETFL, 0);
 fcntl(listenfd, F_SETFL, i | O_NONBLOCK);
 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL);
 
- if (!newconn){ 
-   perror("aim_newconn");
-   return NULL;
- }
 if (!newconn){ 
+    perror("aim_newconn");
+    return NULL;
 }
 
- newconn->fd = listenfd;
- newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
- newconn->priv = priv;
faimdprintf(2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
 newconn->fd = listenfd;
 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
 newconn->priv = priv;
 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
 
- return newconn;
 return newconn;
 }
  
-/*
+/**
  * aim_oft_getfile_request - request a particular file over an established getfile connection
  * @sess: your session
  * @conn: the established OFT getfile connection
  * @name: filename to request
  * @size: size of the file 
  *
+ *
+ * returns -1 on error, 0 on successful enqueuing
  */
 faim_export int aim_oft_getfile_request(struct aim_session_t *sess, struct aim_conn_t *conn, const unsigned char *name, const int size)
 {
   struct command_tx_struct *newoft;
   struct aim_filetransfer_priv *ft;
-  if(!sess || !conn || !conn->priv || !name)
-    return 0;
+  if (!sess || !conn || !conn->priv || !name)
+    return -1;
 
if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x120c, conn, 0))) {
-   faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
-   return -1;
- }
 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120c, 0))) {
+    faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n");
+    return -1;
 }
 
- newoft->lock = 1;
 newoft->lock = 1;
 
- memcpy(newoft->hdr.oft.magic, "OFT2", 4);
- newoft->hdr.oft.hdr2len = 0x100 - 8;
 memcpy(newoft->hdr.oft.magic, "OFT2", 4);
 newoft->hdr.oft.hdr2len = 0x100 - 8;
 
- ft = (struct aim_filetransfer_priv *)conn->priv;
- ft->fh.filesleft = 1;
- ft->fh.totfiles = 1;
- ft->fh.totparts = 1;
- ft->fh.partsleft = 1;
- ft->fh.totsize = size;
- ft->fh.size = size;
- ft->fh.checksum = 0;
- memcpy(ft->fh.name, name, strlen(name));
- memset(ft->fh.name+strlen(name), 0, 1);
-
if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
-   newoft->lock = 0;
-   aim_tx_destroy(newoft);
-   return -1;
- }
 ft = (struct aim_filetransfer_priv *)conn->priv;
 ft->fh.filesleft = 1;
 ft->fh.totfiles = 1;
 ft->fh.totparts = 1;
 ft->fh.partsleft = 1;
 ft->fh.totsize = size;
 ft->fh.size = size;
 ft->fh.checksum = 0;
 memcpy(ft->fh.name, name, strlen(name));
 memset(ft->fh.name+strlen(name), 0, 1);
+
 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) {
+    newoft->lock = 0;
+    aim_tx_destroy(newoft);
+    return -1;
 }
 
if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
-   newoft->lock = 0;
-   aim_tx_destroy(newoft);
-   return -1;
- }
 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) {
+    newoft->lock = 0;
+    aim_tx_destroy(newoft);
+    return -1;
 }
 
- newoft->lock = 0;
 newoft->lock = 0;
 
- aim_tx_enqueue(sess, newoft);
- return 0;
 aim_tx_enqueue(sess, newoft);
 return 0;
 }
  
-/*
+/**
  * aim_oft_getfile_ack - acknowledge a getfile download as complete
  * @sess: your session
  * @conn: the getfile conn to send the ack over 
  *
- * call this function after you have read all the data in a particular
- * filetransfer 
+ * Call this function after you have read all the data in a particular
+ * filetransfer. Returns -1 on error, 0 on apparent success
  *
  */
-faim_export int aim_oft_getfile_ack(struct aim_session_t *sess, struct aim_conn_t *conn) {
+faim_export int aim_oft_getfile_ack(struct aim_session_t *sess, struct aim_conn_t *conn) 
+{
   struct command_tx_struct *newoft;
   struct aim_filetransfer_priv *ft;
 
-  if(!sess || !conn || !conn->priv)
+  if (!sess || !conn || !conn->priv)
     return -1;
 
-  if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0202, conn, 0))) {
-    faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
+  if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) {
+    faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n");
     return -1;
   } 
 
@@ -1868,7 +1836,7 @@ faim_export int aim_oft_getfile_ack(struct aim_session_t *sess, struct aim_conn_
 
  ft = (struct aim_filetransfer_priv *)conn->priv;
 
- if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
+ if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
    newoft->lock = 0;
    aim_tx_destroy(newoft);
    return -1;
@@ -1879,7 +1847,7 @@ faim_export int aim_oft_getfile_ack(struct aim_session_t *sess, struct aim_conn_
  return 0;
 }
  
-/*
+/**
  * aim_oft_getfile_end - end a getfile.
  * @sess: your session
  * @conn: the getfile connection 
@@ -1892,11 +1860,11 @@ faim_export int aim_oft_getfile_end(struct aim_session_t *sess, struct aim_conn_
   struct command_tx_struct *newoft;
   struct aim_filetransfer_priv *ft;
   
-  if(!sess || !conn || !conn->priv)
+  if (!sess || !conn || !conn->priv)
     return -1;
 
-  if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0204, conn, 0))) {
-    faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
+  if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0204, 0))) {
+    faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n");
     return -1;
   }
   
@@ -1917,7 +1885,7 @@ faim_export int aim_oft_getfile_end(struct aim_session_t *sess, struct aim_conn_
   ft->fh.recvcsum = ft->fh.checksum;
   ft->fh.flags = 0x21;
   
-  if(!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
+  if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
     newoft->lock = 0;
     aim_tx_destroy(newoft);
     return -1;
index ce4886afed67a003047031aa8530d19e9c09c1f7..58ce8c7e3860499ce514e039ebb9c3b839a6ecfa 100644 (file)
--- a/src/im.c
+++ b/src/im.c
@@ -86,7 +86,7 @@ faim_export unsigned long aim_send_im(struct aim_session_t *sess,
   if (strlen(msg) >= MAXMSGLEN)
     return -1;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(msg)+256)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(msg)+256)))
     return -1;
 
   newpacket->lock = 1; /* lock struct */
@@ -209,7 +209,7 @@ faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
   i += 2;
 
   if (channel != 0x01) {
-    printf("faim: icbm: ICBM recieved on unsupported channel.  Ignoring. (chan = %04x)\n", channel);
+    faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel.  Ignoring. (chan = %04x)\n", channel);
     return 1;
   }
 
@@ -243,7 +243,7 @@ faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
     msg = msgblock+j;
   }
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0004, 0x0006)) || (i = 0))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0006)) || (i = 0))
     i = userfunc(sess, command, channel, sn, msg, icbmflags, flag1, flag2);
   
   if (msgblock)
@@ -307,11 +307,10 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
   /*
    *
    */
-  if ((channel != 0x01) && (channel != 0x02))
-    {
-      printf("faim: icbm: ICBM received on an unsupported channel.  Ignoring.\n (chan = %04x)", channel);
-      return 1;
-    }
+  if ((channel != 0x01) && (channel != 0x02)) {
+    faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel.  Ignoring.\n (chan = %04x)", channel);
+    return 1;
+  }
 
   /*
    * Extract the standard user info block.
@@ -329,7 +328,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
    * never be two TLVs of the same type in one block.
    * 
    */
-  i += aim_extractuserinfo(command->data+i, &userinfo);
+  i += aim_extractuserinfo(sess, command->data+i, &userinfo);
   
   /*
    * Read block of TLVs (not including the userinfo data).  All 
@@ -370,7 +369,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        */
       msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
       if (!msgblocktlv || !msgblocktlv->value) {
-       printf("faim: icbm: major error! no message block TLV found!\n");
+       faimdprintf(sess, 0, "icbm: major error! no message block TLV found!\n");
        aim_freetlvchain(&tlvlist);
        return 1;
       }
@@ -425,7 +424,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
       j += 2;
       
       if (flag1 || flag2)
-       printf("faim: icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
+       faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
       
       /* 
        * Message string. 
@@ -438,7 +437,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
       /*
        * Call client.
        */
-      userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+      userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
       if (userfunc)
        i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2, finlen, fingerprint);
       else 
@@ -458,7 +457,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        */
       block1 = aim_gettlv(tlvlist, 0x0005, 1);
       if (!block1) {
-       printf("faim: no tlv 0x0005 in rendezvous transaction!\n");
+       faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
        aim_freetlvchain(&tlvlist);
        return 1; /* major problem */
       }
@@ -474,7 +473,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        * Next comes the cookie.  Should match the ICBM cookie.
        */
       if (memcmp(block1->value+2, cookie, 8) != 0) 
-       printf("faim: rend: warning cookies don't match!\n");
+       faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
 
       /*
        * The next 16bytes are a capability block so we can
@@ -488,9 +487,9 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        * Read off one capability string and we should have it ID'd.
        * 
        */
-      reqclass = aim_getcap(block1->value+2+8, 0x10);
+      reqclass = aim_getcap(sess, block1->value+2+8, 0x10);
       if (reqclass == 0x0000) {
-       printf("faim: rend: no ID block\n");
+       faimdprintf(sess, 0, "rend: no ID block\n");
        aim_freetlvchain(&tlvlist);
        return 1;
       }
@@ -509,13 +508,11 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        
        type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
 
-       if(type != 17) {
-         if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) {
-           printf("faim: non-data rendezvous thats not in cache!\n");
-           aim_freetlvchain(&list2);
-           aim_freetlvchain(&tlvlist);
-           return 1;
-         }
+       if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
+         faimdprintf(sess, 0, "non-data rendezvous thats not in cache %d/%s!\n", type, cookie);
+         aim_freetlvchain(&list2);
+         aim_freetlvchain(&tlvlist);
+         return 1;
        }
 
        if (cook->type == AIM_COOKIETYPE_OFTGET) {
@@ -531,15 +528,15 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                errorcode = aim_gettlv16(list2, 0x000b, 1);
              
              if (errorcode)
-               printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
+               faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
            }
          } else {
-           printf("faim: no data attached to file transfer\n");
+           faimdprintf(sess, 0, "no data attached to file transfer\n");
          }
        } else if (cook->type == AIM_CAPS_VOICE) {
-         printf("faim: voice request cancelled\n");
+         faimdprintf(sess, 0, "voice request cancelled\n");
        } else {
-         printf("faim: unknown cookie cache type %d\n", cook->type);
+         faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
        }
        
        if (list2)
@@ -557,7 +554,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
         * Call client.
         */
 #if 0
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
@@ -571,7 +568,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
       } else if (reqclass & AIM_CAPS_VOICE) {
        struct aim_msgcookie_t *cachedcook;
 
-       printf("faim: rend: voice!\n");
+       faimdprintf(sess, 0, "rend: voice!\n");
 
        if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
          return 1;
@@ -580,15 +577,15 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
        cachedcook->data = NULL;
 
-       if (aim_cachecookie(sess, cachedcook) != 0)
-         printf("faim: ERROR caching message cookie\n");
+       if (aim_cachecookie(sess, cachedcook) == -1)
+         faimdprintf(sess, 0, "ERROR caching message cookie\n");
 
        /* XXX: implement all this */
 
        /*
         * Call client.
         */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0)) {
          i = userfunc(sess, command, channel, reqclass, &userinfo);
        }
@@ -612,9 +609,8 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                  4443 /*aimutil_get16(porttlv->value)*/);
        }
 
-       printf("faim: rend: directIM request from %s (%s)\n",
-              userinfo.sn,
-              ip);
+       faimdprintf(sess, 0, "rend: directIM request from %s (%s)\n",
+                   userinfo.sn, ip);
 
        /* XXX: there are a couple of different request packets for
        *          different things */
@@ -627,7 +623,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        /*
         * Call client.
         */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
@@ -655,7 +651,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        /*
         * Call client.
         */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
@@ -681,7 +677,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        memset(ip, 0, 30);
 
        if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
-         free(cachedcook);
+         aim_cookie_free(sess, cachedcook);
          return 0;
        }
 
@@ -689,7 +685,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
          struct aim_tlv_t *iptlv, *porttlv;
 
          if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
-           free(cachedcook);
+           aim_cookie_free(sess, cachedcook);
            return 0;
          }
 
@@ -701,12 +697,12 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                   aimutil_get16(porttlv->value));
        }
 
-       printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip);
+       faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo.sn, ip);
 
        /*
         * Call client.
         */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
@@ -747,11 +743,11 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
          desc = aim_gettlv_str(list2, 0x000c, 1);
        }
 
-       printf("faim: rend: file transfer request from %s for %s: %s (%s)\n",
-              userinfo.sn,
-              miscinfo->value+8,
-              desc, 
-              ip);
+       faimdprintf(sess, 0, "rend: file transfer request from %s for %s: %s (%s)\n",
+                   userinfo.sn,
+                   miscinfo->value+8,
+                   desc, 
+                   ip);
        
        memcpy(cachedcook->cookie, cookie, 8);
        
@@ -762,8 +758,8 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        cachedcook->type = AIM_COOKIETYPE_OFTSEND;
        cachedcook->data = ft;
 
-       if (aim_cachecookie(sess, cachedcook) != 0)
-         printf("faim: ERROR caching message cookie\n");
+       if (aim_cachecookie(sess, cachedcook) == -1)
+         faimdprintf(sess, 0, "ERROR caching message cookie\n");
        
        
        aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
@@ -774,16 +770,15 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        /*
         * Call client.
         */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
+       userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
                       channel, 
                       reqclass,
                       &userinfo);
-      } else {
-       printf("faim: rend: unknown rendezvous 0x%04x\n", reqclass);
-      }
+      } else
+       faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", reqclass);
 
       aim_freetlvchain(&list2);
     }
@@ -813,7 +808,7 @@ faim_export unsigned long aim_denytransfer(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int curbyte, i;
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+6)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6)))
     return -1;
 
   newpacket->lock = 1;
@@ -845,7 +840,7 @@ faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int curbyte;
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+16)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16)))
     return -1;
 
   newpacket->lock = 1;
@@ -892,7 +887,7 @@ faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess,
   snac = aim_remsnac(sess, snacid);
 
   if (!snac) {
-    printf("faim: msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
+    faimdprintf(sess, 0, "msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
     dest = NULL;
   } else
     dest = snac->data;
@@ -902,7 +897,7 @@ faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess,
   /*
    * Call client.
    */
-  userfunc = aim_callhandler(command->conn, 0x0004, 0x0001);
+  userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x0001);
   if (userfunc)
     ret =  userfunc(sess, command, dest, reason);
   else
@@ -942,7 +937,7 @@ faim_internal int aim_parse_missedcall(struct aim_session_t *sess,
   /*
    * Extract the standard user info block.
    */
-  i += aim_extractuserinfo(command->data+i, &userinfo);
+  i += aim_extractuserinfo(sess, command->data+i, &userinfo);
   
   nummissed = aimutil_get16(command->data+i);
   i += 2;
@@ -953,7 +948,7 @@ faim_internal int aim_parse_missedcall(struct aim_session_t *sess,
   /*
    * Call client.
    */
-  userfunc = aim_callhandler(command->conn, 0x0004, 0x000a);
+  userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x000a);
   if (userfunc)
     ret =  userfunc(sess, command, channel, &userinfo, nummissed, reason);
   else
index 6b1c3aed29d5b9747bcf57419c705f81f8ea0079..de05b79118d0a8bed449b57058111610631cab1f 100644 (file)
@@ -26,7 +26,7 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
   if (!sess || !conn || !sn)
     return 0;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 12+1+strlen(sn))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 12+1+strlen(sn))))
     return -1;
 
   newpacket->lock = 1;
@@ -67,7 +67,7 @@ faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
   snac = aim_remsnac(sess, snacid);
 
   if (!snac) {
-    printf("faim: locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
+    faimdprintf(sess, 0, "locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
     dest = NULL;
   } else
     dest = snac->data;
@@ -77,7 +77,7 @@ faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
   /*
    * Call client.
    */
-  userfunc = aim_callhandler(command->conn, 0x0002, 0x0001);
+  userfunc = aim_callhandler(sess, command->conn, 0x0002, 0x0001);
   if (userfunc)
     ret =  userfunc(sess, command, dest, reason);
   else
@@ -129,7 +129,7 @@ u_char aim_caps[8][16] = {
    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
 };
 
-faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen)
+faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen)
 {
   u_short ret = 0;
   int y;
@@ -153,7 +153,7 @@ faim_internal unsigned short aim_getcap(unsigned char *capblock, int buflen)
       }
     }
     if (!identified) {
-      printf("faim: unknown capability!\n");
+      faimdprintf(sess, 0, "unknown capability!\n");
       ret |= 0xff00;
     }
 
@@ -209,7 +209,7 @@ faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
  * AIM is fairly regular about providing user info.  This
  * is a generic routine to extract it in its standard form.
  */
-faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
+faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char *buf, struct aim_userinfo_s *outinfo)
 {
   int i = 0;
   int tlvcnt = 0;
@@ -373,7 +373,7 @@ faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinf
        if (!len)
          break;
        
-       outinfo->capabilities = aim_getcap(buf+i+4, len);
+       outinfo->capabilities = aim_getcap(sess, buf+i+4, len);
       }
       break;
       
@@ -417,28 +417,29 @@ faim_internal int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinf
     default:
       {
        int len,z = 0, y = 0, x = 0;
-       char tmpstr[80];
-       printf("faim: userinfo: **warning: unexpected TLV:\n");
-       printf("faim: userinfo:   sn    =%s\n", outinfo->sn);
-       printf("faim: userinfo:   curtlv=0x%04x\n", curtlv);
-       printf("faim: userinfo:   type  =0x%04x\n",aimutil_get16(&buf[i]));
-       printf("faim: userinfo:   length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
-       printf("faim: userinfo:   data: \n");
+       char tmpstr[160];
+
+        faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n");
+       faimdprintf(sess, 0, "userinfo:   sn    =%s\n", outinfo->sn);
+       faimdprintf(sess, 0, "userinfo:   curtlv=0x%04x\n", curtlv);
+       faimdprintf(sess, 0, "userinfo:   type  =0x%04x\n",aimutil_get16(&buf[i]));
+       faimdprintf(sess, 0, "userinfo:   length=0x%04x\n", len = aimutil_get16(&buf[i+2]));
+       faimdprintf(sess, 0, "userinfo:   data: \n");
        while (z<len)
          {
-           x = sprintf(tmpstr, "faim: userinfo:      ");
+           x = snprintf(tmpstr, sizeof(tmpstr), "userinfo:      ");
            for (y = 0; y < 8; y++)
              {
                if (z<len)
                  {
-                   sprintf(tmpstr+x, "%02x ", buf[i+4+z]);
+                   snprintf(tmpstr+x, sizeof(tmpstr)-x, "%02x ", buf[i+4+z]);
                    z++;
                    x += 3;
                  }
                else
                  break;
              }
-           printf("%s\n", tmpstr);
+           faimdprintf(sess, 0, "%s\n", tmpstr);
          }
       }
       break;
@@ -474,9 +475,9 @@ faim_internal int aim_parse_oncoming_middle(struct aim_session_t *sess,
   rxcallback_t userfunc=NULL;
 
   i = 10;
-  i += aim_extractuserinfo(command->data+i, &userinfo);
+  i += aim_extractuserinfo(sess, command->data+i, &userinfo);
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
+  userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING);
   if (userfunc)
     i = userfunc(sess, command, &userinfo);
 
@@ -498,7 +499,7 @@ faim_internal int aim_parse_offgoing_middle(struct aim_session_t *sess,
   strncpy(sn, (char *)command->data+11, (int)command->data[10]);
   sn[(int)command->data[10]] = '\0';
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
+  userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
   if (userfunc)
     i = userfunc(sess, command, sn);
 
@@ -527,7 +528,7 @@ faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
   origsnac = aim_remsnac(sess, snacid);
 
   if (!origsnac || !origsnac->data) {
-    printf("faim: parse_userinfo_middle: major problem: no snac stored!\n");
+    faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n");
     return 1;
   }
 
@@ -541,7 +542,7 @@ faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
     /*
      * extractuserinfo will give us the basic metaTLV information
      */
-    i += aim_extractuserinfo(command->data+i, &userinfo);
+    i += aim_extractuserinfo(sess, command->data+i, &userinfo);
   
     /*
      * However, in this command, there's usually more TLVs following...
@@ -562,7 +563,7 @@ faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
       text = aim_gettlv_str(tlvlist, 0x0004, 1);
     }
 
-    userfunc = aim_callhandler(command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
+    userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
     if (userfunc) {
       i = userfunc(sess,
                   command, 
@@ -577,7 +578,7 @@ faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
     aim_freetlvchain(&tlvlist);
     break;
   default:
-    printf("faim: parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
+    faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
     break;
   }
 
@@ -647,7 +648,7 @@ faim_export int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_con
   if (!sess || !conn || !info)
     return 0;
 
-  if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   tx->lock = 1;
@@ -675,7 +676,7 @@ faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_con
   if (!sess || !conn || !sn)
     return 0;
 
-  if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+1+strlen(sn))))
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
     return -1;
 
   tx->lock = 1;
index 1ca04ec0e70994fcfe376c5cf178ab623f84efad..392efe75677bc516a9c34c38e6d91c4026e135e0 100644 (file)
 static int aim_encode_password_md5(const char *password, const char *key, md5_byte_t *digest);
 static int aim_encode_password(const char *password, unsigned char *encoded);
 
-/*
- * FIXME: Reimplement the TIS stuff.
- */
-#ifdef TIS_TELNET_PROXY
-#include "tis_telnet_proxy.h"
-#endif
-
 faim_export int aim_sendconnack(struct aim_session_t *sess,
                                struct aim_conn_t *conn)
 {
@@ -27,7 +20,7 @@ faim_export int aim_sendconnack(struct aim_session_t *sess,
   
   struct command_tx_struct *newpacket;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0001, conn, 4)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0001, 4)))
     return -1;
 
   newpacket->lock = 1;
@@ -110,7 +103,7 @@ faim_export int aim_request_login(struct aim_session_t *sess,
 
   aim_sendconnack(sess, conn);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+2+2+strlen(sn))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+2+2+strlen(sn))))
     return -1;
 
   newpacket->lock = 1;
@@ -157,7 +150,7 @@ faim_export int aim_send_login (struct aim_session_t *sess,
   if (!clientinfo || !sn || !password)
     return -1;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   newpacket->lock = 1;
@@ -397,7 +390,7 @@ faim_internal int aim_authparse(struct aim_session_t *sess,
     ; /* no idea what this is */
 
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0017, 0x0003)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0017, 0x0003)))
     ret = userfunc(sess, command, sn, errorcode, errurl, regstatus, email, bosip, cookie, latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo, latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
 
 
@@ -449,7 +442,7 @@ faim_internal int aim_authkeyparse(struct aim_session_t *sess, struct command_rx
   memcpy(key, command->data+12, keylen);
   key[keylen] = '\0';
   
-  if ((userfunc = aim_callhandler(command->conn, 0x0017, 0x0007)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0017, 0x0007)))
     ret = userfunc(sess, command, (char *)key);
 
   free(key);  
@@ -473,7 +466,7 @@ faim_export unsigned long aim_sendauthresp(struct aim_session_t *sess,
   struct command_tx_struct *tx;
   struct aim_tlvlist_t *tlvlist = NULL;
 
-  if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0004, conn, 1152)))
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0004, 1152)))
     return -1;
   
   tx->lock = 1;
@@ -522,7 +515,7 @@ faim_export int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_
   struct command_tx_struct *tx;
   int i = 0;
 
-  if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+0x22)))
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+0x22)))
     return -1;
 
   tx->lock = 1;
@@ -561,7 +554,7 @@ faim_export unsigned long aim_sendredirect(struct aim_session_t *sess,
   struct aim_tlvlist_t *tlvlist = NULL;
   int i = 0;
 
-  if (!(tx = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   tx->lock = 1;
index 889297beb4768990531e4563e98f406666da174b..5bde289b536cddd45813b4b86bf70f99ce7830b2 100644 (file)
@@ -29,21 +29,20 @@ faim_export char *aim_getbuildstring(void)
   return string;
 }
 
-#if debug > 0
-faim_internal void faimdprintf(int dlevel, const char *format, ...)
+faim_internal void faimdprintf(struct aim_session_t *sess, int dlevel, const char *format, ...)
 {
-  if (dlevel >= debug) {
+  if (!sess) {
+    fprintf(stderr, "faimdprintf: no session! boo! (%d, %s)\n", dlevel, format);
+    return;
+  }
+
+  if ((dlevel <= sess->debug) && sess->debugcb) {
     va_list ap;
-    
+
     va_start(ap, format);
-    vfprintf(stderr, format, ap);
+    sess->debugcb(sess, dlevel, format, ap);
     va_end(ap);
   }
+
   return;
 }
-#else
-faim_internal void faimdprintf(int dlevel, const char *format, ...)
-{
-  return;
-}
-#endif
index 5a32a0bbf01526e676c1c2ba2a0e0f849e0da7f0..252d41e899650eb5d0133cf6b30da5dd3b06063b 100644 (file)
@@ -81,7 +81,7 @@ faim_export unsigned long aim_bos_changevisibility(struct aim_session_t *sess,
   listcount = aimutil_itemcnt(localcpy, '&');
   packlen = aimutil_tokslen(localcpy, 99, '&') + listcount + 9;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen)))
     return -1;
 
   newpacket->lock = 1;
@@ -158,18 +158,14 @@ faim_export unsigned long aim_bos_setbuddylist(struct aim_session_t *sess,
   i = 0;
   tmpptr = strtok(localcpy, "&");
   while ((tmpptr != NULL) && (i < 150)) {
-#if debug > 0
-    printf("---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
-#endif
+    faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
     len += 1+strlen(tmpptr);
     i++;
     tmpptr = strtok(NULL, "&");
   }
-#if debug > 0
-  printf("*** send buddy list len: %d (%x)\n", len, len);
-#endif
+  faimdprintf(sess, 2, "*** send buddy list len: %d (%x)\n", len, len);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, len)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, len)))
     return -1;
 
   newpacket->lock = 1;
@@ -182,9 +178,7 @@ faim_export unsigned long aim_bos_setbuddylist(struct aim_session_t *sess,
   i = 0;
   tmpptr = strtok(localcpy, "&");
   while ((tmpptr != NULL) & (i < 150)) {
-#if debug > 0
-    printf("---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
-#endif
+    faimdprintf(sess, 2, "---adding %d: %s (%d)\n", i, tmpptr, strlen(tmpptr));
     newpacket->data[j] = strlen(tmpptr);
     memcpy(&(newpacket->data[j+1]), tmpptr, strlen(tmpptr));
     j += 1+strlen(tmpptr);
@@ -217,7 +211,7 @@ faim_export unsigned long aim_bos_setprofile(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i = 0, tmp, caplen;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152+strlen(profile)+1+(awaymsg?strlen(awaymsg):0))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152+strlen(profile)+1+(awaymsg?strlen(awaymsg):0))))
     return -1;
 
   i += aim_putsnac(newpacket->data, 0x0002, 0x004, 0x0000, sess->snac_nextid);
@@ -289,7 +283,7 @@ faim_internal int aim_parse_bosrights(struct aim_session_t *sess,
   if (aim_gettlv(tlvlist, 0x0002, 1)) 
     maxdenies = aim_gettlv16(tlvlist, 0x0002, 1);
   
-  if ((userfunc = aim_callhandler(command->conn, 0x0009, 0x0003)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0009, 0x0003)))
     ret = userfunc(sess, command, maxpermits, maxdenies);
 
   aim_freetlvchain(&tlvlist);
@@ -321,7 +315,7 @@ faim_export unsigned long aim_bos_clientready(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int toolcount = sizeof(tools)/sizeof(struct aim_tool_version);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
     return -1;
 
   newpacket->lock = 1;
@@ -364,7 +358,7 @@ faim_export unsigned long aim_bos_ackrateresp(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int packlen = 20, i=0;
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen)))
     return (sess->snac_nextid);
   
   newpacket->lock = 1;
@@ -419,7 +413,7 @@ faim_export unsigned long aim_setversions(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int i;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + (4*12))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + (4*12))))
     return -1;
 
   newpacket->lock = 1;
@@ -505,7 +499,7 @@ faim_export unsigned long aim_flap_nop(struct aim_session_t *sess,
 {
   struct command_tx_struct *newpacket;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0005, conn, 0)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0005, 0)))
     return sess->snac_nextid;
 
   newpacket->lock = 1;
@@ -556,7 +550,7 @@ faim_export int aim_send_warning(struct aim_session_t *sess, struct aim_conn_t *
   struct command_tx_struct *newpacket;
   int curbyte;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(destsn)+13)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, strlen(destsn)+13)))
     return -1;
 
   newpacket->lock = 1;
@@ -608,7 +602,7 @@ faim_internal unsigned long aim_genericreq_n(struct aim_session_t *sess,
 {
   struct command_tx_struct *newpacket;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10)))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10)))
     return 0;
 
   newpacket->lock = 1;
@@ -637,7 +631,7 @@ faim_internal unsigned long aim_genericreq_l(struct aim_session_t *sess,
   if (!longdata)
     return aim_genericreq_n(sess, conn, family, subtype);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_long))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_long))))
     return -1;
 
   newpacket->lock = 1;
@@ -665,7 +659,7 @@ faim_internal unsigned long aim_genericreq_s(struct aim_session_t *sess,
   if (!shortdata)
     return aim_genericreq_n(sess, conn, family, subtype);
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+sizeof(u_short))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+sizeof(u_short))))
     return -1;
 
   newpacket->lock = 1;
@@ -714,7 +708,7 @@ faim_export unsigned long aim_addicbmparam(struct aim_session_t *sess,
   struct command_tx_struct *newpacket;
   int packlen = 10+16, i=0;
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen)))
     return (sess->snac_nextid);
   
   newpacket->lock = 1;
@@ -765,7 +759,7 @@ faim_export unsigned long aim_setdirectoryinfo(struct aim_session_t *sess, struc
   if(zip)
     packlen += (strlen(zip) + 4);
     
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen+10)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10)))
     return -1;
 
   newpacket->lock = 1;
@@ -822,7 +816,7 @@ faim_export unsigned long aim_setuserinterests(struct aim_session_t *sess, struc
     packlen += (strlen(interest5) + 4) ;
 
     
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, packlen+10)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, packlen+10)))
     return -1;
 
   newpacket->lock = 1;
@@ -861,7 +855,7 @@ faim_export unsigned long aim_icq_setstatus(struct aim_session_t *sess,
   
   data = 0x00030000 | status; /* yay for error checking ;^) */
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10 + 4)))
+  if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10 + 4)))
     return -1;
 
   newpacket->lock = 1;
index 5e7e7c950460c8655e9704aae2bea38fa1f87757..5ffa5902bc734e6d88ce9854dc4572aac2e02e6e 100644 (file)
@@ -2,8 +2,6 @@
  * Cookie Caching stuff. Adam wrote this, apparently just some
  * derivatives of n's SNAC work. I cleaned it up, added comments.
  * 
- * I'm going to rewrite this stuff eventually, honest. -jbm
- * 
  */
 
 /*
 #define FAIM_INTERNAL
 #include <aim.h>
 
-/*
- * aim_cachecookie: 
- * appends a cookie to the cookie list for sess.
- * - if cookie->cookie for type cookie->type is found, -1 is returned
- * - copies cookie struct; you need to free() it afterwards;
- * - cookie->data is not copied, but passed along. don't free it.
- * - cookie->type is just passed across.
+/**
+ * aim_cachecookie - appends a cookie to the cookie list
+ * @sess: session to add to
+ * @cookie: pointer to struct to append
+ *
+ * if cookie->cookie for type cookie->type is found, updates the
+ * ->addtime of the found structure; otherwise adds the given cookie
+ * to the cache
+ *
+ * returns -1 on error, 0 on append, 1 on update.  the cookie you pass
+ * in may be free'd, so don't count on its value after calling this!
  * 
- * returns -1 on error, 0 on success.  
  */
 faim_internal int aim_cachecookie(struct aim_session_t *sess,
                                  struct aim_msgcookie_t *cookie)
@@ -34,34 +35,32 @@ faim_internal int aim_cachecookie(struct aim_session_t *sess,
   if (!sess || !cookie)
     return -1;
 
-  printf("\t\tCC cache %d %s", cookie->type, cookie->cookie);
-  if(cookie->type == AIM_COOKIETYPE_OFTGET) {
-    struct aim_filetransfer_priv *priv;
-    priv = cookie->data;
-    printf("%s\n", priv->sn);
-  } else
-    printf("\n");
-
   if( (newcook = aim_checkcookie(sess, cookie->cookie, cookie->type)) ) {
-    printf("aim_cachecookie: cookie already cached\n");
-    return -1;
+    if(newcook != cookie) {
+      aim_cookie_free(sess, newcook);
+    } else {
+      newcook->addtime = time(NULL);
+      return 1;
+    }
   }
-  
-  if (!(newcook = malloc(sizeof(struct aim_msgcookie_t))))
-    return -1;
-  memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t));
-  
-  newcook->next = sess->msgcookies;
-  sess->msgcookies = newcook;
+
+  cookie->addtime = time(NULL);  
+
+  cookie->next = sess->msgcookies;
+  sess->msgcookies = cookie;
 
   return 0;
 }
 
-/*
- * aim_uncachecookie:
- * takes a cookie string and grabs the cookie struct associated with
- * it. removes struct from chain.  returns the struct if found, or
- * NULL on not found.
+/**
+ * aim_uncachecookie - grabs a cookie from the cookie cache (removes it from the list)
+ * @sess: session to grab cookie from
+ * @cookie: cookie string to look for
+ * @type: cookie type to look for
+ *
+ * takes a cookie string and a cookie type and finds the cookie struct associated with that duple, removing it from the cookie list ikn the process.
+ *
+ * if found, returns the struct; if none found (or on error), returns NULL:
  */
 faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type)
 {
@@ -70,8 +69,6 @@ faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *se
   if (!cookie || !sess->msgcookies)
     return NULL;
 
-  printf("\t\tCC uncache %d %s\n", type, cookie);
-
   for (prev = &sess->msgcookies; (cur = *prev); ) {
     if ((cur->type == type) && 
        (memcmp(cur->cookie, cookie, 8) == 0)) {
@@ -84,6 +81,16 @@ faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *se
   return NULL;
 }
 
+/**
+ * aim_mkcookie - generate an aim_msgcookie_t *struct from a cookie string, a type, and a data pointer.
+ * @c: pointer to the cookie string array
+ * @type: cookie type to use
+ * @data: data to be cached with the cookie
+ *
+ * returns NULL on error, a pointer to the newly-allocated cookie on
+ * success.
+ *
+ */
 faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, void *data) 
 {
   struct aim_msgcookie_t *cookie;
@@ -100,13 +107,24 @@ faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, v
   
   return cookie;
 }
-  
-faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, const unsigned char *cookie, const int type)
+
+/**
+ * aim_checkcookie - check to see if a cookietuple has been cached
+ * @sess: session to check for the cookie in
+ * @cookie: pointer to the cookie string array
+ * @type: type of the cookie to look for
+ *
+ * this returns a pointer to the cookie struct (still in the list) on
+ * success; returns NULL on error/not found
+ *
+ */
+
+faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, 
+                                                     const unsigned char *cookie, 
+                                                     const int type)
 {
   struct aim_msgcookie_t *cur;
 
-  printf("\t\tCC check %d %s\n", type, cookie);  
-
   for (cur = sess->msgcookies; cur; cur = cur->next) {
     if ((cur->type == type) && 
        (memcmp(cur->cookie, cookie, 8) == 0))
@@ -116,18 +134,41 @@ faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess
   return NULL;
 }
 
-faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie) {
+#if 0 /* debugging feature */
+faim_internal int aim_dumpcookie(struct aim_msgcookie_t *cookie) 
+{
+  if(!cookie)
+    return -1;
+  printf("\tCookie at %p: %d/%s with %p, next %p\n", cookie, cookie->type, cookie->cookie, cookie->data, cookie->next);
+  return 0;
+}
+#endif
+
+/**
+ * aim_cookie_free - free an aim_msgcookie_t struct
+ * @sess: session to remove the cookie from
+ * @cookiep: the address of a pointer to the cookie struct to remove
+ *
+ * this function removes the cookie *cookie from teh list of cookies
+ * in sess, and then frees all memory associated with it. including
+ * its data! if you want to use the private data after calling this,
+ * make sure you copy it first.
+ *
+ * returns -1 on error, 0 on success.
+ *
+ */
+
+faim_internal int aim_cookie_free(struct aim_session_t *sess, 
+                                 struct aim_msgcookie_t *cookie) 
+{
   struct aim_msgcookie_t *cur, **prev;
 
   if (!sess || !cookie)
     return -1;
 
-  /* 
-   * Make sure its not in the list somewhere still.
-   *
-   * If this actually happens, theres been a major coding failure 
-   * on my part. However, that does not reduce its occurance likelyhood.
-   */
+  if(!cookie)
+    return 0;
+
   for (prev = &sess->msgcookies; (cur = *prev); ) {
     if (cur == cookie) {
       *prev = cur->next;
@@ -135,6 +176,9 @@ faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcooki
       prev = &cur->next;
   }
 
+  if(cookie->data)
+    free(cookie->data);
+
   free(cookie);
 
   return 0;
index cd0a082bdeb591d81e2f1198dbbc92c214f8e953..16ce8205df5bf873bb421e45f09f27494f7e0d67 100644 (file)
@@ -175,9 +175,9 @@ faim_internal int bleck(struct aim_session_t *sess,struct command_rx_struct *wor
   subtype= aimutil_get16(workingPtr->data+2);
 
   if((family < maxf) && (subtype+1 < maxs) && (literals[family][subtype] != NULL))
-    printf("bleck: null handler for %04x/%04x (%s)\n", family, subtype, literals[family][subtype+1]);
+    faimdprintf(sess, 0, "bleck: null handler for %04x/%04x (%s)\n", family, subtype, literals[family][subtype+1]);
   else
-    printf("bleck: null handler for %04x/%04x (no literal)\n",family,subtype);
+    faimdprintf(sess, 0, "bleck: null handler for %04x/%04x (no literal)\n",family,subtype);
 
   return 1;
 }
@@ -194,7 +194,7 @@ faim_export int aim_conn_addhandler(struct aim_session_t *sess,
   if (!conn)
     return -1;
 
-  faimdprintf(1, "aim_conn_addhandler: adding for %04x/%04x\n", family, type);
+  faimdprintf(sess, 1, "aim_conn_addhandler: adding for %04x/%04x\n", family, type);
 
   if (!(newcb = (struct aim_rxcblist_t *)calloc(1, sizeof(struct aim_rxcblist_t))))
     return -1;
@@ -241,29 +241,31 @@ faim_export int aim_clearhandlers(struct aim_conn_t *conn)
  return 0;
 }
 
-faim_internal rxcallback_t aim_callhandler(struct aim_conn_t *conn,
-                                        u_short family,
-                                        u_short type)
+faim_internal rxcallback_t aim_callhandler(struct aim_session_t *sess,
+                                          struct aim_conn_t *conn,
+                                          unsigned short family,
+                                          unsigned short type)
 {
   struct aim_rxcblist_t *cur;
 
   if (!conn)
     return NULL;
 
-  faimdprintf(1, "aim_callhandler: calling for %04x/%04x\n", family, type);
+  faimdprintf(sess, 1, "aim_callhandler: calling for %04x/%04x\n", family, type);
   
-  cur = conn->handlerlist;
-  while(cur)
-    {
-      if ( (cur->family == family) && (cur->type == type) )
-       return cur->handler;
-      cur = cur->next;
-    }
+  for (cur = conn->handlerlist; cur; cur = cur->next) {
+    if ((cur->family == family) && (cur->type == type))
+      return cur->handler;
+  }
 
-  if (type==0xffff)
-    return NULL;
+  if (type == AIM_CB_SPECIAL_DEFAULT) {
+    faimdprintf(sess, 1, "aim_callhandler: no default handler for family 0x%04x\n", family);
+    return NULL; /* prevent infinite recursion */
+  }
+
+  faimdprintf(sess, 1, "aim_callhandler: no handler for  0x%04x/0x%04x\n", family, type);
 
-  return aim_callhandler(conn, family, 0xffff);
+  return aim_callhandler(sess, conn, family, AIM_CB_SPECIAL_DEFAULT);
 }
 
 faim_internal int aim_callhandler_noparam(struct aim_session_t *sess,
@@ -273,7 +275,7 @@ faim_internal int aim_callhandler_noparam(struct aim_session_t *sess,
                                          struct command_rx_struct *ptr)
 {
   rxcallback_t userfunc = NULL;
-  userfunc = aim_callhandler(conn, family, type);
+  userfunc = aim_callhandler(sess, conn, family, type);
   if (userfunc)
     return userfunc(sess, ptr);
   return 1; /* XXX */
@@ -308,7 +310,7 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
   struct command_rx_struct *workingPtr = NULL;
   
   if (sess->queue_incoming == NULL) {
-    faimdprintf(1, "parse_generic: incoming packet queue empty.\n");
+    faimdprintf(sess, 1, "parse_generic: incoming packet queue empty.\n");
     return 0;
   } else {
     workingPtr = sess->queue_incoming;
@@ -327,7 +329,7 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
           (workingPtr->conn->type != AIM_CONN_TYPE_RENDEZVOUS)) || 
          ((workingPtr->hdrtype == AIM_FRAMETYPE_OSCAR) && 
           (workingPtr->conn->type == AIM_CONN_TYPE_RENDEZVOUS))) {
-       printf("faim: rxhandlers: incompatible frame type %d on connection type 0x%04x\n", workingPtr->hdrtype, workingPtr->conn->type);
+       faimdprintf(sess, 0, "rxhandlers: incompatible frame type %d on connection type 0x%04x\n", workingPtr->hdrtype, workingPtr->conn->type);
        workingPtr->handled = 1;
        continue;
       }
@@ -348,7 +350,7 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
        
        head = aimutil_get32(workingPtr->data);
        if ((head == 0x00000001) && (workingPtr->commandlen == 4)) {
-         faimdprintf(1, "got connection ack on auth line\n");
+         faimdprintf(sess, 1, "got connection ack on auth line\n");
          workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, workingPtr);
        } else if (workingPtr->hdr.oscar.type == 0x04) {
          /* Used only by the older login protocol */
@@ -547,7 +549,7 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
          break;
        }
        case 0x0013: {
-         printf("lalala: 0x%04x/0x%04x\n", family, subtype);
+         faimdprintf(sess, 0, "lalala: 0x%04x/0x%04x\n", family, subtype);
          break;
        }
        case AIM_CB_FAM_SPECIAL: 
@@ -621,9 +623,9 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
          else if (subtype == 0x0006)
            workingPtr->handled = aim_chat_parse_incoming(sess, workingPtr);
          else  
-           printf("Chat: unknown snac %04x/%04x\n", family, subtype); 
+           faimdprintf(sess, 0, "Chat: unknown snac %04x/%04x\n", family, subtype); 
        } else {
-         printf("Chat: unknown snac %04x/%04x\n", family, subtype);
+         faimdprintf(sess, 0, "Chat: unknown snac %04x/%04x\n", family, subtype);
          workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_DEFAULT, workingPtr);
        }
        break;
@@ -631,13 +633,13 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
       case AIM_CONN_TYPE_RENDEZVOUS: {
        /* make sure that we only get OFT frames on these connections */
        if (workingPtr->hdrtype != AIM_FRAMETYPE_OFT) {
-         printf("faim: internal error: non-OFT frames on OFT connection\n");
+         faimdprintf(sess, 0, "internal error: non-OFT frames on OFT connection\n");
          workingPtr->handled = 1; /* get rid of it */
          break;
        }
        
        /* XXX: implement this */
-       printf("faim: OFT frame!\n");
+       faimdprintf(sess, 0, "faim: OFT frame!\n");
        
        break;
       }
@@ -646,7 +648,7 @@ faim_export int aim_rxdispatch(struct aim_session_t *sess)
        break;
       }
       default:
-       printf("\ninternal error: unknown connection type (very bad.) (type = %d, fd = %d, commandlen = %02x)\n\n", workingPtr->conn->type, workingPtr->conn->fd, workingPtr->commandlen);
+       faimdprintf(sess, 0, "internal error: unknown connection type (very bad.) (type = %d, fd = %d, commandlen = %02x)\n\n", workingPtr->conn->type, workingPtr->conn->fd, workingPtr->commandlen);
        workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr);
        break;
       }        
@@ -682,7 +684,7 @@ faim_internal int aim_parse_msgack_middle(struct aim_session_t *sess, struct com
   memset(sn, 0, sizeof(sn));
   strncpy(sn, (char *)command->data+i, snlen);
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0004, 0x000c)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0004, 0x000c)))
     ret =  userfunc(sess, command, type, sn);
 
   return ret;
@@ -769,7 +771,7 @@ faim_internal int aim_parse_ratechange_middle(struct aim_session_t *sess, struct
   maxavg = aimutil_get32(command->data+i);
   i += 4;
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x000a)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x000a)))
     ret =  userfunc(sess, command, code, rateclass, windowsize, clear, alert, limit, disconnect, currentavg, maxavg);
 
   return ret;
@@ -789,9 +791,9 @@ faim_internal int aim_parse_evilnotify_middle(struct aim_session_t *sess, struct
 
   memset(&userinfo, 0, sizeof(struct aim_userinfo_s));
   if (command->commandlen-i)
-    i += aim_extractuserinfo(command->data+i, &userinfo);
+    i += aim_extractuserinfo(sess, command->data+i, &userinfo);
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0010)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0010)))
     ret = userfunc(sess, command, newevil, &userinfo);
   
   return ret;
@@ -829,7 +831,7 @@ faim_internal int aim_parsemotd_middle(struct aim_session_t *sess,
     return ret;
   }
   
-  userfunc = aim_callhandler(command->conn, 0x0001, 0x0013);
+  userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0013);
   if (userfunc)
     ret =  userfunc(sess, command, id, msg);
 
@@ -854,7 +856,7 @@ faim_internal int aim_parse_hostonline(struct aim_session_t *sess,
   for (i = 0; i < famcount; i++)
     families[i] = aimutil_get16(command->data+((i*2)+10));
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0003)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0003)))
     ret = userfunc(sess, command, famcount, families);
 
   free(families);
@@ -871,7 +873,7 @@ faim_internal int aim_parse_accountconfirm(struct aim_session_t *sess,
 
   status = aimutil_get16(command->data+10);
 
-  if ((userfunc = aim_callhandler(command->conn, 0x0007, 0x0007)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0007, 0x0007)))
     ret = userfunc(sess, command, status);
 
   return ret;  
@@ -916,7 +918,7 @@ faim_internal int aim_parse_infochange(struct aim_session_t *sess,
        tlv = aim_grabtlv(command->data+i);
 
       /* XXX fix so its only called once for the entire packet */
-      if ((userfunc = aim_callhandler(command->conn, 0x0007, subtype)))
+      if ((userfunc = aim_callhandler(sess, command->conn, 0x0007, subtype)))
        userfunc(sess, command, perms, tlv->type, tlv->length, tlv->value, str);
 
       if (tlv)
@@ -943,7 +945,7 @@ faim_internal int aim_parse_hostversions(struct aim_session_t *sess,
 
   vercount = (command->commandlen-10)/4;
   
-  if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0018)))
+  if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0018)))
     ret = userfunc(sess, command, vercount, command->data+10);
 
   return ret;  
@@ -974,7 +976,7 @@ faim_internal int aim_handleredirect_middle(struct aim_session_t *sess,
      * Chat hack.
      *
      */
-    if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005)))
+    if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0005)))
       ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange);
       free(sess->pendingjoin);
       sess->pendingjoin = NULL;
@@ -982,7 +984,7 @@ faim_internal int aim_handleredirect_middle(struct aim_session_t *sess,
   } else if (!serviceid || !ip || !cookie) { /* yeep! */
     ret = 1;
   } else {
-    if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005)))
+    if ((userfunc = aim_callhandler(sess, command->conn, 0x0001, 0x0005)))
       ret =  userfunc(sess, command, serviceid, ip, cookie);
   }
 
@@ -1004,17 +1006,17 @@ faim_internal int aim_parse_unknown(struct aim_session_t *sess,
   if (!sess || !command)
     return 1;
 
-  faimdprintf(1, "\nRecieved unknown packet:");
+  faimdprintf(sess, 1, "\nRecieved unknown packet:");
 
   for (i = 0; i < command->commandlen; i++)
     {
       if ((i % 8) == 0)
-       faimdprintf(1, "\n\t");
+       faimdprintf(sess, 1, "\n\t");
 
-      faimdprintf(1, "0x%2x ", command->data[i]);
+      faimdprintf(sess, 1, "0x%2x ", command->data[i]);
     }
   
-  faimdprintf(1, "\n\n");
+  faimdprintf(sess, 1, "\n\n");
 
   return 1;
 }
@@ -1037,7 +1039,7 @@ faim_internal int aim_negchan_middle(struct aim_session_t *sess,
   if (aim_gettlv(tlvlist, 0x000b, 1))
     msg = aim_gettlv_str(tlvlist, 0x000b, 1);
 
-  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR))) 
+  if ((userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR))) 
     ret =  userfunc(sess, command, code, msg);
 
   aim_freetlvchain(&tlvlist);
@@ -1069,7 +1071,7 @@ faim_internal int aim_parse_generalerrs(struct aim_session_t *sess,
   if (command->commandlen > 10)
     error = aimutil_get16(command->data+10);
 
-  if ((userfunc = aim_callhandler(command->conn, family, subtype))) 
+  if ((userfunc = aim_callhandler(sess, command->conn, family, subtype))) 
     ret = userfunc(sess, command, error);
 
   return ret;
index e1b8f4d662b08ecdc1d3e51d4a7171183ee72f63..d177c8278f5bcc18e53d2a971ddb74167b490256 100644 (file)
@@ -74,7 +74,7 @@ faim_export int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *c
   if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) 
     return aim_get_command_rendezvous(sess, conn);
   if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
-    printf("out on fd %d\n", conn->fd);
+    faimdprintf(sess, 0, "out on fd %d\n", conn->fd);
     return 0; 
   }
 
@@ -98,7 +98,7 @@ faim_export int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *c
    * or we break.  We must handle it just in case.
    */
   if (generic[0] != 0x2a) {
-    faimdprintf(1, "Bad incoming data!");
+    faimdprintf(sess, 1, "Bad incoming data!");
     aim_conn_close(conn);
     faim_mutex_unlock(&conn->active);
     return -1;
index 7b795f7afad2d5cb25e7b9061c22e7cfc63e0c0a..649a9fce978659017a54671e8d56d42fcd0aca8b 100644 (file)
@@ -18,7 +18,7 @@ faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess,
   if (!address)
     return -1;
 
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+strlen(address))))
+  if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+strlen(address))))
     return -1;
 
   newpacket->lock = 1;
@@ -48,11 +48,11 @@ faim_internal unsigned long aim_parse_searcherror(struct aim_session_t *sess, st
   i += 4;
   
   if(!(snac = aim_remsnac(sess, snacid))) {
-    faimdprintf(2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
+    faimdprintf(sess, 2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
     return 0;
   }
 
-  if((userfunc = aim_callhandler(command->conn, 0x000a, 0x0001)))
+  if((userfunc = aim_callhandler(sess, command->conn, 0x000a, 0x0001)))
     ret = userfunc(sess, command, snac->data /* address */);
   else
     ret = 0;
@@ -82,7 +82,7 @@ faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *sess, st
   i += 4;
 
   if(!(snac = aim_remsnac(sess, snacid))) {
-    faimdprintf(2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
+    faimdprintf(sess, 2, "faim: couldn't get a snac for %d, probably should crash.\n", snacid);
     return 0;
   }
 
@@ -94,7 +94,7 @@ faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *sess, st
 
   while((cur = aim_gettlv_str(tlvlist, 0x0001, j+1)) && j < m) {
     if(!(buf = realloc(buf, (j+1) * (MAXSNLEN+1))))
-      faimdprintf(2, "faim: couldn't realloc buf. oh well.\n");
+      faimdprintf(sess, 2, "faim: couldn't realloc buf. oh well.\n");
 
     strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN);
     free(cur);
@@ -104,7 +104,7 @@ faim_internal unsigned long aim_parse_searchreply(struct aim_session_t *sess, st
 
   aim_freetlvchain(&tlvlist);
 
-  if((userfunc = aim_callhandler(command->conn, 0x000a, 0x0003)))
+  if((userfunc = aim_callhandler(sess, command->conn, 0x000a, 0x0003)))
     ret = userfunc(sess, command, snac->data /* address */, j, buf);
   else
     ret = 0;
index e45b660c1daf44af9813fb518168e8a5f5694b68..96f288fb48685b8f01385626f65d57b9bd3a836a 100644 (file)
@@ -43,8 +43,12 @@ faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess,
   snac.type = type;
   snac.flags = flags;
 
-  snac.data = malloc(datalen);
-  memcpy(snac.data, data, datalen);
+  if (datalen) {
+    if (!(snac.data = malloc(datalen)))
+      return 0; /* er... */
+    memcpy(snac.data, data, datalen);
+  } else
+    snac.data = NULL;
 
   return aim_newsnac(sess, &snac);
 }
index 99f2ba5b9df1bcbd6208674d6f1ca1a8b0386973..3119a2df0c65eaad60cafe4d42fea0eb8ae5e21f 100644 (file)
--- a/src/tlv.c
+++ b/src/tlv.c
@@ -49,10 +49,9 @@ faim_export struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
               * theres no special cases to this special case.
               *   - mid (30jun2000)
               */
-             if ((type == 0x0013) && (length != 0x0002)) {
-               printf("faim: skipping TLV t(0013) with invalid length (0x%04x)\n", length);
+             if ((type == 0x0013) && (length != 0x0002))
                length = 0x0002;
-             else {
+             else {
                cur = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
                memset(cur, 0x00, sizeof(struct aim_tlvlist_t));
 
index dbd99c5f144b13286de893605f9bb255a229a98f..2a1a92af88c49713158d6f4e0c5dd0cd0dd0e9e8 100644 (file)
  * chan = channel for OSCAR, hdrtype for OFT
  *
  */
-faim_internal struct command_tx_struct *aim_tx_new(unsigned char framing, int chan, struct aim_conn_t *conn, 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;
 
   if (!conn) {
-    printf("aim_tx_new: ERROR: no connection specified\n");
+    faimdprintf(sess, 0, "aim_tx_new: ERROR: no connection specified\n");
     return NULL;
   }
 
+  /* For sanity... */
+  if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) || (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT)) {
+    if (framing != AIM_FRAMETYPE_OFT) {
+      faimdprintf(sess, 0, "aim_tx_new: attempted to allocate inappropriate frame type for rendezvous connection\n");
+      return NULL;
+    }
+  } else {
+    if (framing != AIM_FRAMETYPE_OSCAR) {
+      faimdprintf(sess, 0, "aim_tx_new: attempted to allocate inappropriate frame type for FLAP connection\n");
+      return NULL;
+    }
+  }
+
   newtx = (struct command_tx_struct *)malloc(sizeof(struct command_tx_struct));
   if (!newtx)
     return NULL;
@@ -53,7 +66,7 @@ faim_internal struct command_tx_struct *aim_tx_new(unsigned char framing, int ch
     newtx->hdr.oft.type = chan;
     newtx->hdr.oft.hdr2len = 0; /* this will get setup by caller */
   } else { 
-    printf("tx_new: unknown framing\n");
+    faimdprintf(sess, 0, "tx_new: unknown framing\n");
   }
 
   return newtx;
@@ -80,7 +93,7 @@ static int aim_tx_enqueue__queuebased(struct aim_session_t *sess, struct command
   struct command_tx_struct *cur;
 
   if (newpacket->conn == NULL) {
-      faimdprintf(1, "aim_tx_enqueue: WARNING: enqueueing packet with no connecetion\n");
+      faimdprintf(sess, 1, "aim_tx_enqueue: WARNING: enqueueing packet with no connecetion\n");
       newpacket->conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
   }
  
@@ -106,12 +119,6 @@ static int aim_tx_enqueue__queuebased(struct aim_session_t *sess, struct command
 
   newpacket->lock = 0; /* unlock so it can be sent */
 
-#if debug == 2
-  faimdprintf(2, "calling aim_tx_printqueue()\n");
-  aim_tx_printqueue(sess);
-  faimdprintf(2, "back from aim_tx_printqueue()\n");
-#endif
-
   return 0;
 }
 
@@ -129,7 +136,7 @@ static int aim_tx_enqueue__queuebased(struct aim_session_t *sess, struct command
 static int aim_tx_enqueue__immediate(struct aim_session_t *sess, struct command_tx_struct *newpacket)
 {
   if (newpacket->conn == NULL) {
-    faimdprintf(1, "aim_tx_enqueue: ERROR: packet has no connection\n");
+    faimdprintf(sess, 1, "aim_tx_enqueue: ERROR: packet has no connection\n");
     if (newpacket->data)
       free(newpacket->data);
     free(newpacket);
@@ -202,41 +209,6 @@ faim_internal unsigned int aim_get_next_txseqnum(struct aim_conn_t *conn)
   return ret;
 }
 
-/*
- *  aim_tx_printqueue()
- *
- *  This is basically for debuging purposes only.  It dumps all the
- *  records in the tx queue and their current status.  Very helpful
- *  if the queue isn't working quite right.
- *
- */
-#if debug == 2
-faim_internal int aim_tx_printqueue(struct aim_session_t *sess)
-{
-  struct command_tx_struct *cur;
-
-  faimdprintf(2, "\ncurrent aim_queue_outgoing...\n");
-  faimdprintf(2, "\ttype seqnum  len  lock sent\n");  
-
-  if (sess->queue_outgoing == NULL)
-    faimdprintf(2, "aim_tx_flushqueue(): queue empty");
-  else {
-      for (cur = sess->queue_outgoing; cur; cur = cur->next) {
-         faimdprintf(2, "\t  %2x  %2x   %4x %4x   %1d    %1d\n", 
-                     cur->hdrtype,
-                     (cur->hdrtype==AIM_FRAMETYPE_OFT)?cur->hdr.oft.type:cur->hdr.oscar.type, 
-                     (cur->hdrtype==AIM_FRAMETYPE_OSCAR)?cur->hdr.oscar.seqnum:0, 
-                     cur->commandlen, cur->lock, 
-                     cur->sent);
-      }
-  }
-
-  faimdprintf(2, "\n(done printing queue)\n");
-  
-  return 0;
-}
-#endif
-
 /*
  *  aim_tx_flushqueue()
  *
@@ -332,7 +304,7 @@ faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx
   if ((cur->hdrtype == AIM_FRAMETYPE_OFT) && cur->commandlen) {
     int curposi;
     for(curposi = 0; curposi < cur->commandlen; curposi++)
-      printf("%02x ", cur->data[curposi]);
+      faimdprintf(sess, 0, "%02x ", cur->data[curposi]);
 
     if (send(cur->conn->fd, cur->data, cur->commandlen, 0) != (int)cur->commandlen) {
       /* 
@@ -352,21 +324,20 @@ faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx
 
   faim_mutex_unlock(&cur->conn->active);
 
-#if debug > 2
-  faimdprintf(2, "\nPacket:");
-  for (i = 0; i < (cur->commandlen + 6); i++) {
-    if ((i % 8) == 0) {
-      faimdprintf(2, "\n\t");
-    }
-    if (curPacket[i] >= ' ' && curPacket[i]<127) {
-      faimdprintf(2, "%c=%02x ", curPacket[i], curPacket[i]);
-    } else {
-      faimdprintf(2, "0x%2x ", curPacket[i]);
+  if (sess->debug >= 2) {
+    int i;
+
+    faimdprintf(sess, 2, "\nOutgoing packet: (only valid for OSCAR)");
+    for (i = 0; i < buflen; i++) {
+      if (!(i % 8)) 
+       faimdprintf(sess, 2, "\n\t");
+      faimdprintf(sess, 2, "0x%02x ", curPacket[i]);
     }
+    faimdprintf(sess, 2, "\n");
   }
-  faimdprintf(2, "\n");
-#endif
+
   cur->lock = 0; /* unlock the struct */
+
   free(curPacket); /* free up full-packet buffer */
 
   return 1; /* success */
@@ -379,7 +350,7 @@ faim_export int aim_tx_flushqueue(struct aim_session_t *sess)
   if (sess->queue_outgoing == NULL)
     return 0;
 
-  faimdprintf(2, "beginning txflush...\n");
+  faimdprintf(sess, 2, "beginning txflush...\n");
   for (cur = sess->queue_outgoing; cur; cur = cur->next) {
     /* only process if its unlocked and unsent */
     if (!cur->lock && !cur->sent) {
diff --git a/utils/.cvsignore b/utils/.cvsignore
new file mode 100644 (file)
index 0000000..3dda729
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
diff --git a/utils/faimtest/.cvsignore b/utils/faimtest/.cvsignore
new file mode 100644 (file)
index 0000000..ef604ba
--- /dev/null
@@ -0,0 +1,5 @@
+Makefile.in
+Makefile
+.deps
+.libs
+faimtest
index 57593b6447de9c82e39b36889159443d2b6ad0c7..c403ab72da21cf6b6d3d8653f4d9075d329ee407 100644 (file)
  *  please contact me at the address below.
  *
  *  Most everything:
- *  (c) 1998 Adam Fritzler, PST, afritz@iname.com
+ *  (c) 1998 Adam Fritzler, PST, mid@zigamoprh.net
  *
  *  The password algorithms
- *  (c) 1998 Brock Wilcox, awwaiid@iname.com
+ *  (c) 1998 Brock Wilcox, awwaiid@zigamorph.net
  *
  *  THERE IS NO CODE FROM AOL'S AIM IN THIS CODE, NOR
  *  WAS THERE ANY DISASSEMBLAGE TO DEFINE PROTOCOL.  All
@@ -58,21 +58,22 @@ static char *dprintf_ctime(void)
   return retbuf;
 }
 
+#define DPRINTF_OUTSTREAM stdout
 #define dprintf(x) { \
-  printf("%s  %s: " x, dprintf_ctime(), "faimtest"); \
-  fflush(stdout); \
+  fprintf(DPRINTF_OUTSTREAM, "%s  %s: " x, dprintf_ctime(), "faimtest"); \
+  fflush(DPRINTF_OUTSTREAM); \
 }
 #define dvprintf(x, y...) { \
-  printf("%s  %s: " x, dprintf_ctime(), "faimtest", y); \
-  fflush(stdout); \
+  fprintf(DPRINTF_OUTSTREAM, "%s  %s: " x, dprintf_ctime(), "faimtest", y); \
+  fflush(DPRINTF_OUTSTREAM); \
 }
 #define dinlineprintf(x) { \
-  printf(x); \
-  fflush(stdout); \
+  fprintf(DPRINTF_OUTSTREAM, x); \
+  fflush(DPRINTF_OUTSTREAM); \
 }
 #define dvinlineprintf(x, y...) { \
-  printf(x, y); \
-  fflush(stdout); \
+  fprintf(DPRINTF_OUTSTREAM, x, y); \
+  fflush(DPRINTF_OUTSTREAM); \
 }
 #define dperror(x) dvprintf("%s: %s\n", x, strerror(errno));
 
@@ -104,8 +105,7 @@ int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_stru
 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-#define FILESUPPORT
-#ifdef FILESUPPORT
+
 int faimtest_getfile_filereq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...);
@@ -113,8 +113,8 @@ int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_st
 int faimtest_getfile_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_getfile_listing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-int faimtest_getfile_recieve(struct aim_session_t *sess, struct command_rx_struct *command, ...);
-#endif
+int faimtest_getfile_receive(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_state4(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...);
@@ -157,10 +157,16 @@ static char *screenname,*password,*server=NULL;
 static char *ohcaptainmycaptain = NULL;
 static int connected = 0;
 
-#ifdef FILESUPPORT
 FILE *listingfile;
 char *listingpath;
-#endif
+
+static void faimtest_debugcb(struct aim_session_t *sess, int level, const char *format, va_list va)
+{
+
+  vfprintf(stderr, format, va);
+
+  return;
+}
 
 int faimtest_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
@@ -247,9 +253,7 @@ int main(int argc, char **argv)
   proxyusername = getenv("SOCKSNAME");
   proxypass = getenv("SOCKSPASS");
 
-#ifdef FILESUPPORT
   listingpath = getenv("LISTINGPATH");
-#endif
 
   while ((i = getopt(argc, argv, "u:p:a:U:P:A:l:c:h")) != EOF) {
     switch (i) {
@@ -289,9 +293,9 @@ int main(int argc, char **argv)
 #endif /* _WIN32 */
 
   /* Pass zero as flags if you want blocking connects */
-  aim_session_init(&aimsess, AIM_SESS_FLAGS_NONBLOCKCONNECT);
+  aim_session_init(&aimsess, AIM_SESS_FLAGS_NONBLOCKCONNECT, 0);
+  aim_setdebuggingcb(&aimsess, faimtest_debugcb); /* still needed even if debuglevel = 0 ! */
 
-#ifdef FILESUPPORT
   if(listingpath) {
     char *listingname;
     if(!(listingname = (char *)calloc(1, strlen(listingpath)+strlen("/listing.txt")))) {
@@ -306,7 +310,6 @@ int main(int argc, char **argv)
 
     free(listingname);
   }
-#endif
 
   if (proxy)
     aim_setupproxy(&aimsess, proxy, proxyusername, proxypass);
@@ -580,7 +583,7 @@ int faimtest_parse_unknown(struct aim_session_t *sess, struct command_rx_struct
   if (!sess || !command)
     return 1;
 
-  dprintf("\nRecieved unknown packet:");
+  dprintf("\nReceived unknown packet:");
   for (i = 0; i < command->commandlen; i++) {
     if ((i % 8) == 0)
       dinlineprintf("\n\t");
@@ -1012,7 +1015,11 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
        aim_getinfo(sess, command->conn, "15853637", AIM_GETINFO_AWAYMESSAGE);
       } else if (!strncmp(tmpstr, "open directim", 13)) {
        struct aim_conn_t *newconn;
-       newconn = aim_directim_initiate(sess, command->conn, NULL, userinfo->sn);
+       printf("faimtest: opening directim to %s\n", (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
+               newconn = aim_directim_initiate(sess, command->conn, NULL, (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
+       if(!newconn || newconn->fd == -1)
+         printf("connection failed!\n");
+       aim_conn_addhandler(sess, newconn,  AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate,0);
       } else if(!(strncmp(tmpstr, "lookup", 6))) {
        aim_usersearch_address(sess, command->conn, tmpstr+7);
       } else if (!strncmp(tmpstr, "reqsendmsg", 10)) {
@@ -1075,7 +1082,6 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       break;
     }
     case AIM_CAPS_GETFILE: {
-#ifdef FILESUPPORT
       char *ip, *cookie;
       struct aim_conn_t *newconn;
       struct aim_fileheader_t *fh;
@@ -1085,12 +1091,16 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       cookie = va_arg(ap, char *);
       va_end(ap);
       
-      dvprintf("faimtest: get file request from %s (at %s)\n", userinfo->sn, ip);
+      dvprintf("faimtest: get file request from %s (at %s) %x\n", userinfo->sn, ip, reqclass);
+
+      fh = aim_getlisting(sess, listingfile);      
 
-      fh = aim_getlisting(listingfile);      
+      newconn = aim_accepttransfer(sess, command->conn, userinfo->sn, cookie, ip, fh->totfiles, fh->totsize, fh->size, fh->checksum, reqclass);
 
-      if( (newconn = aim_accepttransfer(sess, command->conn, userinfo->sn, cookie, ip, fh->totfiles, fh->totsize, fh->size, fh->checksum, reqclass)) == NULL ) {
+      if( (!newconn) || (newconn->fd == -1) ) {
        dprintf("faimtest: getfile: requestconn: apparent error in accepttransfer\n");
+       if(newconn)
+         aim_conn_kill(sess, &newconn);
        break;
       }
 
@@ -1106,7 +1116,6 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       dprintf("faimtest: getfile connect succeeded, handlers added.\n");
 
       break;
-#endif
     }
     case AIM_CAPS_SENDFILE: {
       dprintf("faimtest: send file!\n");
@@ -1158,10 +1167,17 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
 
       dvprintf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, priv->ip);
       
-      if (!(newconn = aim_directim_connect(sess, command->conn, priv))) {
+      newconn = aim_directim_connect(sess, command->conn, priv);
+
+      if ( (!newconn) || (newconn->fd == -1) ) {
        dprintf("faimtest: icbm: imimage: could not connect\n");
+
+       if (newconn)
+         aim_conn_kill(sess, &newconn);
+
        break;
       }
+
       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
@@ -1186,12 +1202,16 @@ int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_str
 {
   va_list ap;
   struct aim_directim_priv *priv;
-  struct aim_conn_t *newconn;
+  struct aim_conn_t *newconn, *listenerconn;
 
   va_start(ap, command);
   newconn = va_arg(ap, struct aim_conn_t *);
+  listenerconn = va_arg(ap, struct aim_conn_t *);
   va_end(ap);
 
+  aim_conn_close(listenerconn);
+  aim_conn_kill(sess, &listenerconn);
+
   priv = (struct aim_directim_priv *)newconn->priv;
 
   dvprintf("faimtest: OFT: DirectIM: intitiate success to %s\n", priv->ip);
@@ -1627,7 +1647,7 @@ int faimtest_chatnav_info(struct aim_session_t *sess, struct command_rx_struct *
     ck = va_arg(ap, char *);
     va_end(ap);
 
-    dvprintf("faimtest: recieved room create reply for %s/0x%04x\n", fqcn, exchange);
+    dvprintf("faimtest: received room create reply for %s/0x%04x\n", fqcn, exchange);
   }
   break;
   default:
@@ -1671,7 +1691,7 @@ int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_str
 }
 
 /*
- * Recieved in response to an IM sent with the AIM_IMFLAGS_ACK option.
+ * Received in response to an IM sent with the AIM_IMFLAGS_ACK option.
  */
 int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
@@ -1689,7 +1709,6 @@ int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *
   return 1;
 }
 
-#ifdef FILESUPPORT
 int faimtest_getfile_filereq(struct aim_session_t *ses, struct command_rx_struct *command, ...)
 {
   va_list ap;
@@ -1715,8 +1734,8 @@ int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_stru
   struct aim_conn_t *oftconn;
   struct aim_fileheader_t *fh;
   char *path, *cookie;
-  int pos, bufpos, bufsize = 2048, i;
-  char buf[2048];
+  int pos, bufpos = 0, bufsize = 2048, i;
+  char *buf;
 
   FILE *file;
 
@@ -1728,6 +1747,9 @@ int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_stru
 
   dvprintf("faimtest: sending file %s(%ld).\n", fh->name, fh->size);
 
+  if(!(buf = malloc(2048)))
+     return -1;
+
   if( (path = (char *)calloc(1, strlen(listingpath) +strlen(fh->name)+2)) == NULL) {
     dperror("calloc");
     dprintf("faimtest: error in calloc of path\n");
@@ -1741,7 +1763,12 @@ int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_stru
     dvprintf("faimtest: getfile_send fopen failed for %s. damn.\n", path);
     return 0;
   }
-  
+
+  /* 
+   * This is a mess. Remember that faimtest is demonstration code
+   * only and for the sake of the gods, don't use this code in any
+   * of your clients. --mid
+   */
   for(pos = 0; pos < fh->size; pos++) {
     bufpos = pos % bufsize;
 
@@ -1770,7 +1797,7 @@ int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_stru
     return -1;
   }
 
-
+  free(buf);
   free(fh);  
   return 1;
 }
@@ -1812,26 +1839,29 @@ int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_st
 int faimtest_getfile_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   va_list ap;
-  struct aim_conn_t *conn;
-  char *sn;
+  struct aim_conn_t *conn, *listenerconn;
   struct aim_filetransfer_priv *priv;
 
   va_start(ap, command);
   conn = va_arg(ap, struct aim_conn_t *);
-  sn = va_arg(ap, char *);
+  listenerconn = va_arg(ap, struct aim_conn_t *);
   va_end(ap);
 
+  aim_conn_close(listenerconn);
+  aim_conn_kill(sess, &listenerconn);
+
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ,  faimtest_getfile_filereq, 0);
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, faimtest_getfile_filesend, 0);
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, faimtest_getfile_complete, 0);      
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, faimtest_getfile_disconnect, 0);      
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING, faimtest_getfile_listing, 0);
   aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ, faimtest_getfile_listingreq, 0);
-  aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECIEVE, faimtest_getfile_recieve, 0);
+  aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE, faimtest_getfile_receive, 0);
+  aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4, faimtest_getfile_state4, 0);
   
   priv = (struct aim_filetransfer_priv *)conn->priv;
 
-  dvprintf("faimtest: getfile: %s (%s) connected to us on %d\n", sn, priv->ip, conn->fd);
+  dvprintf("faimtest: getfile: %s (%s) connected to us on %d\n", priv->sn, priv->ip, conn->fd);
   return 1;
 }
 
@@ -1881,9 +1911,8 @@ int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_st
   va_list ap;
   struct aim_conn_t *oftconn;
   struct aim_fileheader_t *fh;
-  int pos, bufpos, bufsize = 2048, i;
-  char buf[2048];
-
+  int pos, bufpos = 0, bufsize = 2048, i;
+  char *buf;
 
   va_start(ap, command);
   oftconn = va_arg(ap, struct aim_conn_t *);
@@ -1892,6 +1921,9 @@ int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_st
 
   dvprintf("faimtest: sending listing of size %ld\n", fh->size);
 
+  if(!(buf = malloc(2048)))
+    return -1;
+
   for(pos = 0; pos < fh->size; pos++) {
     bufpos = pos % bufsize;
 
@@ -1920,10 +1952,11 @@ int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_st
   }
 
   dprintf("faimtest: sent listing\n");
+  free(buf);
   return 0;
 }
 
-int faimtest_getfile_recieve(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+int faimtest_getfile_receive(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   va_list ap;
   struct aim_conn_t *conn;
@@ -1940,17 +1973,31 @@ int faimtest_getfile_recieve(struct aim_session_t *sess, struct command_rx_struc
 
   for(pos = 0; pos < ft->fh.size; pos++) {
     read(conn->fd, &data, 1);
-    dvprintf("%c(%02x) ", data, data);
+    printf("%c(%02x) ", data, data);
   }
    
-  dprintf("\n");
+  printf("\n");
 
-  aim_oft_getfile_ack(sess, conn);
   aim_oft_getfile_end(sess, conn);
 
   return 0;
 }
-#endif
+
+int faimtest_getfile_state4(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *conn;
+
+  va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  va_end(ap);
+
+  aim_conn_close(conn);
+  aim_conn_kill(sess, &conn);
+  return 0;
+}
+
+
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   static char *codes[5] = {"invalid",
This page took 0.311753 seconds and 5 git commands to generate.