changeset 21758:430827922828

Avoid checking for new message in the inbox when not actually connected. This helps avoid a half-dozen assertions by not trying to act on a closed socket.
author Kevin Stange <kevin@simguy.net>
date Tue, 04 Dec 2007 05:43:15 +0000
parents 61725f2eb4a6
children 41489d141def 6360da6f3cc1
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/session.c libpurple/protocols/myspace/session.h
diffstat 3 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Tue Dec 04 02:50:44 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Dec 04 05:43:15 2007 +0000
@@ -1369,7 +1369,9 @@
 	msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply);
 
 	body = msim_msg_get_dictionary(reply, "body");
-	g_return_if_fail(body != NULL);
+
+	if (body == NULL)
+		return;
 
 	old_inbox_status = session->inbox_status;
 
@@ -1433,6 +1435,11 @@
 
 	session = (MsimSession *)data;
 
+	if (!MSIM_SESSION_VALID(session)) {
+		purple_debug_info("msim", "msim_check_inbox: session invalid, stopping the mail check.\n");
+		return FALSE;
+	}
+
 	purple_debug_info("msim", "msim_check_inbox: checking mail\n");
 	g_return_val_if_fail(msim_send(session, 
 			"persist", MSIM_TYPE_INTEGER, 1,
@@ -1645,7 +1652,7 @@
 
 	/* Check mail if they want to. */
 	if (purple_account_get_check_mail(session->account)) {
-		purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK, 
+		session->inbox_handle = purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK, 
 				(GSourceFunc)msim_check_inbox, session);
 		msim_check_inbox(session);
 	}
--- a/libpurple/protocols/myspace/session.c	Tue Dec 04 02:50:44 2007 +0000
+++ b/libpurple/protocols/myspace/session.c	Tue Dec 04 05:43:15 2007 +0000
@@ -63,6 +63,7 @@
 	session->next_rid = 1;
 	session->last_comm = time(NULL);
 	session->inbox_status = 0;
+	session->inbox_handle = 0;
 	
 	return session;
 }
@@ -90,6 +91,11 @@
 		msim_msg_free(session->server_info);
 	}
 	
+	/* Stop checking the inbox at the end of the session. */
+	if (session->inbox_handle) {
+		purple_timeout_remove(session->inbox_handle);
+	}
+
 	g_free(session);
 }
 
--- a/libpurple/protocols/myspace/session.h	Tue Dec 04 02:50:44 2007 +0000
+++ b/libpurple/protocols/myspace/session.h	Tue Dec 04 05:43:15 2007 +0000
@@ -45,6 +45,7 @@
 	guint next_rid;                     /**< Next request/response ID */
 	time_t last_comm;                   /**< Time received last communication */
 	guint inbox_status;                 /**< Bit field of inbox notifications */
+	guint inbox_handle;                 /**< The handle for the mail check timer */
 } MsimSession;
 
 /* Check if an MsimSession is valid */