]> andersk Git - libfaim.git/commitdiff
- Sun Jul 16 11:03:28 GMT 2000
authormid <mid>
Sun, 16 Jul 2000 11:10:07 +0000 (11:10 +0000)
committermid <mid>
Sun, 16 Jul 2000 11:10:07 +0000 (11:10 +0000)
   - Fixed 0001/000a chat printf.  (Actually a one liner a few days ago.)
   - Started integrating josh's 3k rendezvous patch.  Currently only
      directim is working.  And its got bugs.  But he's not online
      right now, so I can't bitch.  I'd love to bitch here, but I'm
      tired.
     - Can definitly accept directim connections and send/recieve.
     - See faimtest for the new callbacks.  (Urg.)
     - Here weeee gooooo.  (Not sure if this will break everyone or not.)

CHANGES
Makefile
aim_chat.c
aim_ft.c [new file with mode: 0644]
aim_im.c
aim_msgcookie.c
aim_rxhandlers.c
aim_rxqueue.c
faim/aim.h
faim/aim_cbtypes.h
utils/faimtest/faimtest.c

diff --git a/CHANGES b/CHANGES
index a9573276192468f2ad88446e26ecaadaee48b3fc..af8e43c4509ff69c8b0476e68e3c9b1aeaf01b08 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,16 @@
 
 No release numbers
 ------------------
+ - Sun Jul 16 11:03:28 GMT 2000
+   - Fixed 0001/000a chat printf.  (Actually a one liner a few days ago.)
+   - Started integrating josh's 3k rendezvous patch.  Currently only
+      directim is working.  And its got bugs.  But he's not online
+      right now, so I can't bitch.  I'd love to bitch here, but I'm 
+      tired. 
+     - Can definitly accept directim connections and send/recieve.
+     - See faimtest for the new callbacks.  (Urg.)
+     - Here weeee gooooo.  (Not sure if this will break everyone or not.)
+
  - Fri Jun 30 00:04:47 UTC 2000
    - Removed the forceful ICQ-related warnings, just in case they're wrong
    - Added three new fields to the client info.  
index 15d1de6b5cedb87b45f0ee4c07f46d37bc316069..fec585bb4189d9d8520f1ee8b812d07797ac27de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@ LIBFAIM_OBJECTS = \
        aim_util.o \
        aim_meta.o \
        aim_msgcookie.o \
+       aim_ft.o \
        aim_ads.o
 
 all: libfaim allutils
index ab49d1205dc869d25641ad2c5f47bbd411891da9..765e19dcd69031a8d6a8edea621f5f5ee38dfec4 100644 (file)
@@ -70,6 +70,8 @@ u_long aim_chat_send_im(struct aim_session_t *sess,
   for (i=0;i<8;i++)
     curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) random());
 
+  aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL));
+
   /*
    * metaTLV start.  -- i assume this is a metaTLV.  it could be the
    *                    channel ID though.
@@ -430,11 +432,13 @@ int aim_chat_parse_incoming(struct aim_session_t *sess,
   i = 10; /* skip snac */
 
   /*
-   * ICBM Cookie.  Ignore it.
+   * ICBM Cookie.  Cache it.
    */ 
   for (z=0; z<8; z++,i++)
     cookie[z] = command->data[i];
 
+  aim_cachecookie(sess, aim_mkcookie(cookie, AIM_COOKIETYPE_ICBM, NULL));
+
   /*
    * Channel ID
    *
@@ -579,6 +583,7 @@ u_long aim_chat_invite(struct aim_session_t *sess,
    */
   for (i=0;i<8;i++)
     curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand());
