]> andersk Git - libfaim.git/commitdiff
- Wed Dec 13 02:26:39 UTC 2000
authormid <mid>
Wed, 13 Dec 2000 02:29:37 +0000 (02:29 +0000)
committermid <mid>
Wed, 13 Dec 2000 02:29:37 +0000 (02:29 +0000)
  - Create aim_cachesnac()
  - Some long overdue cleanups

13 files changed:
CHANGES
aim_auth.c
aim_buddylist.c
aim_chat.c
aim_chatnav.c
aim_ft.c
aim_im.c
aim_info.c
aim_misc.c
aim_rxhandlers.c
aim_search.c
aim_snac.c
faim/aim.h

diff --git a/CHANGES b/CHANGES
index 5ee16cd56d88d893664f74f2ed2ab17aa22fc8a2..61a370455d5420843a7fdaf455cf96d554b3b7d8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
index 1fb9cfa5bf47923cdffc2b16c52b57afd343e3fa..d110451aed7e7c00a64264ff1daefb3d647f0c9d 100644 (file)
@@ -52,20 +52,9 @@ faim_export unsigned long aim_auth_clientready(struct aim_session_t *sess,
 
   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 @@ faim_export unsigned long aim_auth_changepasswd(struct aim_session_t *sess,
 
   aim_tx_enqueue(sess, newpacket);
 
-  {
-    struct aim_snac_t snac;
-    
-    snac.id = sess->snac_nextid;
-    snac.family = 0x0001;
-    snac.type = 0x0004;
-    snac.flags = 0x0000;
-
-    snac.data = NULL;
-
-    aim_newsnac(sess, &snac);
-  }
+  aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, NULL, 0);
 
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
index 26165bc0d41eaf2d7c10cccbe512fa435be2e4ef..a9b9ef8fbb91717f0c04d0ca3901a80720530320 100644 (file)
@@ -28,23 +28,9 @@ faim_export unsigned long aim_add_buddy(struct aim_session_t *sess,
 
    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;
-
-      snac.data = malloc( strlen( sn ) + 1 );
-      memcpy( snac.data, sn, strlen( sn ) + 1 );
-
-      aim_newsnac(sess, &snac);
-   }
-#endif
-
-   return( sess->snac_nextid++ );
+   aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
+
+   return sess->snac_nextid;
 }
 
 faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess,
@@ -69,21 +55,9 @@ faim_export unsigned long aim_remove_buddy(struct aim_session_t *sess,
 
    aim_tx_enqueue(sess, newpacket);
 
-   {
-      struct aim_snac_t snac;
-    
-      snac.id = sess->snac_nextid;
-      snac.family = 0x0003;
-      snac.type = 0x0005;
-      snac.flags = 0x0000;
-
-      snac.data = malloc( strlen( sn ) + 1 );
-      memcpy( snac.data, sn, strlen( sn ) + 1 );
-
-      aim_newsnac(sess, &snac );
-   }
+   aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
 
-   return( sess->snac_nextid++ );
+   return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
@@ -92,7 +66,6 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
   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 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
   /*
    * 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 @@ faim_internal int aim_parse_buddyrights(struct aim_session_t *sess,
    * 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);
index 85331edaf10b04e37660d4390b776604b0ddc658..5af5728fac89f2c89295fc93be3a6a9f3f3c625f 100644 (file)
@@ -173,23 +173,9 @@ faim_export unsigned long aim_chat_join(struct aim_session_t *sess,
   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;
-
-    snac.data = malloc(strlen(roomname)+1);
-    strcpy(snac.data, roomname);
-
-    aim_newsnac(sess, &snac);
-  }
+  aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, roomname, strlen(roomname)+1);
 
-#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 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
   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 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
   /*
    * 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 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
   /* 
    * 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 @@ faim_internal int aim_chat_parse_infoupdate(struct aim_session_t *sess,
   /* 
    * 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 @@ faim_internal int aim_chat_parse_joined(struct aim_session_t *sess,
     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 @@ faim_internal int aim_chat_parse_leave(struct aim_session_t *sess,
     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,
index 4c93af17ac7fcf08d1883d1d1f50eccdf50395f1..6d4ad424f19f27529aec35ce58a8b64616d8a064 100644 (file)
 faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess,
                                                struct aim_conn_t *conn)
 {
-  struct aim_snac_t snac;
+  aim_genericreq_n(sess, conn, 0x000d, 0x0002);
 
-  snac.id = 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 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
           * 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 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
               * 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 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
               * 
               */
              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 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       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 @@ faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct comm
       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 @@ faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess,
 {
   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 @@ faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess,
   /* 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;
 }
index b47eef68b9c2ebbab920745b2782b2cfa75903f9..84ce4df33300d646fe931383a4e7ec6d23f0263a 100644 (file)
--- a/aim_ft.c
+++ b/aim_ft.c
@@ -423,24 +423,6 @@ faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
    * 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 @@ faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess,
    * 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;
 }
 
index 216d2c040306f00d5202b47205148e16b1c4d191..9d0cbd9042ac02522648fc078810b9d12ddfd510 100644 (file)
--- a/aim_im.c
+++ b/aim_im.c
@@ -118,25 +118,10 @@ faim_export unsigned long aim_send_im(struct aim_session_t *sess,
 
   aim_tx_enqueue(sess, newpacket);
 
-#ifdef USE_SNAC_FOR_IMS
- {
-    struct aim_snac_t snac;
+  aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1);
+  aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
 
-    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 (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
@@ -467,14 +452,13 @@ faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
          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 */
index 0abbcf5db9907b1bb332bf2eba606e36b7e55ec1..396ddb9994ada66dce037693abea0cbbc97f7fe9 100644 (file)
@@ -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 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
                                      unsigned short infotype)
 {
   struct command_tx_struct *newpacket;
+  struct aim_priv_inforeq privdata;
   int i = 0;
 
   if (!sess || !conn || !sn)
@@ -39,22 +40,11 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
   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;
-
-    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);
-  }
+  strncpy(privdata.sn, sn, sizeof(privdata.sn));
+  privdata.infotype = infotype;
+  aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
 
