diff libpurple/protocols/jabber/ping.c @ 26569:bc7fac8e2f79

propagate from branch 'im.pidgin.pidgin' (head f144c6bda9daf701aa891c875fce7a4dedd611ae) to branch 'im.pidgin.cpw.darkrain42.xmpp.bosh' (head 8b60514f2b44295e87ee3587669aec5059556149)
author Paul Aurich <paul@darkrain42.org>
date Sun, 05 Apr 2009 21:13:10 +0000
parents ae41d8e827e3
children d00a8111e479
line wrap: on
line diff
--- a/libpurple/protocols/jabber/ping.c	Sun Apr 05 03:25:00 2009 +0000
+++ b/libpurple/protocols/jabber/ping.c	Sun Apr 05 21:13:10 2009 +0000
@@ -23,50 +23,63 @@
 #include "internal.h"
 
 #include "debug.h"
-#include "xmlnode.h"
 
 #include "jabber.h"
 #include "ping.h"
 #include "iq.h"
 
-void
-jabber_ping_parse(JabberStream *js, xmlnode *packet)
+static void jabber_keepalive_pong_cb(JabberStream *js)
 {
-	JabberIq *iq;
-
-	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") );
-
-	jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
-
-	jabber_iq_send(iq);
+	purple_timeout_remove(js->keepalive_timeout);
+	js->keepalive_timeout = -1;
 }
 
-static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet,
-		gpointer data)
+void
+jabber_ping_parse(JabberStream *js, const char *from,
+                  JabberIqType type, const char *id, xmlnode *ping)
 {
-	const char *type = xmlnode_get_attrib(packet, "type");
+	if (type == JABBER_IQ_GET) {
+		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT);
+
+		if (from)
+			xmlnode_set_attrib(iq->node, "to", from);
+		xmlnode_set_attrib(iq->node, "id", id);
+
+		jabber_iq_send(iq);
+	} else if (type == JABBER_IQ_SET) {
+		/* XXX: error */
+	}
+}
 
-	purple_debug_info("jabber", "jabber_ping_result_cb\n");
-	if(type && !strcmp(type, "result")) {
+static void jabber_ping_result_cb(JabberStream *js, const char *from,
+                                  JabberIqType type, const char *id,
+                                  xmlnode *packet, gpointer data)
+{
+	char *own_bare_jid = g_strdup_printf("%s@%s", js->user->node,
+	                                     js->user->domain);
+
+	if (!from || !strcmp(from, own_bare_jid)) {
+		/* If the pong is from our bare JID, treat it as a return from the
+		 * keepalive functions */
+		jabber_keepalive_pong_cb(js);
+	}
+	g_free(own_bare_jid);
+
+	if (type == JABBER_IQ_RESULT) {
 		purple_debug_info("jabber", "PONG!\n");
 	} else {
 		purple_debug_info("jabber", "(not supported)\n");
 	}
 }
 
-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 +87,5 @@
 	jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL);
 	jabber_iq_send(iq);
 
-
-
 	return TRUE;
 }