changeset 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 2a9ec10e0c4c
children d082b2a71ee7
files src/protocols/oscar/aim.h src/protocols/oscar/auth.c src/protocols/oscar/chat.c src/protocols/oscar/conn.c src/protocols/oscar/ft.c src/protocols/oscar/oscar.c src/protocols/oscar/rxqueue.c src/protocols/oscar/txqueue.c
diffstat 8 files changed, 71 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/aim.h	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/aim.h	Fri Nov 26 03:52:00 2004 +0000
@@ -567,7 +567,7 @@
 
 faim_export aim_conn_t *aim_conn_findbygroup(aim_session_t *sess, fu16_t group);
 faim_export aim_session_t *aim_conn_getsess(aim_conn_t *conn);
-faim_export void aim_conn_close(aim_conn_t *deadconn);
+faim_export void aim_conn_close(aim_session_t *sess, aim_conn_t *deadconn);
 faim_export aim_conn_t *aim_newconn(aim_session_t *, int type, const char *dest);
 faim_export aim_conn_t *aim_select(aim_session_t *, struct timeval *, int *);
 faim_export int aim_conn_in_sess(aim_session_t *sess, aim_conn_t *conn);
--- a/src/protocols/oscar/auth.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/auth.c	Fri Nov 26 03:52:00 2004 +0000
@@ -58,7 +58,7 @@
 {
 	md5_state_t state;
 
-	md5_init(&state);	
+	md5_init(&state);
 	md5_append(&state, (const md5_byte_t *)key, strlen(key));
 	md5_append(&state, (const md5_byte_t *)password, strlen(password));
 	md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
@@ -76,7 +76,7 @@
 	md5_append(&state, (const md5_byte_t *)password, strlen(password));
 	md5_finish(&state, (md5_byte_t *)&passdigest);
 
-	md5_init(&state);	
+	md5_init(&state);
 	md5_append(&state, (const md5_byte_t *)key, strlen(key));
 	md5_append(&state, (const md5_byte_t *)&passdigest, 16);
 	md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
@@ -118,7 +118,7 @@
 	aim_frame_t *fr;
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+length)))
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4+2+2+length)))
 		return -ENOMEM;
 
 	aimbs_put32(&fr->data, 0x00000001);
@@ -259,7 +259,7 @@
 	aim_tlvlist_write(&fr->data, &tl);
 
 	aim_tlvlist_free(&tl);
-	
+
 	aim_tx_enqueue(sess, fr);
 
 	return 0;
@@ -302,7 +302,7 @@
 	 * Check for an error code.  If so, we should also
 	 * have an error url.
 	 */
-	if (aim_tlv_gettlv(tlvlist, 0x0008, 1)) 
+	if (aim_tlv_gettlv(tlvlist, 0x0008, 1))
 		info->errorcode = aim_tlv_get16(tlvlist, 0x0008, 1);
 	if (aim_tlv_gettlv(tlvlist, 0x0004, 1))
 		info->errorurl = aim_tlv_getstr(tlvlist, 0x0004, 1);
@@ -435,9 +435,9 @@
 {
 	aim_frame_t fr;
 	aim_rxcallback_t userfunc;
-	
+
 	fr.conn = conn;
-	
+
 	if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007)))
 		userfunc(sess, &fr, "");
 
@@ -459,7 +459,7 @@
 	aim_frame_t *fr;
 	aim_snacid_t snacid;
 	aim_tlvlist_t *tl = NULL;
-	
+
 	if (!sess || !conn || !sn)
 		return -EINVAL;
 
@@ -510,7 +510,7 @@
 	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
 		ret = userfunc(sess, rx, keystr);
 
-	free(keystr); 
+	free(keystr);
 
 	return ret;
 }
--- a/src/protocols/oscar/chat.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/chat.c	Fri Nov 26 03:52:00 2004 +0000
@@ -107,7 +107,7 @@
 	if (!(conn = aim_chat_getconn(sess, name)))
 		return -ENOENT;
 
