im.pidgin.pidgin: dc6923294f5f33ff7a52a998e1b9e9ad47be0211

evands at pidgin.im evands at pidgin.im
Wed Jan 2 01:47:16 EST 2008


-----------------------------------------------------------------
Revision: dc6923294f5f33ff7a52a998e1b9e9ad47be0211
Ancestor: e38250347e7d1ebc4ee631a2a3833a500a22e375
Author: evands at pidgin.im
Date: 2008-01-02T06:36:35
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h

ChangeLog: 

Keep track of the keepalive timeout source so it can be removed when the account disconnects. This prevents a possible crash if the timeout fired after the account disconnected.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	9aa29fcda99363d5a029fdad7eb706f58ce724c4
+++ libpurple/protocols/jabber/jabber.c	3a500ce77c7f66820177d937c60e9bf613f54a1e
@@ -391,25 +391,27 @@ static void jabber_pong_cb(JabberStream 
 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) 
 {
 	purple_timeout_remove(GPOINTER_TO_INT(timeout));
+	js->keepalive_timeout = -1;
 }
 
 static gboolean jabber_pong_timeout(PurpleConnection *gc)
 {
 	purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 					_("Ping timeout"));
+	js->keepalive_timeout = -1;
 	return FALSE;
 }
 
 void jabber_keepalive(PurpleConnection *gc)
 {
-	JabberIq *iq = jabber_iq_new(gc->proto_data, JABBER_IQ_GET);
-	guint timeout;
+	JabberStream *js = gc->proto_data;
+	JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET);
 
-        xmlnode *ping = xmlnode_new_child(iq->node, "ping");
-        xmlnode_set_namespace(ping, "urn:xmpp:ping");
+	xmlnode *ping = xmlnode_new_child(iq->node, "ping");
+	xmlnode_set_namespace(ping, "urn:xmpp:ping");
 
-	timeout = purple_timeout_add_seconds(20, (GSourceFunc)(jabber_pong_timeout), gc);
-        jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(timeout));
+	js->keepalive_timeout = purple_timeout_add_seconds(20, (GSourceFunc)(jabber_pong_timeout), gc);
+	jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(js->keepalive_timeout));
 	jabber_iq_send(iq);
 }
 
@@ -612,6 +614,7 @@ jabber_login(PurpleAccount *account)
 	js->next_id = g_random_int();
 	js->write_buffer = purple_circ_buffer_new(512);
 	js->old_length = -1;
+	js->keepalive_timeout = -1;
 
 	if(!js->user) {
 		purple_connection_error_reason (gc,
@@ -1311,6 +1314,9 @@ void jabber_close(PurpleConnection *gc)
 	g_free(js->old_uri);
 	g_free(js->old_track);
 
+	if (js->keepalive_timeout != -1)
+		purple_timeout_remove(js->keepalive_timeout);
+	
 	g_free(js);
 
 	gc->proto_data = NULL;
============================================================
--- libpurple/protocols/jabber/jabber.h	bd69d4d5a3582c944f64074f736efab857b089d2
+++ libpurple/protocols/jabber/jabber.h	dcf93b0868c254669630cf11ec098f499b52845c
@@ -193,6 +193,9 @@ struct _JabberStream
 	char *old_track;
 	
 	char *host;
+	
+	/* A purple timeout tag for the keepalive */
+	int keepalive_timeout;
 };
 
 typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *shortname, const gchar *namespace);


More information about the Commits mailing list