/soc/2015/koosha/main: db5b4c0dfb74: Send acks to server when re...

Koosha Khajehmoogahi koosha at posteo.de
Mon Aug 10 10:17:34 EDT 2015


Changeset: db5b4c0dfb74dc93dbffd1432563ffb8de3ee2f9
Author:	 Koosha Khajehmoogahi <koosha at posteo.de>
Date:	 2015-08-10 16:04 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/koosha/main/rev/db5b4c0dfb74

Description:

Send acks to server when receiving requests for acks

diffstat:

 libpurple/protocols/jabber/jabber.c |  31 ++++++++++++++++++++++++++++++-
 libpurple/protocols/jabber/jabber.h |   3 +++
 2 files changed, 33 insertions(+), 1 deletions(-)

diffs (83 lines):

diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -392,6 +392,18 @@ void jabber_process_packet(JabberStream 
 	name = (*packet)->name;
 	xmlns = purple_xmlnode_get_namespace(*packet);
 
+	/* Count received stanzas to include when acking
+	 * via <a/> (stream management) to the server */
+	if (purple_strequal(name, "iq") ||
+	    purple_strequal(name, "presence") ||
+	    purple_strequal(name, "message"))
+	{
+		if (G_MAXUINT32 == js->stanzas_recvd)
+			js->stanzas_recvd = 0;
+		else
+			js->stanzas_recvd++;
+	}
+
 	if (purple_strequal(name, "iq")) {
 		jabber_iq_parse(js, *packet);
 	} else if (purple_strequal(name, "presence")) {
@@ -424,8 +436,10 @@ void jabber_process_packet(JabberStream 
 				tls_init(js);
 			/* TODO: Handle <failure/>, I guess? */
 		}
+	} else if (purple_strequal(name, "r") && purple_strequal(xmlns, NS_XMPP_SM)) {
+		jabber_send_stream_ack(js);
 	} else {
-		purple_debug_warning("jabber", "Unknown packet: %s\n", (*packet)->name);
+		purple_debug_warning("jabber", "Unknown packet: %s\n", name);
 	}
 }
 
@@ -667,6 +681,20 @@ void jabber_send_signal_cb(PurpleConnect
 	g_free(txt);
 }
 
+void jabber_send_stream_ack(JabberStream *js)
+{
+	PurpleXmlNode *ack = purple_xmlnode_new("a");
+	gchar *h = g_strdup_printf("%d", js->stanzas_recvd);
+	purple_xmlnode_set_attrib(ack, "h", h);
+	purple_xmlnode_set_namespace(ack, NS_XMPP_SM);
+
+	purple_debug_info("jabber", "Sending ack (<a/>) with h='%d'\n", js->stanzas_recvd);
+
+	jabber_send(js, ack);
+	g_free(h);
+	purple_xmlnode_free(ack);
+}
+
 void jabber_send(JabberStream *js, PurpleXmlNode *packet)
 {
 	purple_signal_emit(purple_connection_get_protocol(js->gc), "jabber-sending-xmlnode", js->gc, &packet);
@@ -1049,6 +1077,7 @@ jabber_stream_new(PurpleAccount *account
 	js->protocol_version.major = 1;
 	js->protocol_version.minor = 0;
 	js->sessions = NULL;
+	js->stanzas_recvd = 0;
 	js->stun_ip = NULL;
 	js->stun_port = 0;
 	js->stun_query = NULL;
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -195,6 +195,8 @@ struct _JabberStream
 	time_t idle;
 	time_t old_idle;
 
+	guint32 stanzas_recvd;
+
 	/** When we last pinged the server, so we don't ping more
 	 *  often than once every minute.
 	 */
@@ -345,6 +347,7 @@ void jabber_stream_features_parse(Jabber
 void jabber_stream_management_parse(JabberStream *js, PurpleXmlNode *packet);
 void jabber_process_packet(JabberStream *js, PurpleXmlNode **packet);
 void jabber_send(JabberStream *js, PurpleXmlNode *data);
+void jabber_send_stream_ack(JabberStream *js);
 void jabber_send_raw(JabberStream *js, const char *data, int len);
 void jabber_send_signal_cb(PurpleConnection *pc, PurpleXmlNode **packet,
                            gpointer unused);



More information about the Commits mailing list