]> andersk Git - libfaim.git/commitdiff
- Fri Dec 1 22:25:56 UTC 2000
authormid <mid>
Fri, 1 Dec 2000 22:32:25 +0000 (22:32 +0000)
committermid <mid>
Fri, 1 Dec 2000 22:32:25 +0000 (22:32 +0000)
  - Fix numerous tiny (but sometimes catastrophic) bugs dealing
      with connection death (particularly with chat connections)
  - *** Any connection with a -1 fd will get returned by aim_select
      immediatly now... your code probably already handles this implicitly.

CHANGES
aim_chat.c
aim_conn.c
aim_rxqueue.c
aim_txqueue.c

diff --git a/CHANGES b/CHANGES
index e1618691fc9794ce179aeb2f507175eff72cc0f1..83d4e92020d5e6a94a4c28a04a2c8fa14eafb6d8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,12 @@
 
 No release numbers
 ------------------
+ - Fri Dec  1 22:25:56 UTC 2000
+  - Fix numerous tiny (but sometimes catastrophic) bugs dealing
+      with connection death (particularly with chat connections)
+  - *** Any connection with a -1 fd will get returned by aim_select
+      immediatly now... your code probably already handles this implicitly.
+
  - Wed Nov 29 17:31:23 UTC 2000
   - Rewrote some of the msgcookie stuff
   - Changed cachecookies to uncachecookies where it makes sense (arg!)
index 1d09b1b168effd29b6a8337beb653259ed621bf9..6ad5d15bd8b60b81dfbc801475d9c0b9edf45f52 100644 (file)
@@ -25,6 +25,10 @@ faim_export struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char
   for (cur = sess->connlist; cur; cur = cur->next) {
     if (cur->type != AIM_CONN_TYPE_CHAT)
       continue;
+    if (!cur->priv) {
+      printf("faim: chat: chat connection with no name! (fd = %d)\n", cur->fd);
+      continue;
+    }
     if (strcmp((char *)cur->priv, name) == 0)
       break;
   }
@@ -38,8 +42,10 @@ faim_export int aim_chat_attachname(struct aim_conn_t *conn, char *roomname)
   if (!conn || !roomname)
     return -1;
 
-  conn->priv = malloc(strlen(roomname)+1);
-  strcpy(conn->priv, roomname);
+  if (conn->priv)
+    free(conn->priv);
+
+  conn->priv = strdup(roomname);
 
   return 0;
 }
@@ -552,7 +558,7 @@ faim_export int aim_chat_leaveroom(struct aim_session_t *sess, char *name)
   struct aim_conn_t *conn;
 
   if ((conn = aim_chat_getconn(sess, name)))
-    aim_conn_kill(sess, &conn);
+    aim_conn_close(conn);
 
   if (!conn)
     return -1;
@@ -574,7 +580,10 @@ faim_export unsigned long aim_chat_invite(struct aim_session_t *sess,
   int i,curbyte=0;
 
   if (!sess || !conn || !sn || !msg || !roomname)
-    return 0;
+    return -1;
+
+  if (conn->type != AIM_CONN_TYPE_BOS)
+    return -1;
 
   if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 1152+strlen(sn)+strlen(roomname)+strlen(msg))))
     return -1;
index b630145f304283e4df4bec1a6d2d5a429faedc75..6914f0ed057f96c5e117014767f64d76a5602367 100644 (file)
@@ -38,6 +38,32 @@ faim_internal void aim_connrst(struct aim_session_t *sess)
   return;
 }
 
