]> andersk Git - libfaim.git/commitdiff
- Fri Sep 22 22:35:51 UTC 2000
authormid <mid>
Fri, 22 Sep 2000 22:44:11 +0000 (22:44 +0000)
committermid <mid>
Fri, 22 Sep 2000 22:44:11 +0000 (22:44 +0000)
  - Apply jbm's patch below
  - Minor cleanup in cb handler stuff

 - Thu Sep 21 20:28:20 CDT 2000 (jbm)
  - DirectIM shouldn't kill us any more.
  - Eliminated a potential segfault in aim_send_im_direct().
  - make tags (yay!).
  - Added an aim_tx_destroy(); need to move the lib over to using it.
  - Got rid of some #if 0 BS code in a couple of places
      (aim_ft::establish() and aim_im::aim_parse_incoming_im_middle()).
  - Added some file transfer stuff (so experimental, i haven't
      had a chance to see if it causes cancer in lab animals).
  - Added to faimtest for all of the above.
  - Added myself to AUTHORS with Real Info.

AUTHORS
CHANGES
Makefile
aim_ft.c
aim_im.c
aim_rxhandlers.c
aim_txqueue.c
faim/aim.h
faim/aim_cbtypes.h
utils/faimtest/faimtest.c

diff --git a/AUTHORS b/AUTHORS
index 988b852a7b8e21110f46a457b9fccb02c8d31c42..5ca139888dc8e130a9180d4ed78657e74e0cc15c 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -11,7 +11,7 @@ D: Wrote most of the wap of crap that you see before you.
 
 N: Josh Myer
 E: josh@joshisanerd.com
-D: [I'm sure he did something -mid]
+D: OFT/ODC (not quite finished yet..), random little things, Munger-At-Large, compile-time warnings.
 
 N: Daniel Reed
 H: n, linuxkitty
diff --git a/CHANGES b/CHANGES
index f1ce549df33253232f1d13e6b5d94fc8cb655b11..822a3c2e631868182bc7bd7ab60824e9d8950154 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,22 @@
 
 No release numbers
 ------------------
+ - Fri Sep 22 22:35:51 UTC 2000
+  - Apply jbm's patch below
+  - Minor cleanup in cb handler stuff
+
+ - Thu Sep 21 20:28:20 CDT 2000 (jbm)
+  - DirectIM shouldn't kill us any more.
+  - Eliminated a potential segfault in aim_send_im_direct().
+  - make tags (yay!).
+  - Added an aim_tx_destroy(); need to move the lib over to using it.
+  - Got rid of some #if 0 BS code in a couple of places 
+      (aim_ft::establish() and aim_im::aim_parse_incoming_im_middle()).
+  - Added some file transfer stuff (so experimental, i haven't 
+      had a chance to see if it causes cancer in lab animals).
+  - Added to faimtest for all of the above.
+  - Added myself to AUTHORS with Real Info.
+
  - Thu Sep 21 00:24:36 UTC 2000
    - Add socks5 proxy support (not tested real well, worked the 
        few times a tried).
index 326ededb184f271f6b052336735e3b63803f8595..5a65b66452e214e4c5aba00e173483c7b88e07c3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -60,4 +60,7 @@ cleanutils:
        $(MAKE) clean
 
 clean: cleanutils
-       rm -f $(LIBFAIM_OBJECTS) $(SONAME) libfaim.a *~ core
\ No newline at end of file
+       rm -f $(LIBFAIM_OBJECTS) $(SONAME) libfaim.a *~ core
+
+tags:
+       etags *.[ch] faim/*.[ch] utils/faimtest/faimtest.c
index b3bf8f7ea12b609032edc62c26dd1cf98aa43f32..c78862f84b68d8969796fdd61d04be2a63041886 100644 (file)
--- a/aim_ft.c
+++ b/aim_ft.c
@@ -102,14 +102,14 @@ faim_export int aim_send_im_direct(struct aim_session_t *sess,
   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) {
+  if (!sess || !conn || !(conn->type) || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv || !msg) {
     printf("faim: directim: invalid arguments\n");
     return -1;
   };
 
+  if (strlen(msg) >= MAXMSGLEN)
+    return -1;
+
   priv = (struct aim_directim_priv *)conn->priv;
 
   /* NULLish Header */
@@ -406,11 +406,6 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
    * allocate and set up our connection
    */
 
-#if 0
-  i = fcntl(listenfd, F_GETFL, 0);
-  fcntl(listenfd, F_SETFL, i | O_NONBLOCK);
-#endif
-
   newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL);
   if (!newconn) { 
     perror("aim_newconn");
@@ -449,6 +444,14 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
   return (newconn);
 } 
 
+/*
+ * struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_directim_priv *priv)
+ * sess is the session to append the conn to,
+ * conn is the BOS connection,
+ * priv is the filled-in priv data structure for the connection
+ * returns conn if connected, NULL on error
+ */
+
 
 faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
                                                    struct aim_conn_t *conn,
@@ -471,140 +474,260 @@ faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
   return newconn;
 }
 
-faim_export unsigned 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 aim_conn_t *aim_directim_getconn(struct aim_session_t *sess, const char *name)
+ * sess is your session, 
+ * name is the name to get,
+ * 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)
+{
+  struct aim_conn_t *cur;
+  struct aim_directim_priv *priv;
+  
+  faim_mutex_lock(&sess->connlistlock);
+  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;
+}
+
+/*
+ * aim_accepttransfer:
+ * accept a file transfer request.
+ * sess is the session,
+ * conn is the BOS conn for the CAP reply
+ * sn is the screenname to send it to,
+ * cookie is the cookie used
+ * ip is the ip to connect to
+ * file is the listing file to use
+ * rendid is CAP type
+ *
+ * returns connection
+ */
+
+faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
+                         struct aim_conn_t *conn, 
+                         char *sn,
+                         char *cookie,
+                         char *ip,
+                         FILE *file,
+                         unsigned short rendid)
 {
   struct command_tx_struct *newpacket, *newoft;
+
+  struct aim_conn_t *newconn;
   struct aim_fileheader_t *listingfh;
+  struct aim_filetransfer_priv *priv;
+  struct aim_msgcookie_t *cachedcook;
+
   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;
+
+    newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
     
-    memcpy(newoft->hdr.oft.magic, "OFT2", 4);
-    newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
+    newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
     
-    if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
-      free(newoft);
-      return -1;
-    }  
+    if (!newconn || (newconn->fd == -1)) {
+      perror("aim_newconn");
+      faimdprintf(2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0);
+      aim_conn_kill(sess, &newconn);
+      return NULL;
+    } else {
+      priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
+      memcpy(priv->cookie, cookie, 8);
+      strncpy(priv->sn, sn, MAXSNLEN);
+      strncpy(priv->ip, ip, sizeof(priv->ip));
+      newconn->priv = (void *)priv;
+      faimdprintf(2, "faim: connected to peer (fd = %d)\n", newconn->fd);
+    }
+    /* cache da cookie. COOOOOKIES! */
 
