]> andersk Git - libfaim.git/commitdiff
- Wed Nov 29 17:31:23 UTC 2000
authormid <mid>
Thu, 30 Nov 2000 01:37:20 +0000 (01:37 +0000)
committermid <mid>
Thu, 30 Nov 2000 01:37:20 +0000 (01:37 +0000)
  - Rewrote some of the msgcookie stuff
  - Changed cachecookies to uncachecookies where it makes sense (arg!)
  - Minor other stuff

CHANGES
aim_chat.c
aim_msgcookie.c
faim/aim.h

diff --git a/CHANGES b/CHANGES
index e261088fcfe19306dc829e377f29d5f9256ecacc..e1618691fc9794ce179aeb2f507175eff72cc0f1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
 
 No release numbers
 ------------------
+ - Wed Nov 29 17:31:23 UTC 2000
+  - Rewrote some of the msgcookie stuff
+  - Changed cachecookies to uncachecookies where it makes sense (arg!)
+  - Minor other stuff
  - Fri Nov 10 08:24:34 UTC 2000
   - Add sess->flags (replaces sess->snaclogin)
   - Remove odd setstatus call in chat parser
index b1f260a88d5174caa6ab87c811c0f6c61f7fca5f..1d09b1b168effd29b6a8337beb653259ed621bf9 100644 (file)
@@ -422,10 +422,11 @@ faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
   struct aim_userinfo_s userinfo;
   rxcallback_t userfunc=NULL;  
   int ret = 1, i = 0, z = 0;
-  u_char cookie[8];
+  unsigned char cookie[8];
   int channel;
   struct aim_tlvlist_t *outerlist;
   char *msg = NULL;
+  struct aim_msgcookie_t *ck;
 
   memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
 
@@ -437,7 +438,11 @@ faim_internal int aim_chat_parse_incoming(struct aim_session_t *sess,
   for (z=0; z<8; z++,i++)
     cookie[z] = command->data[i];
 
-  aim_cachecookie(sess, aim_mkcookie(cookie, AIM_COOKIETYPE_ICBM, NULL));
+  if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) {
+    if (ck->data)
+      free(ck->data);
+    free(ck);
+  }
 
   /*
    * Channel ID
@@ -583,6 +588,8 @@ faim_export unsigned long aim_chat_invite(struct aim_session_t *sess,
    */
   for (i=0;i<8;i++)
     curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand());
+
+  /* XXX this should get uncached by the unwritten 'invite accept' handler */
   aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL));
 
   /*
index 4ef8c8aa8a36091d0f0d8afcbdf56f63071ab395..c9cb58a93570e8cb38e02c926224c76f90265433 100644 (file)
  * - newcook->addtime is updated accordingly;
  * - cookie->type is just passed across.
  * 
- * returns -1 on error, 0 on success.  */
-
+ * returns -1 on error, 0 on success.  
+ */
 faim_internal int aim_cachecookie(struct aim_session_t *sess,
                                  struct aim_msgcookie_t *cookie)
 {
-  struct aim_msgcookie_t *newcook = NULL, *cur = NULL;
-  
+  struct aim_msgcookie_t *newcook;
+
   if (!cookie)
     return -1;
 
@@ -46,30 +46,18 @@ faim_internal int aim_cachecookie(struct aim_session_t *sess,
       
       free(cookie->data);
     }
-    return(0);
+
+    return 0;
   }
   
   if (!(newcook = malloc(sizeof(struct aim_msgcookie_t))))
     return -1;
   memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t));
   newcook->addtime = time(NULL);
-
-  if(newcook->next)
-    printf("faim: cachecookie: newcook->next isn't NULL ???\n");
-
-  newcook->next = NULL;
-  
-  cur = sess->msgcookies;
   
-  if (cur == NULL) {
-    sess->msgcookies = newcook;
-    return 0;
-  }
+  newcook->next = sess->msgcookies;
+  sess->msgcookies = newcook;
 
-  while (cur->next != NULL)
-    cur = cur->next;
-  cur->next = newcook;
-  
   return 0;
 }
 