+  aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL));
 
   /*
    * Channel (2)
diff --git a/aim_ft.c b/aim_ft.c
new file mode 100644 (file)
index 0000000..7a77717
--- /dev/null
+++ b/aim_ft.c
@@ -0,0 +1,1081 @@
+#include <faim/aim.h>
+
+#include <sys/utsname.h> /* for aim_directim_initiate */
+#include <arpa/inet.h> /* for inet_ntoa */
+
+/* aim_msgcookies.c is mostly new. just look at the diff and replace yours, easiest. */
+
+/* 
+   function name       where i had it
+   aim_send_im_direct aim_im.c
+   aim_directim_initiate aim_im.c
+   aim_filetransfer_accept aim_im.c
+   aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored.
+   establish aim_misc.c
+   aim_get_command_rendezvous aim_rxqueue.c
+   oft_getfh aim_rxqueue.c
+*/
+
+int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
+{
+  int acceptfd = 0;
+  rxcallback_t userfunc;
+  struct sockaddr cliaddr;
+  socklen_t clilen = sizeof(cliaddr);
+  int ret = 0;
+
+  /*
+   * Listener sockets only have incoming connections. No data.
+   */
+  if( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1)
+    return -1;
+
+  if (cliaddr.sa_family != AF_INET) /* just in case IPv6 really is happening */
+    return -1;
+
+  switch(cur->subtype) {
+  case AIM_CONN_SUBTYPE_OFT_DIRECTIM: {
+    struct aim_directim_priv *priv;
+    
+    priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_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(!cur->priv)
+      cur->priv = priv; /* what happens if there is one?! -- mid */
+
+    cur->type = AIM_CONN_TYPE_RENDEZVOUS;
+    close(cur->fd); /* should we really do this? seems like the client should decide. maybe clone the connection and keep the listener open. -- mid */
+    cur->fd = acceptfd;
+
+    if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE)))
+      ret = userfunc(sess, NULL, cur);
+                                  
+    break;
+  }
+  case AIM_CONN_SUBTYPE_OFT_GETFILE: {
+    struct aim_filetransfer_priv *priv;
+
+    priv->state = 0;
+
+    priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_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(!cur->priv)
+      cur->priv = priv;
+
+    if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
+      ret = userfunc(sess, NULL, cur);
+    break;
+  } 
+  default: {
+    /* XXX */
+  }
+  }
+  return ret;
+}
+
+
+/*
+ * aim_send_im_direct:
+ * sess - session
+ * conn - directim connection
+ * msg  - null-terminated string to send
+ */
+
+int aim_send_im_direct(struct aim_session_t *sess, 
+                      struct aim_conn_t *conn,
+                      char *msg)
+{
+  struct command_tx_struct *newpacket , *newpacket2; 
+
+  /* newpacket contains a real header with data, newpacket2 is just a
+     null packet, with a cookie and a lot of 0x00s. newpacket is the
+     "i'm sending", newpacket2 is the "i'm typing".*/
+
+  /* uhm. the client should send those as two seperate things -- mid */
+
+  struct aim_directim_priv *priv = NULL;
+  int i;
+
+  if (strlen(msg) >= MAXMSGLEN)
+    return -1;
+
+  if (!sess || !conn || !(conn->type) || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) {
+    printf("faim: directim: invalid arguments\n");
+    return -1;
+  };
+
+  priv = (struct aim_directim_priv *)conn->priv;
+
+  /* NULLish Header */
+
+  if (!(newpacket2 = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, 0))) {
+    printf("faim: directim: tx_new2 failed\n");
+    return -1;
+  }                                                                           
+
+  newpacket2->lock = 1; /* lock struct */
+
+  memcpy(newpacket2->hdr.oft.magic, "ODC2", 4);
+  newpacket2->hdr.oft.hdr2len = 0x44;
+
+  if (!(newpacket2->hdr.oft.hdr2 = calloc(1,newpacket2->hdr.oft.hdr2len))) {
+    free(newpacket2);
+    return -1;
+  }
+
+  i = 0;
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+
+  i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, priv->cookie, 8);
+
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+
+  i += aimutil_put32(newpacket2->hdr.oft.hdr2+i, 0x00000000);
+
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x000e);
+
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+
+  i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
+  
+  i = 52; /* 0x34 */
+  i += aimutil_put8(newpacket2->hdr.oft.hdr2+i, 0x00); /* 53 */
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); /* 55 */
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 61 */
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 65 */
+  i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */
+
+  newpacket2->lock = 0;
+  newpacket2->data = NULL;
+  
+  aim_tx_enqueue(sess, newpacket2);
+
+  /* Header packet */
+
+  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) {
+    printf("faim: directim: tx_new failed\n");
+    return -1;
+  }
+
+  newpacket->lock = 1; /* lock struct */
+
+  memcpy(newpacket->hdr.oft.magic, "ODC2", 4);
+  newpacket->hdr.oft.hdr2len = 0x54;
+
+  if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) {
+    free(newpacket);
+    return -1;
+  }
+
+  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, 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);
+  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_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
+  
+  i = 52; /* 0x34 */
+  i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00); /* 53 */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); /* 55 */
+  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);/* 61 */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 65 */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */
+
+  /* values grabbed from a dump */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); /* 69 */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c);
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 71 */
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);/* 73 */ 
+  i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);/* 73 */ 
+  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));
+
+  newpacket->lock = 0;
+
+  aim_tx_enqueue(sess, newpacket);
+
+  return 0;
+}
+
+/*
+ * aim_directim_intitiate:
+ * For those times when we want to open up the directim channel ourselves.
+ * sess is your session,
+ * conn is the BOS conn,
+ * priv is a dummy priv value (we'll let it get filled in later) (if
+ * you pass a NULL, we alloc one) 
+ * destsn is the SN to connect to.  
+ */
+
+
+struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
+                         struct aim_conn_t *conn,
+                         struct aim_directim_priv *priv,
+                         char *destsn)
+{
+  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;
+  struct utsname myname;
+
+  char cap[16];
+  char d[4]; /* XXX: IPv6. *cough* */
+
+  /*
+   * Open our socket
+   */
+
+  if( (listenfd = aim_listenestablish(port)) == -1)
+    return NULL;
+
+  /*
+   * 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); /* 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)))
+    return NULL;
+
+  newpacket->lock = 1; /* lock struct */
+
+  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) random() % 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;
+  
+  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);  /* cache da 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);
+
+  /* 
+   * enTLV start
+   */
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032);
+
+  /*
+   * 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);
+
+  /*
+   * 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);
+
+  /*
+   * 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 */
+
+  /*
+   * 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: umm.. dunno. Zigamorph[1]?
+   * [1]: see esr's TNHD.
+   */
+
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
+  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
+
+  printf("curbyte: 0x%x\n",curbyte);
+
+  newpacket->commandlen = curbyte;
+  newpacket->lock = 0;
+
+  aim_tx_enqueue(sess, newpacket);
+
+  /*
+   * 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);
+  if (!newconn) { 
+    perror("aim_newconn");
+    aim_conn_kill(sess, &newconn);
+    return NULL;
+  } 
+
+  newconn->fd = listenfd;
+  newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
+  newconn->priv = priv;
+  printf("faim: listening (fd = %d, unconnected)\n", newconn->fd);
+
+  /*
+   * XXX We need some way of closing the listener socket after
+   * n seconds of no connection. -- mid
+   */
+
+#ifdef USE_SNAC_FOR_IMS
+ {
+    struct aim_snac_t snac;
+
+    snac.id = sess->snac_nextid;
+    snac.family = 0x0004;
+    snac.type = 0x0006;
+    snac.flags = 0x0000;
+
+    snac.data = malloc(strlen(destsn)+1);
+    memcpy(snac.data, destsn, strlen(destsn)+1);
+
+    aim_newsnac(sess, &snac);
+
+    aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
+  }
+#endif
+  
+  return (newconn);
+} 
+
+
+struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
+                                       struct aim_conn_t *conn,
+                                       struct aim_directim_priv *priv )
+{
+  struct aim_conn_t *newconn = NULL;;
+
+  newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, priv->ip);
+  if (!newconn || (newconn->fd == -1)) { 
+    printf("could not connect to %s\n", priv->ip);
+    perror("aim_newconn");
+    aim_conn_kill(sess, &newconn);
+    return NULL;
+  } else {    
+    newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
+    newconn->priv = priv;
+    printf("faim: connected to peer (fd = %d)\n", newconn->fd);
+    return newconn;
+  }
+  return newconn;
+}
+
+u_long aim_accepttransfer(struct aim_session_t *sess,
+                         struct aim_conn_t *conn, 
+                         struct aim_conn_t *oftconn,
+                         char *sn,
+                         char *cookie,
+                         unsigned short rendid)
+{
+  struct command_tx_struct *newpacket, *newoft;
+  struct aim_fileheader_t *listingfh;
+  int curbyte, i;
+  /* now for the oft bits */
+
+  if(rendid == AIM_CAPS_GETFILE) {
+    printf("jbm: getfile request accept\n");
+    if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, oftconn, 0))) {
+      printf("faim: accept_transfer: tx_new OFT failed\n");
+      return -1;
+    }
+    
+    newoft->lock = 1;
+    
+    memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+    newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
+    
+    if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
+      free(newoft);
+      return -1;
+    }  
+
+    listingfh = aim_getlisting(sess);
+
+    memcpy(listingfh->bcookie, cookie, 8);
+
+    curbyte = 0;
+    
+    for(i = 0; i < 8; i++)
+      curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, cookie[i]);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->nrecvd);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->recvcsum);
+
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
+    curbyte += 32;
+
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->flags);
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset);
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset);
+
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69);
+    curbyte += 69;
+    
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16);
+    curbyte += 16;
+
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage);
+
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
+    curbyte += 64;
+
+    free(listingfh);
+
+    newoft->lock = 0;
+    aim_tx_enqueue(sess, newoft);
+    printf("faim: getfile: OFT listing enqueued.\n");
+    
+  }
+
+
+  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16)))
+    return -1;
+  
+  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]);
+  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]);
+  curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
+
+  newpacket->lock = 0;
+  aim_tx_enqueue(sess, newpacket);
+
+
+
+  return (sess->snac_nextid++);
+}
+
+/*
+ * aim_getlisting()
+ * 
+ * Get file listing.txt info. where else to put it? i
+ * dunno. client-side issue for sure tho. for now we just side-step
+ * the issue with a nice default. =)
+ *  
+ */
+
+struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess) 
+{
+  struct aim_fileheader_t *fh;
+
+  if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
+    return NULL;
+
+  fh->encrypt     = 0x0000;
+  fh->compress    = 0x0000;
+  fh->totfiles    = 0x0001;
+  fh->filesleft   = 0x0001;
+  fh->totparts    = 0x0001;
+  fh->partsleft   = 0x0001;
+  fh->totsize     = 0x00000064;
+  fh->size        = 0x00000024; /* ls -l listing.txt */
+  fh->modtime     = (int)time(NULL); /*0x39441fb4; */
+  fh->checksum    = 0xb8350000;
+  fh->rfcsum      = 0x00000000;
+  fh->rfsize      = 0x00000000;
+  fh->cretime     = 0x00000000;
+  fh->rfcsum      = 0x00000000;
+  fh->nrecvd      = 0x00000000;
+  fh->recvcsum    = 0x00000000;
+
+  memset(fh->idstring, 0, 32/*sizeof(fh->idstring)*/);
+  memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", 32/*sizeof(fh->idstring)*/);
+  memset(fh->idstring+strlen(fh->idstring), 0, 32-strlen(fh->idstring)); /* jbm hack */ 
+
+  fh->flags       = 0x02;
+  fh->lnameoffset = 0x1a;
+  fh->lsizeoffset = 0x10;
+
+  memset(fh->dummy, 0, 69/*sizeof(fh->dummy)*/);
+  /*  fh->dummy = ;*/
+
+  memset(fh->macfileinfo, 0, 16/*sizeof(fh->macfileinfo)*/);
+  /*  fh->macfileinfo = ; */
+
+  fh->nencode     = 0x0000;
+  fh->nlanguage   = 0x0000;
+
+  memset(fh->name, 0, 64/*sizeof(fh->name)*/);
+  memcpy(fh->name, "listing.txt", 64 /*sizeof(fh->name)*/);
+  memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); /* jbm hack */
+
+  printf("jbm: fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
+  return fh;
+}
+
+/*
+ * establish: create a listening socket on a port. you need to call
+ * accept() when it's connected.
+ * portnum is the port number to bind to.
+ * returns your fd
+ */
+
+int aim_listenestablish(u_short portnum)
+{
+  int listenfd;
+  const int on = 1;
+  struct addrinfo hints, *res, *ressave;
+  char serv[5];
+  sprintf(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;
+}
+
+int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
+{
+
+  /* XXX: NOT THREAD SAFE RIGHT NOW. the locks are acting up. deal. -- jbm */
+
+  unsigned char hdrbuf1[6];
+  unsigned char *hdr = NULL;
+  int hdrlen, hdrtype;
+  int flags = 0;
+  rxcallback_t userfunc = NULL;
+
+
+  memset(hdrbuf1, 0, sizeof(hdrbuf1));
+
+  if ( (hdrlen = read(conn->fd, hdrbuf1, 6)) < 6) {    
+    if(hdrlen < 0)
+      perror("read");
+    printf("faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen);
+    aim_conn_kill(sess, &conn);
+    return -1; /* return -1 prematurely signal'd a bad read(). it's *
+              * direct, so we don't really care if the connection *
+              * falls apart.  -- jbm                              */
+  }
+
+  hdrlen = aimutil_get16(hdrbuf1+4);
+
+  hdrlen -= 6;
+  if (!(hdr = malloc(hdrlen)))
+    return -1;
+
+  //    faim_mutex_lock(&conn->active);
+  if (read(conn->fd, hdr, hdrlen) < hdrlen) {
+    perror("read");
+    printf("faim: rend: read2 error\n");
+    free(hdr);
+    //    faim_mutex_unlock(&conn->active);
+    aim_conn_kill(sess, &conn);
+    return 0; /* see comment on previous read check */
+  }
+
+  //  faim_mutex_unlock(&conn->active);
+
+  hdrtype = aimutil_get16(hdr);  
+
+  switch (hdrtype) {
+  case 0x0001: { /* directim */
+    int payloadlength = 0;
+    char *snptr = NULL;
+    struct aim_directim_priv *priv;
+    int i;
+
+    priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
+
+    payloadlength = aimutil_get32(hdr+22);
+    flags = aimutil_get16(hdr+32);
+    snptr = hdr+38;
+
+    strncpy(priv->sn, snptr, MAXSNLEN);
+
+    /*    printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); */
+
+    if (flags == 0x000e) {
+      //      printf("faim: directim: %s has started typing. yippee.\n", snptr);
+      if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
+       return userfunc(sess, NULL, snptr);
+    } else if ((flags == 0x0000) && payloadlength) {
+      unsigned char *msg;
+      if(! (msg = calloc(1, payloadlength+1)) )
+       return 0;
+      
+      /* XXX: theres got to be a better way */
+      /* XXX: that's a moot point, as the locks never seem to be free. */
+      /*
+       faim_mutex_lock(&conn->active);
+      */
+
+      if (recv(conn->fd, msg, payloadlength, MSG_WAITALL) < payloadlength) {
+       perror("read");
+       printf("faim: rend: read3 error\n");
+       free(msg);
+       // faim_mutex_unlock(&conn->active);
+       aim_conn_kill(sess, &conn);
+       return 0;
+      }
+      //      faim_mutex_unlock(&conn->active);
+      msg[payloadlength] = '\0';
+      //   printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+
+      if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
+       i = userfunc(sess, NULL, conn, snptr, msg);
+      
+      free(msg);
+      return i;
+    }
+    break;
+  } 
+  case 0x1209: { /* get file first */
+    struct aim_filetransfer_priv *ft;
+    struct aim_fileheader_t *fh;
+    struct aim_msgcookie_t *cook;
+
+
+    int commandlen;
+    char *data;
+
+    printf("faim: rend: fileget 0x1209\n");
+
+    if(hdrlen != 0x100)
+      printf("faim: fileget_command(1209): um. hdrlen != 0x100.. 0x%x\n", hdrlen);
+    
+    if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
+      printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      return 0;
+    }
+
+    fh = aim_oft_getfh(hdr);
+
+    memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
+    
+    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+
+    if(cook->data)
+      free(cook->data); /* XXX */
+  
+    cook->data = ft;
+    
+    aim_cachecookie(sess, cook);
+
+    commandlen = 36;
+
+    data = calloc(1, commandlen);
+    memcpy(data, "01/01/1999 00:00      100 file.txt\r\n", commandlen);
+
+    if (write(conn->fd, data, commandlen) != commandlen) {
+      perror("listing write error");
+    }
+
+    printf("jbm: hit end of 1209\n");
+
+    break;
+  }
+  case 0x120b: { /* get file second */
+    struct aim_filetransfer_priv *ft;
+    struct aim_msgcookie_t *cook;
+
+    struct aim_fileheader_t *fh;
+
+    printf("faim: rend: fileget 120b\n");
+
+    if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
+      printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      return 0;
+    }
+
+    if(hdrlen != 0x100)
+      printf("faim: fileget_command(120b): um. hdrlen != 0x100..\n");
+    
+    fh = aim_oft_getfh(hdr);
+
+    memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
+    
+    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+  
+    if(cook->data)
+      free(cook->data); /* XXX: integrate cookie caching */
+
+    cook->data = ft;
+    
+    aim_cachecookie(sess, cook);
+    
+    break;
+  }
+  case 0x120c: { /* yet more get file */
+    struct aim_filetransfer_priv *ft;
+    struct aim_msgcookie_t *cook;
+    struct aim_fileheader_t *listingfh;
+    struct command_tx_struct *newoft;
+    int curbyte, i;
+    
+    printf("faim: rend: fileget 120c\n");
+
+    if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
+      printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      return 0;
+    }
+
+    if(hdrlen != 0x100)
+      printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n");
+
+    listingfh = aim_oft_getfh((char *)hdr);
+
+    memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t));
+    
+    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+  
+    if(cook->data)
+      free(cook->data); /* XXX */
+
+    cook->data = ft;
+    
+    aim_cachecookie(sess, cook);
+
+    printf("faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
+    if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0/*listingfh->size*/))) {
+      printf("faim: send_final_transfer: tx_new OFT failed\n");
+      return 0;
+    }
+    
+    /* XXX: actually implement Real Handling of all this */
+
+    printf("jbm: listingfh->size: 0x%lx\n", listingfh->size);
+
+    newoft->lock = 1;
+
+    /*    if(!(newoft->data = calloc(1, listingfh->size))) {
+      printf("newoft data malloc failed. bombing.\n");
+      return 0;
+      }*/
+
+    if(newoft->commandlen > 0) {
+      int i;
+      bzero(newoft->data, newoft->commandlen);
+      for(i = 0; i < newoft->commandlen; i++)
+       newoft->data[i] = 0x30 + (i%10);
+
+      //      memcpy(newoft->data, "This has been a Test\r\n-josh\r\n", newoft->commandlen);
+    }
+
+    memcpy(newoft->hdr.oft.magic, "OFT2", 4);
+    newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
+    
+    if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
+      if(newoft->data)
+       free(newoft->data); /* XXX: make this into a destructor function */
+      free(newoft);
+      return 0;
+    }  
+
+    memcpy(listingfh->bcookie, ft->fh.bcookie, 8);
+
+    curbyte = 0;
+    
+    for(i = 0; i < 8; i++)
+      curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->bcookie[i]);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0 /*listingfh->nrecvd*/);
+    curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0/*listingfh->recvcsum*/);
+
+    strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
+    curbyte += 32;
+
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, 0x20 /*listingfh->flags */);
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset);
+    curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset);
+
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69);
+    curbyte += 69;
+    
+    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16);
+    curbyte += 16;
+
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode);
+    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage);
+
+    strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
+    curbyte += 64;
+
+    free(listingfh);
+
+    newoft->lock = 0;
+    aim_tx_enqueue(sess, newoft);
+    printf("jbm: OFT listing enqueued.\n");
+
+    break;
+  }
+  case 0x0202: { /* get file: ready to recieve data */
+    char *c;
+    int i;
+
+    struct aim_fileheader_t *fh;    
+    fh = aim_oft_getfh((char *)hdr);
+
+    c = (char *)calloc(1, fh->size);
+
+    printf("looks like we're ready to send data.(oft 0x0202)\n");
+
+
+    
+    for(i = 0; i < fh->size; i++)
+      c[i] = 0x30 + (i%10);
+
+    if ( (i = write(conn->fd, c, fh->size)) != fh->size ) {
+      printf("whoopsy, didn't write it all...\n");
+    }
+
+    break;
+  }
+  case 0x0204: { /* get file: finished. close it up */
+    printf("looks like we're done with a transfer (oft 0x0204)\n");
+    aim_conn_kill(sess, &conn);
+    break;
+  }
+  default: {
+    printf("OFT frame: type %04x\n", hdrtype);  
+    /* data connection may be unreliable here */
+    break;
+  }
+  } /* switch */
+
+  free(hdr);
+  
+  return 0;
+}
+
+/*
+ * this currently feeds totally bogus data
+ */
+
+struct aim_fileheader_t *aim_oft_getfh(char *hdr) 
+{
+  struct aim_fileheader_t *fh;
+  int i, j;
+
+  if(!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
+    return NULL;
+
+  /* [0] and [1] are the type. we can ignore those here. */
+
+  i = 2;
+
+  for(j = 0; j < 8; j++, i++)
+    fh->bcookie[j] = hdr[i];
+  fh->encrypt = aimutil_get16(hdr+i);
+  i += 2;
+  fh->compress = aimutil_get16(hdr+i);
+  i += 2;
+  fh->totfiles = aimutil_get16(hdr+i);
+  i += 2;
+  fh->filesleft = aimutil_get16(hdr+i);
+  i += 2;
+  fh->totparts = aimutil_get16(hdr+i);
+  i += 2;
+  fh->partsleft = aimutil_get16(hdr+i);
+  i += 2;
+  fh->totsize = aimutil_get32(hdr+i);
+  i += 4;
+  fh->size = aimutil_get32(hdr+i);
+  i += 4;
+  fh->modtime = aimutil_get32(hdr+i);
+  i += 4;
+  fh->checksum = aimutil_get32(hdr+i);
+  i += 4;
+  fh->rfrcsum = aimutil_get32(hdr+i);
+  i += 4;
+  fh->rfsize = aimutil_get32(hdr+i);
+  i += 4;
+  fh->cretime = aimutil_get32(hdr+i);
+  i += 4;
+  fh->rfcsum = aimutil_get32(hdr+i);
+  i += 4;
+  fh->nrecvd = aimutil_get32(hdr+i);
+  i += 4;
+  fh->recvcsum = aimutil_get32(hdr+i);
+  i += 4;
+
+  memcpy(fh->idstring, hdr+i, 32);
+  i += 32;
+
+  fh->flags = aimutil_get8(hdr+i);
+  i += 1;
+  fh->lnameoffset = aimutil_get8(hdr+i);
+  i += 1;
+  fh->lsizeoffset = aimutil_get8(hdr+i);
+  i += 1;
+
+  memcpy(fh->dummy, hdr+i, 69);
+  i += 69;
+
+  memcpy(fh->macfileinfo, hdr+i, 16);
+  i += 16;
+
+  fh->nencode = aimutil_get16(hdr+i);
+  i += 2;
+  fh->nlanguage = aimutil_get16(hdr+i);
+  i += 2;
+
+  memcpy(fh->name, hdr+i, 64);
+  i += 64;
+
+  return fh;
+}
index 8c619086c92ad804b5d9ea81dabc21e488c71dfc..531e01846d79f825da3f0a2b5d22311c0ca23fcd 100644 (file)
--- a/aim_im.c
+++ b/aim_im.c
@@ -139,88 +139,6 @@ u_long aim_send_im(struct aim_session_t *sess,
   return (sess->snac_nextid++);
 }
 
-struct aim_directim_priv {
-  unsigned char cookie[8];
-  char sn[MAXSNLEN+1];
-};
-
-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 (strlen(msg) >= MAXMSGLEN)
-    return -1;
-
-  if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) {
-    printf("faim: directim: invalid arguments\n");
-    return -1;
-  }
-
-  if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) {
-    printf("faim: directim: tx_new failed\n");
-    return -1;
-  }
-
-  newpacket->lock = 1; /* lock struct */
-
-  priv = (struct aim_directim_priv *)conn->priv;
-
-  newpacket->hdr.oft.hdr2len = 0x44;
-
-  if (!(newpacket->hdr.oft.hdr2 = malloc(newpacket->hdr.oft.hdr2len))) {
-    free(newpacket);
-    return -1;
-  }
-
-  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, 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);
-  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_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
-  
-  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);
-  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);
-
-  memcpy(newpacket->data, msg, strlen(msg));
-
-  newpacket->lock = 0;
-
-  aim_tx_enqueue(sess, newpacket);
-
-  return 0;
-}
-
 int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
                                 struct command_rx_struct *command)
 {
@@ -382,7 +300,7 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
      u_int j = 0, y = 0, z = 0;
       char *msg = NULL;
       u_int icbmflags = 0;
-      struct aim_tlv_t *msgblocktlv, *tmptlv;
+      struct aim_tlv_t *msgblocktlv;
       u_char *msgblock;
       u_short flag1,flag2;
            
@@ -535,8 +453,11 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
       
       if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
        struct aim_msgcookie_t *cook;
+       int type;
+       
+       type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
 
-       if ((cook = aim_uncachecookie(sess, cookie)) == NULL) {
+       if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) {
          printf("faim: non-data rendezvous thats not in cache!\n");
          aim_freetlvchain(&list2);
          aim_freetlvchain(&tlvlist);
@@ -544,21 +465,21 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        }
 
        if (cook->type == AIM_CAPS_SENDFILE) {
-         struct aim_filetransfer_t *ft;
+         struct aim_filetransfer_priv *ft;
 
          if (cook->data) {
            struct aim_tlv_t *errortlv;
            int errorcode = -1;
 
-           ft = (struct aim_filetransfer_t *)cook->data;
+           ft = (struct aim_filetransfer_priv *)cook->data;
 
            if ((errortlv = aim_gettlv(list2, 0x000b, 1))) {
              errorcode = aimutil_get16(errortlv->value);
            }
            if (errorcode) {
-             printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sender, ft->ip, ft->filename, errorcode);
+             printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
            } else if (status == 0x0002) { /* connection accepted */
-             printf("faim: transfer from %s (%s) for %s accepted\n", ft->sender, ft->ip, ft->filename);
+             printf("faim: transfer from %s (%s) for %s accepted\n", ft->sn, ft->ip, ft->fh.name);
            }
            free(cook->data);
          } else {
@@ -594,14 +515,18 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                       &userinfo);
 
       } else if (reqclass & AIM_CAPS_VOICE) {
-       struct aim_msgcookie_t cachedcook;
+       struct aim_msgcookie_t *cachedcook;
 
        printf("faim: rend: voice!\n");
 
-       memcpy(cachedcook.cookie, cookie, 8);
-       cachedcook.type = AIM_CAPS_VOICE;
-       cachedcook.data = NULL;
-       if (aim_cachecookie(sess, &cachedcook) != 0)
+       if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
+         return 1;
+
+       memcpy(cachedcook->cookie, cookie, 8);
+       cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
+       cachedcook->data = NULL;
+
+       if (aim_cachecookie(sess, cachedcook) != 0)
          printf("faim: ERROR caching message cookie\n");
 
        /* XXX: implement all this */
@@ -611,19 +536,15 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
         */
        userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0)) {
-         i = userfunc(sess, 
-                      command, 
-                      channel, 
-                      reqclass,
-                      &userinfo);
+         i = userfunc(sess, command, channel, reqclass, &userinfo);
        }