-    listingfh = aim_getlisting(sess);
+    if(!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) {
+      faimdprintf(1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n");
+      /* XXX die here, or go on? search for cachedcook for future references */
+    }
 
-    memcpy(listingfh->bcookie, cookie, 8);
+    if(cachedcook)
+      memcpy(cachedcook->cookie, cookie, 8);
+  
+    /*  strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); */
 
-    curbyte = 0;
+    if(cachedcook) { /* see above calloc of cachedcook */
+      cachedcook->type = AIM_COOKIETYPE_OFTGET;
+      cachedcook->data = (void *)priv;
+    
+      if (aim_cachecookie(sess, cachedcook) != 0)
+       faimdprintf(1, "faim: ERROR caching message cookie\n");
+    }
+  
+    if(rendid == AIM_CAPS_GETFILE) {
+      faimdprintf(2, "faim: getfile request accept\n");
+      if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, newconn, 0))) {
+       faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
+       /* XXX: what else do we need to clean up here? */
+       return NULL;
+      }
+    
+      newoft->lock = 1;
     
-    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.magic, "OFT2", 4);
+      newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
     
-    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16);
-    curbyte += 16;
+      if(!(listingfh = aim_getlisting(file))) {
+       return NULL;
+      }      
 
-    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode);
-    curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage);
+      if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
+       free(newoft);
+       return NULL;
+      }  
 
-    memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
-    curbyte += 64;
+      memcpy(listingfh->bcookie, cookie, 8);
 
-    free(listingfh);
+      aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, listingfh);
 
-    newoft->lock = 0;
-    aim_tx_enqueue(sess, newoft);
-    printf("faim: getfile: OFT listing enqueued.\n");
+      free(listingfh);
+
+      newoft->lock = 0;
+      aim_tx_enqueue(sess, newoft);
+      printf("faim: getfile: OFT listing enqueued.\n");
     
-  }
+    }
 
+    /* OSCAR CAP accept packet */
 
-  if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16)))
-    return -1;
+    if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16)))
+      return NULL;
   
-  newpacket->lock = 1;
+    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);
-
-
+    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++);
+    return newconn;
+  }
+  return NULL;
 }
 
 /*
- * aim_getlisting()
+ * aim_getlisting(FILE *file)
  * 
- * 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. =)
- *  
+ * file is an opened listing file
+ * returns a pointer to the filled-in fileheader_t
+ *
+ * currently omits checksum. we'll fix this when AOL breaks us, i
+ * guess.
+ *
  */
 
-faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess
+faim_internal struct aim_fileheader_t *aim_getlisting(FILE *file
 {
   struct aim_fileheader_t *fh;
+  u_long totsize = 0, size = 0, checksum = 0xffff0000;
+  short totfiles = 0;
+  char *linebuf, sizebuf[9];
+  
+  int linelength = 1024;
+
+  /* XXX: if we have a line longer than 1024chars, God help us. */
+  if( (linebuf = (char *)calloc(1, linelength)) == NULL ) {
+    faimdprintf(2, "linebuf calloc failed\n");
+    return NULL;
+  }  
+
+  if(fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */
+    perror("getlisting END1 fseek:");
+    faimdprintf(2, "getlising fseek END1 error\n");
+  }
+
+  if(fgetpos(file, &size) == -1) {
+    perror("getlisting END1 getpos:");
+    faimdprintf(2, "getlising getpos END1 error\n");
+  }
+
+  if(fseek(file, 0, SEEK_SET) != 0) {
+    perror("getlesting fseek(SET):");
+    faimdprintf(2, "faim: getlisting: couldn't seek to beginning of listing file\n");
+  }
+
+  bzero(linebuf, linelength);
+
+  size = 0;
+
+  while(fgets(linebuf,  linelength, file)) {
+    totfiles++;
+    bzero(sizebuf, 9);
+
+    size += strlen(linebuf);
+    
+    if(strlen(linebuf) < 23) {
+      faimdprintf(2, "line \"%s\" too short. skipping\n", linebuf);
+      continue;
+    }
+    if(linebuf[strlen(linebuf)-1] != '\n') {
+      faimdprintf(2, "faim: OFT: getlisting -- hit EOF or line too long!\n");
+    }
+
+    memcpy(sizebuf, linebuf+17, 8);
+
+    totsize += strtol(sizebuf, NULL, 10);
+    bzero(linebuf, linelength);
+  }   
+
+  /*  if(size != 0) {
+    faimdprintf(2, "faim: getlisting: size != 0 after while.. %i\n", size);
+    }*/
+
+  if(fseek(file, 0, SEEK_SET) == -1) {
+    perror("getlisting END2 fseek:");
+    faimdprintf(2, "getlising fseek END2 error\n");
+  }  
+
+  free(linebuf);
+
+  /* we're going to ignore checksumming the data for now -- that
+   * requires walking the whole listing.txt. it should probably be
+   * done at register time and cached, but, eh. */  
 
   if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
     return NULL;
 
+  printf( "faim: OFT: getlisting: totfiles: %u, totsize: %lu, size: %lu\n", totfiles, totsize, size);
+
   fh->encrypt     = 0x0000;
-  fh->compress    = 0x0000;
-  fh->totfiles    = 0x0001;
-  fh->filesleft   = 0x0001;
+  fh->compress    = 0x0000; 
+  fh->totfiles    = totfiles;
+  fh->filesleft   = totfiles; /* is this right ?*/
   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->totsize     = totsize;
+  fh->size        = size; /* ls -l listing.txt */
+  fh->modtime     = (int)time(NULL); /* we'll go with current time for now */
+  fh->checksum    = checksum; /* XXX: checksum ! */
   fh->rfcsum      = 0x00000000;
   fh->rfsize      = 0x00000000;
   fh->cretime     = 0x00000000;
@@ -612,28 +735,25 @@ faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess
   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 */ 
+  /*  memset(fh->idstring, 0, sizeof(fh->idstring)); */
+  memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring));
+  memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring));
 
   fh->flags       = 0x02;
   fh->lnameoffset = 0x1a;
   fh->lsizeoffset = 0x10;
 
-  memset(fh->dummy, 0, 69/*sizeof(fh->dummy)*/);
-  /*  fh->dummy = ;*/
+  /*  memset(fh->dummy, 0, sizeof(fh->dummy)); */
+  memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo));
 
