]> andersk Git - libfaim.git/commitdiff
- Sat Sep 8 07:32:27 PDT 2001
authormid <mid>
Sat, 8 Sep 2001 14:46:05 +0000 (14:46 +0000)
committermid <mid>
Sat, 8 Sep 2001 14:46:05 +0000 (14:46 +0000)
  - Clean up ft.c slightly.  Direct IM now works.  In both directions.
   - This could still use a lot more help.  It should use bstreams more.

CHANGES
include/aim.h
include/aim_internal.h
src/conn.c
src/ft.c
src/im.c
src/txqueue.c
utils/faimtest/faimtest.c
utils/faimtest/ft.c

diff --git a/CHANGES b/CHANGES
index 5929472a1e9befe6ddda42ecd26e707a93569392..5728a35a0c15603688f90d7d3de3b40a923ebf0e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
 
 No release numbers
 ------------------
+ - Sat Sep  8 07:32:27 PDT 2001
+  - Clean up ft.c slightly.  Direct IM now works.  In both directions.
+   - This could still use a lot more help.  It should use bstreams more.
+
  - Sat Sep  8 00:55:46 PDT 2001
   - Chatnav loop fix. (Err. I shouldn't code when I'm that tired.)
   - Remove some things from BUGS
index cb0b8d429a40ef37a105a85eb8d3ae50290a7480..ffd7c8c625fc2f375417b8379e44481e9cf849fc 100644 (file)
@@ -268,6 +268,7 @@ typedef struct aim_conn_s {
        flap_seqnum_t seqnum;
        fu32_t status;
        void *priv; /* misc data the client may want to store */
+       void *internal; /* internal conn-specific libfaim data */
        time_t lastactivity; /* time of last transmit */
        int forcedlatency; 
        void *handlerlist;
@@ -609,11 +610,6 @@ faim_export int aim_ads_clientready(aim_session_t *sess, aim_conn_t *conn);
 faim_export int aim_ads_requestads(aim_session_t *sess, aim_conn_t *conn);
 
 /* aim_im.c */
-struct aim_directim_priv {
-       fu8_t cookie[8];
-       char sn[MAXSNLEN+1];
-       fu8_t ip[30];
-};
 
 struct aim_fileheader_t {
 #if 0
@@ -716,8 +712,9 @@ struct aim_incomingim_ch1_args {
 };
 
 struct aim_incomingim_ch2_args {
-       unsigned short reqclass;
-       unsigned short status;
+       fu8_t cookie[8];
+       fu16_t reqclass;
+       fu16_t status;
        union {
                struct {
                        fu32_t checksum;
@@ -727,7 +724,9 @@ struct aim_incomingim_ch2_args {
                } icon;
                struct {
                } voice;
-               struct aim_directim_priv *directim;
+               struct {
+                       fu8_t ip[22]; /* xxx.xxx.xxx.xxx:xxxxx\0 */
+               } imimage;
                struct {
                        char *msg;
                        char *encoding;
@@ -748,8 +747,9 @@ faim_export int aim_send_im(aim_session_t *, aim_conn_t *, const char *destsn, u
 faim_export int aim_send_icon(aim_session_t *sess, aim_conn_t *conn, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu32_t iconsum);
 faim_export fu32_t aim_iconsum(const fu8_t *buf, int buflen);
 faim_export int aim_send_im_direct(aim_session_t *, aim_conn_t *, const char *msg);
-faim_export aim_conn_t *aim_directim_initiate(aim_session_t *, aim_conn_t *, struct aim_directim_priv *, const char *destsn);
-faim_export aim_conn_t *aim_directim_connect(aim_session_t *, aim_conn_t *, struct aim_directim_priv *);
+faim_export const char *aim_directim_getsn(aim_conn_t *conn);
+faim_export aim_conn_t *aim_directim_initiate(aim_session_t *, aim_conn_t *, const char *destsn);
+faim_export aim_conn_t *aim_directim_connect(aim_session_t *, const char *sn, const char *addr, const fu8_t *cookie);
 
 faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn);
 faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size);
index 1c79bd51bf1860cf61eed81312c4ff70031e3217..e4ac4379e7e0919237007c4034dc59cfe37c9eed 100644 (file)
@@ -109,7 +109,6 @@ faim_internal aim_conn_t *aim_cloneconn(aim_session_t *sess, aim_conn_t *src);
 faim_internal void aim_clonehandlers(aim_session_t *sess, aim_conn_t *dest, aim_conn_t *src);
 
 faim_internal int aim_oft_buildheader(unsigned char *,struct aim_fileheader_t *);
-faim_internal int aim_listenestablish(u_short);
 
 faim_internal int aim_parse_unknown(aim_session_t *, aim_frame_t *, ...);
 
@@ -128,6 +127,12 @@ struct aim_tool_version {
        fu16_t toolversion;
 };
 
+struct aim_directim_intdata {
+       fu8_t cookie[8];
+       char sn[MAXSNLEN+1];
+       char ip[22];
+};
+
 faim_internal fu16_t aim_getcap(aim_session_t *sess, aim_bstream_t *bs, int len);
 faim_internal int aim_putcap(aim_bstream_t *bs, fu16_t caps);
 
index 0c6168671da0c54ac7854fb8d2f2738b12250892..cd0ef3624ff59a93c0a604a56a0d417f5eaae591 100644 (file)
@@ -144,6 +144,8 @@ faim_export void aim_conn_kill(aim_session_t *sess, aim_conn_t **deadconn)
                aim_conn_close(*deadconn);
        if ((*deadconn)->priv)
                free((*deadconn)->priv);
+       if ((*deadconn)->internal)
+               free((*deadconn)->internal);
        free(*deadconn);
        deadconn = NULL;
 
@@ -425,6 +427,7 @@ faim_internal aim_conn_t *aim_cloneconn(aim_session_t *sess, aim_conn_t *src)
        conn->subtype = src->subtype;
        conn->seqnum = src->seqnum;
        conn->priv = src->priv;
+       conn->internal = src->internal;
        conn->lastactivity = src->lastactivity;
        conn->forcedlatency = src->forcedlatency;
        conn->sessv = src->sessv;
index fabd309dd03a512b0c3b0ff2124a631e4b7fca69..0ab1140b54c2b12995740cb0ab3480eac492c433 100644 (file)
--- a/src/ft.c
+++ b/src/ft.c
 
 #endif
 
-#if 0
-
 /* TODO: 
    o look for memory leaks.. there's going to be shitloads, i'm sure. 
 */
 
+static int listenestablish(fu16_t portnum);
 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr);
  
 /**
@@ -36,82 +35,69 @@ static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr);
  * 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)
+faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur)
 { 
-  int acceptfd = 0;
-  aim_rxcallback_t userfunc;
-  struct sockaddr cliaddr;
-  int clilen = sizeof(cliaddr);
-  int ret = 0;
-  struct aim_conn_t *newconn;
-
-  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);
-    aim_conn_close(cur);
-    return -1;
-  } 
-
-  /* safe? maybe cur->priv should be NULLed after this. --mid */
+       int acceptfd = 0;
+       struct sockaddr cliaddr;
+       int clilen = sizeof(cliaddr);
+       int ret = 0;
+       aim_conn_t *newconn;
 
-  /* 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 ((acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1)
+               return 0; /* not an error */
 
-  if (!(newconn = aim_cloneconn(sess, cur))) {
-    close(acceptfd);
-    aim_conn_close(cur);
-    return -1;
-  }
+       if (cliaddr.sa_family != AF_INET) { /* just in case IPv6 really is happening */
+               close(acceptfd);
+               aim_conn_close(cur);
+               return -1;
+       } 
 
-  newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
-  newconn->fd = acceptfd;
+       if (!(newconn = aim_cloneconn(sess, cur))) {
+               close(acceptfd);
+               aim_conn_close(cur);
+               return -1;
+       }
 
-  switch(newconn->subtype) {
-  case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { 
-    struct aim_directim_priv *priv;
+       newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
+       newconn->fd = acceptfd;
 
-    priv = cur->priv;
+       if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { 
+               struct aim_directim_intdata *priv;
+               aim_rxcallback_t userfunc;
 
-    newconn->priv = cur->priv;
+               priv = (struct aim_directim_intdata *)(newconn->internal = cur->internal);
+               cur->internal = NULL;
 
-    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));
 
-    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(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 ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE)))
+                       ret = userfunc(sess, NULL, newconn, cur);
 
+       } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) {
+#if 0
+               struct aim_filetransfer_priv *priv;
+               aim_rxcallback_t userfunc;
 
-    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));
+               newconn->priv = cur->priv;
+               cur->priv = NULL;
+               priv = (struct aim_filetransfer_priv *)newconn->priv;
 
