cpw.darkrain42.xmpp.iq-handlers: d949c128: Make the XMPP keepalive use jabber_ping_...

paul at darkrain42.org paul at darkrain42.org
Tue Feb 3 13:20:42 EST 2009


-----------------------------------------------------------------
Revision: d949c12854ee58512ea6a3b7e12d22624dc6bd73
Ancestor: 0cf0a536882d488833622bcd62f627679d1bba88
Author: paul at darkrain42.org
Date: 2009-02-03T17:39:14
Branch: im.pidgin.cpw.darkrain42.xmpp.iq-handlers
URL: http://d.pidgin.im/viewmtn/revision/info/d949c12854ee58512ea6a3b7e12d22624dc6bd73

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

ChangeLog: 

Make the XMPP keepalive use jabber_ping_jid instead of building it itself.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	cad41bf7f2dadca3ef77f90d44ae139f7dd16d37
+++ libpurple/protocols/jabber/jabber.c	3fcf5a3a71ed8205aa86f1a91b9684ec375820ea
@@ -439,17 +439,11 @@ void jabber_send(JabberStream *js, xmlno
 	g_free(txt);
 }
 
-static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused)
+static gboolean jabber_keepalive_timeout(PurpleConnection *gc)
 {
-	purple_timeout_remove(js->keepalive_timeout);
-	js->keepalive_timeout = -1;
-}
-
-static gboolean jabber_pong_timeout(PurpleConnection *gc)
-{
 	JabberStream *js = gc->proto_data;
 	purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-					_("Ping timeout"));
+	                               _("Ping timeout"));
 	js->keepalive_timeout = -1;
 	return FALSE;
 }
@@ -459,14 +453,9 @@ void jabber_keepalive(PurpleConnection *
 	JabberStream *js = gc->proto_data;
 
 	if (js->keepalive_timeout == -1) {
-		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET);
-		
-		xmlnode *ping = xmlnode_new_child(iq->node, "ping");
-		xmlnode_set_namespace(ping, "urn:xmpp:ping");
-		
-		js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc);
-		jabber_iq_set_callback(iq, jabber_pong_cb, NULL);
-		jabber_iq_send(iq);
+		jabber_ping_jid(js, NULL);
+		js->keepalive_timeout = purple_timeout_add_seconds(120,
+				(GSourceFunc)(jabber_keepalive_timeout), gc);
 	}
 }
 
@@ -2421,10 +2410,16 @@ static PurpleCmdRet jabber_cmd_ping(Purp
 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv,
 		const char *cmd, char **args, char **error, void *data)
 {
+	PurpleAccount *account;
+	PurpleConnection *pc;
+
 	if(!args || !args[0])
 		return PURPLE_CMD_RET_FAILED;
 
-	if(!jabber_ping_jid(conv, args[0])) {
+	account = purple_conversation_get_account(conv);
+	pc = purple_account_get_connection(account);
+
+	if(!jabber_ping_jid(pc->proto_data, args[0])) {
 		*error = g_strdup_printf(_("Unable to ping user %s"), args[0]);
 		return PURPLE_CMD_RET_FAILED;
 	}
============================================================
--- libpurple/protocols/jabber/ping.c	64371688909af8a9ff7fb1d747d1b74393b33a1f
+++ libpurple/protocols/jabber/ping.c	e412dd4726c1517ab22f22a280be7829d08fe12c
@@ -23,12 +23,17 @@
 #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)
 {
@@ -58,11 +63,19 @@ static void jabber_ping_result_cb(Jabber
 }
 
 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 {
@@ -70,15 +83,16 @@ static void jabber_ping_result_cb(Jabber
 	}
 }
 
-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");
@@ -86,7 +100,5 @@ gboolean jabber_ping_jid(PurpleConversat
 	jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL);
 	jabber_iq_send(iq);
 
-
-
 	return TRUE;
 }
============================================================
--- libpurple/protocols/jabber/ping.h	40882a772ad4d66936f6543ed7b4d3dc09ed264c
+++ libpurple/protocols/jabber/ping.h	1d6faea661ed7a6b77368e334563d7a7a6a01eb1
@@ -23,13 +23,9 @@
 #define _PURPLE_JABBER_PING_H_
 
 #include "jabber.h"
-#include "conversation.h"
+#include "xmlnode.h"
 
-void jabber_ping_parse(JabberStream *js,
-						xmlnode *packet);
+void jabber_ping_parse(JabberStream *js, xmlnode *packet);
+gboolean jabber_ping_jid(JabberStream *js, const char *jid);
 
-
-gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid);
-
-
 #endif /* _PURPLE_JABBER_PING_H_ */


More information about the Commits mailing list