-  memset(fh->macfileinfo, 0, 16/*sizeof(fh->macfileinfo)*/);
-  /*  fh->macfileinfo = ; */
-
-  fh->nencode     = 0x0000;
+  fh->nencode     = 0x0000; /* we need to figure out these encodings for filenames */
   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 */
+  /*  memset(fh->name, 0, sizeof(fh->name)); */
+  memcpy(fh->name, "listing.txt", sizeof(fh->name));
+  memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name));
 
-  printf("jbm: fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
+  faimdprintf(2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
   return fh;
 }
 
@@ -712,9 +832,6 @@ faim_internal int aim_listenestablish(u_short portnum)
 
 faim_internal 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;
@@ -727,27 +844,74 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
   faim_mutex_lock(&conn->active); /* gets locked down for the entirety */
 
   if ( (hdrlen = aim_recv(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);
+    faimdprintf(2, "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);
     faim_mutex_unlock(&conn->active);
     aim_conn_close(conn);
-    return -1;
+    
+    if(hdrlen < 0)
+      perror("read");
+    else { /* disconnected */
+      int i = -1;
+      switch(conn->subtype) {
+      case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { /* XXX: clean up cookies here ? */
+       struct aim_directim_priv *priv;
+       if(!(priv = (struct aim_directim_priv *)conn->priv) )
+         return -1; /* not much we can do */
+
+       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) )
+         i = userfunc(sess, NULL, conn, priv->sn);
+       else
+         aim_conn_kill(sess, &conn);
+
+       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTIM);
+      }
+      case AIM_CONN_SUBTYPE_OFT_GETFILE: {
+       struct aim_filetransfer_priv *priv;
+       if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
+         return -1;
+
+       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) )
+         i = userfunc(sess, NULL, conn, priv->sn);
+       else
+         aim_conn_kill(sess, &conn);
+
+       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
+      }
+      case AIM_CONN_SUBTYPE_OFT_SENDFILE: {
+       struct aim_filetransfer_priv *priv;
+       if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
+         return -1;
+
+       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) )
+         i = userfunc(sess, NULL, conn, priv->sn);
+       else
+         aim_conn_kill(sess, &conn);
+
+
+       aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
+      }
+      }
+
+    return i;
+    }
   }
 
   hdrlen = aimutil_get16(hdrbuf1+4);
 
   hdrlen -= 6;
-  if (!(hdr = malloc(hdrlen)))
+  if (!(hdr = malloc(hdrlen))) {
+    faim_mutex_unlock(&conn->active);
     return -1;
+  }
 
   if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) {
     perror("read");
-    printf("faim: rend: read2 error\n");
+    faimdprintf(2,"faim: rend: read2 error\n");
     free(hdr);
     faim_mutex_unlock(&conn->active);
     aim_conn_close(conn);
-    return 0; /* see comment on previous read check */
+    return -1;
   }
 
   hdrtype = aimutil_get16(hdr);  
@@ -767,9 +931,7 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
     strncpy(priv->sn, snptr, MAXSNLEN);
 
-#if 0
-    printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); 
-#endif
+    faimdprintf(2, "faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); 
 
     if (flags == 0x000e) {
       faim_mutex_unlock(&conn->active);
@@ -780,7 +942,7 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
       if(! (msg = calloc(1, payloadlength+1)) ) {
        faim_mutex_unlock(&conn->active);
-       return 0;
+       return -1;
       }
       
       if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) {
@@ -793,9 +955,8 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
       }
       faim_mutex_unlock(&conn->active);
       msg[payloadlength] = '\0';
-#if 0     
-      printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
-#endif
+      faimdprintf(2, "faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+
 
       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
        i = userfunc(sess, NULL, conn, snptr, msg);
@@ -804,31 +965,82 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
       return i;
     }
     break;
-  } 
-  case 0x1209: { /* get file first */
+  }
+#if 0
+  /* currently experimental to a non-compiling degree */
+  case 0x1108: { /* getfile listing.txt incoming tx->rx */
     struct aim_filetransfer_priv *ft;
     struct aim_fileheader_t *fh;
     struct aim_msgcookie_t *cook;
+    struct aim_conn_type *newoft;
 
     int commandlen;
     char *data;
 
-    printf("faim: rend: fileget 0x1209\n");
+    faimdprintf(2,"faim: rend: fileget 0x1108\n");
+    
+    if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
+      faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      faim_mutex_unlock(&conn->active);
+      return -1;
+    }
 
-    if(hdrlen != 0x100)
-      printf("faim: fileget_command(1209): um. hdrlen != 0x100.. 0x%x\n", hdrlen);
+    ft->state = 1; /* we're waaaaiiiting.. */
+
+    fh = aim_oft_getfh(hdr);
+
+    memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
     
+    if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
+      faim_mutex_unlock(&conn->active);
+      return -1;
+    }
+
+    if(cook->data)
+      free(cook->data);
+
+    cook->data = ft;
+
+    aim_cachecookie(sess, cook);
+
+    if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1209, conn, 0))) {
+      /* XXX: what else do we need to clean up here? */
+      faim_mutex_unlock(&conn->active);
+      return -1;
+    }
+
+
+    aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, ft->fh); /* no change */
+    newoft->lock = 0;
+    aim_tx_enqueue(sess, newoft);
+    break;
+  }
+#endif 
+  case 0x1209: { /* get file listing ack rx->tx */
+    struct aim_filetransfer_priv *ft;
+    struct aim_fileheader_t *fh;
+    struct aim_msgcookie_t *cook;
+
+    int commandlen;
+    char *data;
+
+    faimdprintf(2,"faim: rend: fileget 0x1209\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");
+      faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
       faim_mutex_unlock(&conn->active);
-      return 0;
+      return -1;
     }
 
     fh = aim_oft_getfh(hdr);
 
     memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
     
-    cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+
+    /* we currently trust the other client to be giving us Valid
+     *  Enough input, else this gets to be a messy function (and we
+     *  won't break like winaim does when it gets bad input =) */
 
     if(cook->data)
       free(cook->data); /* XXX */
@@ -837,17 +1049,36 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
     
     aim_cachecookie(sess, cook);
 
-    commandlen = 36;
+    /* XXX: have this send chunks of the file instead of the whole
+     * file. requires rethinking some code. */
+
+    if(fseek(sess->oft.listing, 0, SEEK_SET) != 0) {
+      perror("get_command_rendezvous 1209 fseek(SET):");
+      faimdprintf(2, "faim: getlisting: couldn't seek to beginning of listing file\n");
+    }
+    commandlen = ft->fh.size;
+
+    if((data = (char *)calloc(1, commandlen)) == NULL) {
+      faimdprintf(2, "faim: get_command_rendezvous 1209: couldn't malloc data.\n");
+      faim_mutex_unlock(&conn->active);
+      return -1;
+
+    }
+
+    for(commandlen = 0; commandlen < ft->fh.size; commandlen++)
+      if( (data[commandlen] = (unsigned char)fgetc(sess->oft.listing)) == EOF)
+       faimdprintf(2, "faim: get_command_rendezvous 1209: got early EOF (error?)\n");
 