-	aim_conn_close(conn);
+	aim_conn_close(sess, conn);
 
 	return 0;
 }
--- 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));
--- a/src/protocols/oscar/ft.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/ft.c	Fri Nov 26 03:52:00 2004 +0000
@@ -196,7 +196,7 @@
 
 	if ((addr.sa_family != PF_INET) && (addr.sa_family != PF_INET6)) {
 		close(acceptfd);
-		aim_conn_close(cur);
+		aim_conn_close(sess, cur);
 		return -1;
 	}
 
@@ -205,7 +205,7 @@
 
 	if (!(newconn = aim_cloneconn(sess, cur))) {
 		close(acceptfd);
-		aim_conn_close(cur);
+		aim_conn_close(sess, cur);
 		return -ENOMEM;
 	}
 
@@ -232,7 +232,7 @@
 
 	} else {
 		faimdprintf(sess, 1,"Got a connection on a listener that's not rendezvous.  Closing connection.\n");
-		aim_conn_close(newconn);
+		aim_conn_close(sess, newconn);
 		ret = -1;
 	}
 
@@ -932,7 +932,7 @@
 	}
 
 	if (ret == -1)
-		aim_conn_close(conn);
+		aim_conn_close(sess, conn);
 
 	return ret;
 }
--- a/src/protocols/oscar/oscar.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/oscar.c	Fri Nov 26 03:52:00 2004 +0000
@@ -880,7 +880,7 @@
 	if (dim->watcher)
 	gaim_input_remove(dim->watcher);
 	if (dim->conn) {
-		aim_conn_close(dim->conn);
+		aim_conn_close(od->sess, dim->conn);
 		aim_conn_kill(od->sess, &dim->conn);
 	}
 	g_free(dim);
@@ -1100,7 +1100,7 @@
 	listenerconn = va_arg(ap, aim_conn_t *);
 	va_end(ap);
 
-	aim_conn_close(listenerconn);
+	aim_conn_close(sess, listenerconn);
 	aim_conn_kill(sess, &listenerconn);
 
 	sn = g_strdup(aim_odc_getsn(newconn));
--- a/src/protocols/oscar/rxqueue.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/rxqueue.c	Fri Nov 26 03:52:00 2004 +0000
@@ -5,7 +5,7 @@
  */
 
 #define FAIM_INTERNAL
-#include <aim.h> 
+#include <aim.h>
 
 #ifndef _WIN32
 #include <sys/socket.h>