-    if ( (userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
-      ret = userfunc(sess, NULL, newconn, cur);
+               snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
 
-    break;
-  }
-  default: { 
-    faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous(??!) Closing conn.\n");
-    aim_conn_close(newconn);
-    break;
-  }
-  }
+               if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
+                       ret = userfunc(sess, NULL, newconn, cur);
+#endif
+       } else { 
+               faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous(??!) Closing conn.\n");
+               aim_conn_close(newconn);
+               ret = -1;
+       }
 
-  return ret;
+       return ret;
 }
-#endif
 
 /**
  * aim_send_im_direct - send IM client-to-client over established connection
@@ -124,107 +110,174 @@ faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_con
  */
 faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg)
 {
-       return -EINVAL;
-#if 0
-  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(sess, 2,"faim: directim: invalid arguments\n");
-    return -1;
-  }
-
-  priv = (struct aim_directim_priv *)conn->priv;
-
-  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 (strlen(msg) >= MAXMSGLEN)
-      return -1;
-    newpacket->hdr.oft.hdr2len = 0x54;
-    if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) { 
-      newpacket->lock = 0;
-      aim_frame_destroy(newpacket);
-      return -1;
-    } 
-  } else { 
-    newpacket->hdr.oft.hdr2len = 0x44;
-    if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) { 
-      newpacket->lock = 0;
-      aim_frame_destroy(newpacket);
-      return -1;
-    } 
-  } 
+       struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal;
+       aim_frame_t *fr;
+       aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */
+
+       if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) 
+               return -EINVAL; 
+
+       if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, strlen(msg))))
+              return -ENOMEM;  
+
+       memcpy(fr->hdr.oft.magic, "ODC2", 4);
+       
+       fr->hdr.oft.hdr2len = 0x44;
+       
+       if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { 
+               aim_frame_destroy(fr);
+               return -ENOMEM;
+       }
+       
+       aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len);
+
+       aimbs_put16(&hdrbs, 0x0006);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_putraw(&hdrbs, intdata->cookie, 8);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put32(&hdrbs, strlen(msg));
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+
+       /* flags -- 0x000e for "typing", 0x0000 for message */
+       aimbs_put16(&hdrbs, msg ? 0x0000 : 0x000e);
+
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn));
+
+       aim_bstream_setpos(&hdrbs, 52); /* bleeehh */
+
+       aimbs_put8(&hdrbs, 0x00);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_put16(&hdrbs, 0x0000);
+
+       /* end of hdr2 */
+
+       if (msg) {
+#if 0 /* XXX this is how you send buddy icon info... */        
+               i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008);
+               i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c);
+               i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
+               i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);
+               i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);
+               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);
+#endif
+               aimbs_putraw(&fr->data, msg, strlen(msg));
+       } 
 
-  memcpy(newpacket->hdr.oft.magic, "ODC2", 4);
-  newpacket->data = NULL;
-
-  i = 0;
-  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006);
-  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
-  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_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  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)
-    i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  else 
-    i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000e);
-
-  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-  i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->sn, strlen(sess->sn));
-  i = 52;
-
-  i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00);
-  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_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_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-
-  /* end of hdr2 */
-
-  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);
-    i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
-    i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);
-    i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);
-    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);
-    if(!(newpacket->data = strdup(msg)))
-      return -1;
-  } 
-  newpacket->lock = 0;
-  aim_tx_enqueue(sess, newpacket);
+       aim_tx_enqueue(sess, fr);
 
-  return 0;
-#endif
+       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 */
 
+static int getlocalip(fu8_t *ip)
+{
+       struct hostent *hptr;
+       char localhost[129];
+
+       /* XXX if available, use getaddrinfo() */
+       /* XXX allow client to specify which IP to use for multihomed boxes */
+
+       if (gethostname(localhost, 128) < 0)
+               return -1;
+
+       if (!(hptr = gethostbyname(localhost)))
+               return -1;
+
+       memcpy(ip, hptr->h_addr_list[0], 4);
+
+       return 0;
+}
+
+/* XXX this should probably go in im.c */
+static int aim_request_directim(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu8_t *ip, fu16_t port, fu8_t *ckret)
+{
+       fu8_t ck[8];
+       aim_frame_t *fr;
+       aim_snacid_t snacid;
+       aim_tlvlist_t *tl = NULL, *itl = NULL;
+       int hdrlen, i;
+       fu8_t *hdr;
+       aim_bstream_t hdrbs;
+
+       if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 256+strlen(destsn))))
+               return -ENOMEM;
+
+       snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
+       aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
+
+       /* 
+        * Generate a random message cookie 
+        *
+        * This cookie needs to be alphanumeric and NULL-terminated to be 
+        * TOC-compatible.
+        *
+        * XXX have I mentioned these should be generated in msgcookie.c?
+        *
+        */
+       for (i = 0; i < 7; i++)
+               ck[i] = 0x30 + ((fu8_t) rand() % 10);
+       ck[7] = '\0';
+
+       if (ckret)
+               memcpy(ckret, ck, 8);
+
+       /* Cookie */
+       aimbs_putraw(&fr->data, ck, 8);
+
+       /* Channel */
+       aimbs_put16(&fr->data, 0x0002);
+
+       /* Destination SN */
+       aimbs_put8(&fr->data, strlen(destsn));
+       aimbs_putraw(&fr->data, destsn, strlen(destsn));
+
+       aim_addtlvtochain_noval(&tl, 0x0003);
+
+       hdrlen = 2+8+16+6+8+6+4;
+       hdr = malloc(hdrlen);
+       aim_bstream_init(&hdrbs, hdr, hdrlen);
+
+       aimbs_put16(&hdrbs, 0x0000);
+       aimbs_putraw(&hdrbs, ck, 8);
+       aim_putcap(&hdrbs, AIM_CAPS_IMIMAGE);
+
+       aim_addtlvtochain16(&itl, 0x000a, 0x0001);
+       aim_addtlvtochain_raw(&itl, 0x0003, 4, ip);
+       aim_addtlvtochain16(&itl, 0x0005, port);
+       aim_addtlvtochain_noval(&itl, 0x000f);
+       
+       aim_writetlvchain(&hdrbs, &itl);
+
+       aim_addtlvtochain_raw(&tl, 0x0005, aim_bstream_curpos(&hdrbs), hdr);
+
+       aim_writetlvchain(&fr->data, &tl);
+
+       free(hdr);
+       aim_freetlvchain(&itl);
+       aim_freetlvchain(&tl);
+
+       aim_tx_enqueue(sess, fr);
+
+       return 0;
+}
+
 /**
  * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves.
  * @sess: your session,
@@ -233,128 +286,55 @@ faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const
  * @destsn: the SN to connect to.
  *
  */
-faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, aim_conn_t *conn, struct aim_directim_priv *priv, const char *destsn)
+faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn)
 { 
-       return NULL;
-#if 0
-  struct command_tx_struct *newpacket;
-  struct aim_conn_t *newconn;
-  struct aim_msgcookie_t *cookie;
-  int curbyte, i, listenfd;
-  short port = 4443;
-  struct hostent *hptr;
-  char localhost[129];
-  unsigned char cap[16];
-  char d[4]; /* IPv6 is a bit bigger... */
-
-  /* XXX: TLVlist-ize this */
-  /* Open our socket */
-
-  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)
-    return NULL;
-  if ( (hptr = gethostbyname(localhost)) == NULL)
-    return NULL;
-  memcpy(&d, hptr->h_addr_list[0], 4);
-
-  aim_putcap(cap, 16, AIM_CAPS_IMIMAGE);
-
-  /* create the OSCAR packet */
-
-  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;
-
-  curbyte = 0;
-  curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
-
-  /* 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) rand() % 20));
-
-  curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
-
-  /* grab all the data for cookie caching */
-  cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t));
-  memcpy(cookie->cookie, newpacket->data+curbyte-8, 8);
-  cookie->type = AIM_COOKIETYPE_OFTIM;
-  priv = cookie->data;
-
-  if (!priv)
-    priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
-  memcpy(priv->cookie, cookie, 8);
-  memcpy(priv->sn, destsn, sizeof(priv->sn));
-  cookie->data = priv;
-  aim_cachecookie(sess, cookie);
-
-  /* Channel ID */
-  curbyte += aimutil_put16(newpacket->data+curbyte,0x0002);
+       aim_conn_t *newconn;
+       aim_msgcookie_t *cookie;
+       struct aim_directim_intdata *priv;
+       int listenfd;
+       fu16_t port = 4443;
+       fu8_t localip[4];
+       fu8_t ck[8];
 