-    data = calloc(1, commandlen);
-    memcpy(data, "01/01/1999 00:00      100 file.txt\r\n", commandlen);
+    commandlen = ft->fh.size;
 
-    if (send(conn->fd, data, commandlen, 0) != commandlen) {
+    if (write(conn->fd, data, commandlen) != commandlen) {
       perror("listing write error");
     }
     faim_mutex_unlock(&conn->active);
 
-    printf("jbm: hit end of 1209\n");
+    faimdprintf(2, "faim: get_command_rendezvous: hit end of 1209\n");
+
+    free(data);
 
     break;
   }
@@ -857,22 +1088,22 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
     struct aim_fileheader_t *fh;
 
-    printf("faim: rend: fileget 120b\n");
+    faimdprintf(2, "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");
+      faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
       faim_mutex_unlock(&conn->active);
-      return 0;
+      return -1;
     }
 
-    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, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
+      faim_mutex_unlock(&conn->active);
+      return -1;
+    }
   
     if(cook->data)
       free(cook->data); /* XXX: integrate cookie caching */
@@ -882,7 +1113,9 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
     aim_cachecookie(sess, cook);
 
     faim_mutex_unlock(&conn->active);
-    
+
+    /* call listing.txt rx confirm */    
+
     break;
   }
   case 0x120c: { /* yet more get file */
@@ -890,24 +1123,30 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
     struct aim_msgcookie_t *cook;
     struct aim_fileheader_t *listingfh;
     struct command_tx_struct *newoft;
-    int curbyte, i;
+
+    int i;
+
+    rxcallback_t userfunc;
     
     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");
       faim_mutex_unlock(&conn->active);
-      return 0;
+      return -1;
     }
 
     if(hdrlen != 0x100)
       printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n");
 
-    listingfh = aim_oft_getfh(hdr);
+    listingfh = aim_oft_getfh((char *)hdr);
 
     memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t));
     
-    cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
+      faim_mutex_unlock(&conn->active);
+      return -1;
+    }
   
     if(cook->data)
       free(cook->data); /* XXX */
@@ -918,121 +1157,89 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 
     faim_mutex_unlock(&conn->active);
 
-    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;
+    faimdprintf(2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
+
+    if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
+      i = userfunc(sess, NULL, conn, &ft->fh, cook->cookie);
+    
+    if(i < 0)
+      return -1;
+      
+    if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0))) {
+      faimdprintf(2, "faim: send_final_transfer: tx_new OFT failed\n");
+      return -1;
     }
     
-    /* 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;
-      memset(newoft->data, 0, newoft->commandlen);
-      for(i = 0; i < (signed)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;
+      newoft->lock = 0;
+      aim_tx_destroy(newoft);
+      return -1;
     }  
-
-    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((char *)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(listingfh->bcookie, ft->fh.bcookie, 8); */
     
-    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);
+    listingfh->nrecvd = 0; /* these need reset for protocol-correctness */
+    listingfh->recvcsum = 0;
 
-    strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
-    curbyte += 64;
+    aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, listingfh);
+    
+    newoft->lock = 0;
+    aim_tx_enqueue(sess, newoft);
+    faimdprintf(2, "faim: OFT: OFT file enqueued.\n");
+    
+    if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
+      return 1;
+    
+    i = userfunc(sess, NULL, conn, listingfh, listingfh->bcookie);
 
     free(listingfh);
 
-    newoft->lock = 0;
-    aim_tx_enqueue(sess, newoft);
-    printf("jbm: OFT listing enqueued.\n");
+    return i;
 
     break;
   }
   case 0x0202: { /* get file: ready to recieve data */
-    char *c;
-    int i;
-
     struct aim_fileheader_t *fh;    
-    fh = aim_oft_getfh(hdr);
-
-    c = (char *)calloc(1, fh->size);
-
-    printf("looks like we're ready to send data.(oft 0x0202)\n");
+    fh = aim_oft_getfh((char *)hdr);
 
+    faimdprintf(2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
 
+    faim_mutex_unlock(&conn->active);
     
-    for(i = 0; i < fh->size; i++)
-      c[i] = 0x30 + (i%10);
+    if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) == NULL)
+      return 1;
 
-    if ( (i = send(conn->fd, c, fh->size, 0)) != fh->size ) {
-      printf("whoopsy, didn't write it all...\n");
-    }
+    return userfunc(sess, NULL, conn, fh);       
 
-    faim_mutex_unlock(&conn->active);
+    free(fh);
 
     break;
   }
   case 0x0204: { /* get file: finished. close it up */
-    printf("looks like we're done with a transfer (oft 0x0204)\n");
+    int i;
+
+    struct aim_fileheader_t *fh;    
+    fh = aim_oft_getfh((char *)hdr);
+
+    faimdprintf(2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
+
     faim_mutex_unlock(&conn->active);
-    aim_conn_close(conn);
+    
+    if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
+      i = userfunc(sess, NULL, conn, fh);
+    else
+      i = 1;
+
+    /*
+         free(fh); */
+    /* not sure where to do this yet, as we need to keep it to allow multiple file sends... bleh */
+
+    return i;
     break;
   }
   default: {
@@ -1049,9 +1256,43 @@ faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct
 }
 
 /*
- * this currently feeds totally bogus data
+ * aim_oft_registerlisting()
+ * sess: aim session
+ * file: opened FILE *
+ * listingdir: the path to listing.txt
+ * returns -1 on error, 0 on success.
+ *
+ * it's not my problem if the listing fd is already set.
  */
 
+faim_export int aim_oft_registerlisting(struct aim_session_t *sess, FILE *file, char* listingdir) 
+{
+  if(!sess)
+    return -1;
+
+  /* XXX: checksum each file in the listing */
+
+#if 0
+   if(sess->oft.listing) {
+     faimdprintf(1, "We already have a file pointer. Closing and overwriting.\n");
+    fclose(sess->oft.listing);
+  }
+#endif
+  sess->oft.listing = file;
+#if 0
+  if(sess->oft.listingdir) {
+    faimdprintf(1, "We already have a directory string. Freeing and overwriting\n");
+    free(sess->oft.listingdir);
+  }
+#endif
+  
+  if( (sess->oft.listingdir = (char *)calloc(1, strlen(listingdir)+1)) )
+    memcpy(sess->oft.listingdir, listingdir, strlen(listingdir));
+  else
+    return -1;
+  return 0;
+}
+
 faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) 
 {
   struct aim_fileheader_t *fh;
@@ -1125,3 +1366,511 @@ faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr)
 
   return fh;
 }