-      } else if (reqclass & AIM_CAPS_IMIMAGE) {
+      } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) {
        char ip[30];
-       struct aim_msgcookie_t cachedcook;
+       struct aim_directim_priv *priv;
 
        memset(ip, 0, sizeof(ip));
        
-       if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
+       if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
          struct aim_tlv_t *iptlv, *porttlv;
          
          iptlv = aim_gettlv(list2, 0x0003, 1);
@@ -641,39 +562,13 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
               userinfo.sn,
               ip);
 
-#if 0
-       {
-         struct aim_conn_t *newconn;
-         
-         newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
-         if (!newconn || (newconn->fd == -1)) { 
-           printf("could not connect to %s\n", ip);
-           perror("aim_newconn");
-           aim_conn_kill(sess, &newconn);
-         } else {
-           struct aim_directim_priv *priv;
-           priv = (struct aim_directim_priv *)malloc(sizeof(struct aim_directim_priv));
-           memcpy(priv->cookie, cookie, 8);
-           strncpy(priv->sn, userinfo.sn, MAXSNLEN);
-           newconn->priv = priv;
-           printf("faim: connected to peer (fd = %d)\n", newconn->fd);
-         }
-       }
-#endif
+       /* XXX: there are a couple of different request packets for
+       *          different things */
        
