]> andersk Git - libfaim.git/blobdiff - aim_snac.c
Integrated session changes needed for Jabber transport. Lots of changes.
[libfaim.git] / aim_snac.c
index f2701ec95a5e185da8692172001cbb10be42ce5e..1d2c4fb3f702025fa946f0e290d1c4c8c5218b22 100644 (file)
  *
  */
 
-#include <aim.h>
-#include <assert.h>
+#include <faim/aim.h>
 
-struct aim_snac_t      *aim_outstanding_snacs = NULL;
-u_long aim_snac_nextid = 0x00000001;
-
-u_long aim_newsnac(struct aim_snac_t *newsnac) {
-       struct aim_snac_t       *snac = NULL, *cur = aim_outstanding_snacs;
+u_long aim_newsnac(struct aim_session_t *sess,
+                  struct aim_snac_t *newsnac) 
+{
+  struct aim_snac_t *snac = NULL, *cur = NULL;
   
-       assert(newsnac != NULL);
-       snac = calloc(1, sizeof(struct aim_snac_t));
-       assert(snac != NULL);
-       memcpy(snac, newsnac, sizeof(struct aim_snac_t));
-       snac->issuetime = time(&snac->issuetime);
-       snac->next = NULL;
+  if (!newsnac)
+    return 0;
 
-       if (cur == NULL) {
-               aim_outstanding_snacs = snac;
-               return(snac->id);
-       }
-       while (cur->next != NULL)
-               cur = cur->next;
-       cur->next = snac;
-       return(snac->id);
-}
+  cur = sess->outstanding_snacs;
 
-struct aim_snac_t      *aim_remsnac(u_long id) {
-       struct aim_snac_t       *cur = aim_outstanding_snacs;
+  snac = calloc(1, sizeof(struct aim_snac_t));
+  if (!snac)
+    return 0;
+  memcpy(snac, newsnac, sizeof(struct aim_snac_t));
+  snac->issuetime = time(&snac->issuetime);
+  snac->next = NULL;
+  
+  if (cur == NULL) {
+    sess->outstanding_snacs = snac;
+    return(snac->id);
+  }
+  while (cur->next != NULL)
+    cur = cur->next;
+  cur->next = snac;
+  return(snac->id);
+}
 
-       if (cur == NULL)
-               return(NULL);
-       if (cur->id == id) {
-               aim_outstanding_snacs = cur->next;
-               return(cur);
-       }
-       while (cur->next != NULL) {
-               if (cur->next->id == id) {
-                       struct aim_snac_t       *tmp = NULL;
+struct aim_snac_t *aim_remsnac(struct aim_session_t *sess, 
+                              u_long id) 
+{
+  struct aim_snac_t *cur;
+  
+  if (cur == NULL)
+    return(NULL);
 
-                       tmp = cur->next;
-                       cur->next = cur->next->next;
-                       return(tmp);
-               }
-               cur = cur->next;
-       }
-       return(NULL);
+  cur = sess->outstanding_snacs;
+  
+  if (cur->id == id) {
+    sess->outstanding_snacs = cur->next;
+    return(cur);
+  }
+  while (cur->next != NULL) {
+    if (cur->next->id == id) {
+      struct aim_snac_t        *tmp = NULL;
+      
+      tmp = cur->next;
+      cur->next = cur->next->next;
+      return(tmp);
+    }
+    cur = cur->next;
+  }
+  return(NULL);
 }
 
 /*
@@ -68,14 +76,17 @@ struct aim_snac_t   *aim_remsnac(u_long id) {
  * why its called _max_age).
  *
  */
-int aim_cleansnacs(int maxage)
+int aim_cleansnacs(struct aim_session_t *sess,
+                  int maxage)
 {
-  struct aim_snac_t *cur = aim_outstanding_snacs;
+  struct aim_snac_t *cur;
   struct aim_snac_t *remed = NULL;
   time_t curtime;
+  cur = sess->outstanding_snacs;
   
   curtime = time(&curtime);
-
   while (cur)
     {
       if ( (cur) && (((cur->issuetime) + maxage) < curtime))
@@ -83,7 +94,7 @@ int aim_cleansnacs(int maxage)
 #if DEBUG > 1
          printf("aimsnac: WARNING purged obsolete snac %ul\n", cur->id);
 #endif
-         remed = aim_remsnac(cur->id);
+         remed = aim_remsnac(sess, cur->id);
          if (remed)
            {
              if (remed->data)
@@ -93,7 +104,7 @@ int aim_cleansnacs(int maxage)
        }
       cur = cur->next;
     }
-
+  
   return 0;
 }
 
This page took 0.038938 seconds and 4 git commands to generate.