+
+faim_export int aim_oft_checksum(char *buffer, int bufsize, int *checksum)
+{    
+  short check0, check1;
+  int i;
+  
+  check0 = ((*checksum & 0xFF000000) >> 16);
+  check1 = ((*checksum & 0x00ff0000) >> 16);
+
+  for(i = 0; i < bufsize; i++) {
+
+    if(i % 2)  { /* use check1 -- second byte */
+      if ( (short)buffer[i] > check1 ) { /* wrapping */
+       
+       check1 += 0x100; /* this is a cheap way to wrap */
+
+       /* if we're wrapping, decrement the other one */
+       if(check0 == 0) /* XXX: check this corner case */
+         check0 = 0x00ff;
+       else
+         check0--;                     
+      }
+
+      check1 -= buffer[i];
+    } else { /* use check0 -- first byte */
+      if ( (short)buffer[i] > check0 ) { /* wrapping */
+       
+       check0 += 0x100; /* this is a cheap way to wrap */
+
+       /* if we're wrapping, decrement the other one */
+       if(check1 == 0) /* XXX: check this corner case */
+         check1 = 0x00ff;
+       else
+         check1--;                     
+      }
+
+      check0 -= buffer[i];
+    } 
+  }
+
+  if(check0 > 0xff || check1 > 0xff) { /* they shouldn't be able to do this. error! */
+    faimdprintf(2, "check0 or check1 is too high: 0x%04x, 0x%04x\n", check0, check1);
+    return -1;
+  }
+  
+  check0 &= 0xff; /* grab just the lowest byte */
+  check1 &= 0xff; /* this should be clean, but just in case */
+
+  *checksum = ((check0 * 0x1000000) + (check1 * 0x10000));
+
+  return *checksum;
+}
+
+
+/*
+ * aim_oft_buildheader:
+ * fills a buffer with network-order fh data.
+ * returns length written; -1 on error.
+ * dest: buffer to fill -- pre-alloced
+ * listingfh: fh to get data from
+ *
+ * DOES NOT DO BOUNDS CHECKING!
+ */
+
+
+faim_internal int aim_oft_buildheader(char *dest,struct aim_fileheader_t *listingfh) 
+{
+  int i, curbyte;
+
+  if(!dest || !listingfh)
+    return -1;
+  
+  curbyte = 0;    
+  for(i = 0; i < 8; i++)
+    curbyte += aimutil_put8(dest+curbyte, listingfh->bcookie[i]);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->encrypt);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->compress);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->totfiles);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->filesleft);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->totparts);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->partsleft);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->totsize);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->size);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->modtime);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->checksum);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->rfrcsum);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->rfsize);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->cretime);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->rfcsum);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->nrecvd);
+  curbyte += aimutil_put32(dest+curbyte, listingfh->recvcsum);
+
+  memcpy(dest+curbyte, listingfh->idstring, 32);
+  curbyte += 32;
+
+  curbyte += aimutil_put8(dest+curbyte, listingfh->flags);
+  curbyte += aimutil_put8(dest+curbyte, listingfh->lnameoffset);
+  curbyte += aimutil_put8(dest+curbyte, listingfh->lsizeoffset);
+
+  memcpy(dest+curbyte, listingfh->dummy, 69);
+  curbyte += 69;
+    
+  memcpy(dest+curbyte, listingfh->macfileinfo, 16);
+  curbyte += 16;
+
+  curbyte += aimutil_put16(dest+curbyte, listingfh->nencode);
+  curbyte += aimutil_put16(dest+curbyte, listingfh->nlanguage);
+
+  memcpy(dest+curbyte, listingfh->name, 64); /* XXX: Filenames longer than 64B */
+  curbyte += 64;
+
+  return curbyte;
+}
+
+/*
+ * int aim_getfile_send(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh)
+ * conn is the OFT connection to shove the data down,
+ * tosend is the FILE * for the file to send
+ * fh is the filled-in fh value
+ * returns -1 on error, 1 on success.
+ */
+
+faim_export int aim_getfile_send(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh)
+{
+  int  pos, bufpos, i; 
+  const int bufsize = 4096;
+  char *buf;
+
+  /* sanity checks */
+  if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->subtype != AIM_CONN_SUBTYPE_OFT_GETFILE) {
+    faimdprintf(1, "getfile_send: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
+    return -1;
+  }
+  
+  if(!tosend) {
+    faimdprintf(1, "getfile_send: file pointer isn't valid\n");
+    return -1;
+  }
+
+  if(!fh) {
+    faimdprintf(1, "getfile_send: fh isn't valid\n");
+    return -1;
+  }
+
+  /* real code */
+
+  if(!(buf = (char *)calloc(1, bufsize))) {
+    perror("faim: getfile_send: calloc:");
+    faimdprintf(2, "getfile_send calloc error\n");
+    return -1;
+  }
+
+  pos = 0;
+
+  if( fseek(tosend, 0, SEEK_SET) == -1) {
+    perror("faim: getfile_send:  fseek:");
+    faimdprintf(2, "getfile_send fseek error\n");
+  }  
+
+  faimdprintf(2, "faim: getfile_send: using %i byte blocks\n", bufsize);
+
+  for(pos = 0; pos < fh->size; pos++) {
+    bufpos = pos % bufsize;
+
+    if(bufpos == 0 && pos > 0) { /* filled our buffer. spit it across the wire */
+      if ( (i = write(conn->fd, buf, bufsize)) != bufsize ) {
+       perror("faim: getfile_send: write1: ");
+       faimdprintf(1, "faim: getfile_send: whoopsy, didn't write it all...\n");
+       free(buf);   
+       return -1;
+      }
+    }
+    if( (buf[bufpos] = fgetc(tosend)) == EOF) {
+      if(pos != fh->size) {
+       printf("faim: getfile_send: hrm... apparent early EOF at pos 0x%x of 0x%lx\n", pos, fh->size);
+       faimdprintf(1, "faim: getfile_send: hrm... apparent early EOF at pos 0x%lx of 0x%lx\n", pos, fh->size);
+       free(buf);   
+       return -1;
+      }
+    }
+      
+      
+  }
+
+  if( (i = write(conn->fd, buf, bufpos+1)) != (bufpos+1)) {
+    perror("faim: getfile_send: write2: ");
+    faimdprintf(1, "faim: getfile_send cleanup: whoopsy, didn't write it all...\n");
+    free(buf);   
+    return -1;
+  }
+
+  free(buf);   
+  
+  fclose(tosend);
+  return 1; 
+}
+
+/*
+ * int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
+ * conn is the OFT connection to shove the data down,
+ * tosend is the FILE * for the file to send
+ * fh is the filled-in fh value
+ * pos is the position to start at (at beginning should be 0, after 5
+ *  bytes are sent should be 5); -1 for "don't seek"
+ * bufsize is the size of the chunk to send
+ *
+ * returns -1 on error, new pos on success.
+ *
+ * 
+ * Notes on usage: 
+ * You don't really have to keep track of pos if you don't want
+ *  to. just always call with -1 for pos, and it'll use the one
+ *  contained within the FILE *.
+ *
+ * if (pos + chunksize > fh->size), we only send as much data as we
+ *  can get (ie: up to fh->size.  
+ */
+
+faim_export int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
+{
+  int bufpos; 
+  char *buf;
+
+  /* sanity checks */
+  if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->type != AIM_CONN_SUBTYPE_OFT_GETFILE) {
+    faimdprintf(1, "faim: getfile_send_chunk: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
+    return -1;
+  }
+  
+  if(!tosend) {
+    faimdprintf(1, "faim: getfile_send_chunk: file pointer isn't valid\n");
+    return -1;
+  }
+
+  if(!fh) {
+    faimdprintf(1, "faim: getfile_send_chunk: fh isn't valid\n");
+    return -1;
+  }
+
+  /* real code */
+
+  if(!(buf = (char *)calloc(1, bufsize))) {
+    perror("faim: getfile_send_chunk: calloc:");
+    faimdprintf(2, "faim: getfile_send_chunk calloc error\n");
+    return -1;
+  }
+  
+  if(pos != -1) {
+    if( fseek(tosend, pos, SEEK_SET) == -1) {
+      perror("faim: getfile_send_chunk:  fseek:");
+      faimdprintf(2, "faim: getfile_send_chunk fseek error\n");
+    }  
+  }
+
+  faimdprintf(2, "faim: getfile_send_chunk: using %i byte blocks\n", bufsize);
+
+  for(bufpos = 0; pos < fh->size; bufpos++, pos++) {
+    if( (buf[bufpos] = fgetc(tosend)) == EOF) {
+      if(pos != fh->size) {
+       faimdprintf(1, "faim: getfile_send_chunk: hrm... apparent early EOF at pos 0x%x of 0x%x\n", pos, fh->size);
+       free(buf);   
+       return -1;
+      }
+    }      
+  }
+
+  if( write(conn->fd, buf, bufpos+1) != (bufpos+1)) {
+    faimdprintf(1, "faim: getfile_send_chunk cleanup: whoopsy, didn't write it all...\n");
+    free(buf);   
+    return -1;
+  }
+
+  free(buf);   
+  
+  return (pos + bufpos);
+}
+
+/*
+ * aim_tx_destroy:
+ * free's tx_command_t's. if command is locked, doesn't free.
+ * returns -1 on error (locked struct); 0 on success.
+ * command is the command to free 
+ */
+
+faim_internal int aim_tx_destroy(struct command_tx_struct *command)
+{
+  if(command->lock)
+    return -1;
+  if(command->data)
+    free(command->data);
+  free(command);
+
+  return 0;
+}
+
+#if 0
+/*
+ * aim_getfile_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.  
+ */
+
+
+faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess,
+                         struct aim_conn_t *conn,
+                         struct aim_getfile_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;
+}
+
+#endif
index 55610a2b176fa237422d049ab7a754fabfbd14fc..216d2c040306f00d5202b47205148e16b1c4d191 100644 (file)
--- a/aim_im.c
+++ b/aim_im.c
@@ -505,13 +505,17 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        /*
         * Call client.
         */
