/soc/2015/koosha/main: 41eda68a595b: count the number of stanzas...

Koosha Khajehmoogahi koosha at posteo.de
Mon Aug 10 13:38:24 EDT 2015


Changeset: 41eda68a595b617208805525bad5e572641f4049
Author:	 Koosha Khajehmoogahi <koosha at posteo.de>
Date:	 2015-08-10 19:35 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/koosha/main/rev/41eda68a595b

Description:

count the number of stanzas sent after enabling stream management

diffstat:

 libpurple/protocols/jabber/jabber.c |  17 ++++++++++++++++-
 libpurple/protocols/jabber/jabber.h |   2 ++
 2 files changed, 18 insertions(+), 1 deletions(-)

diffs (54 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
@@ -154,8 +154,9 @@ static void jabber_session_init(JabberSt
 		sm = g_strdup_printf("<enable xmlns='" NS_XMPP_SM "' resume='true' />");
 		jabber_send_raw(js, sm, -1);
 		g_free(sm);
-		/* From now on, count the number of stanzas received */
+		/* From now on, count the number of stanzas sent and received */
 		js->stanzas_recvd = 0;
+		js->stanzas_sent  = 0;
 	}
 }
 
@@ -703,6 +704,19 @@ void jabber_send_stream_ack(JabberStream
 
 void jabber_send(JabberStream *js, PurpleXmlNode *packet)
 {
+	const char *name = packet->name;
+	if (js->server_caps & JABBER_CAP_SM) {
+		if (purple_strequal(name, "message") ||
+		    purple_strequal(name, "presence") ||
+		    purple_strequal(name, "iq"))
+		{
+			if (G_UNLIKELY(G_MAXUINT32 == js->stanzas_sent))
+				js->stanzas_sent = 0;
+			else
+				js->stanzas_sent++;
+		}
+	}
+
 	purple_signal_emit(purple_connection_get_protocol(js->gc), "jabber-sending-xmlnode", js->gc, &packet);
 }
 
@@ -1084,6 +1098,7 @@ jabber_stream_new(PurpleAccount *account
 	js->protocol_version.minor = 0;
 	js->sessions = NULL;
 	js->has_sm = FALSE;
+	js->stanzas_sent = 0;
 	js->stanzas_recvd = 0;
 	js->stun_ip = NULL;
 	js->stun_port = 0;
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
@@ -197,6 +197,8 @@ struct _JabberStream
 
 	/* Whether stream management is enabled or not */
 	gboolean has_sm;
+	/* Number of stanzas sent and received after enabling stream management */
+	guint32 stanzas_sent;
 	guint32 stanzas_recvd;
 
 	/** When we last pinged the server, so we don't ping more



More information about the Commits mailing list