changeset 1248:920c86b753d7

[gaim-migrate @ 1258] bah committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 13 Dec 2000 03:31:15 +0000
parents f50146ce818e
children 3e44de27622d
files libfaim/CHANGES libfaim/aim_auth.c libfaim/aim_buddylist.c libfaim/aim_chat.c libfaim/aim_chatnav.c libfaim/aim_ft.c libfaim/aim_im.c libfaim/aim_info.c libfaim/aim_misc.c libfaim/aim_rxhandlers.c libfaim/aim_search.c libfaim/aim_snac.c libfaim/faim/aim.h
diffstat 13 files changed, 130 insertions(+), 305 deletions(-) [+]
line wrap: on
line diff
--- a/libfaim/CHANGES	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/CHANGES	Wed Dec 13 03:31:15 2000 +0000
@@ -1,6 +1,10 @@
 
 No release numbers
 ------------------
+ - Wed Dec 13 02:26:39 UTC 2000
+  - Create aim_cachesnac()
+  - Some long overdue cleanups
+
  - Wed Dec 13 00:38:56 UTC 2000
   - Added the client update/version info to the authresp callback
   - Added the prototype for aim_getfile_send_chunk to aim.h
--- a/libfaim/aim_auth.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_auth.c	Wed Dec 13 03:31:15 2000 +0000
@@ -52,20 +52,9 @@
 
   aim_tx_enqueue(sess, newpacket);
 
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0001;
-    snac.type = 0x0004;
-    snac.flags = 0x0000;
+  aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, NULL, 0);
 
-    snac.data = NULL;
-
-    aim_newsnac(sess, &snac);
-  }
-
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess,
@@ -90,18 +79,7 @@
 
   aim_tx_enqueue(sess, newpacket);
 
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0001;
-    snac.type = 0x0004;
-    snac.flags = 0x0000;
+  aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, NULL, 0);
 
-    snac.data = NULL;
-
-    aim_newsnac(sess, &snac);
-  }
-
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
--- a/libfaim/aim_buddylist.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_buddylist.c	Wed Dec 13 03:31:15 2000 +0000
@@ -28,23 +28,9 @@
 
    aim_tx_enqueue(sess, newpacket );
 
-#if 0 /* do we really need this code? */
-   {
-      struct aim_snac_t snac;
-    
-      snac.id = sess->snac_nextid;
-      snac.family = 0x0003;
-      snac.type = 0x0004;
-      snac.flags = 0x0000;
+   aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
 
-      snac.data = malloc( strlen( sn ) + 1 );
-      memcpy( snac.data, sn, strlen( sn ) + 1 );
-
-      aim_newsnac(sess, &snac);
-   }
-#endif
-
-   return( sess->snac_nextid++ );
+   return sess->snac_nextid;
 }
 
 faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess,
@@ -69,21 +55,9 @@
 
    aim_tx_enqueue(sess, newpacket);
 
-   {
-      struct aim_snac_t snac;
-    
-      snac.id = sess->snac_nextid;
-      snac.family = 0x0003;
-      snac.type = 0x0005;
-      snac.flags = 0x0000;
+   aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
 
-      snac.data = malloc( strlen( sn ) + 1 );
-      memcpy( snac.data, sn, strlen( sn ) + 1 );
-
-      aim_newsnac(sess, &snac );
-   }
-
-   return( sess->snac_nextid++ );
+   return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
@@ -92,7 +66,6 @@
   rxcallback_t userfunc = NULL;
   int ret=1;
   struct aim_tlvlist_t *tlvlist;
-  struct aim_tlv_t *tlv;
   unsigned short maxbuddies = 0, maxwatchers = 0;
 
   /* 
@@ -104,9 +77,8 @@
   /*
    * TLV type 0x0001: Maximum number of buddies.
    */
-  if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) {
-    maxbuddies = aimutil_get16(tlv->value);
-  }
+  if (aim_gettlv(tlvlist, 0x0001, 1))
+    maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1);
 
   /*
    * TLV type 0x0002: Maximum number of watchers.
@@ -114,12 +86,10 @@
    * XXX: what the hell is a watcher? 
    *
    */
