diff libpurple/protocols/jabber/ping.c @ 25645:ced3d4ab745a

propagate from branch 'im.pidgin.pidgin' (head 8d4081da0c186c04dc75d736d688bf4f20e52676) to branch 'im.pidgin.cpw.darkrain42.xmpp.iq-handlers' (head 9a25f2e3149558150e52b40d5c119965ed617e37)
author Paul Aurich <paul@darkrain42.org>
date Sun, 08 Feb 2009 03:34:25 +0000
parents 36c73d036026 42dd7e591031
children 050052891c55
line wrap: on
line diff
--- a/libpurple/protocols/jabber/ping.c	Sun Feb 08 00:23:43 2009 +0000
+++ b/libpurple/protocols/jabber/ping.c	Sun Feb 08 03:34:25 2009 +0000
@@ -23,34 +23,59 @@
 #include "internal.h"
 
 #include "debug.h"
-#include "xmlnode.h"
 
 #include "jabber.h"
 #include "ping.h"
 #include "iq.h"
 
+static void jabber_keepalive_pong_cb(JabberStream *js)
+{
+	purple_timeout_remove(js->keepalive_timeout);
+	js->keepalive_timeout = -1;
+}
+
 void
 jabber_ping_parse(JabberStream *js, xmlnode *packet)
 {
-	JabberIq *iq;
+	const char *type, *id, *from;
+
+	type = xmlnode_get_attrib(packet, "type");
+	from = xmlnode_get_attrib(packet, "from");
+	id   = xmlnode_get_attrib(packet, "id");
 
+	if (!type) {
+		purple_debug_warning("jabber", "jabber_ping with no type\n");
+		return;
+	}
+	
 	purple_debug_info("jabber", "jabber_ping_parse\n");
 
-	iq = jabber_iq_new(js, JABBER_IQ_RESULT);
-
-	xmlnode_set_attrib(iq->node, "to", xmlnode_get_attrib(packet, "from") );
+	if (!strcmp(type, "get")) {
+		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT);
 
-	jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
+		xmlnode_set_attrib(iq->node, "to", from);
+		xmlnode_set_attrib(iq->node, "id", id);
 
-	jabber_iq_send(iq);
+		jabber_iq_send(iq);
+	} else if (!strcmp(type, "set")) {
+		/* XXX: error */
+	}
 }
 
 static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet,
-		gpointer data)
+                                  gpointer data)
 {
 	const char *type = xmlnode_get_attrib(packet, "type");
+	const char *from = xmlnode_get_attrib(packet, "from");
 
 	purple_debug_info("jabber", "jabber_ping_result_cb\n");
+
+	if (!from || !strcmp(from, js->user->domain)) {
+		/* If the pong is from our server, treat it as a return from the
+		 * keepalive functions */
+		jabber_keepalive_pong_cb(js);
+	}
+
 	if(type && !strcmp(type, "result")) {
 		purple_debug_info("jabber", "PONG!\n");
 	} else {
@@ -58,15 +83,16 @@
 	}
 }
 
-gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid)
+gboolean jabber_ping_jid(JabberStream *js, const char *jid)
 {
 	JabberIq *iq;
 	xmlnode *ping;
 
 	purple_debug_info("jabber", "jabber_ping_jid\n");
 
-	iq = jabber_iq_new(conv->account->gc->proto_data, JABBER_IQ_GET);
-	xmlnode_set_attrib(iq->node, "to", jid);
+	iq = jabber_iq_new(js, JABBER_IQ_GET);
+	if (jid)
+		xmlnode_set_attrib(iq->node, "to", jid);
 
 	ping = xmlnode_new_child(iq->node, "ping");
 	xmlnode_set_namespace(ping, "urn:xmpp:ping");
@@ -74,7 +100,5 @@
 	jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL);
 	jabber_iq_send(iq);
 
-
-
 	return TRUE;
 }