+#if 0
        userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
        if (userfunc || (i = 0))
          i = userfunc(sess, 
                       command, 
                       channel, 
                       reqclass,
-                      &userinfo);
+                      &userinfo,
+                      ip,
+                      cookie);
+#endif
 
       } else if (reqclass & AIM_CAPS_VOICE) {
        struct aim_msgcookie_t *cachedcook;
@@ -541,7 +545,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        char ip[30];
        struct aim_directim_priv *priv;
 
-       memset(ip, 0, sizeof(ip));
+       memset(ip, 0, 30);
        
        if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
          struct aim_tlv_t *iptlv, *porttlv;
@@ -549,7 +553,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
          iptlv = aim_gettlv(list2, 0x0003, 1);
          porttlv = aim_gettlv(list2, 0x0005, 1);
 
-         snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d", 
+         snprintf(ip, 30, "%d.%d.%d.%d:%d", 
                  aimutil_get8(iptlv->value+0),
                  aimutil_get8(iptlv->value+1),
                  aimutil_get8(iptlv->value+2),
@@ -623,7 +627,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
          return 0;
 
-       memset(ip, 0, sizeof(ip));
+       memset(ip, 0, 30);
 
        if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
          free(cachedcook);
@@ -638,7 +642,7 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
            return 0;
          }
 
-         snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
+         snprintf(ip, 30, "%d.%d.%d.%d:%d",
                   aimutil_get8(iptlv->value+0),
                   aimutil_get8(iptlv->value+1),
                   aimutil_get8(iptlv->value+2),
@@ -648,40 +652,6 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
 
        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.
         */
@@ -691,7 +661,9 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
                       command, 
                       channel, 
                       reqclass,
-                      &userinfo);
+                      &userinfo,
+                      ip,
+                      cookie);
 
       } else if (reqclass & AIM_CAPS_SENDFILE) {
 #if 0
index fa2429e3454b0f82fa80ee847a284de3ab880779..4f5cf74c8b78899a22a17618b7d0d9abd72679b2 100644 (file)
@@ -188,14 +188,15 @@ faim_export int aim_conn_addhandler(struct aim_session_t *sess,
                        rxcallback_t newhandler,
                        u_short flags)
 {
-  struct aim_rxcblist_t *newcb,*cur;
+  struct aim_rxcblist_t *newcb;
 
   if (!conn)
     return -1;
 
   faimdprintf(1, "aim_conn_addhandler: adding for %04x/%04x\n", family, type);
 
-  newcb = (struct aim_rxcblist_t *)calloc(1, sizeof(struct aim_rxcblist_t));
+  if (!(newcb = (struct aim_rxcblist_t *)calloc(1, sizeof(struct aim_rxcblist_t))))
+    return -1;
   newcb->family = family;
   newcb->type = type;
   newcb->flags = flags;
@@ -205,32 +206,37 @@ faim_export int aim_conn_addhandler(struct aim_session_t *sess,
     newcb->handler = newhandler;
   newcb->next = NULL;
   
-  cur = conn->handlerlist;
-  if (!cur)
+  if (!conn->handlerlist)
     conn->handlerlist = newcb;
-  else 
-    {
-      while (cur->next)
-       cur = cur->next;
-      cur->next = newcb;
-    }
+  else {
+    struct aim_rxcblist_t *cur;
+
+    cur = conn->handlerlist;
+
+    while (cur->next)
+      cur = cur->next;
+    cur->next = newcb;
+  }
 
   return 0;
 }
 
 faim_export int aim_clearhandlers(struct aim_conn_t *conn)
 {
- struct aim_rxcblist_t *cur,*tmp;
+ struct aim_rxcblist_t *cur;
+
  if (!conn)
    return -1;
 
  cur = conn->handlerlist;
- while(cur)
-   {
-     tmp = cur->next;
-     free(cur);
-     cur = tmp;
-   }
+ while(cur) {
+   struct aim_rxcblist_t *tmp;
+
+   tmp = cur->next;
+   free(cur);
+   cur = tmp;
+ }
+
  return 0;
 }
 
@@ -255,6 +261,7 @@ faim_internal rxcallback_t aim_callhandler(struct aim_conn_t *conn,
 
   if (type==0xffff)
     return NULL;
+
   return aim_callhandler(conn, family, 0xffff);
 }
 
index 2344073a287db48715cd274d859934f8391cceb2..6f6b3c10d301313f1e354c8d81ffe2e8ff1cf454 100644 (file)
@@ -273,10 +273,10 @@ faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx
   } else if (cur->hdrtype == AIM_FRAMETYPE_OFT) {
     int z = 0;
 
-    z += aimutil_put8(curPacket+z, 0x4f);
-    z += aimutil_put8(curPacket+z, 0x44);
-    z += aimutil_put8(curPacket+z, 0x43);
-    z += aimutil_put8(curPacket+z, 0x32);
+    z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[0]);
+    z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[1]);
+    z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[2]);
+    z += aimutil_put8(curPacket+z, cur->hdr.oft.magic[3]);
 
     z += aimutil_put16(curPacket+z, cur->hdr.oft.hdr2len + 8);
     z += aimutil_put16(curPacket+z, cur->hdr.oft.type);