-  if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) {
-    maxwatchers = aimutil_get16(tlv->value);
-  }
+  if (aim_gettlv(tlvlist, 0x0002, 1))
+    maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1);
   
-  userfunc = aim_callhandler(command->conn, 0x0003, 0x0003);
-  if (userfunc)
+  if ((userfunc = aim_callhandler(command->conn, 0x0003, 0x0003)))
     ret =  userfunc(sess, command, maxbuddies, maxwatchers);
 
   aim_freetlvchain(&tlvlist);
--- a/libfaim/aim_chat.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_chat.c	Wed Dec 13 03:31:15 2000 +0000
@@ -173,23 +173,9 @@
   newpacket->lock = 0;
   aim_tx_enqueue(sess, newpacket);
 
-#if 0
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0001;
-    snac.type = 0x0004;
-    snac.flags = 0x0000;
+  aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, roomname, strlen(roomname)+1);
 
-    snac.data = malloc(strlen(roomname)+1);
-    strcpy(snac.data, roomname);
-
-    aim_newsnac(sess, &snac);
-  }
-
-#endif
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo)
@@ -240,7 +226,6 @@
   u_short tlvcount = 0;
   struct aim_tlvlist_t *tlvlist;
   char *roomdesc = NULL;
-  struct aim_tlv_t *tmptlv;
   unsigned short unknown_c9 = 0;
   unsigned long creationtime = 0;
   unsigned short maxmsglen = 0;
@@ -277,12 +262,8 @@
   /*
    * Type 0x006f: Number of occupants.
    */
-  if (aim_gettlv(tlvlist, 0x006f, 1)) {
-    struct aim_tlv_t *tmptlv;
-    tmptlv = aim_gettlv(tlvlist, 0x006f, 1);
-    
-    usercount = aimutil_get16(tmptlv->value);
-  }
+  if (aim_gettlv(tlvlist, 0x006f, 1))
+    usercount = aim_gettlv16(tlvlist, 0x006f, 1);
 
   /*
    * Type 0x0073:  Occupant list.
@@ -304,26 +285,26 @@
   /* 
    * Type 0x00c9: Unknown. (2 bytes)
    */
-  if ((tmptlv = aim_gettlv(tlvlist, 0x00c9, 1)))
-    unknown_c9 = aimutil_get16(tmptlv->value);
+  if (aim_gettlv(tlvlist, 0x00c9, 1))
+    unknown_c9 = aim_gettlv16(tlvlist, 0x00c9, 1);
   
   /* 
    * Type 0x00ca: Creation time (4 bytes)
    */
-  if ((tmptlv = aim_gettlv(tlvlist, 0x00ca, 1)))
-    creationtime = aimutil_get32(tmptlv->value);
+  if (aim_gettlv(tlvlist, 0x00ca, 1))
+    creationtime = aim_gettlv32(tlvlist, 0x00ca, 1);
 
   /* 
    * Type 0x00d1: Maximum Message Length
    */
-  if ((tmptlv = aim_gettlv(tlvlist, 0x00d1, 1)))
-    maxmsglen = aimutil_get16(tmptlv->value);
+  if (aim_gettlv(tlvlist, 0x00d1, 1))
+    maxmsglen = aim_gettlv16(tlvlist, 0x00d1, 1);
 
   /* 
    * Type 0x00d2: Unknown. (2 bytes)
    */
-  if ((tmptlv = aim_gettlv(tlvlist, 0x00d2, 1)))
-    unknown_d2 = aimutil_get16(tmptlv->value);;
+  if (aim_gettlv(tlvlist, 0x00d2, 1))
+    unknown_d2 = aim_gettlv16(tlvlist, 0x00d2, 1);
 
   /* 
    * Type 0x00d3: Room Description
@@ -334,12 +315,11 @@
   /* 
    * Type 0x00d5: Unknown. (1 byte)
    */
-  if ((tmptlv = aim_gettlv(tlvlist, 0x00d5, 1)))
-    unknown_d5 = aimutil_get8(tmptlv->value);;
+  if (aim_gettlv(tlvlist, 0x00d5, 1))
+    unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1);
 
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE);
-  if (userfunc) {
+  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE))) {
     ret = userfunc(sess,
 		   command, 
 		   &roominfo,
@@ -375,8 +355,7 @@
     i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]);
   }
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN);
-  if (userfunc) {	
+  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN))) {
     ret = userfunc(sess,
 		   command, 
 		   curcount,
@@ -402,8 +381,7 @@
     i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]);
   }
 