-#if 0
-       memcpy(cachedcook.cookie, cookie, 8);
-       
-       ft = malloc(sizeof(struct aim_filetransfer_t));
-       strncpy(ft->sender, userinfo.sn, sizeof(ft->sender));
-       strncpy(ft->ip, ip, sizeof(ft->ip));
-       ft->filename = strdup(miscinfo->value+8);
-       cachedcook.type = AIM_CAPS_SENDFILE; 
-       cachedcook.data = ft;
-
-       if (aim_cachecookie(sess, &cachedcook) != 0)
-         printf("faim: ERROR caching message cookie\n");
-#endif 
+       priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
+       memcpy(priv->ip, ip, sizeof(priv->ip));
+       memcpy(priv->sn, userinfo.sn, sizeof(priv->sn));
+       memcpy(priv->cookie, cookie, sizeof(priv->cookie));
 
        /*
         * Call client.
@@ -684,7 +579,7 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                       command, 
                       channel, 
                       reqclass,
-                      &userinfo);
+                      &userinfo, priv);
 
       } else if (reqclass & AIM_CAPS_CHAT) {
        struct aim_tlv_t *miscinfo;
@@ -722,7 +617,75 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
          free(encoding);
          free(lang);
       } else if (reqclass & AIM_CAPS_GETFILE) {
+       char ip[30];
+       char *desc = NULL;
+       struct aim_msgcookie_t *cachedcook;
+       struct aim_filetransfer_priv *ft;
+       struct aim_tlv_t *miscinfo;
+       struct aim_conn_t *newconn;
+
+       if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
+         return 0;
+
+       memset(ip, 0, sizeof(ip));
+
+       if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
+         free(cachedcook);
+         return 0;
+       }
+
+       if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
+         struct aim_tlv_t *iptlv, *porttlv;
 
+         if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
+           free(cachedcook);
+           return 0;
+         }
+
+         snprintf(ip, sizeof(ip)-1, "%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),
+                  aimutil_get16(porttlv->value));
+       }
+
+       printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip);
+
+#if 0 /* XXX finish this */
+       newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
+       if (!newconn || (newconn->fd == -1)) {
+         printf("could not connect to %s\n", ip);
+         perror("aim_newconn");
+         aim_conn_kill(sess, &newconn);
+       } else {
+         struct aim_filetransfer_priv *priv;
+         priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
+         memcpy(priv->cookie, cookie, 8);
+         strncpy(priv->sn, userinfo.sn, MAXSNLEN);
+         newconn->priv = priv;
+         printf("faim: connected to peer (fd = %d)\n", newconn->fd);
+       }
+
+       memcpy(cachedcook->cookie, cookie, 8);
+
+       ft = malloc(sizeof(struct aim_filetransfer_priv));
+       ft->state = 1;
+       strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
+       strncpy(ft->ip, ip, sizeof(ft->ip));
+#if 0
+       strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
+#endif
+       cachedcook->type = AIM_COOKIETYPE_OFTGET;
+       cachedcook->data = ft;
+
+       if (aim_cachecookie(sess, cachedcook) != 0)
+         printf("faim: ERROR caching message cookie\n");
+
+       aim_accepttransfer(sess, command->conn, newconn, ft->sn, cookie, AIM_CAPS_GETFILE);
+
+       free(desc);
+#endif
        /*
         * Call client.
         */