index 1ba146edeb05353d2605ea1053c58736bd4c9702..1be9b9c90ad5e23fda6e186e4dee23e2aa8fb79a 100644 (file)
@@ -276,6 +276,14 @@ struct command_tx_struct {
   struct command_tx_struct *next; /* ptr to next struct in list */
 };
 
+/*
+ * OFT session: random oft cruft, per-session.
+ *
+ */
+struct aim_oft_session_t {
+  FILE *listing;
+  char *listingdir;
+};
 
 /*
  * AIM Session: The main client-data interface.  
@@ -296,6 +304,11 @@ struct aim_session_t {
    */
   void *aux_data;
 
+  /* 
+   * OFT Data 
+   */
+
+  struct aim_oft_session_t oft;
 
   /* ---- Internal Use Only ------------------------ */
   /* 
@@ -535,8 +548,10 @@ faim_export unsigned long aim_setversions(struct aim_session_t *sess, struct aim
 faim_export unsigned long aim_setdirectoryinfo(struct aim_session_t *sess, struct aim_conn_t *conn, char *first, char *middle, char *last, char *maiden, char *nickname, char *street, char *city, char *state, char *zip, int country, unsigned short privacy);
 faim_export unsigned long aim_setuserinterests(struct aim_session_t *sess, struct aim_conn_t *conn, char *interest1, char *interest2, char *interest3, char *interest4, char *interest5, unsigned short privacy);
 
-faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t*);
+faim_internal struct aim_fileheader_t *aim_getlisting(FILE *);
+faim_internal int aim_oft_buildheader(char *,struct aim_fileheader_t *);
 faim_internal int aim_listenestablish(u_short);
+faim_internal int aim_tx_destroy(struct command_tx_struct *);
 
 /* aim_rxhandlers.c */
 faim_export int aim_rxdispatch(struct aim_session_t *);
@@ -671,7 +686,8 @@ faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_con
 #define AIM_TRANSFER_DENY_DECLINE 0x0001
 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002
 faim_export unsigned long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code);
-faim_export unsigned 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);
+faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn,char *cookie,char *ip, FILE *file, unsigned short rendid);
+
 
 faim_export unsigned long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short);
 faim_internal int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
index ab5388a0e1d1772568dea7e67626f79fb0c61640..6e8fa74227d5a874b84aa68c6f7c6b0be9ffd786 100644 (file)
  *
  * See non-SNAC note below.
  */
-#define AIM_CB_OFT_DIRECTIMCONNECTREQ 0x0001
+#define AIM_CB_OFT_DIRECTIMCONNECTREQ 0x0001/* connect request -- actually an OSCAR CAP*/
 #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_DIRECTIMTYPING 0x0004
+#define AIM_CB_OFT_DIRECTIMINITIATE 0x0005
+
+#define AIM_CB_OFT_GETFILECONNECTREQ 0x0006 /* connect request -- actually an OSCAR CAP*/
+#define AIM_CB_OFT_GETFILEFILEREQ 0x0007    /* recieved file request */
+#define AIM_CB_OFT_GETFILEFILESEND 0x0008   /* recieved file request confirm -- send data */
+#define AIM_CB_OFT_GETFILECOMPLETE 0x0009   /* recieved file send complete*/
+#define AIM_CB_OFT_GETFILEINITIATE 0x000a   /* request for file get acknowledge */
+#define AIM_CB_OFT_GETFILEDISCONNECT 0x000b   /* OFT connection disconnected.*/
+
+#define AIM_CB_OFT_SENDFILEDISCONNECT 0x000c   /* OFT connection disconnected.*/
+
 