-  userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE);
-  if (userfunc) {
+  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE))) {
     ret = userfunc(sess,
 		   command, 
 		   curcount,
--- a/libfaim/aim_chatnav.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_chatnav.c	Wed Dec 13 03:31:15 2000 +0000
@@ -14,18 +14,9 @@
 faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess,
 						struct aim_conn_t *conn)
 {
-  struct aim_snac_t snac;
-
-  snac.id = aim_genericreq_n(sess, conn, 0x000d, 0x0002);
+  aim_genericreq_n(sess, conn, 0x000d, 0x0002);
 
-  snac.family = 0x000d;
-  snac.type = 0x0002;
-  snac.flags = 0x0000;
-  snac.data = NULL;
-  
-  aim_newsnac(sess, &snac);
-
-  return (sess->snac_nextid); /* already incremented */
+  return sess->snac_nextid;
 }
 
 faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess,
@@ -105,11 +96,7 @@
 	   * Type 0x0002: Maximum concurrent rooms.
 	   */ 
 	  if (aim_gettlv(tlvlist, 0x0002, 1))
-	    {
-	      struct aim_tlv_t *maxroomstlv;
-	      maxroomstlv = aim_gettlv(tlvlist, 0x0002, 1);
-	      maxrooms = aimutil_get8(maxroomstlv->value);
-	    }
+	    maxrooms = aim_gettlv8(tlvlist, 0x0002, 1);
 
 	  /* 
 	   * Type 0x0003: Exchange information
@@ -145,11 +132,9 @@
 	       * Type 0x0002: Unknown
 	       */
 	      if (aim_gettlv(innerlist, 0x0002, 1)) {
-		struct aim_tlv_t *tmptlv;
-		unsigned short classperms = 0;
+		unsigned short classperms;
 
-		tmptlv = aim_gettlv(innerlist, 0x0002, 1);
-		classperms = aimutil_get16(tmptlv->value);
+		classperms = aim_gettlv16(innerlist, 0x0002, 1);
 		
 		printf("faim: class permissions %x\n", classperms);
 	      }
@@ -201,12 +186,9 @@
 	       * 
 	       */
 	      if (aim_gettlv(innerlist, 0x00d5, 1)) {
-		struct aim_tlv_t *tmptlv;
-		unsigned char createperms = 0;
+		unsigned char createperms;
 
-		tmptlv = aim_gettlv(innerlist, 0x00d5, 1);
-		createperms = aimutil_get8(tmptlv->value);
-		
+		createperms = aim_gettlv8(innerlist, 0x00d5, 1);
 	      }
 
 	      /*
@@ -315,7 +297,7 @@
       unsigned long createtime = 0;
       unsigned char createperms;
       int i, cklen;
-      struct aim_tlv_t *bigblock, *tmp;
+      struct aim_tlv_t *bigblock;
 
       i = 10;
       if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) {
@@ -365,23 +347,23 @@
       if (aim_gettlv(innerlist, 0x006a, 1))
 	fqcn = aim_gettlv_str(innerlist, 0x006a, 1);
 
-      if ((tmp = aim_gettlv(innerlist, 0x00c9, 1)))
-	flags = aimutil_get16(tmp->value);
+      if (aim_gettlv(innerlist, 0x00c9, 1))
+	flags = aim_gettlv16(innerlist, 0x00c9, 1);
 
-      if ((tmp = aim_gettlv(innerlist, 0x00ca, 1)))
-	createtime = aimutil_get32(tmp->value);
+      if (aim_gettlv(innerlist, 0x00ca, 1))
+	createtime = aim_gettlv32(innerlist, 0x00ca, 1);
 
-      if ((tmp = aim_gettlv(innerlist, 0x00d1, 1)))
-	maxmsglen = aimutil_get16(tmp->value);
+      if (aim_gettlv(innerlist, 0x00d1, 1))
+	maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1);
 
-      if ((tmp = aim_gettlv(innerlist, 0x00d2, 1)))
-	maxoccupancy = aimutil_get16(tmp->value);
+      if (aim_gettlv(innerlist, 0x00d2, 1))
+	maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1);
 
       if (aim_gettlv(innerlist, 0x00d3, 1))
 	name = aim_gettlv_str(innerlist, 0x00d3, 1);
 
-      if ((tmp = aim_gettlv(innerlist, 0x00d5, 1)))
-	createperms = aimutil_get8(tmp->value);
+      if (aim_gettlv(innerlist, 0x00d5, 1))
+	createperms = aim_gettlv8(innerlist, 0x00d5, 1);
 
       if ((userfunc = aim_callhandler(command->conn, 0x000d, 0x0009))) {
 	ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
@@ -417,7 +399,6 @@
 {
   struct command_tx_struct *newpacket; 
   int i;
-  struct aim_snac_t snac;
 
   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+12+strlen("invite")+strlen(name))))
     return -1;
@@ -445,15 +426,9 @@
   /* room name */
   i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name);
 