-  /* 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);
+       if (getlocalip(localip) == -1)
+               return NULL;
 
-  /* enTLV start */
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032);
+       if ((listenfd = listenestablish(port)) == -1)
+               return NULL;
 
-  /* Flag data / ICBM Parameters  */
-  curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
-  curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
+       aim_request_directim(sess, conn, destsn, localip, port, ck);
 
-  /* Cookie  */
-  curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8);
+       cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t));
+       memcpy(cookie->cookie, ck, 8);
+       cookie->type = AIM_COOKIETYPE_OFTIM;
 
-  /*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);
+       priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata));
 
-  /* 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]);
-  /* 0005/0002: Port */
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
-  curbyte += aimutil_put16(newpacket->data+curbyte, port);
+       memcpy(priv->cookie, ck, 8);
+       memcpy(priv->sn, destsn, sizeof(priv->sn));
+       cookie->data = priv;
+       aim_cachecookie(sess, cookie);
 
-  /* 000f/0000: ?? */
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
-  newpacket->commandlen = curbyte;
-  newpacket->lock = 0;
-  aim_tx_enqueue(sess, newpacket);
+       /* XXX switch to aim_cloneconn()? */
+       if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) {
+               close(listenfd);
+               return NULL;
+       }
 
+       /* this one is for the conn */
+       priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata));
 
-  /* XXX switch to aim_cloneconn()? */
-  if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL)))
-    return NULL;
+       memcpy(priv->cookie, ck, 8);
+       memcpy(priv->sn, destsn, sizeof(priv->sn));
 
-  newconn->fd = listenfd;
-  newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
-  newconn->priv = priv;
-  newconn->lastactivity = time(NULL);
+       newconn->fd = listenfd;
+       newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
+       newconn->internal = priv;
+       newconn->lastactivity = time(NULL);
 
-  faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
+       faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd);
 
-  return newconn;
-#endif
+       return newconn;
 } 
 
 #if 0
@@ -390,40 +370,70 @@ faim_export unsigned int aim_oft_listener_clean(struct aim_session_t *sess, time
 } 
 #endif 
 
+faim_export const char *aim_directim_getsn(aim_conn_t *conn)
+{
+       struct aim_directim_intdata *intdata;
+
+       if (!conn)
+              return NULL;
+
+       if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || 
+                       (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM))
+              return NULL;
+
+       if (!conn->internal)
+               return NULL;
+
+       intdata = (struct aim_directim_intdata *)conn->internal;
+
+       return intdata->sn;
+}
+
 /**
  * aim_directim_connect - connect to buddy for directim
  * @sess: the session to append the conn to,
- * @conn: the BOS connection,
- * @priv: the filled-in priv data structure for the connection 
+ * @sn: the SN we're connecting to
+ * @addr: address to connect to
+ *
+ * This is a wrapper for aim_newconn.
+ *
+ * If addr is NULL, the socket is not created, but the connection is 
+ * allocated and setup to connect.
  *
- * returns conn if connected, %NULL on error
  */
-faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, aim_conn_t *conn, struct aim_directim_priv *priv)
+faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie)
 { 
-       return NULL;
-#if 0
-  struct aim_conn_t *newconn = NULL;
+       aim_conn_t *newconn;
+       struct aim_directim_intdata *intdata;
 
-  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(sess, 2, "could not connect to %s\n", priv->ip);
-    perror("aim_newconn");
-    return newconn;
-  }
+       if (!sess || !sn)
+               return NULL;
 
-  newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
-  newconn->priv = priv;
-  faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd);
+       if (!(intdata = malloc(sizeof(struct aim_directim_intdata))))
+               return NULL;
+       memset(intdata, 0, sizeof(struct aim_directim_intdata));
 
-  return newconn;
-#endif
+       memcpy(intdata->cookie, cookie, 8);
+       strncpy(intdata->sn, sn, sizeof(intdata->sn));
+       strncpy(intdata->ip, addr, sizeof(intdata->ip));
+
+       /* XXX verify that non-blocking connects actually work */
+       if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) {
+               free(intdata);
+               return NULL;
+       }
+
+       if (!newconn || (newconn->fd == -1)) {
+               free(intdata);
+               return newconn;
+       }
+
+       newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
+       newconn->internal = intdata;
+
+       return newconn;
 } 
 
-#if 0
 /**
  * aim_directim_getconn - find a directim conn for buddy name
  * @sess: your session,
@@ -432,26 +442,27 @@ faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, aim_conn_t *co
  * returns conn for directim with name, %NULL if none found. 
  *
  */
-faim_export struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess, const char *name)
+faim_export aim_conn_t *aim_directim_getconn(aim_session_t *sess, const char *name)
 {
-  struct aim_conn_t *cur;
-  struct aim_directim_priv *priv;
+       aim_conn_t *cur;
 
-  if (!sess || !name)
-    return NULL;
+       if (!sess || !name || !strlen(name))
+               return NULL;
 
-  faim_mutex_lock(&sess->connlistlock);
+       for (cur = sess->connlist; cur; cur = cur->next) {
+               struct aim_directim_intdata *intdata;
+               
+               if ((cur->type != AIM_CONN_TYPE_RENDEZVOUS) || (cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM))
+                       continue;
 
-  for (cur = sess->connlist; cur; cur = cur->next) {
-    if (cur->type != AIM_CONN_TYPE_RENDEZVOUS || cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)
-      continue;
-    priv = cur->priv;
-    if (aim_sncmp(priv->sn, name) == 0)
-      break;
-  } faim_mutex_unlock(&sess->connlistlock);
-  return cur;
+               intdata = cur->internal;
+
+               if (aim_sncmp(intdata->sn, name) == 0)
+                       break;
+       }
+
+       return cur;
 } 
-#endif
 
 /**
  * aim_accepttransfer - accept a file transfer request
@@ -756,663 +767,627 @@ faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *f
  * you need to call accept() when it's connected. returns your fd 
  *
  */
-faim_export int aim_listenestablish(fu16_t portnum)
+static int listenestablish(fu16_t portnum)
 {
-       return -EINVAL;
-#if 0
 #if defined(__linux__)
-  /* XXX what other OS's support getaddrinfo? */
-  int listenfd;
-  const int on = 1;
-  struct addrinfo hints, *res, *ressave;
-  char serv[5];
-
-  snprintf(serv, sizeof(serv), "%d", portnum);
-  memset(&hints, 0, sizeof(struct addrinfo));
-  hints.ai_flags = AI_PASSIVE;
-  hints.ai_family = AF_UNSPEC;
-  hints.ai_socktype = SOCK_STREAM;
-  if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) {
-    perror("getaddrinfo");
-    return -1;
-  } 
-  ressave = res;
-  do { 
-    listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);    
-    if (listenfd < 0)
-      continue;
-    setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-    if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
-      break;
-    /* success */
-    close(listenfd);
-  } while ( (res = res->ai_next) );
-
-  if (!res)
-    return -1;
-  
-  if (listen(listenfd, 1024)!=0) { 
-    perror("listen");
-    return -1;
-  } 
+       /* XXX what other OS's support getaddrinfo? */
+       int listenfd;
+       const int on = 1;
+       struct addrinfo hints, *res, *ressave;
+       char serv[5];
+
+       snprintf(serv, sizeof(serv), "%d", portnum);
+       memset(&hints, 0, sizeof(struct addrinfo));
+       hints.ai_flags = AI_PASSIVE;
+       hints.ai_family = AF_UNSPEC;
+       hints.ai_socktype = SOCK_STREAM;
+       if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) {
+               perror("getaddrinfo");
+               return -1;
+       } 
+       ressave = res;
+       do { 
+               listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);    
+               if (listenfd < 0)
+                       continue;
+               setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+               if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
+                       break;
+               /* success */
+               close(listenfd);
+       } while ( (res = res->ai_next) );
+
+       if (!res)
+               return -1;
+
+       if (listen(listenfd, 1024)!=0) { 
+               perror("listen");
+               return -1;
+       } 
+
+       freeaddrinfo(ressave);
+       return listenfd;
+#else
+       int listenfd;
+       const int on = 1;
+       struct sockaddr_in sockin;
+
+       if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+               perror("socket(listenfd)");
+               return -1;
+       }
+
+       if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on) != 0)) {
+               perror("setsockopt(listenfd)");
+               close(listenfd);
+               return -1;
+       } 
+
+       memset(&sockin, 0, sizeof(struct sockaddr_in));
+       sockin.sin_family = AF_INET;
+       sockin.sin_port = htons(portnum);
+
+       if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
+               perror("bind(listenfd)");
+               close(listenfd);
+               return -1;
+       }
+       if (listen(listenfd, 4) != 0) {
+               perror("listen(listenfd)");
+               close(listenfd);
+               return -1;
+       }
+       return listenfd;
+#endif
+} 
 
