# HG changeset patch # User Sean Egan # Date 1197963212 0 # Node ID e13609ce45488ab730ed2470307000771a609ae5 # Parent 42cf060f1c76f11a59074ee68ca956162003e2b1 Send XMPP Pings to the server instead of whitespace for our keepalives. Timeout the connection if there's no response in 20 seconds diff -r 42cf060f1c76 -r e13609ce4548 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Tue Dec 18 06:29:46 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.c Tue Dec 18 07:33:32 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