-  snac.id = sess->snac_nextid;
-  snac.family = 0x000d;
-  snac.type = 0x0008;
-  snac.flags = 0x0000;
-  snac.data = NULL;
-  
-  aim_newsnac(sess, &snac);
+  aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0);
 
   aim_tx_enqueue(sess, newpacket);
 
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
--- a/libfaim/aim_ft.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_ft.c	Wed Dec 13 03:31:15 2000 +0000
@@ -423,24 +423,6 @@
    * 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);
 } 
 
@@ -1859,24 +1841,6 @@
    * 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;
 }
 
--- a/libfaim/aim_im.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_im.c	Wed Dec 13 03:31:15 2000 +0000
@@ -118,25 +118,10 @@
 
   aim_tx_enqueue(sess, newpacket);
 
-#ifdef USE_SNAC_FOR_IMS
- {
-    struct aim_snac_t snac;
-
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0004;
-    snac.type = 0x0006;
-    snac.flags = 0x0000;
+  aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1);
+  aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
 
-    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 (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
@@ -467,14 +452,13 @@
 	  struct aim_filetransfer_priv *ft;
 
 	  if (cook->data) {
-	    struct aim_tlv_t *errortlv;
-	    int errorcode = -1;
+	    int errorcode = -1; /* XXX shouldnt this be 0? */
 
 	    ft = (struct aim_filetransfer_priv *)cook->data;
 
-	    if ((errortlv = aim_gettlv(list2, 0x000b, 1))) {
-	      errorcode = aimutil_get16(errortlv->value);
-	    }
+	    if (aim_gettlv(list2, 0x000b, 1))
+	      errorcode = aim_gettlv16(list2, 0x000b, 1);
+
 	    if (errorcode) {
 	      printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
 	    } else if (status == 0x0002) { /* connection accepted */
--- a/libfaim/aim_info.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_info.c	Wed Dec 13 03:31:15 2000 +0000
@@ -10,7 +10,7 @@
 #include <faim/aim.h>
 
 struct aim_priv_inforeq {
-  char sn[MAXSNLEN];
+  char sn[MAXSNLEN+1];
   unsigned short infotype;
 };
 
@@ -20,6 +20,7 @@
 				      unsigned short infotype)
 {
   struct command_tx_struct *newpacket;
+  struct aim_priv_inforeq privdata;
   int i = 0;
 
   if (!sess || !conn || !sn)
@@ -39,22 +40,11 @@
   newpacket->lock = 0;
   aim_tx_enqueue(sess, newpacket);
 
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0002;
-    snac.type = 0x0005;
-    snac.flags = 0x0000;
+  strncpy(privdata.sn, sn, sizeof(privdata.sn));
+  privdata.infotype = infotype;
+  aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
 
-    snac.data = malloc(sizeof(struct aim_priv_inforeq));
-    strcpy(((struct aim_priv_inforeq *)snac.data)->sn, sn);
-    ((struct aim_priv_inforeq *)snac.data)->infotype = infotype;
-
-    aim_newsnac(sess, &snac);
-  }
-
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
--- a/libfaim/aim_misc.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_misc.c	Wed Dec 13 03:31:15 2000 +0000
@@ -267,7 +267,6 @@
   rxcallback_t userfunc = NULL;
   int ret=1;
   struct aim_tlvlist_t *tlvlist;
-  struct aim_tlv_t *tlv;
   unsigned short maxpermits = 0, maxdenies = 0;
 
   /* 
@@ -279,21 +278,18 @@
   /*
    * TLV type 0x0001: Maximum number of buddies on permit list.
    */
-  if ((tlv = aim_gettlv(tlvlist, 0x0001, 1))) {
-    maxpermits = aimutil_get16(tlv->value);
-  }
+  if (aim_gettlv(tlvlist, 0x0001, 1))
+    maxpermits = aim_gettlv16(tlvlist, 0x0001, 1);
 
   /*
    * TLV type 0x0002: Maximum number of buddies on deny list.
    *
    */
-  if ((tlv = aim_gettlv(tlvlist, 0x0002, 1))) {
-    maxdenies = aimutil_get16(tlv->value);
-  }
+  if (aim_gettlv(tlvlist, 0x0002, 1)) 
+    maxdenies = aim_gettlv16(tlvlist, 0x0002, 1);
   
-  userfunc = aim_callhandler(command->conn, 0x0009, 0x0003);
-  if (userfunc)
-    ret =  userfunc(sess, command, maxpermits, maxdenies);
+  if ((userfunc = aim_callhandler(command->conn, 0x0009, 0x0003)))
+    ret = userfunc(sess, command, maxpermits, maxdenies);
 
   aim_freetlvchain(&tlvlist);
 
--- a/libfaim/aim_rxhandlers.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_rxhandlers.c	Wed Dec 13 03:31:15 2000 +0000
@@ -734,66 +734,45 @@
 faim_internal int aim_handleredirect_middle(struct aim_session_t *sess,
 			      struct command_rx_struct *command, ...)
 {
-  struct aim_tlv_t *tmptlv = NULL;
-  int serviceid = 0x00;
-  unsigned char cookie[AIM_COOKIELEN];
+  int serviceid = 0;
+  unsigned char *cookie = NULL;
   char *ip = NULL;
   rxcallback_t userfunc = NULL;
   struct aim_tlvlist_t *tlvlist;
   int ret = 1;
   
-  if (!(tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10)))
-    {
-      printf("libfaim: major bug: unable to read tlvchain from redirect\n");
-      return ret;
-    }
-  
-  if (!(tmptlv = aim_gettlv(tlvlist, 0x000d, 1))) 
-    {
-      printf("libfaim: major bug: no service ID in tlvchain from redirect\n");
-      aim_freetlvchain(&tlvlist);
-      return ret;
-    }
-  serviceid = aimutil_get16(tmptlv->value);
+  tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10);
+
+  if (aim_gettlv(tlvlist, 0x000d, 1))
+    serviceid = aim_gettlv16(tlvlist, 0x000d, 1);
+  if (aim_gettlv(tlvlist, 0x0005, 1))
+    ip = aim_gettlv_str(tlvlist, 0x0005, 1);
+  if (aim_gettlv(tlvlist, 0x0006, 1))
+    cookie = aim_gettlv_str(tlvlist, 0x0006, 1);
 
-  if (!(ip = aim_gettlv_str(tlvlist, 0x0005, 1))) 
-    {
-      printf("libfaim: major bug: no IP in tlvchain from redirect (service 0x%02x)\n", serviceid);
-      free(ip);
-      aim_freetlvchain(&tlvlist);
-      return ret;
-    }
-  
-  if (!(tmptlv = aim_gettlv(tlvlist, 0x0006, 1)))
-    {
-      printf("libfaim: major bug: no cookie in tlvchain from redirect (service 0x%02x)\n", serviceid);
-      free(ip);
-      aim_freetlvchain(&tlvlist);
-      return ret;
-    }
-  memcpy(cookie, tmptlv->value, AIM_COOKIELEN);
+  if ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) {
 
-  if (serviceid == AIM_CONN_TYPE_CHAT)
-    {
-      /*
-       * Chat hack.
-       *
-       */
-      userfunc = aim_callhandler(command->conn, 0x0001, 0x0005);
-      if (userfunc)
-	ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange);
+    /*
+     * Chat hack.
+     *
+     */
+    if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005)))
+      ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange);
       free(sess->pendingjoin);
       sess->pendingjoin = NULL;
       sess->pendingjoinexchange = 0;