-  freeaddrinfo(ressave);
-  return listenfd;
+static int getcommand_getfile(aim_session_t *sess, aim_conn_t *conn)
+{
+#if 0
+       struct aim_filetransfer_priv *ft;
+       aim_rxcallback_t userfunc;
+
+       ft = conn->priv;
+       if (ft->state == 2) {
+               /* waiting on listing data */
+               int ret = 0;
+               char *listing;
+               struct command_tx_struct *newoft;
+
+               if (!(listing = malloc(ft->fh.size)))
+                       return -1;
+
+               ft->state = 0;
+               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(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);
+                       return -1;
+               }
+
+               memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+               newoft->hdr.oft.hdr2len = 0x100 - 8;
+
+               /* 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;
+
+               if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
+                       aim_frame_destroy(newoft);
+                       free(listing);
+                       return -1;
+               }
+
+               if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh))))
+                       faimdprintf(sess, 2, "eek! bh fail listing\n");
+
+               /* send the 120b */
+               aim_tx_enqueue(sess, newoft);
+               if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) )
+                       ret = userfunc(sess, NULL, conn, ft, listing);
+
+               free(listing);
+               return ret;
+       }
+
+       if (ft->state == 3) { 
+               /* waiting on file data */
+               if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) 
+                       return userfunc(sess, NULL, conn, ft);
+               return 0;
+       }
+
+       if (ft->state == 4) {
+               if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) )
+                       return userfunc(sess, NULL, conn);
+               aim_conn_close(conn);
+               return 0;
+       }       
+
+       return 0;
 #else
-  int listenfd;
-  const int on = 1;
-  struct sockaddr_in sockin;
+       return -1;
+#endif
+}
 
-  if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-    perror("socket(listenfd)");
-    return -1;
-  }
+static void disconnected_sendfile(aim_session_t *sess, aim_conn_t *conn)
+{
+       aim_frame_t fr;
+       aim_rxcallback_t userfunc;
+       aim_msgcookie_t *cook;
+       struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv;
 
-  if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on) != 0)) {
-    perror("setsockopt(listenfd)");
-    close(listenfd);
-    return -1;
-  } 
-  
-  memset(&sockin, 0, sizeof(struct sockaddr_in));
-  sockin.sin_family = AF_INET;
-  sockin.sin_port = htons(portnum);
+       cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
+       aim_cookie_free(sess, cook);
 
-  if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
-    perror("bind(listenfd)");
-    close(listenfd);
-    return -1;
-  }
-  if (listen(listenfd, 4) != 0) {
-    perror("listen(listenfd)");
-    close(listenfd);
-    return -1;
-  }
-  return listenfd;
-#endif
-#endif
-} 
+       fr.conn = conn;
 
-/**
- * aim_get_command_rendezvous - OFT equivalent of aim_get_command
- * @sess: session to work on
- * @conn: conn to pull data from 
- *
- * this reads and handles data from conn->fd. currently a little rough
- * around the edges
- */
-faim_internal int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn)
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) ) 
+               userfunc(sess, &fr, priv->sn);
+
+       return;
+}
+
+static void disconnected_getfile(aim_session_t *sess, aim_conn_t *conn)
 {
-#if 0
-  unsigned char hdrbuf1[6];
-  unsigned char *hdr = NULL;
-  int hdrlen, hdrtype;
-  int flags = 0;
-  aim_rxcallback_t userfunc = NULL;
-  
-  if (!sess || !conn || !conn->priv)
-    return -1;
+       aim_frame_t fr;
+       aim_rxcallback_t userfunc;
+       aim_msgcookie_t *cook;
+       struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv;
 
-  memset(hdrbuf1, 0, sizeof(hdrbuf1));
-  faim_mutex_lock(&conn->active);
-  
- /* gets locked down for the entirety */
-
-  if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE ) { 
-    struct aim_filetransfer_priv *ft;
-    ft = conn->priv;
-    if (ft->state == 2) {
-      /* waiting on listing data */
-      int ret = 0;
-      char *listing;
-      struct command_tx_struct *newoft;
-      if (!(listing = malloc(ft->fh.size))) {
-       faim_mutex_unlock(&conn->active);
-       return -1;
-      }
+       cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
+       aim_cookie_free(sess, cook);
 
-     ft->state = 0;
-     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(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);
-       return -1;
-     }
-
-     newoft->lock = 1;
-
-     memcpy(newoft->hdr.oft.magic, "OFT2", 4);
-     newoft->hdr.oft.hdr2len = 0x100 - 8;
-     
-     /* 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;
-     
-     if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
-       newoft->lock = 0;
-       aim_frame_destroy(newoft);
-       free(listing);
-       faim_mutex_unlock(&conn->active);
-       return -1;
-     }
-     
-     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(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) { 
-     /* waiting on file data */
-     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(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)
-     perror("read");
-   else { /* disconnected */
-     char *screenname = NULL;
-     int ret;
-     struct aim_msgcookie_t *cook;
-
-     switch(conn->subtype) { 
-     case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { 
-       struct aim_directim_priv *priv = NULL;
-       if (!(priv = (struct aim_directim_priv *)conn->priv) )
-        return -1;
-
-       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);
-        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))
-        return -1;
-       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);
-        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))
-        return -1;
-
-       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);
-        ret = userfunc(sess, NULL, conn, screenname);
-        free(screenname);
-        return ret;
-       }
-       break;
-     } 
-     }
-
-     aim_conn_close(conn);
-     return -1;
-   }
- }
+       fr.conn = conn;
 
- hdrlen = aimutil_get16(hdrbuf1+4);
hdrlen -= 6;
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) )
              userfunc(sess, &fr, priv->sn);
 
- if (!(hdr = malloc(hdrlen))) { 
-   faim_mutex_unlock(&conn->active);
-   return -1;
- }
+       return;
+}
 
