changeset 21861:eb9f928a369d

merge of '245a620adeb2dc4767ee8db9e6c7cafa287b8f8d' and '43f59273fcae687e1b252460cebdf2f12f2fde6f'
author Mark Doliner <mark@kingant.net>
date Tue, 18 Dec 2007 07:39:57 +0000
parents e13609ce4548 (diff) f23c41e65f63 (current diff)
children ae58ffd5e929
files
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Tue Dec 18 07:37:55 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue Dec 18 07:39:57 2007 +0000
@@ -388,9 +388,29 @@
 	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