+/**
+ * aim_conn_init - Reset a connection to default values.
+ * @deadconn: Connection to be reset
+ *
+ * Initializes and/or resets a connection structure.
+ *
+ */
+static void aim_conn_init(struct aim_conn_t *deadconn)
+{
+  if (!deadconn)
+    return;
+
+  deadconn->fd = -1;
+  deadconn->subtype = -1;
+  deadconn->type = -1;
+  deadconn->seqnum = 0;
+  deadconn->lastactivity = 0;
+  deadconn->forcedlatency = 0;
+  deadconn->handlerlist = NULL;
+  deadconn->priv = NULL;
+  faim_mutex_init(&deadconn->active);
+  faim_mutex_init(&deadconn->seqnum_lock);
+  
+  return;
+}
+
 /**
  * aim_conn_getnext - Gets a new connection structure.
  * @sess: Session
@@ -53,7 +79,7 @@ faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *sess)
     return NULL;
 
   memset(newconn, 0, sizeof(struct aim_conn_t));
-  aim_conn_close(newconn);
+  aim_conn_init(newconn);
   newconn->next = NULL;
 
   faim_mutex_lock(&sess->connlistlock);
@@ -69,32 +95,6 @@ faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *sess)
   return newconn;
 }
 
-/**
- * aim_conn_init - Reset a connection to default values.
- * @deadconn: Connection to be reset
- *
- * Initializes and/or resets a connection structure.
- *
- */
-static void aim_conn_init(struct aim_conn_t *deadconn)
-{
-  if (!deadconn)
-    return;
-
-  deadconn->fd = -1;
-  deadconn->subtype = -1;
-  deadconn->type = -1;
-  deadconn->seqnum = 0;
-  deadconn->lastactivity = 0;
-  deadconn->forcedlatency = 0;
-  deadconn->handlerlist = NULL;
-  deadconn->priv = NULL;
-  faim_mutex_init(&deadconn->active);
-  faim_mutex_init(&deadconn->seqnum_lock);
-  
-  return;
-}
-
 /**
  * aim_conn_kill - Close and free a connection.
  * @sess: Session for the connection
@@ -131,7 +131,8 @@ faim_export void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **d
   /* XXX: do we need this for txqueue too? */
   aim_rxqueue_cleanbyconn(sess, *deadconn);
 
-  aim_conn_close(*deadconn);
+  if ((*deadconn)->fd != -1) 
+    aim_conn_close(*deadconn);
   if ((*deadconn)->priv)
     free((*deadconn)->priv);
   free(*deadconn);
@@ -146,34 +147,22 @@ faim_export void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **d
  *
  * Close (but not free) a connection.
  *
+ * This leaves everything untouched except for clearing the 
+ * handler list and setting the fd to -1 (used to recognize
+ * dead connections).
+ *
  */
 faim_export void aim_conn_close(struct aim_conn_t *deadconn)
 {
-  int typesav = -1, subtypesav = -1;
-  void *privsav = NULL;
 
   faim_mutex_destroy(&deadconn->active);
   faim_mutex_destroy(&deadconn->seqnum_lock);
   if (deadconn->fd >= 3)
     close(deadconn->fd);
+  deadconn->fd = -1;
   if (deadconn->handlerlist)
     aim_clearhandlers(deadconn);
 
-  typesav = deadconn->type;
-  subtypesav = deadconn->subtype;
-
-  if (deadconn->priv && (deadconn->type != AIM_CONN_TYPE_RENDEZVOUS)) {
-    free(deadconn->priv);
-    deadconn->priv = NULL;
-  }
-  privsav = deadconn->priv;
-
-  aim_conn_init(deadconn);
-
-  deadconn->type = typesav;
-  deadconn->subtype = subtypesav;
-  deadconn->priv = privsav;
-
   return;
 }
 
@@ -547,7 +536,12 @@ faim_export struct aim_conn_t *aim_select(struct aim_session_t *sess,
 
   faim_mutex_lock(&sess->connlistlock);
   for (cur = sess->connlist; cur; cur = cur->next) {
-    if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
+    if (cur->fd == -1) {
+      /* don't let invalid/dead connections sit around */
+      *status = 2;
+      faim_mutex_unlock(&sess->connlistlock);
+      return cur;
+    } else if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
       FD_SET(cur->fd, &wfds);
       haveconnecting++;
     }
index a26648afa234719f637e9e440cd31f9a320bc390..bbdb2078b72b5492f62c98d582fb27be6ff3202a 100644 (file)
@@ -57,6 +57,9 @@ faim_export int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *c
   if (!sess || !conn)
     return 0;
 
+  if (conn->fd == -1)
+    return -1; /* its a aim_conn_close()'d connection */
+
   if (conn->fd < 3)  /* can happen when people abuse the interface */
     return 0;
 
index 9871f938c523691feec5ab0905175e4eb8ec04d2..bc5eab3767fd4cc2b449d2f7867e5e50761461c4 100644 (file)
@@ -306,7 +306,7 @@ faim_internal int aim_tx_sendframe(struct aim_session_t *sess, struct command_tx
   if (send(cur->conn->fd, curPacket, buflen, 0) != buflen) {
     faim_mutex_unlock(&cur->conn->active);
     cur->sent = 1;
-    aim_conn_kill(sess, &cur->conn);
+    aim_conn_close(cur->conn);
     return 0; /* bail out */
   }
 
This page took 0.068003 seconds and 5 git commands to generate.