- if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) {
-   perror("read");
-   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);
-
- switch (hdrtype) {
- case 0x0001: {    /* directim */
-   int payloadlength = 0;
-   char *snptr = NULL;
-   struct aim_directim_priv *priv;
-   int i;
-
-   if (!(priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)))) {
-     faim_mutex_unlock(&conn->active);
-     free(hdr);
-     return -1;
-   }
-   
-   payloadlength = aimutil_get32(hdr+22);
-   flags = aimutil_get16(hdr+32);
-   snptr = (char *)hdr+38;
-   strncpy(priv->sn, snptr, MAXSNLEN);
-
-   faimdprintf(sess, 2, "faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, priv->sn);
-
-   free(hdr);
-   hdr = NULL;
-
-   if (flags == 0x000e) { 
-     faim_mutex_unlock(&conn->active);
-     if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
-       return userfunc(sess, NULL, conn);
-   } else {
-
-     if ((flags == 0x0000) && payloadlength) { 
-       unsigned char *msg;
-
-       if (!(msg = calloc(1, payloadlength+1))) {
-        faim_mutex_unlock(&conn->active);
-        return -1;
-       }
-
-       if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) {
-        perror("read");
-        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(sess, 2, "faim: directim: %s/%04x/%04x/%s\n", priv->sn, payloadlength, flags, msg);
-
-       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
-        i = userfunc(sess, NULL, conn, msg);
-       else {
-         faimdprintf(sess, 0, "directim: %s/%04x/%04x/%s\n", priv->sn, payloadlength, flags, msg);
-        i = 1;
-       }
-
-       free(msg);
-
-       return i;
-     }
-   }
-   break;
- }
- case 0x1108: { /* getfile listing.txt incoming tx->rx */
-   struct aim_filetransfer_priv *ft;
-   struct aim_fileheader_t *fh;
-   struct aim_msgcookie_t *cook;
-   struct command_tx_struct *newoft;
+static void disconnected_directim(aim_session_t *sess, aim_conn_t *conn)
+{
+       aim_frame_t fr;
+       struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal;
+       aim_rxcallback_t userfunc;
+       aim_msgcookie_t *cook;
 
-   faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n");
-   fh = aim_oft_getfh(hdr);
+       cook = aim_uncachecookie(sess, intdata->cookie, AIM_COOKIETYPE_OFTIM);
+       aim_cookie_free(sess, cook);
 
-   free(hdr);
-   hdr = NULL;
+       fr.conn = conn;
 
-   faim_mutex_unlock(&conn->active);
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) )
+               userfunc(sess, &fr, intdata->sn);
 
-   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
-     faim_mutex_unlock(&conn->active);
-     free(fh);
-     return -1;
-   }
+       return;
+}
 
-   ft = cook->data;
+static int handlehdr_directim(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+       aim_frame_t fr;
+       aim_rxcallback_t userfunc;
+       fu32_t payloadlength;
+       fu16_t flags;
+       char *snptr = NULL;
 
-   /* we're waaaaiiiting.. for listing.txt */
-   ft->state = 2;
+       fr.conn = conn;
 
-   memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
-   free(fh);
+       payloadlength = aimutil_get32(hdr+22);
+       flags = aimutil_get16(hdr+32);
+       snptr = (char *)hdr+38;
 
-   if(aim_cachecookie(sess, cook) == -1) {
-     faimdprintf(sess, 1, "error caching cookie\n");
-     return -1;
-   }     
+       faimdprintf(sess, 2, "faim: OFT frame: handlehdr_directim: %04x / %04x / %s\n", payloadlength, flags, snptr);
 
-   if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) {
-     aim_conn_close(conn);
-     return -1;
-   }
+       if (flags == 0x000e) { 
+               int ret = 0;
 
-   memcpy(newoft->hdr.oft.magic, "OFT2", 4);
-   newoft->hdr.oft.hdr2len = 0x100 - 8;
+               if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
+                       ret = userfunc(sess, &fr, snptr);
 
-   if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
-     newoft->lock = 0;
-     aim_frame_destroy(newoft);
-     return -1;
-   }
+               return ret;
 
-   if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
-     newoft->lock = 0;
-     aim_frame_destroy(newoft);
-     return -1;
-   }
+       } else if ((flags == 0x0000) && payloadlength) { 
+               char *msg;
+               int ret = 0;
 
-   newoft->lock = 0;
-   aim_tx_enqueue(sess, newoft);
-   break;
-   
- } 
- case 0x1209: { /* get file listing ack rx->tx */
-   struct aim_filetransfer_priv *ft;
-   struct aim_fileheader_t *fh;
-   struct aim_msgcookie_t *cook;
-   int ret = 0;
+               if (!(msg = calloc(1, payloadlength+1)))
+                       return -1;
 
-   if(!(fh = aim_oft_getfh(hdr))) {
-     perror("getfh");
-     free(hdr);
-     return -1;
-   }   
+               if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) {
+                       free(msg);
+                       return -1;
+               }
 
-   free(hdr);
-   hdr = NULL;
+               msg[payloadlength] = '\0';
 
-   faim_mutex_unlock(&conn->active);
+               if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
+                       ret = userfunc(sess, &fr, snptr, msg);
 
-   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);
+               free(msg);
 
-   ft = cook->data;   
+               return ret;
+       }
 
-   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(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ)))
-     ret = userfunc(sess, NULL, conn, fh);
+       return 0;
+}
 
-   faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n");
+static int handlehdr_getfile_listing(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_filetransfer_priv *ft;
+       struct aim_fileheader_t *fh;
+       struct aim_msgcookie_t *cook;
+       struct command_tx_struct *newoft;
+       aim_rxcallback_t userfunc;
 
-   free(fh);
+       faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n");
+       fh = aim_oft_getfh(hdr);
 
-   return ret;
+       faim_mutex_unlock(&conn->active);
 
-   break;
- }
- case 0x120b: {    /* getfile listing.txt rx confirm */
-   struct aim_filetransfer_priv *ft;
-   struct aim_msgcookie_t *cook;
-   struct aim_fileheader_t *fh;
+       if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+               free(fh);
+               return -1;
+       }
 
-   fh = aim_oft_getfh(hdr);
+       ft = cook->data;
 
-   free(hdr);
-   hdr = NULL;
+       /* we're waaaaiiiting.. for listing.txt */
+       ft->state = 2;
 
-   faim_mutex_unlock(&conn->active);
+       memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
+       free(fh);
 
-   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET)))     {
-     free(fh);
-     return -1;
-   }
+       if(aim_cachecookie(sess, cook) == -1) {
+               faimdprintf(sess, 1, "error caching cookie\n");
+               return -1;
+       }     
 
-   free(fh);
+       if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) {
+               aim_conn_close(conn);
+               return -1;
+       }
 
-   ft = cook->data;
+       memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+       newoft->hdr.oft.hdr2len = 0x100 - 8;
 
-   if (aim_cachecookie(sess, cook) == -1) {
-     return -1;
-   }
+       if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
+               newoft->lock = 0;
+               aim_frame_destroy(newoft);
+               return -1;
+       }
 
-   if((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM)))
-     return userfunc(sess, NULL, conn);
+       if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) {
+               newoft->lock = 0;
+               aim_frame_destroy(newoft);
+               return -1;
+       }
 
-   break;
- }
- case 0x120c: { /* getfile file request */
-   struct aim_filetransfer_priv *ft;
-   struct aim_msgcookie_t *cook;
-   struct aim_fileheader_t *fh;
-   struct command_tx_struct *newoft;
-   int i = 0;
+       newoft->lock = 0;
+       aim_tx_enqueue(sess, newoft);
+#endif
+       return -1;
+}
 
-   fh = aim_oft_getfh(hdr);
+static int handlehdr_getfile_listing2(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_filetransfer_priv *ft;
+       struct aim_fileheader_t *fh;
+       struct aim_msgcookie_t *cook;
+       int ret = 0;
+       aim_rxcallback_t userfunc;
+       
+       fh = aim_oft_getfh(hdr);
 
-   free(hdr);
-   hdr = NULL;
+       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);
 
-   faim_mutex_unlock(&conn->active);
+       ft = cook->data;
 
-   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
-     faimdprintf(sess, 2, "no cookie in 120c\n");
-     return -1;
-   }
+       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);
 
-   ft = cook->data;
-   memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
-   free(fh);
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ)))
+               ret = userfunc(sess, NULL, conn, fh);
 
-   aim_cachecookie(sess, cook);
+       faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n");
 
-   faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
+       free(fh);
 
-   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
-     i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie);
+       return ret;
+#else
+       return -1;
+#endif
+}
 
-   if (i < 0)
-     return i;
+static int handlehdr_getfile_listing3(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_filetransfer_priv *ft;
+       struct aim_msgcookie_t *cook;
+       struct aim_fileheader_t *fh;
+       aim_rxcallback_t userfunc;
 
-   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;
-   }
+       fh = aim_oft_getfh(hdr);
 
-   newoft->lock = 1;
-   memcpy(newoft->hdr.oft.magic, "OFT2", 4);
-   newoft->hdr.oft.hdr2len = 0x100 - 8;
+       if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+               free(fh);
+               return -1;
+       }
 
-   if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
-     newoft->lock = 0;
-     aim_frame_destroy(newoft);
-     return -1;
-   } 
+       free(fh);
 
-   /* protocol BS: nrecvd, recvcsum to 0, flags to 0x20. */
-   ft->fh.nrecvd = 0;
-   ft->fh.recvcsum = 0;
-   ft->fh.flags = 0x20;
+       ft = cook->data;
 
