diff libfaim/aim_snac.c @ 237:6ced2f1c8b24

[gaim-migrate @ 247] How cool is this, libfaim is making a comeback. I completely redid everything, as was necessary because of the updates to libfaim since gaim 0.9.7. You can sign on and send/recv IMs, but there's a bad lag between display updates that I haven't figured out how to fix yet. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 20 May 2000 00:30:53 +0000
parents 68b230f8da5f
children 0f14e6d8a51b
line wrap: on
line diff
--- a/libfaim/aim_snac.c	Thu May 18 18:20:18 2000 +0000
+++ b/libfaim/aim_snac.c	Sat May 20 00:30:53 2000 +0000
@@ -13,51 +13,60 @@
  */
 
 #include <aim.h>
-#include <assert.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;
+
+  cur = sess->outstanding_snacs;
 
-	if (cur == NULL) {
-		aim_outstanding_snacs = snac;
-		return(snac->id);
-	}
-	while (cur->next != NULL)
-		cur = cur->next;
-	cur->next = snac;
-	return(snac->id);
+  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);
 }
 
-struct aim_snac_t	*aim_remsnac(u_long id) {
-	struct aim_snac_t	*cur = aim_outstanding_snacs;
+struct aim_snac_t *aim_remsnac(struct aim_session_t *sess, 
+			       u_long id) 
+{
+  struct aim_snac_t *cur;
+
+  cur = sess->outstanding_snacs;
+
+  if (cur == NULL)
+    return(NULL);
 
-	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;
-
-			tmp = cur->next;
-			cur->next = cur->next->next;
-			return(tmp);
-		}
-		cur = cur->next;
-	}
-	return(NULL);
+  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,22 +77,25 @@
  * 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))
 	{
 #if DEBUG > 1
-	  printf("aimsnac: WARNING purged obsolete snac %ul\n", cur->id);
+	  printf("aimsnac: WARNING purged obsolete snac %08lx\n", cur->id);
 #endif
-	  remed = aim_remsnac(cur->id);
+	  remed = aim_remsnac(sess, cur->id);
 	  if (remed)
 	    {
 	      if (remed->data)
@@ -93,16 +105,16 @@
 	}
       cur = cur->next;
     }
-
+  
   return 0;
 }
 
 int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid)
 {
   int curbyte = 0;
-  curbyte += aimutil_put16(buf+curbyte,family&0xffff);
-  curbyte += aimutil_put16(buf+curbyte,subtype&0xffff);
-  curbyte += aimutil_put16(buf+curbyte,flags&0xffff);
-  curbyte += aimutil_put32(buf+curbyte,snacid);
+  curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff));
+  curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff));
+  curbyte += aimutil_put32(buf+curbyte, snacid);
   return curbyte;
 }