-    }
-  else
-    {
-      userfunc = aim_callhandler(command->conn, 0x0001, 0x0005);
-      if (userfunc)
-	ret =  userfunc(sess, command, serviceid, ip, cookie);
-    }
+  } else if (!serviceid || !ip || !cookie) { /* yeep! */
+    ret = 1;
+  } else {
+    if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x0005)))
+      ret =  userfunc(sess, command, serviceid, ip, cookie);
+  }
 
-  free(ip);
+  if (ip)
+    free(ip);
+  if (cookie)
+    free(cookie);
+
   aim_freetlvchain(&tlvlist);
 
   return ret;
@@ -829,25 +808,24 @@
   struct aim_tlvlist_t *tlvlist;
   char *msg = NULL;
   unsigned short code = 0;
-  struct aim_tlv_t *tmptlv;
   rxcallback_t userfunc = NULL;
   int ret = 1;
 
   tlvlist = aim_readtlvchain(command->data, command->commandlen);
 
-  if ((tmptlv = aim_gettlv(tlvlist, 0x0009, 1)))
-    code = aimutil_get16(tmptlv->value);
+  if (aim_gettlv(tlvlist, 0x0009, 1))
+    code = aim_gettlv16(tlvlist, 0x0009, 1);
 
-  if ((tmptlv = aim_gettlv(tlvlist, 0x000b, 1)))
+  if (aim_gettlv(tlvlist, 0x000b, 1))
     msg = aim_gettlv_str(tlvlist, 0x000b, 1);
 