-   aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh));
+       if (aim_cachecookie(sess, cook) == -1)
+               return -1;
 
-   newoft->lock = 0;
-   aim_tx_enqueue(sess, newoft);
+       if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM)))
+               return userfunc(sess, NULL, conn);
+#endif
+       return -1;
+}
 
-   faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n");
+static int handlehdr_getfile_request(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_filetransfer_priv *ft;
+       struct aim_msgcookie_t *cook;
+       struct aim_fileheader_t *fh;
+       struct command_tx_struct *newoft;
+       int i = 0;
+       aim_rxcallback_t userfunc;
 
-   return i;
+       fh = aim_oft_getfh(hdr);
 
-   break;
- }
- case 0x0101: {    /* getfile: sending data  */
-   struct aim_fileheader_t *fh;
-   struct aim_filetransfer_priv *ft;
-   struct aim_msgcookie_t *cook;
-   struct command_tx_struct *newoft;
+       if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+               free(fh);
+               return -1;
+       }
 
-   fh = aim_oft_getfh(hdr);
+       ft = cook->data;
+       memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
+       free(fh);
 
-   free(hdr);
-   hdr = NULL;
+       aim_cachecookie(sess, cook);
 
-   faim_mutex_unlock(&conn->active);
+       faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
 
-   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
-     free(fh);
-     return -1;
-   }
-   free(fh);
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
+               i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie);
 
-   ft = cook->data;
+       if (i < 0)
+               return i;
 
-   ft->state = 3;
+       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;
+       }
 
-   if (aim_cachecookie(sess, cook) == -1) {
-     perror("aim_cachecookie");
-     return -1;
-   }
+       newoft->lock = 1;
+       memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+       newoft->hdr.oft.hdr2len = 0x100 - 8;
 
-   faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name);
+       if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
+               aim_frame_destroy(newoft);
+               return -1;
+       } 
 
-   if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) {
-     aim_conn_close(conn);
-     faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n");
-     return -1;
-   }
+       /* protocol BS: nrecvd, recvcsum to 0, flags to 0x20. */
+       ft->fh.nrecvd = 0;
+       ft->fh.recvcsum = 0;
+       ft->fh.flags = 0x20;
 
-   newoft->lock = 1;
-   memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+       aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh));
 
-   newoft->hdr.oft.hdr2len = 0x100 - 8;
+       newoft->lock = 0;
+       aim_tx_enqueue(sess, newoft);
 
-   if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
-     newoft->lock = 0;
-     aim_frame_destroy(newoft);
-     return -1;
-   }
+       faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n");
 
-   aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh));
+       return i;
+#else
+       return -1;
+#endif
+}
 
-   newoft->lock = 0;
-   aim_tx_enqueue(sess, newoft);
+static int handlehdr_getfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_fileheader_t *fh;
+       struct aim_filetransfer_priv *ft;
+       struct aim_msgcookie_t *cook;
+       struct command_tx_struct *newoft;
+       aim_rxcallback_t userfunc;
 
-   faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n");
+       fh = aim_oft_getfh(hdr);
 
-   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
-     return 1;
+       if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+               free(fh);
+               return -1;
+       }
 
-   break;
- }
- 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;
+       free(fh);
 
-   fh = aim_oft_getfh(hdr);
+       ft = cook->data;
 
-   free(hdr);
-   hdr = NULL;
+       ft->state = 3;
 
-   faim_mutex_unlock(&conn->active);
+       if (aim_cachecookie(sess, cook) == -1)
+               return -1;
 
-   if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
-     free(fh);
-     return -1;
-   }
-   
-   ft = cook->data;
+       faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name);
 
-   faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
+       if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) {
+               faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n");
+               return -1;
+       }
 
-   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) )
-     ret = userfunc(sess, NULL, conn, fh);
+       newoft->lock = 1;
+       memcpy(newoft->hdr.oft.magic, "OFT2", 4);
 
-   free(fh);
+       newoft->hdr.oft.hdr2len = 0x100 - 8;
 
-   return ret;
-   break;
- }
- case 0x0204: {    /* get file: finished. close it up */
-   int i;
-   struct aim_fileheader_t *fh;
+       if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
+               aim_frame_destroy(newoft);
+               return -1;
+       }
+
+       aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh));
+
+       newoft->lock = 0;
+       aim_tx_enqueue(sess, newoft);
 
-   if(!(fh = aim_oft_getfh(hdr)))
-     return -1;
+       faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n");
 
-   free(hdr);
-   hdr = NULL;
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
+               return 1;
+#else
+       return -1;
+#endif
+}
 
-   faim_mutex_unlock(&conn->active);
+static int handlehdr_getfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_fileheader_t *fh;
+       struct aim_filetransfer_priv *ft;
+       struct aim_msgcookie_t *cook;
+       int ret = 1;
+       aim_rxcallback_t userfunc;
 
-   faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
+       fh = aim_oft_getfh(hdr);
 
-   if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
-     i = userfunc(sess, NULL, conn, fh);
-   else 
-     i = 1;
+       if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) {
+               free(fh);
+               return -1;
+       }
 
-   if (conn)
-     aim_conn_close(conn);
+       ft = cook->data;
 
-   free(fh);
+       faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
 
-   return i;
-   break;
- }
- default: {
-   free(hdr);
-   hdr = NULL;
-   faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype);
-   faim_mutex_unlock(&conn->active);
-   break;
- } 
- } /* switch */
-
- if (hdr) {
-    faimdprintf(sess, 0, "hdr wasn't freed by a rendezvous switch case (hdrtype: %0x04x)!\n", hdrtype);
-   free(hdr);
-   hdr = NULL;
- }
- return 0;
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) )
+               ret = userfunc(sess, NULL, conn, fh);
+
+       free(fh);
+
+       return ret;
 #else
- return -1;
-#endif 
+       return -1;
+#endif
+}
+
+static int handlehdr_getfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr)
+{
+#if 0
+       struct aim_fileheader_t *fh;
+       aim_rxcallback_t userfunc;
+
+       fh = aim_oft_getfh(hdr);
+
+       faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
+
+       if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
+               userfunc(sess, NULL, conn, fh);
+
+       free(fh);
+#endif
+
+       return -1;
+}
+
+/**
+ * aim_get_command_rendezvous - OFT equivalent of aim_get_command
+ * @sess: session to work on
+ * @conn: conn to pull data from 
+ *
+ * this reads and handles data from conn->fd. currently a little rough
+ * around the edges
+ */
+faim_internal int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn)
+{
+       fu8_t hdrbuf1[6];
+       fu8_t *hdr = NULL;
+       int hdrlen, hdrtype;
+       int ret = -1;
+
+       if (!sess || !conn)
+               return -1;
+
+       memset(hdrbuf1, 0, sizeof(hdrbuf1));
+
+       /* I guess? I didn't understand any of that mess... */
+       if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE)
+               return getcommand_getfile(sess, conn);
+
+       /* XXX fix all the error cases here */
+       if (aim_recv(conn->fd, hdrbuf1, 6) < 6) {
+
+               faimdprintf(sess, 2, "faim: rend: read error (fd: %i)\n", conn->fd);
+
+               if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)
+                       disconnected_directim(sess, conn);
+               else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE)
+                       disconnected_getfile(sess, conn);
+               else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE)
+                       disconnected_sendfile(sess, conn);
+
+               aim_conn_close(conn);
+
+               return -1;
+       }
+
+       hdrlen = aimutil_get16(hdrbuf1+4);
+       hdrlen -= 6;
+
+       hdr = malloc(hdrlen);
+
+       if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) {
+               faimdprintf(sess, 2, "faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen);
+               free(hdr);
+               aim_conn_close(conn);
+               return -1;
+       }
+
+       hdrtype = aimutil_get16(hdr);
+
+       if (hdrtype == 0x0001)
+               ret = handlehdr_directim(sess, conn, hdr);
+       else if (hdrtype == 0x1108) /* getfile listing.txt incoming tx->rx */
+               ret = handlehdr_getfile_listing(sess, conn, hdr);
+       else if (hdrtype == 0x1209) /* get file listing ack rx->tx */
+               ret = handlehdr_getfile_listing2(sess, conn, hdr);
+       else if (hdrtype == 0x120b) /* get file listing rx confirm */
+               ret = handlehdr_getfile_listing3(sess, conn, hdr);
+       else if (hdrtype == 0x120c) /* getfile request */
+               ret = handlehdr_getfile_request(sess, conn, hdr);
+       else if (hdrtype == 0x0101) /* getfile sending data */
+               ret = handlehdr_getfile_sending(sess, conn, hdr);
+       else if (hdrtype == 0x0202) /* getfile recv data */
+               ret = handlehdr_getfile_recv(sess, conn, hdr);
+       else if (hdrtype == 0x0204) /* getfile finished */
+               ret = handlehdr_getfile_finish(sess, conn, hdr);
+       else {
+               faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype);
+               ret = -1;
+       }
+       
+       free(hdr);
+
+       if (ret == -1)
+               aim_conn_close(conn);
+
+       return ret;
 }
 
 #if 0