-#define AIM_CB_OFT_GETFILECONNECT 0x0004
-#define AIM_CB_OFT_GETFILECOMPLETE 0x0005
-#define AIM_CB_OFT_GETFILEINITIATE 0x0007
 
 /*
  * SNAC Family: Internal Messages
index 7106502b1129e9b6f09b8f1d75f3bffa2334006d..ac8d18fdcde244dec068f4aad64f34519d078f67 100644 (file)
@@ -74,6 +74,14 @@ int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_stru
 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+#define FILESUPPORT
+#ifdef FILESUPPORT
+int faimtest_getfile_filereq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+#endif
+
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
@@ -143,8 +151,14 @@ int main(void)
   int keepgoing = 1;
   char *proxy, *proxyusername, *proxypass;
 
+  char *listingpath;
+
   int selstat = 0;
 
+#ifdef FILESUPPORT
+  FILE *listingfile;
+#endif
+
   if ( !(screenname = getenv("SCREENNAME")) ||
        !(password = getenv("PASSWORD")))
     {
@@ -158,6 +172,10 @@ int main(void)
   proxyusername = getenv("SOCKSNAME");
   proxypass = getenv("SOCKSPASS");
 
+#ifdef FILESUPPORT
+  listingpath = getenv("LISTINGPATH");
+#endif
+
 #ifdef _WIN32
   if (initwsa() != 0) {
     printf("faimtest: could not initialize windows sockets\n");
@@ -167,6 +185,25 @@ int main(void)
 
   aim_session_init(&aimsess);
 
+#ifdef FILESUPPORT
+  if(listingpath) {
+    char *listingname;
+    if(!(listingname = (char *)calloc(1, strlen(listingpath)+strlen("/listing.txt")))) {
+      perror("listingname calloc.");
+      exit(-1);
+    }
+    sprintf(listingname, "%s/listing.txt", listingpath);
+    if( (listingfile = fopen(listingname, "r")) == NULL) {
+      printf("Couldn't open %s... bombing.\n", listingname);
+      exit(-1);
+    }
+
+    aim_oft_registerlisting(&aimsess, listingfile, listingpath);
+
+    free(listingname);
+  }
+#endif
+
   if (proxy)
     aim_setupproxy(&aimsess, proxy, proxyusername, proxypass);
 
@@ -212,16 +249,16 @@ int main(void)
     case 2: /* incoming data pending */
       if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
        if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
-         printf("connection error (rend)\n");
+         printf("connection error (rend out)\n");
        }
       } else {
        if (aim_get_command(&aimsess, waitingconn) >= 0) {
          aim_rxdispatch(&aimsess);
        } else {
-         printf("connection error\n");
+         printf("connection error (type 0x%04x:0x%04x)\n", waitingconn->type, waitingconn->subtype);
          aim_conn_kill(&aimsess, &waitingconn);
          if (!aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS)) {
-           printf("major connetion error\n");
+           printf("major connection error\n");
            keepgoing = 0;
          }
        }
@@ -313,9 +350,7 @@ int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *c
       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);
+    case AIM_CONN_TYPE_RENDEZVOUS: /* empty */
       break;
 
     default:
@@ -737,8 +772,33 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       break;
     }
     case AIM_CAPS_GETFILE: {
-      printf("faimtset: get file!\n");
+#ifdef FILESUPPORT
+      char *ip, *cookie;
+      struct aim_conn_t *newconn;
+
+      userinfo = va_arg(ap, struct aim_userinfo_s *);
+      ip = va_arg(ap, char *);
+      cookie = va_arg(ap, char *);
+      va_end(ap);
+      
+      printf("faimtest: get file request from %s (at %s)\n", userinfo->sn, ip);
+
+      sleep(1);
+
+      if( (newconn = aim_accepttransfer(sess, command->conn, userinfo->sn, cookie, ip, sess->oft.listing, reqclass)) == NULL ) {
+       printf("faimtest: getfile: requestconn: apparent error in accepttransfer\n");
+       break;
+      }
+      
+      aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ,  faimtest_getfile_filereq, 0);
+      aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, faimtest_getfile_filesend, 0);
+      aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, faimtest_getfile_complete, 0);      
+      aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, faimtest_getfile_disconnect, 0);      
+
+      printf("faimtest: getfile connect succeeded, handlers added.\n");
+
       break;
+#endif
     }
     case AIM_CAPS_SENDFILE: {
       printf("faimtest: send file!\n");
@@ -814,7 +874,6 @@ 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;
@@ -839,7 +898,6 @@ int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_str
 
   return 1;
 }
-#endif
 
 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
@@ -896,7 +954,18 @@ int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_str
 
 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
-  printf("faimtest: directim_disconnect\n");
+  va_list ap;
+  struct aim_conn_t *conn;
+  char *sn;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  sn = va_arg(ap, char *);
+  va_end(ap);
+
+  aim_conn_kill(sess, &conn);
+
+  printf("faimtest: directim: disconnected from %s\n", sn);
   return 1;
 }
 
@@ -1297,6 +1366,102 @@ int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *
   return 1;
 }
 
+#ifdef FILESUPPORT
+int faimtest_getfile_filereq(struct aim_session_t *ses, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *oftconn;
+  struct aim_fileheader_t *fh;
+  char *cookie;
+
+  ap = va_start(ap, command);
+  oftconn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  cookie = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: request for file %s.\n", fh->name);
+
+  return 1;
+}
+
+
+int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *oftconn;
+  struct aim_fileheader_t *fh;
+  char *path, *cookie;
+
+  FILE *file;
+
+  ap = va_start(ap, command);
+  oftconn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  cookie = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: sending file %s.\n", fh->name);
+
+  if( (path = (char *)calloc(1, strlen(sess->oft.listingdir) +strlen(fh->name)+2)) == NULL) {
+    perror("calloc:");
+    printf("faimtest: error in calloc of path\n");
+    return 0; /* XXX: no idea what winaim expects here =) */
+  }
+  
+  snprintf(path, strlen(sess->oft.listingdir)+strlen(fh->name)+2, "%s/%s", sess->oft.listingdir, fh->name);
+
+
+  if( (file = fopen(path, "r")) == NULL) {
+    printf("faimtest: getfile_send fopen failed for %s. damn.\n", path);
+    return 0;
+  }
+
+  if (aim_getfile_send(oftconn, file, fh) == -1) {
+    printf("faimtest: getfile_send failed. damn.\n");
+  } else {
+    printf("faimtest: looks like getfile went clean\n");
+  }
+
+  free(fh);  
+  return 1;
+}
+
+int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...) 
+{
+  va_list ap;
+  struct aim_conn_t *conn;
+  struct aim_fileheader_t *fh;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  va_end(ap);
+
+  printf("faimtest: completed file transfer for %s.\n", fh->name);
+
+  /*  aim_conn_kill(sess, &conn); */ /* we'll let winaim close the conn */
+  return 1;
+}
+
+int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *conn;
+  char *sn;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  sn = va_arg(ap, char *);
+  va_end(ap);
+
+  aim_conn_kill(sess, &conn);
+
+  printf("faimtest: getfile: disconnected from %s\n", sn);
+  return 1;
+}
+#endif
+
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   va_list ap;
@@ -1308,7 +1473,7 @@ int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_stru
 
   printf("faimtest: ratechange: %lu\n", newrate);
 
-  return (1);
+  return 1;
 }
 
 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...)
This page took 0.122987 seconds and 5 git commands to generate.