@@ -735,26 +698,17 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                       &userinfo);
 
       } else if (reqclass & AIM_CAPS_SENDFILE) {
-       /*
-        * Call client.
-        */
-       userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
-       if (userfunc || (i = 0))
-         i = userfunc(sess, 
-                      command, 
-                      channel, 
-                      reqclass,
-                      &userinfo);
 #if 0
-       char ip[30];
-       char *desc = NULL;
-       struct aim_msgcookie_t cachedcook;
-       struct aim_filetransfer_t *ft;
-       struct aim_tlv_t *miscinfo;
+       char ip[30];
+       char *desc = NULL;
+       struct aim_msgcookie_t *cachedcook;
+       struct aim_filetransfer_priv *ft;
+       struct aim_tlv_t *miscinfo;
 
        memset(ip, 0, sizeof(ip));
        
-       miscinfo = aim_gettlv(list2, 0x2711, 1);
+       if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)))
+         return 0;
 
        if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
          struct aim_tlv_t *iptlv, *porttlv;
@@ -780,24 +734,34 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
               desc, 
               ip);
        
-       memcpy(cachedcook.cookie, cookie, 8);
+       memcpy(cachedcook->cookie, cookie, 8);
        
-       ft = malloc(sizeof(struct aim_filetransfer_t));
-       strncpy(ft->sender, userinfo.sn, sizeof(ft->sender));
+       ft = malloc(sizeof(struct aim_filetransfer_priv));
+       strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
        strncpy(ft->ip, ip, sizeof(ft->ip));
-       ft->filename = strdup(miscinfo->value+8);
-       cachedcook.type = AIM_CAPS_SENDFILE; 
-       cachedcook.data = ft;
+       strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
+       cachedcook->type = AIM_COOKIETYPE_OFTSEND;
+       cachedcook->data = ft;
 
-       if (aim_cachecookie(sess, &cachedcook) != 0)
+       if (aim_cachecookie(sess, cachedcook) != 0)
          printf("faim: ERROR caching message cookie\n");
        
        
-       aim_accepttransfer(sess, command->conn, ft->sender, cookie, AIM_CAPS_SENDFILE);
-
-       free(desc);
+       aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
+       
+       if (desc)
+         free(desc);
 #endif 
-       i = 1;
+       /*
+        * Call client.
+        */
+       userfunc = aim_callhandler(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);
       }
@@ -814,39 +778,6 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
   return i;
 }
 
-u_long aim_accepttransfer(struct aim_session_t *sess,
-                         struct aim_conn_t *conn, 
-                         char *sender,
-                         char *cookie,
-                         unsigned short rendid)
-{
-  struct command_tx_struct *newpacket;
-  int curbyte, i;
-
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+4+2+8+16)))
-    return -1;
-
-  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]);
-  curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
-  curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
-  curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
-  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]);
-  curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
-
-  newpacket->lock = 0;
-  aim_tx_enqueue(sess, newpacket);
-
-  return (sess->snac_nextid++);
-}
-
 /*
  * Possible codes:
  *    AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
index 3481162d4c85f59aee530541c8ff6fc9e310cd69..cd4e8e50ff4b641695911a44c2bac13f021c6743 100644 (file)
@@ -1,11 +1,31 @@
+/*
+ * 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
+ * 
+ */
 
 /*
- *
- *
+ * I'm assuming that cookies are type-specific. that is, we can have
+ * "1234578" for type 1 and type 2 concurrently. if i'm wrong, then we
+ * lose some error checking. if we assume cookies are not type-specific and are
+ * wrong, we get quirky behavior when cookies step on each others' toes.
  */
 
 #include <faim/aim.h>
 
+/*
+ * aim_cachecookie: 
+ * appends a cookie to the cookie list for sess.
+ * - if cookie->cookie for type cookie->type is found, addtime is updated.
+ * - copies cookie struct; you need to free() it afterwards;
+ * - cookie->data is not copied, but passed along. don't free it.
+ * - newcook->addtime is updated accordingly;
+ * - cookie->type is just passed across.
+ * 
+ * returns -1 on error, 0 on success.  */
+
 int aim_cachecookie(struct aim_session_t *sess,
                    struct aim_msgcookie_t *cookie)
 {
@@ -14,45 +34,68 @@ int aim_cachecookie(struct aim_session_t *sess,
   if (!cookie)
     return -1;
 
+  if( (newcook = aim_checkcookie(sess, cookie->cookie, cookie->type)) ) {
+    newcook->addtime = time(NULL);
+    if(cookie->data != newcook->data) {
+      
+      printf("faim: cachecookie: matching cookie/type pair "
+            "%x%x%x%x%x%x%x%x/%x has different *data. free()ing cookie copy..\n",
+            cookie->cookie[0], cookie->cookie[1], cookie->cookie[2],
+            cookie->cookie[3], cookie->cookie[4], cookie->cookie[5],
+            cookie->cookie[6], cookie->cookie[7], cookie->type);
+      
+      free(cookie->data);
+    }
+    return(0);
+  }
+  
   if (!(newcook = malloc(sizeof(struct aim_msgcookie_t))))
     return -1;
   memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t));
   newcook->addtime = time(NULL);
