diff src/protocols/oscar/conn.c @ 10267:9cafe038c95e

[gaim-migrate @ 11413] This is some white-space cleanup for oscar, and send an empty channel 4 FLAP when disconnecting. This would have hopefully fixed the problem Luke was seeing where his AIM account wasn't being signed offline for a few hours. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 26 Nov 2004 03:52:00 +0000
parents 4e7fe18a36b7
children 361c9170d8af
line wrap: on
line diff
--- a/src/protocols/oscar/conn.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/conn.c	Fri Nov 26 03:52:00 2004 +0000
@@ -158,8 +158,8 @@
 	aim_rxqueue_cleanbyconn(sess, *deadconn);
 	aim_tx_cleanqueue(sess, *deadconn);
 
-	if ((*deadconn)->fd != -1) 
-		aim_conn_close(*deadconn);
+	if ((*deadconn)->fd != -1)
+		aim_conn_close(sess, *deadconn);
 
 	/*
 	 * XXX ->priv should never be touched by the library. I know
@@ -203,7 +203,7 @@
 
 		while (cur) {
 			tmp = cur->next;
-			aim_conn_close(cur);
+			aim_conn_close(sess, cur);
 			connkill_real(sess, &cur);
 			cur = tmp;
 		}
@@ -248,7 +248,7 @@
 {
 	aim_conn_t *newconn;
 
-	if (!(newconn = malloc(sizeof(aim_conn_t)))) 	
+	if (!(newconn = malloc(sizeof(aim_conn_t))))
 		return NULL;
 	memset(newconn, 0, sizeof(aim_conn_t));
 
@@ -277,7 +277,7 @@
 {
 	aim_conn_t *cur, **prev;
 
-	if (!deadconn || !*deadconn)	
+	if (!deadconn || !*deadconn)
 		return;
 
 	for (prev = &sess->connlist; (cur = *prev); ) {
@@ -297,6 +297,28 @@
 }
 
 /**
+ * This sends an empty channel 4 SNAC.  This is sent to signify
+ * that we're logging off.  This shouldn't really be necessary--
+ * usually the AIM server will detect that the TCP connection has
+ * been destroyed.
+ */
+static int
+aim_flap_close(aim_session_t *sess, aim_conn_t *conn)
+{
+	aim_frame_t *fr;
+
+	if (!sess || !conn)
+		return -EINVAL;
+
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 0)))
+		return -ENOMEM;
+
+	aim_tx_enqueue(sess, fr);
+
+	return 0;
+}
+
+/**
  * Close (but not free) a connection.
  *
  * This leaves everything untouched except for clearing the 
@@ -308,11 +330,13 @@
  *
  * @param deadconn The connection to close.
  */
-faim_export void aim_conn_close(aim_conn_t *deadconn)
+faim_export void aim_conn_close(aim_session_t *sess, aim_conn_t *deadconn)
 {
 	aim_rxcallback_t userfunc;
 
-	if (deadconn->fd >= 3)
+	aim_flap_close(sess, deadconn);
+
+	if (deadconn->fd >= 0)
 		close(deadconn->fd);
 
 	deadconn->fd = -1;
@@ -343,7 +367,7 @@
 	aim_conn_t *cur;
 
 	for (cur = sess->connlist; cur; cur = cur->next) {
-		if ((cur->type == type) && 
+		if ((cur->type == type) &&
 				!(cur->status & AIM_CONN_STATUS_INPROGRESS))
 			break;
 	}
@@ -687,7 +711,7 @@
  * @param timeout How long to wait
  * @param status Return status
  * @return If @status is 2, returns connection with pending data, otherwise %NULL
- */ 
+ */
 faim_export aim_conn_t *aim_select(aim_session_t *sess, struct timeval *timeout, int *status)
 {
 	aim_conn_t *cur;
@@ -734,7 +758,7 @@
 	if (!haveconnecting && sess->queue_outgoing) {
 		*status = 1;
 		return NULL;
-	} 
+	}
 
 	if ((i = select(maxfd+1, &fds, &wfds, NULL, timeout))>=1) {
 		for (cur = sess->connlist; cur; cur = cur->next) {
@@ -805,7 +829,7 @@
 	}
 
 	strncpy(sess->socksproxy.server, server, sizeof(sess->socksproxy.server));
-	if (username && strlen(username)) 
+	if (username && strlen(username))
 		strncpy(sess->socksproxy.username, username, sizeof(sess->socksproxy.username));
 	if (password && strlen(password))
 		strncpy(sess->socksproxy.password, password, sizeof(sess->socksproxy.password));