@@ -79,7 +67,6 @@ faim_internal int aim_cachecookie(struct aim_session_t *sess,
  * it. removes struct from chain.  returns the struct if found, or
  * NULL on not found.
  */
-
 faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type)
 {
   struct aim_msgcookie_t *cur;
@@ -87,23 +74,28 @@ faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *se
   if (!cookie || !sess->msgcookies)
     return NULL;
 
-  cur = sess->msgcookies;
+  if ((sess->msgcookies->type == type) && 
+      (memcmp(sess->msgcookies->cookie, cookie, 8) == 0)) {
+    struct aim_msgcookie_t *tmp;
 
-  if ( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type) ) {
-    sess->msgcookies = cur->next;
-    return cur;
+    tmp = sess->msgcookies;
+    sess->msgcookies = sess->msgcookies->next;
+
+    return tmp;
   } 
 
-  while (cur->next) {
-    if ( (memcmp(cur->next->cookie, cookie, 8) == 0) && (cur->next->type == type) ) {
+  for (cur = sess->msgcookies; cur->next; cur = cur->next) {
+    if ((cur->next->type == type) &&
+       (memcmp(cur->next->cookie, cookie, 8) == 0)) {
       struct aim_msgcookie_t *tmp;
       
       tmp = cur->next;
       cur->next = cur->next->next;
+
       return tmp;
     }
-    cur = cur->next;
   }
+
   return NULL;
 }
 
@@ -123,15 +115,14 @@ faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *se
 faim_export int aim_purgecookies(struct aim_session_t *sess, int maxage)
 {
   struct aim_msgcookie_t *cur;
-  struct aim_msgcookie_t *remed = NULL;
   time_t curtime;
  
-  cur = sess->msgcookies;
-  
-  curtime = time(&curtime);
-  while (cur) {
-    if ( (cur->addtime) > (curtime - maxage) ) {
+  curtime = time(NULL);
+
+  for (cur = sess->msgcookies; cur; cur = cur->next) {
+    if (cur->addtime > (time(NULL) - maxage)) {
+      struct aim_msgcookie_t *remed = NULL;
+
 #if DEBUG > 1
       printf("aimmsgcookie: WARNING purged obsolete message cookie %x%x%x%x %x%x%x%x\n",
             cur->cookie[0], cur->cookie[1], cur->cookie[2], cur->cookie[3],
@@ -145,9 +136,6 @@ faim_export int aim_purgecookies(struct aim_session_t *sess, int maxage)
        free(remed);
       }
     }
-
-    cur = cur->next;
-
   }
   
   return 0;
@@ -157,42 +145,34 @@ faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, v
 {
   struct aim_msgcookie_t *cookie;
 
-  if(!c)
-    return(NULL);
+  if (!c)
+    return NULL;
 
-  if( (cookie = calloc(1, sizeof(struct aim_msgcookie_t))) == NULL)
-    return(NULL);
+  if (!(cookie = calloc(1, sizeof(struct aim_msgcookie_t))))
+    return NULL;
   
   cookie->data = data;
-
   cookie->type = type;
-  
   memcpy(cookie->cookie, c, 8);
   
-  return(cookie);
+  return cookie;
 }
   
 faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, unsigned char *cookie, int type)
 {
   struct aim_msgcookie_t *cur;
   
-  if(!sess->msgcookies)
-    return NULL;
-
-  cur = sess->msgcookies;
-
-  if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type))
-    return(cur);
-
-  while( (cur = cur->next) )
-    if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type))
-      return(cur);
+  for (cur = sess->msgcookies; cur; cur = cur->next) {
+    if ((cur->type == type) && 
+       (memcmp(cur->cookie, cookie, 8) == 0))
+      return cur;
+  }
 
-  return(NULL);
+  return NULL;
 }
 
 static int aim_freecookie(struct aim_msgcookie_t *cookie) {
-  return(0);
+  return 0;
 } 
 
 faim_internal int aim_msgcookie_gettype(int reqclass) {
index 46e2e8f88f6b1697daf70ee802885df855f7dce2..e0ed0b37178c4a89c3623a6b4926f4c76c74ffea 100644 (file)
@@ -1,6 +1,9 @@
 /* 
  * Main libfaim header.  Must be included in client for prototypes/macros.
  *
+ * "come on, i turned a chick lesbian; i think this is the hackish equivalent"
+ *                                                -- Josh Meyer
+ *
  */
 
 #ifndef __AIM_H__
This page took 0.081534 seconds and 5 git commands to generate.