-  newcook->next = NULL;
 
+  if(newcook->next)
+    printf("faim: cachecookie: newcook->next isn't NULL ???\n");
+
+  newcook->next = NULL;
+  
   cur = sess->msgcookies;
   
   if (cur == NULL) {
     sess->msgcookies = newcook;
     return 0;
   }
+
   while (cur->next != NULL)
     cur = cur->next;
   cur->next = newcook;
-
+  
   return 0;
 }
 
-struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, 
-                                         char *cookie)
+/*
+ * 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.
+ */
+
+struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type)
 {
   struct aim_msgcookie_t *cur;
 
-  if (!cookie)
+  if (!cookie || !sess->msgcookies)
     return NULL;
 
-  if (!sess->msgcookies)
-    return NULL;
+  cur = sess->msgcookies;
 
-  if (memcmp(sess->msgcookies->cookie, cookie, 8) == 0) {
-    cur = sess->msgcookies;
+  if ( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type) ) {
     sess->msgcookies = cur->next;
     return cur;
   } 
 
-  cur = sess->msgcookies;
   while (cur->next) {
-    if (memcmp(cur->next->cookie, cookie, 8) == 0) {
+    if ( (memcmp(cur->next->cookie, cookie, 8) == 0) && (cur->next->type == type) ) {
       struct aim_msgcookie_t *tmp;
       
       tmp = cur->next;
@@ -65,10 +108,20 @@ struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess,
 }
 
 /*
+ * aim_purgecookies:
+ * purge out old cookies
+ *
+ * finds old cookies, calls uncache on them.  
+ *
+ * this is highly inefficient, but It Works. and i don't feel like
+ * totally rewriting this. it might have some concurrency issues as
+ * well, if i rewrite it.
+ *
+ * i'll avoid the puns.  
  */
-int aim_purgecookies(struct aim_session_t *sess)
+
+int aim_purgecookies(struct aim_session_t *sess, int maxage)
 {
-  int maxage = 5*60;
   struct aim_msgcookie_t *cur;
   struct aim_msgcookie_t *remed = NULL;
   time_t curtime;
@@ -78,22 +131,93 @@ int aim_purgecookies(struct aim_session_t *sess)
   curtime = time(&curtime);
  
   while (cur) {
-    if ( (cur) && (((cur->addtime) + maxage) < curtime)) {
+    if ( (cur->addtime) > (curtime - maxage) ) {
 #if DEBUG > 1
       printf("aimmsgcookie: WARNING purged obsolete message cookie %x%x%x%x %x%x%x%x\n",
             cur->cookie[0], cur->cookie[1], cur->cookie[2], cur->cookie[3],
             cur->cookie[4], cur->cookie[5], cur->cookie[6], cur->cookie[7]);
 #endif
-      remed = aim_uncachecookie(sess, cur->cookie);
+
+      remed = aim_uncachecookie(sess, cur->cookie, cur->type);
       if (remed) {
        if (remed->data)
          free(remed->data);
        free(remed);
       }
     }
+
     cur = cur->next;
+
   }
   
   return 0;
 }
 
+struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, void *data) 
+{
+  struct aim_msgcookie_t *cookie;
+
+  if(!c)
+    return(NULL);
+
+  if( (cookie = calloc(1, sizeof(struct aim_msgcookie_t))) == NULL)
+    return(NULL);
+  
+  cookie->data = data;
+
+  cookie->type = type;
+  
+  memcpy(cookie->cookie, c, 8);
+  
+  return(cookie);
+}
+  
+struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, char *cookie, int type)
+{
+  struct aim_msgcookie_t *cur;
+  
+  if(!sess->msgcookies)
+    return NULL;
+
+  cur = sess->msgcookies;
+
+  if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type))
+    return(cur);
+
+  while( (cur = cur->next) )
+    if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type))
+      return(cur);
+
+  return(NULL);
+}
+
+int aim_freecookie(struct aim_msgcookie_t *cookie) {
+  return(0);
+} 
+
+int aim_msgcookie_gettype(int reqclass) {
+  /* XXX: hokey-assed. needs fixed. */
+  switch(reqclass) {
+  case AIM_CAPS_BUDDYICON:
+    return AIM_COOKIETYPE_OFTICON;
+    break;
+  case AIM_CAPS_VOICE:
+    return AIM_COOKIETYPE_OFTVOICE;
+    break;
+  case AIM_CAPS_IMIMAGE:
+    return AIM_COOKIETYPE_OFTIMAGE;
+    break;
+  case AIM_CAPS_CHAT:
+    return AIM_COOKIETYPE_CHAT;
+    break;
+  case AIM_CAPS_GETFILE:
+    return AIM_COOKIETYPE_OFTGET;
+    break;
+  case AIM_CAPS_SENDFILE:
+    return AIM_COOKIETYPE_OFTSEND;
+    break;
+  default:
+    return AIM_COOKIETYPE_UNKNOWN;
+    break;
+  }           
+}
index 6f8a2e4802c07c992baf455e0f9f363a55b70c7d..e03040249678f2a9bd58466ad5074d967347e2fc 100644 (file)
@@ -586,6 +586,10 @@ int aim_rxdispatch(struct aim_session_t *sess)
        
        break;
       }
+      case AIM_CONN_TYPE_RENDEZVOUS_OUT: {
+       /* not possible */
+       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);
        workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr);
@@ -606,7 +610,7 @@ int aim_rxdispatch(struct aim_session_t *sess)
 }
 
 int aim_parsemotd_middle(struct aim_session_t *sess,
-                             struct command_rx_struct *command, ...)
+                        struct command_rx_struct *command, ...)
 {
   rxcallback_t userfunc = NULL;
   char *msg;
index 763f8ecc8fd748a7790e6c3838fa84dacf8cdbf5..75aa8bcdef2d4fafb13b45695d92095564732aa7 100644 (file)
@@ -29,6 +29,8 @@ int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *conn)
    */
   if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) 
     return aim_get_command_rendezvous(sess, conn);