@@ -16,11 +16,11 @@
  */
 faim_internal int aim_recv(int fd, void *buf, size_t count)
 {
-	int left, cur; 
+	int left, cur;
 
 	for (cur = 0, left = count; left; ) {
 		int ret;
-		
+
 		ret = recv(fd, ((unsigned char *)buf)+cur, left, 0);
 
 		/* Of course EOF is an error, only morons disagree with that. */
@@ -44,7 +44,7 @@
 
 	if (!bs || (fd < 0) || (count < 0))
 		return -1;
-	
+
 	if (count > (bs->len - bs->offset))
 		count = bs->len - bs->offset; /* truncate to remaining space */
 
@@ -86,7 +86,7 @@
 {
 	fu8_t hdr_raw[6];
 	aim_bstream_t hdr;
-	
+
 	fr->hdrtype = AIM_FRAMETYPE_FLAP;
 
 	/*
@@ -102,7 +102,7 @@
 	 */
 	aim_bstream_init(&hdr, hdr_raw, sizeof(hdr_raw));
 	if (aim_bstream_recv(&hdr, conn->fd, 6) < 6) {
-		aim_conn_close(conn);
+		aim_conn_close(sess, conn);
 		return -1;
 	}
 
@@ -114,9 +114,9 @@
 	 */
 	if (aimbs_get8(&hdr) != 0x2a) {
 		faimdprintf(sess, 0, "Invalid FLAP frame received on FLAP connection!");
-		aim_conn_close(conn);
+		aim_conn_close(sess, conn);
 		return -1;
-	}	
+	}
 
 	fr->hdr.flap.channel = aimbs_get8(&hdr);
 	fr->hdr.flap.seqnum = aimbs_get16(&hdr);
@@ -142,7 +142,7 @@
 	 */
 	aim_bstream_init(&hdr, hdr_raw, sizeof(hdr_raw));
 	if (aim_bstream_recv(&hdr, conn->fd, 8) < 8) {
-		aim_conn_close(conn);
+		aim_conn_close(sess, conn);
 		return -1;
 	}
 
@@ -212,7 +212,7 @@
 		/* read the payload */
 		if (aim_bstream_recv(&fr->data, conn->fd, payloadlen) < payloadlen) {
 			aim_frame_destroy(fr); /* free's payload */
-			aim_conn_close(conn);
+			aim_conn_close(sess, conn);
 			return -1;
 		}
 	} else
@@ -234,7 +234,7 @@
 
 	fr->conn->lastactivity = time(NULL);
 
-	return 0;  
+	return 0;
 }
 
 /*
@@ -270,7 +270,7 @@
 	for (currx = sess->queue_incoming; currx; currx = currx->next) {
 		if ((!currx->handled) && (currx->conn == conn))
 			currx->handled = 1;
-	}	
+	}
 
 	return;
 }
--- a/src/protocols/oscar/txqueue.c	Fri Nov 26 02:57:23 2004 +0000
+++ b/src/protocols/oscar/txqueue.c	Fri Nov 26 03:52:00 2004 +0000
@@ -51,13 +51,13 @@
 	if (!(fr = (aim_frame_t *)calloc(1, sizeof(aim_frame_t))))
 		return NULL;
 
-	fr->conn = conn; 
+	fr->conn = conn;
 	fr->hdrtype = framing;
 	if (fr->hdrtype == AIM_FRAMETYPE_FLAP)
 		fr->hdr.flap.channel = chan;
 	else if (fr->hdrtype == AIM_FRAMETYPE_OFT)
 		fr->hdr.rend.type = chan;
-	else 
+	else
 		faimdprintf(sess, 0, "tx_new: unknown framing\n");
 
 	if (datalen > 0) {
@@ -83,7 +83,7 @@
 static flap_seqnum_t aim_get_next_txseqnum(aim_conn_t *conn)
 {
 	flap_seqnum_t ret;
-	
+
 	ret = ++conn->seqnum;
 
 	return ret;
@@ -161,7 +161,7 @@
 
 faim_export int aim_tx_setenqueue(aim_session_t *sess, int what, int (*func)(aim_session_t *, aim_frame_t *))
 {
-	
+
 	if (what == AIM_TX_QUEUED)
 		sess->tx_enqueue = &aim_tx_enqueue__queuebased;
 	else if (what == AIM_TX_IMMEDIATE) 
@@ -178,7 +178,7 @@
 
 faim_internal int aim_tx_enqueue(aim_session_t *sess, aim_frame_t *fr)
 {
-	
+
 	/*
 	 * If we want to send on a connection that is in progress, we have to force
 	 * them to use the queue based version. Otherwise, use whatever they
@@ -231,7 +231,7 @@
 		 * up an actual txqueue and a GAIM_INPUT_WRITE callback and only write when we
 		 * can. Why is this file called txqueue anyway? Lets rename it to txblock.
 		 */
-		if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) && 
+		if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) &&
 		    (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) {
 			const char *sn = aim_odc_getsn(conn);
 			aim_rxcallback_t userfunc;
@@ -286,7 +286,7 @@
 	aim_bstream_rewind(&bs);
 	if (aim_bstream_send(&bs, fr->conn, bslen) != bslen)
 		err = -errno;
-	
+
 	free(bs_raw); /* XXX aim_bstream_free */
 
 	fr->handled = 1;