/soc/2015/koosha/main: c10fa2e7a6ba: XEP-0198: initial parser fo...

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


Changeset: c10fa2e7a6bab5b1fe521e83a471e5387af48320
Author:	 Koosha Khajehmoogahi <koosha at posteo.de>
Date:	 2015-08-10 01:26 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/koosha/main/rev/c10fa2e7a6ba

Description:

XEP-0198: initial parser for <enabled> packets

diffstat:

 libpurple/protocols/jabber/jabber.c |  38 +++++++++++++++++++++++++++++++++++++
 libpurple/protocols/jabber/jabber.h |   1 +
 2 files changed, 39 insertions(+), 0 deletions(-)

diffs (80 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
@@ -138,6 +138,7 @@ jabber_session_initialized_cb(JabberStre
 
 static void jabber_session_init(JabberStream *js)
 {
+	char *sm;
 	JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
 	PurpleXmlNode *session;
 
@@ -147,6 +148,13 @@ static void jabber_session_init(JabberSt
 	purple_xmlnode_set_namespace(session, NS_XMPP_SESSION);
 
 	jabber_iq_send(iq);
+
+	/* Enable stream management with resumptions */
+	if (js->server_caps & JABBER_CAP_SM) {
+		sm = g_strdup_printf("<enable xmlns='" NS_XMPP_SM "' resume='true' />");
+		jabber_send_raw(js, sm, -1);
+		g_free(sm);
+	}
 }
 
 static void jabber_bind_result_cb(JabberStream *js, const char *from,
@@ -340,6 +348,34 @@ static void jabber_stream_handle_error(J
 	g_free(msg);
 }
 
+/*
+ * TODO: parse the 'location' attribute as well
+ */
+void jabber_stream_management_parse(JabberStream *js, PurpleXmlNode *packet)
+{
+	const char *resume, *id, *max;
+	PurpleAccount *account;
+	gboolean resume_enabled;
+	resume = purple_xmlnode_get_attrib(packet, "resume");
+	account = purple_connection_get_account(js->gc);
+
+	resume_enabled = resume && (purple_strequal(resume, "1") || purple_strequal(resume, "true"));
+
+	purple_debug_info( "jabber", "Stream management %s resumption is enabled.\n",
+				resume_enabled ? "with" : "without" );
+
+	if (resume_enabled) {
+		id = purple_xmlnode_get_attrib(packet, "id");
+		purple_account_set_string(account, "sm_id", id);
+
+		/* max means the maximum possible resumption time in seconds
+		 * supported by server */
+		max = purple_xmlnode_get_attrib(packet, "max");
+		if (max)
+			purple_account_set_string(account, "sm_max", max);
+	}
+}
+
 static void tls_init(JabberStream *js);
 
 void jabber_process_packet(JabberStream *js, PurpleXmlNode **packet)
@@ -362,6 +398,8 @@ void jabber_process_packet(JabberStream 
 		jabber_presence_parse(js, *packet);
 	} else if (purple_strequal(name, "message")) {
 		jabber_message_parse(js, *packet);
+	} else if (purple_strequal(name, "enabled") && purple_strequal(xmlns, NS_XMPP_SM)) {
+		jabber_stream_management_parse(js, *packet);
 	} else if (purple_strequal(xmlns, NS_XMPP_STREAMS)) {
 		if (g_str_equal(name, "features"))
 			jabber_stream_features_parse(js, *packet);
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
@@ -342,6 +342,7 @@ extern GList *jabber_identities;
 G_MODULE_EXPORT GType jabber_protocol_get_type(void);
 
 void jabber_stream_features_parse(JabberStream *js, PurpleXmlNode *packet);
+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_raw(JabberStream *js, const char *data, int len);



More information about the Commits mailing list