-  return (sess->snac_nextid++);
+  return sess->snac_nextid;
 }
 
 faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
index 56e4a5b34fabc3fa06742e32381029ef9262d5e2..368215a6200039a65de8e2e029e1c98329be2098 100644 (file)
@@ -267,7 +267,6 @@ faim_internal int aim_parse_bosrights(struct aim_session_t *sess,
   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 @@ faim_internal int aim_parse_bosrights(struct aim_session_t *sess,
   /*
    * 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);
 
index df0c499d8a48de0d64960c9fe772549b2bc71a28..10c9ee35d0b9bc16b5492407373d0cc7300c7158 100644 (file)
@@ -734,66 +734,45 @@ faim_internal int aim_parsemotd_middle(struct aim_session_t *sess,
 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);
-
-  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)
-    {
-      /*
-       * Chat hack.
-       *
-       */
-      userfunc = aim_callhandler(command->conn, 0x0001, 0x0005);
-      if (userfunc)
-       ret =  userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin, (int)sess->pendingjoinexchange);
+  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 ((serviceid == AIM_CONN_TYPE_CHAT) && sess->pendingjoin) {
+
+    /*
+     * 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);
+  }
+
+  if (ip)
+    free(ip);
+  if (cookie)
+    free(cookie);
 
-  free(ip);
   aim_freetlvchain(&tlvlist);
 
   return ret;
@@ -829,25 +808,24 @@ faim_internal int aim_negchan_middle(struct aim_session_t *sess,
   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;
 }
index 1963592a7e911c779b7cc6fa7e30425bcd05612b..a8c4e1cfd75143485428988fbad2920acef9e5a3 100644 (file)
@@ -28,20 +28,8 @@ faim_export unsigned long aim_usersearch_address(struct aim_session_t *sess,
 
   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;
 }
 
index 64b884a3c7c2cf50b9565979d5fa970c0728e833..ae46e47ed28b1af41fb51206c4439ca5ff611774 100644 (file)
@@ -30,6 +30,25 @@ faim_internal void aim_initsnachash(struct aim_session_t *sess)
   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.
index 0c960080fab708954af99622b4e1d6f839f68838..1bd0014b9eba9bd3eec9f073245a0556d71cbb13 100644 (file)
@@ -505,6 +505,7 @@ struct aim_snac_t {
 };
 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);
This page took 0.116635 seconds and 5 git commands to generate.