index e2070bc062c512422ac2ad7c0adacd8dd4585eb3..1c7e795e255e4e0ce29894117dda6deca750b559 100644 (file)
--- a/src/im.c
+++ b/src/im.c
@@ -624,6 +624,87 @@ static int incomingim_ch1(aim_session_t *sess, aim_module_t *mod, aim_frame_t *r
        return ret;
 }
 
+static int incomingim_ch2_buddyicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
+{
+       aim_rxcallback_t userfunc;
+       int ret = 0;
+       aim_tlv_t *miscinfo;
+       aim_bstream_t tbs;
+
+       miscinfo = aim_gettlv(list2, 0x2711, 1);
+       aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
+
+       args->info.icon.checksum = aimbs_get32(&tbs);
+       args->info.icon.length = aimbs_get32(&tbs);
+       args->info.icon.timestamp = aimbs_get32(&tbs);
+       args->info.icon.icon = aimbs_getraw(&tbs, args->info.icon.length);
+
+       if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+               ret = userfunc(sess, rx, 0x0002, userinfo, args);
+
+       free(args->info.icon.icon);
+
+       return ret;
+}
+
+static int incomingim_ch2_imimage(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
+{
+       aim_rxcallback_t userfunc;
+       int ret = 0;
+
+       /* Primary IP address */
+       if (aim_gettlv(list2, 0x0003, 1)) {
+               aim_tlv_t *tlv;
+
+               tlv = aim_gettlv(list2, 0x0003, 1);
+
+               snprintf(args->info.imimage.ip, sizeof(args->info.imimage.ip),
+                                       "%d.%d.%d.%d:4443",
+                                       tlv->value[0],
+                                       tlv->value[1],
+                                       tlv->value[2],
+                                       tlv->value[3]);
+       }
+
+       /* 
+        * Alternate IP address
+        *
+        * Sort of.  The peer doesn't send this -- the OSCAR
+        * server does.  So it will be the IP address that the
+        * peer is directly connected to the internet with, which 
+        * may not be the same as the IP above.  If these two
+        * values differ, it's rather unlikely that this
+        * rendezvous is going to happen...
+        *
+        */
+       if (aim_gettlv(list2, 0x0004, 1))
+               ;
+               
+       /* Port number (not correct -- ignore) */
+       if (aim_gettlv(list2, 0x0005, 1)) 
+               ;
+
+       /* Unknown -- two bytes = 0x0001 */
+       if (aim_gettlv(list2, 0x000a, 1))
+               ;
+
+       /* Unknown -- no value */
+       if (aim_gettlv(list2, 0x000f, 1))
+               ;
+
+       faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n", userinfo->sn, args->info.imimage.ip);
+
+       /* 
+        * XXX: there are a couple of different request packets for
+        *          different things 
+        */
+
+       if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+               ret = userfunc(sess, rx, 0x0002, userinfo, args);
+
+       return ret;
+}
+
 /* XXX Ugh.  I think its obvious. */
 static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_tlvlist_t *tlvlist, fu8_t *cookie)
 {
@@ -660,6 +741,7 @@ static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *r
        cookie2 = aimbs_getraw(&bbs, 8);
        if (memcmp(cookie, cookie2, 8) != 0) 
                faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
+       memcpy(args.cookie, cookie2, 8);
        free(cookie2);
 
        /*
@@ -687,6 +769,7 @@ static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *r
         */
        list2 = aim_readtlvchain(&bbs);
 
+#if 0 /* this should be in the per-type blocks */
        if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
                aim_msgcookie_t *cook;
                int type;
@@ -734,26 +817,14 @@ static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *r
 
                return 1;
        }
+#endif
 
        /*
         * The rest of the handling depends on what type it is.
         */
        if (args.reqclass & AIM_CAPS_BUDDYICON) {
-               aim_tlv_t *miscinfo;
-               aim_bstream_t tbs;
 
-               miscinfo = aim_gettlv(list2, 0x2711, 1);
-               aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
-
-               args.info.icon.checksum = aimbs_get32(&tbs);
-               args.info.icon.length = aimbs_get32(&tbs);
-               args.info.icon.timestamp = aimbs_get32(&tbs);
-               args.info.icon.icon = aimbs_getraw(&tbs, args.info.icon.length);
-
-               if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
-                       ret = userfunc(sess, rx, channel, userinfo, &args);
-
-               free(args.info.icon.icon);
+               ret = incomingim_ch2_buddyicon(sess, mod, rx, snac, userinfo, &args, list2);
 
        } else if (args.reqclass & AIM_CAPS_VOICE) {
                aim_msgcookie_t *cachedcook;
@@ -778,40 +849,8 @@ static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *r
                        ret = userfunc(sess, rx, channel, userinfo, &args);
 
        } else if (args.reqclass & AIM_CAPS_IMIMAGE) {
-               char ip[30];
-               struct aim_directim_priv *priv;
-
-               memset(ip, 0, sizeof(ip));
-
-               if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
-                       aim_tlv_t *iptlv, *porttlv;
-                         
-                       iptlv = aim_gettlv(list2, 0x0003, 1);
-                       porttlv = aim_gettlv(list2, 0x0005, 1);
-
-                       snprintf(ip, 30, "%d.%d.%d.%d:%d", 
-                               aimutil_get8(iptlv->value+0),
-                               aimutil_get8(iptlv->value+1),
-                               aimutil_get8(iptlv->value+2),
-                               aimutil_get8(iptlv->value+3),
-                               4443 /*aimutil_get16(porttlv->value)*/);
-               }
-
-               faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n",
-                               userinfo->sn, ip);
-
-               /* 
-                * XXX: there are a couple of different request packets for
-                *          different things 
-                */
 
-               args.info.directim = priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); /* XXX error */
-               memcpy(priv->ip, ip, sizeof(priv->ip));
-               memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
-               memcpy(priv->cookie, cookie, sizeof(priv->cookie));
-
-               if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
-                       ret = userfunc(sess, rx, channel, userinfo, &args);
+               ret = incomingim_ch2_imimage(sess, mod, rx, snac, userinfo, &args, list2);
 
        } else if (args.reqclass & AIM_CAPS_CHAT) {
                aim_tlv_t *miscinfo;
index 0d28b0e6e66a2f4897beb4b8b9ac678c308e2eb5..8e2d4e82bf1d36df289d6941fd37dd44495411cf 100644 (file)
@@ -317,10 +317,12 @@ static int sendframe_oft(aim_session_t *sess, aim_frame_t *fr)
        aimbs_put16(&hbs, fr->hdr.oft.type);
        aimbs_putraw(&hbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len);
 
+       aim_bstream_rewind(&hbs);
+       
        if (aim_bstream_send(&hbs, fr->conn, hbslen) != hbslen) {
 
                err = -errno;
-
+               
        } else if (aim_bstream_curpos(&fr->data)) {
                int len;
 
@@ -336,6 +338,7 @@ static int sendframe_oft(aim_session_t *sess, aim_frame_t *fr)
        fr->handled = 1;
        fr->conn->lastactivity = time(NULL);
 
+
        return err;
 }
 
index 377295c597c60950c770edad7a5c90920aabbc34..d49d8b45d2a8baa124a774c9b01328c1e02b9254 100644 (file)
@@ -306,12 +306,10 @@ int main(int argc, char **argv)
                                cmd_gotkey();
                        } else {
                                if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
-#if 0
                                        if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
                                                dprintf("connection error (rend out)\n");
                                                aim_conn_kill(&aimsess, &waitingconn);
                                        }