+  if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) 
+    return 0; 
 
   /*
    * Read FLAP header.  Six bytes:
@@ -122,82 +124,6 @@ int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *conn)
   return 0;  
 }
 
-int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
-{
-  unsigned char hdrbuf1[6];
-  unsigned char *hdr = NULL;
-  int hdrlen, hdrtype;
-  int payloadlength = 0;
-  int flags = 0;
-  char *snptr = NULL;
-
-  if (read(conn->fd, hdrbuf1, 6) < 6) {
-    perror("read");
-    printf("faim: rend: read error\n");
-    aim_conn_kill(sess, &conn);
-    return -1;
-  }
-
-  hdrlen = aimutil_get16(hdrbuf1+4);
-
-  hdrlen -= 6;
-  hdr = malloc(hdrlen);
-
-  faim_mutex_lock(&conn->active);
-  if (read(conn->fd, hdr, hdrlen) < hdrlen) {
-    perror("read");
-    printf("faim: rend: read2 error\n");
-    free(hdr);
-    faim_mutex_unlock(&conn->active);
-    aim_conn_kill(sess, &conn);
-    return -1;
-  }
-  
-  hdrtype = aimutil_get16(hdr);  
-
-  switch (hdrtype) {
-  case 0x0001: {
-    payloadlength = aimutil_get32(hdr+22);
-    flags = aimutil_get16(hdr+32);
-    snptr = hdr+38;
-
-    printf("OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr);
-
-    if (flags == 0x000e) {
-      printf("directim: %s has started typing\n", snptr);
-    } else if ((flags == 0x0000) && payloadlength) {
-      unsigned char *buf;
-      buf = malloc(payloadlength+1);
-
-      /* XXX theres got to be a better way */
-      faim_mutex_lock(&conn->active);
-      if (recv(conn->fd, buf, payloadlength, MSG_WAITALL) < payloadlength) {
-       perror("read");
-       printf("faim: rend: read3 error\n");
-       free(buf);
-       faim_mutex_unlock(&conn->active);
-       aim_conn_kill(sess, &conn);
-       return -1;
-      }
-      faim_mutex_unlock(&conn->active);
-      buf[payloadlength] = '\0';
-      printf("directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, buf);
-      aim_send_im_direct(sess, conn, buf);
-      free(buf);
-    }
-    break;
-  }
-  default:
-    printf("OFT frame: type %04x\n", hdrtype);  
-    /* data connection may be unreliable here */
-    break;
-  } /* switch */
-
-  free(hdr);
-  
-  return 0;
-}
-
 /*
  * Purge recieve queue of all handled commands (->handled==1).  Also
  * allows for selective freeing using ->nofree so that the client can
index 63b1a1d9c2d071f858e908b1623a45c04e42a2b5..bbc1d30b1b7f450a8ccbf4abcab8c29f369edb84 100644 (file)
 #include <stdarg.h>
 #include <errno.h>
 
+#ifdef _WIN32
+#include <windows.h>
+#include <time.h>
+#include <io.h>
+#else
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/time.h>
+#include <unistd.h>
+#endif
+
 #ifdef FAIM_USEPTHREADS
 #include <pthread.h>
 #define faim_mutex_t pthread_mutex_t 
 #define faim_mutex_unlock(x) *x = 0;
 #endif
 
-#ifdef _WIN32
-#include <windows.h>
-#include <time.h>
-#include <io.h>
-#else
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <unistd.h>
-#endif
-
 /* Portability stuff (DMP) */
 
 #ifdef _WIN32
@@ -167,7 +167,19 @@ struct client_info_s {
 #define AIM_CONN_TYPE_BOS           0x0002
 #define AIM_CONN_TYPE_CHAT          0x000e
 #define AIM_CONN_TYPE_CHATNAV       0x000d
+
+/* they start getting arbitrary in rendezvous stuff =) */
 #define AIM_CONN_TYPE_RENDEZVOUS    0x0101 /* these do not speak OSCAR! */
+#define AIM_CONN_TYPE_RENDEZVOUS_OUT 0x0102 /* socket waiting for accept() */
+
+/*
+ * Subtypes, we need these for OFT stuff.
+ */
+#define AIM_CONN_SUBTYPE_OFT_DIRECTIM  0x0001
+#define AIM_CONN_SUBTYPE_OFT_GETFILE   0x0002
+#define AIM_CONN_SUBTYPE_OFT_SENDFILE  0x0003
+#define AIM_CONN_SUBTYPE_OFT_BUDDYICON 0x0004
+#define AIM_CONN_SUBTYPE_OFT_VOICE     0x0005
 
 /*
  * Status values returned from aim_conn_new().  ORed together.
@@ -182,7 +194,8 @@ struct client_info_s {
 
 struct aim_conn_t {
   int fd;
-  int type;
+  unsigned short type;
+  unsigned short subtype;
   int seqnum;
   int status;
   void *priv; /* misc data the client may want to store */
@@ -199,11 +212,12 @@ struct command_rx_struct {
   unsigned char hdrtype; /* defines which piece of the union to use */
   union {
     struct { 
-      char type;        
+      char type;
       unsigned short seqnum;     
     } oscar;
     struct {
       unsigned short type;
+      unsigned char magic[4]; /* ODC2 OFT2 */
       unsigned short hdr2len;
       unsigned char *hdr2; /* rest of bloated header */
     } oft;
@@ -227,6 +241,7 @@ struct command_tx_struct {
     } oscar;
     struct {
       unsigned short type;
+      unsigned char magic[4]; /* ODC2 OFT2 */
       unsigned short hdr2len;
       unsigned char *hdr2;
     } oft;
@@ -362,8 +377,9 @@ int aim_counttlvchain(struct aim_tlvlist_t **list);
  */
 int aim_get_command(struct aim_session_t *, struct aim_conn_t *);
 int aim_rxdispatch(struct aim_session_t *);
-u_long aim_debugconn_sendconnect(struct aim_session_t *sess,
-                                struct aim_conn_t *conn);
+
+u_long aim_debugconn_sendconnect(struct aim_session_t *sess, struct aim_conn_t *conn);
+
 int aim_logoff(struct aim_session_t *);
 
 void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn);
@@ -375,6 +391,8 @@ u_long aim_genericreq_n(struct aim_session_t *, struct aim_conn_t *conn, u_short
 u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *);
 u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *);
 
+struct aim_fileheader_t *aim_oft_getfh(char *hdr);
+
 /* aim_login.c */
 int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
@@ -399,7 +417,7 @@ void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn
 int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...);
 int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...);
 int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...);
-
+int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn);
 
 struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen);
 int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *);
@@ -479,6 +497,9 @@ u_long aim_bos_reqlocaterights(struct aim_session_t *, struct aim_conn_t *);
 u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *);
 u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn);
 
+struct aim_fileheader_t *aim_getlisting(struct aim_session_t*);
+int aim_listenestablish(u_short);
+
 /* aim_rxhandlers.c */
 int aim_rxdispatch(struct aim_session_t *);
 int aim_authparse(struct aim_session_t *, struct command_rx_struct *);
@@ -489,6 +510,12 @@ int aim_parse_generalerrs(struct aim_session_t *, struct command_rx_struct *comm
 int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 
 /* aim_im.c */
+struct aim_directim_priv {
+  unsigned char cookie[8];
+  char sn[MAXSNLEN+1];
+  char ip[30];
+};
+
 #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */
 #define AIM_IMFLAGS_ACK  0x02 /* request a receipt notice */
 
@@ -499,6 +526,10 @@ u_long aim_seticbmparam(struct aim_session_t *, struct aim_conn_t *conn);
 int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *);
 int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command);
 
+struct aim_conn_t * aim_directim_intiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *);
+int aim_send_im_direct(struct aim_session_t *, struct aim_conn_t *, char *);
+struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *);
+
 /* aim_info.c */
 #define AIM_CAPS_BUDDYICON 0x01
 #define AIM_CAPS_VOICE 0x02
@@ -522,20 +553,79 @@ struct aim_msgcookie_t {
   struct aim_msgcookie_t *next;
 };
 
-struct aim_filetransfer_t {
-  char sender[MAXSNLEN];       
+struct aim_fileheader_t {
+#if 0
+  char  magic[4];            /* 0 */
+  short hdrlen;           /* 4 */
+  short hdrtype;             /* 6 */
+#endif
+  char  bcookie[8];       /* 8 */
+  short encrypt;          /* 16 */
+  short compress;         /* 18 */
+  short totfiles;         /* 20 */
+  short filesleft;        /* 22 */
+  short totparts;         /* 24 */
+  short partsleft;        /* 26 */
+  long  totsize;          /* 28 */
+  long  size;             /* 32 */
+  long  modtime;          /* 36 */
+  long  checksum;         /* 40 */
+  long  rfrcsum;          /* 44 */
+  long  rfsize;           /* 48 */
+  long  cretime;          /* 52 */
+  long  rfcsum;           /* 56 */
+  long  nrecvd;           /* 60 */
+  long  recvcsum;         /* 64 */
+  char  idstring[32];     /* 68 */
+  char  flags;            /* 100 */
+  char  lnameoffset;      /* 101 */
+  char  lsizeoffset;      /* 102 */
+  char  dummy[69];        /* 103 */
+  char  macfileinfo[16];  /* 172 */
+  short nencode;          /* 188 */
+  short nlanguage;        /* 190 */
+  char  name[64];         /* 192 */
+                          /* 256 */
+};
+
+struct aim_filetransfer_priv {
+  char sn[MAXSNLEN];
+  char cookie[8];
   char ip[30];
-  char *filename;
+  int state;
+  struct aim_fileheader_t fh;
 };
+
+#define AIM_COOKIETYPE_UNKNOWN  0x00
+#define AIM_COOKIETYPE_ICBM     0x01
+#define AIM_COOKIETYPE_ADS      0x02
+#define AIM_COOKIETYPE_BOS      0x03
+#define AIM_COOKIETYPE_IM       0x04
+#define AIM_COOKIETYPE_CHAT     0x05
+#define AIM_COOKIETYPE_CHATNAV  0x06
+/* we'll move OFT up a bit to give breathing room.  not like it really
+ * matters. */
+#define AIM_COOKIETYPE_OFTIM    0x10
+#define AIM_COOKIETYPE_OFTGET   0x11
+#define AIM_COOKIETYPE_OFTSEND  0x12
+#define AIM_COOKIETYPE_OFTVOICE 0x13
+#define AIM_COOKIETYPE_OFTIMAGE 0x14
+#define AIM_COOKIETYPE_OFTICON  0x15
+
 int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie);
-struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie);
-int aim_purgecookies(struct aim_session_t *sess);
+int aim_purgecookies(struct aim_session_t *sess, int maxage);
+struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type);
+struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *);
+struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, char *, int);
+int aim_getcookietype(int);
+
+int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur);
 
 #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000
 #define AIM_TRANSFER_DENY_DECLINE 0x0001
 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
-u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short rendid);
+u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn,struct aim_conn_t *oftconn, char *sender, char *cookie, unsigned short rendid);
 
 u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
 int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
index 3943e10aa78581c33fdcc029029bfdd65194b93a..ab5388a0e1d1772568dea7e67626f79fb0c61640 100644 (file)
@@ -24,6 +24,7 @@
 #define AIM_CB_FAM_CTN 0x000d /* ChatNav */
 #define AIM_CB_FAM_CHT 0x000e /* Chat */
 #define AIM_CB_FAM_ATH 0x0017
+#define AIM_CB_FAM_OFT 0xfffe /* OFT/Rvous */
 #define AIM_CB_FAM_SPECIAL 0xffff /* Internal libfaim use */
 
 /*
 #define AIM_CB_ATH_AUTHREQ 0x0006
 #define AIM_CB_ATH_AUTHRESPONSE 0x0007
 
+/*
+ * OFT Services
+ *
+ * See non-SNAC note below.
+ */
+#define AIM_CB_OFT_DIRECTIMCONNECTREQ 0x0001
+#define AIM_CB_OFT_DIRECTIMINCOMING 0x0002
+#define AIM_CB_OFT_DIRECTIMDISCONNECT 0x0003
+#define AIM_CB_OFT_DIRECTIMTYPING 0x0006
+#define AIM_CB_OFT_DIRECTIMINITIATE 0x0007
+
+#define AIM_CB_OFT_GETFILECONNECT 0x0004
+#define AIM_CB_OFT_GETFILECOMPLETE 0x0005
+#define AIM_CB_OFT_GETFILEINITIATE 0x0007
+
 /*
  * SNAC Family: Internal Messages
  *
index 7b3c07add566eb2a3bee3490392e7d2f83037b26..e650edfd3eac853947e9bfcc9b11114a6ebf4022 100644 (file)
@@ -67,6 +67,13 @@ int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *com
 int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 
+int faimtest_directim_request(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+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, ...);
+
 int faimtest_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   if (command->data) {
@@ -143,11 +150,21 @@ int main(void)
       break;
 
     case 2: /* incoming data pending */
-      if (aim_get_command(&aimsess, waitingconn) < 0) {
-         printf("\afaimtest: connection error!\n");
-         keepgoing = 0; /* fall through and hit the aim_logoff() */
-      } else
-       aim_rxdispatch(&aimsess);
+      if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
+       if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
+         printf("connection error (rend)\n");
+       }
+      } else {
+       if (aim_get_command(&aimsess, waitingconn) >= 0) {
+         aim_rxdispatch(&aimsess);
+       } else {
+         printf("connection error\n");
+         if (!aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS)) {
+           printf("major connetion error\n");
+           keepgoing = 0;
+         }
+       }
+      }
       break;
       
     default:
@@ -213,6 +230,12 @@ int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *c
       aim_bos_ackrateresp(sess, command->conn);
       aim_chat_clientready(sess, command->conn);
       break;
+
+    case AIM_CONN_TYPE_RENDEZVOUS: /* this is an overloaded function?? - mid */
+      aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
+      aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
+      break;
+
     default:
       fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
     }
@@ -545,7 +568,7 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
        aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
        //aim_chat_join(sess, command->conn, "thishereisaname2_chat85");
       } else if (!strncmp(tmpstr, "create", 6)) {
-       aim_chatnav_createroom(sess, aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), "WorldDomination", 0x0004);
+       aim_chatnav_createroom(sess,aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), (strlen(tmpstr) < 7)?"WorldDomination":tmpstr+7, 0x0004);
       } else if (!strncmp(tmpstr, "close chatnav", 13)) {
        struct aim_conn_t *chatnavconn;
        chatnavconn = aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV);
@@ -557,6 +580,10 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       else if (!strncmp(tmpstr, "getinfo", 7)) {
        aim_getinfo(sess, command->conn, "75784102", AIM_GETINFO_GENERALINFO);
        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);
+       //aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate, 0);
       } else if (!strncmp(tmpstr, "sendmsg", 7)) {
        int i;
        i = atoi(tmpstr+8);
@@ -654,6 +681,32 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       aim_chat_join(sess, command->conn, 0x0004, roominfo->name);
       break;
     }  
+    case AIM_CAPS_IMIMAGE: {
+      struct aim_directim_priv *priv;
+      struct aim_conn_t *newconn;
+
+      printf("faimtest: icbm: rendezvous imimage\n");
+     
+      userinfo = va_arg(ap, struct aim_userinfo_s *);
+      priv = va_arg(ap, struct aim_directim_priv *);
+      va_end(ap);
+
+      printf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, priv->ip);
+      
+      if (!(newconn = aim_directim_connect(sess, command->conn, priv))) {
+       printf("faimtest: icbm: imimage: could not connect\n");
+       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);
+
+      aim_send_im_direct(sess, newconn, "goodday");
+
+      printf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
+
+      break;
+    }
     default:
       printf("faimtest: icbm: unknown reqclass (%d)\n", reqclass);
     } /* switch */
@@ -664,6 +717,105 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
   return 1;
 }
 
+#if 0
+int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_directim_priv *priv;
+  struct aim_conn_t *newconn;
+
+  ap = va_start(ap, command);
+  newconn = va_arg(ap, struct aim_conn_t *);
+  va_end(ap);
+
+  priv = (struct aim_directim_priv *)newconn->priv;
+
+  printf("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_send_im_direct(sess, newconn, "goodday");
+
+  printf("faimtest: OFT: DirectIM: connected to %s\n", priv->sn);
+
+  return 1;
+}
+#endif
+
+int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_directim_priv *priv;
+  
+  ap = va_start(ap, command);
+  priv = va_arg(ap, struct aim_directim_priv *);
+
+  va_end(ap);
+  
+  printf("faimtest: directim_connect\n");
+
+  return 1;
+}
+
+int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  char *sn = NULL, *msg = NULL;
+  struct aim_conn_t *conn;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  sn = va_arg(ap, char *);
+  msg = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: Directim from %s: %s\n", sn, msg);
+  if (!strncmp(msg, "sendmsg", 7)) {
+    int i;
+    i = atoi(msg+8);
+    if (i < 10000) {
+      char *newbuf;
+      int z;
+      
+      newbuf = malloc(i+1);
+      for (z = 0; z < i; z++) {
+       newbuf[z] = (z % 10)+0x30;
+      }
+      newbuf[i] = '\0';
+      aim_send_im_direct(sess, conn, newbuf);
+      free(newbuf);
+    }
+  } else if (!strncmp(msg, "goodday", 7)) {
+    aim_send_im_direct(sess, 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);
+  }
+  return 1;
+}
+
+int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  printf("faimtest: directim_disconnect\n");
+  return 1;
+}
+
+int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  char *sn;
+  
+  ap = va_start(ap, command);
+  sn = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn);
+  return 1;
+}
+
 int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
This page took 0.13341 seconds and 5 git commands to generate.