im.pidgin.pidgin: 245a620adeb2dc4767ee8db9e6c7cafa287b8f8d

seanegan at pidgin.im seanegan at pidgin.im
Tue Dec 18 02:41:03 EST 2007


-----------------------------------------------------------------
Revision: 245a620adeb2dc4767ee8db9e6c7cafa287b8f8d
Ancestor: e0eabac69254edb27d4593284b26558fddc089da
Author: seanegan at pidgin.im
Date: 2007-12-18T07:33:32
Branch: im.pidgin.pidgin

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

ChangeLog: 

Send XMPP Pings to the server instead of whitespace for our keepalives. Timeout the connection if there's no response in 20 seconds

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	eea6e7d81fa04f0cc37dae64741e2b910f56b45c
+++ libpurple/protocols/jabber/jabber.c	2330bff326c57b0af35a8e92d91ad78287655cec
@@ -388,9 +388,29 @@ void jabber_send(JabberStream *js, xmlno
 	g_free(txt);
 }
 
+static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) 
+{
+	g_source_remove(GPOINTER_TO_INT(timeout));
+}
+
+static gboolean jabber_pong_timeout(PurpleConnection *gc)
+{
+	purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+					_("Ping timeout"));
+	return FALSE;
+}
+
 void jabber_keepalive(PurpleConnection *gc)
 {
-	jabber_send_raw(gc->proto_data, "\t", -1);
+	JabberIq *iq = jabber_iq_new(gc->proto_data, JABBER_IQ_GET);
+	guint timeout;
+
+        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));
+	jabber_iq_send(iq);
 }
 
 static void


More information about the Commits mailing list