-#endif
                                } else {
                                        if (aim_get_command(&aimsess, waitingconn) >= 0) {
                                                aim_rxdispatch(&aimsess);
@@ -319,7 +317,6 @@ int main(int argc, char **argv)
                                                dvprintf("connection error (type 0x%04x:0x%04x)\n", waitingconn->type, waitingconn->subtype);
                                                /* we should have callbacks for all these, else the library will do the conn_kill for us. */
                                                if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS) {
-                                                       dprintf("connection error: rendezvous connection. you forgot register a disconnect callback, right?\n");          
                                                        aim_conn_kill(&aimsess, &waitingconn);
                                                } else
                                                        aim_conn_kill(&aimsess, &waitingconn);
@@ -1056,9 +1053,9 @@ static int faimtest_handlecmd(aim_session_t *sess, aim_conn_t *conn, struct aim_
                aim_getinfo(sess, conn, "midendian", AIM_GETINFO_GENERALINFO);
                aim_getinfo(sess, conn, "midendian", AIM_GETINFO_AWAYMESSAGE);
 
-       } else if (!strncmp(tmpstr, "open directim", 13)) {
+       } else if (strstr(tmpstr, "open directim")) {
 
-               directim_start(sess, conn, (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
+               directim_start(sess, conn, userinfo->sn);
 
        } else if(!(strncmp(tmpstr, "lookup", 6))) {
 
index c7168e675c488b478f7b84630ab15a4d1b1b6e62..0ced87f0a90950fcc79e6bebe9d0681f933e432f 100644 (file)
@@ -1,8 +1,9 @@
 
 #include "faimtest.h"
 
-static int faimtest_directim_connect(aim_session_t *sess, aim_frame_t *fr, ...)
+static int directim_connect(aim_session_t *sess, aim_frame_t *fr, ...)
 {
+#if 0
          va_list ap;
          struct aim_directim_priv *priv;
          
@@ -10,35 +11,28 @@ static int faimtest_directim_connect(aim_session_t *sess, aim_frame_t *fr, ...)
          priv = va_arg(ap, struct aim_directim_priv *);
 
          va_end(ap);
-         
+#endif   
          dprintf("faimtest: directim_connect\n");
 
          return 1;
 }
 
-static int faimtest_directim_incoming(aim_session_t *sess, aim_frame_t *fr, ...)
+static int directim_incoming(aim_session_t *sess, aim_frame_t *fr, ...)
 {
        va_list ap;
-       char *msg;
-       aim_conn_t *conn;
-       struct aim_directim_priv *priv;
+       char *sn, *msg;
 
        va_start(ap, fr);
-       conn = va_arg(ap, aim_conn_t *);
+       sn = va_arg(ap, char *);
        msg = va_arg(ap, char *);
        va_end(ap);
 
-       if (!(priv = conn->priv)) {
-               dvprintf("faimtest: directim: no private struct on conn with fd %d\n", conn->fd);
-               return 0;
-       }
+       dvprintf("faimtest: Directim from %s: %s\n", sn, msg);
 
-       dvprintf("faimtest: Directim from %s: %s\n", priv->sn, msg);
-
-       if (!strncmp(msg, "sendmsg", 7)) {
+       if (strstr(msg, "sendmsg")) {
                int i;
 
-               i = atoi(msg+8);
+               i = atoi(strstr(msg, "sendmsg")+8);
                if (i < 10000) {
                        char *newbuf;
                        int z;
@@ -47,58 +41,50 @@ static int faimtest_directim_incoming(aim_session_t *sess, aim_frame_t *fr, ...)
                        for (z = 0; z < i; z++)
                                newbuf[z] = (z % 10)+0x30;
                        newbuf[i] = '\0';
-                       aim_send_im_direct(sess, conn, newbuf);
+                       aim_send_im_direct(sess, fr->conn, newbuf);
                        free(newbuf);
                }
 
-       } else if (!strncmp(msg, "goodday", 7)) {
+       } else if (strstr(msg, "goodday")) {
 
-               aim_send_im_direct(sess, conn, "Good day to you, too");
+               aim_send_im_direct(sess, fr->conn, "Good day to you, too");
 
        } else {
                char newmsg[1024];
 
                snprintf(newmsg, sizeof(newmsg), "unknown (%s)\n", msg);
-               aim_send_im_direct(sess, conn, newmsg);
+               aim_send_im_direct(sess, fr->conn, newmsg);
        }
 
        return 1;
 }
 
-static int faimtest_directim_disconnect(aim_session_t *sess, aim_frame_t *fr, ...)
+static int directim_disconnect(aim_session_t *sess, aim_frame_t *fr, ...)
 {
        va_list ap;
-       aim_conn_t *conn;
        char *sn;
 
        va_start(ap, fr);
-       conn = va_arg(ap, aim_conn_t *);
        sn = va_arg(ap, char *);
        va_end(ap);
 
        dvprintf("faimtest: directim: disconnected from %s\n", sn);
 
-       aim_conn_kill(sess, &conn);
+       aim_conn_kill(sess, &fr->conn);
 
        return 1;
 }
 
-static int faimtest_directim_typing(aim_session_t *sess, aim_frame_t *fr, ...)
+static int directim_typing(aim_session_t *sess, aim_frame_t *fr, ...)
 {
        va_list ap;
-       aim_conn_t *conn;
-       struct aim_directim_priv *priv;
+       char *sn;
 
        va_start(ap, fr);
-       conn = va_arg(ap, aim_conn_t *);
+       sn = va_arg(ap, char *);
        va_end(ap);
 
-       if (!(priv = (struct aim_directim_priv *)conn->priv)) {
-               dvprintf("faimtest: no private struct on conn with fd %d!\n", conn->fd);
-               return 0;
-       }
-
-       dvprintf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", priv->sn);
+       dvprintf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn);
 
        return 1;
 }
@@ -106,7 +92,6 @@ static int faimtest_directim_typing(aim_session_t *sess, aim_frame_t *fr, ...)
 static int faimtest_directim_initiate(aim_session_t *sess, aim_frame_t *fr, ...)
 {
        va_list ap;
-       struct aim_directim_priv *priv;
        aim_conn_t *newconn, *listenerconn;
 
        va_start(ap, fr);
@@ -117,17 +102,13 @@ static int faimtest_directim_initiate(aim_session_t *sess, aim_frame_t *fr, ...)
        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);
-
-       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);
+       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, directim_incoming, 0);
+       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, directim_disconnect, 0);
+       aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, directim_typing, 0);
 
        aim_send_im_direct(sess, newconn, "goodday");
 
-       dvprintf("faimtest: OFT: DirectIM: connected to %s\n", priv->sn);
+       dvprintf("faimtest: OFT: DirectIM: connected to %s\n", aim_directim_getsn(newconn));
 
        return 1;
 }
@@ -484,8 +465,8 @@ void directim_start(aim_session_t *sess, aim_conn_t *conn, const char *sn)
        aim_conn_t *newconn;
 
        printf("faimtest: opening directim to %s\n", sn);
-       
-       newconn = aim_directim_initiate(sess, conn, NULL, sn);
+       
+       newconn = aim_directim_initiate(sess, conn, sn);
 
        if (!newconn || (newconn->fd == -1)) {
 
@@ -504,22 +485,22 @@ void directim_requested(aim_session_t *sess, aim_conn_t *conn, struct aim_userin
 {
        aim_conn_t *newconn;
 
+       dvprintf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, args->info.imimage.ip);
 
-       dvprintf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, args->info.directim->ip);
-
-       /* XXX why does these need conn? */
-       newconn = aim_directim_connect(sess, conn, args->info.directim);
+       newconn = aim_directim_connect(sess, userinfo->sn, args->info.imimage.ip, args->cookie);
 
        if (!newconn || (newconn->fd == -1)) {
+
                dprintf("faimtest: icbm: imimage: could not connect\n");
 
                if (newconn)
                        aim_conn_kill(sess, &newconn);
+
        } else {
 
-               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);
+               aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, directim_incoming, 0);
+               aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, directim_disconnect, 0);
+               aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, directim_typing, 0);
 
                dvprintf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
 
This page took 0.200343 seconds and 5 git commands to generate.