+ struct aim_conn_t *newconn, *cur;
+
+ if (!(newconn = malloc(sizeof(struct aim_conn_t))))
+ return NULL;
+
+ memset(newconn, 0, sizeof(struct aim_conn_t));
+ aim_conn_close(newconn);
+ newconn->next = NULL;
+
+ faim_mutex_lock(&sess->connlistlock);
+ if (sess->connlist == NULL)
+ sess->connlist = newconn;
+ else {
+ for (cur = sess->connlist; cur->next; cur = cur->next)
+ ;
+ cur->next = newconn;
+ }
+ faim_mutex_unlock(&sess->connlistlock);
+
+ return newconn;
+}
+
+void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn)
+{
+ struct aim_conn_t *cur;
+
+ if (!deadconn || !*deadconn)
+ return;
+
+ faim_mutex_lock(&sess->connlistlock);
+ if (sess->connlist == NULL)
+ ;
+ else if (sess->connlist->next == NULL) {
+ if (sess->connlist == *deadconn)
+ sess->connlist = NULL;
+ } else {
+ cur = sess->connlist;
+ while (cur->next) {
+ if (cur->next == *deadconn) {
+ cur->next = cur->next->next;
+ break;
+ }
+ cur = cur->next;
+ }
+ }
+ faim_mutex_unlock(&sess->connlistlock);
+
+ /* XXX: do we need this for txqueue too? */
+ aim_rxqueue_cleanbyconn(sess, *deadconn);
+
+ aim_conn_close(*deadconn);
+ free(*deadconn);
+ deadconn = NULL;
+
+ return;