-  userfunc = aim_callhandler(command->conn, 
-			     AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR);
-  if (userfunc)
+  if ((userfunc = aim_callhandler(command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR))) 
     ret =  userfunc(sess, command, code, msg);
 
   aim_freetlvchain(&tlvlist);
-  free(msg);
+
+  if (msg)
+    free(msg);
 
   return ret;
 }
--- a/libfaim/aim_search.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_search.c	Wed Dec 13 03:31:15 2000 +0000
@@ -28,20 +28,8 @@
 
   aim_tx_enqueue(sess, newpacket);
 
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x000a;
-    snac.type = 0x0002;
-    snac.flags = 0x0000;
+  aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, address, strlen(address)+1);
 
-    snac.data = malloc(strlen(address)+1);
-    memcpy(snac.data, address, strlen(address)+1);
-
-    aim_newsnac(sess, &snac);
-  }
-
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
--- a/libfaim/aim_snac.c	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/aim_snac.c	Wed Dec 13 03:31:15 2000 +0000
@@ -30,6 +30,25 @@
   return;
 }
 
+faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess,
+					  const unsigned short family,
+					  const unsigned short type,
+					  const unsigned short flags,
+					  const void *data, const int datalen)
+{
+  struct aim_snac_t snac;
+
+  snac.id = sess->snac_nextid++;
+  snac.family = family;
+  snac.type = type;
+  snac.flags = flags;
+
+  snac.data = malloc(datalen);
+  memcpy(snac.data, data, datalen);
+
+  return aim_newsnac(sess, &snac);
+}
+
 /*
  * Clones the passed snac structure and caches it in the
  * list/hash.
--- a/libfaim/faim/aim.h	Wed Dec 13 00:51:37 2000 +0000
+++ b/libfaim/faim/aim.h	Wed Dec 13 03:31:15 2000 +0000
@@ -505,6 +505,7 @@
 };
 faim_internal void aim_initsnachash(struct aim_session_t *sess);
 faim_internal unsigned long aim_newsnac(struct aim_session_t *, struct aim_snac_t *newsnac);
+faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess, const unsigned short family, const unsigned short type, const unsigned short flags, const void *data, const int datalen);
 faim_internal struct aim_snac_t *aim_remsnac(struct aim_session_t *, u_long id);
 faim_internal int aim_cleansnacs(struct aim_session_t *, int maxage);
 faim_internal int aim_putsnac(u_char *, int, int, int, u_long);