changeset 29961:618c4165d4f8

jabber: Treat the version properly. Granted, consensus among XMPP folks is that bumping the minor would break almost everything, but that's no reason not to be accurate ourselves.
author Paul Aurich <paul@darkrain42.org>
date Tue, 09 Mar 2010 23:09:54 +0000
parents 13f320cde14f
children 32fe87f58d06
files libpurple/protocols/jabber/bosh.c libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/parser.c
diffstat 5 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c	Tue Mar 09 22:44:59 2010 +0000
+++ b/libpurple/protocols/jabber/bosh.c	Tue Mar 09 23:09:54 2010 +0000
@@ -521,7 +521,7 @@
 	}
 
 	if (version) {
-		const char *dot = strstr(version, ".");
+		const char *dot = strchr(version, '.');
 		int major, minor = 0;
 
 		purple_debug_info("jabber", "BOSH connection manager version %s\n", version);
--- a/libpurple/protocols/jabber/buddy.c	Tue Mar 09 22:44:59 2010 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Tue Mar 09 23:09:54 2010 +0000
@@ -1824,7 +1824,8 @@
 	if(!jb)
 		return m;
 
-	if (js->protocol_version == JABBER_PROTO_0_9 && jb != js->user_jb) {
+	if (js->protocol_version.major == 0 && js->protocol_version.minor == 9 &&
+			jb != js->user_jb) {
 		if(jb->invisible & JABBER_INVIS_BUDDY) {
 			act = purple_menu_action_new(_("Un-hide From"),
 			                           PURPLE_CALLBACK(jabber_buddy_make_visible),
--- a/libpurple/protocols/jabber/jabber.c	Tue Mar 09 22:44:59 2010 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue Mar 09 23:09:54 2010 +0000
@@ -870,7 +870,8 @@
 	js->old_length = 0;
 	js->keepalive_timeout = 0;
 	/* Set the default protocol version to 1.0. Overridden in parser.c. */
-	js->protocol_version = JABBER_PROTO_1_0;
+	js->protocol_version.major = 1;
+	js->protocol_version.minor = 0;
 	js->sessions = NULL;
 	js->stun_ip = NULL;
 	js->stun_port = 0;
--- a/libpurple/protocols/jabber/jabber.h	Tue Mar 09 22:44:59 2010 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Tue Mar 09 23:09:54 2010 +0000
@@ -105,9 +105,9 @@
 	xmlParserCtxt *context;
 	xmlnode *current;
 
-	enum {
-		JABBER_PROTO_0_9,
-		JABBER_PROTO_1_0
+	struct {
+		guint8 major;
+		guint8 minor;
 	} protocol_version;
 
 	JabberSaslMech *auth_mech;
--- a/libpurple/protocols/jabber/parser.c	Tue Mar 09 22:44:59 2010 +0000
+++ b/libpurple/protocols/jabber/parser.c	Tue Mar 09 23:09:54 2010 +0000
@@ -44,15 +44,26 @@
 	if(!element_name) {
 		return;
 	} else if(!xmlStrcmp(element_name, (xmlChar*) "stream")) {
-		js->protocol_version = JABBER_PROTO_0_9;
+		js->protocol_version.major = 0;
+		js->protocol_version.minor = 9;
 		for(i=0; i < nb_attributes * 5; i += 5) {
 			int attrib_len = attributes[i+4] - attributes[i+3];
 			char *attrib = g_strndup((gchar *)attributes[i+3], attrib_len);
 
-			if(!xmlStrcmp(attributes[i], (xmlChar*) "version")
-					&& !strcmp(attrib, "1.0")) {
-				js->protocol_version = JABBER_PROTO_1_0;
+			if(!xmlStrcmp(attributes[i], (xmlChar*) "version")) {
+				const char *dot = strchr(attrib, '.');
+
+				js->protocol_version.major = atoi(attrib);
+				js->protocol_version.minor = dot ? atoi(dot + 1) : 0;
 				g_free(attrib);
+
+				/* TODO: Check this against the spec; I'm not sure if the check
+				 * against minor is accurate.
+				 */
+				if (js->protocol_version.major > 1 || js->protocol_version.minor > 0)
+					purple_connection_error_reason(js->gc,
+							PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
+							_("XMPP Version Mismatch"));
 			} else if(!xmlStrcmp(attributes[i], (xmlChar*) "id")) {
 				g_free(js->stream_id);
 				js->stream_id = attrib;
@@ -255,7 +266,8 @@
 		}
 	}
 
-	if (js->protocol_version == JABBER_PROTO_0_9 && !js->gc->disconnect_timeout &&
+	if (js->protocol_version.major == 0 && js->protocol_version.minor == 9 &&
+			!js->gc->disconnect_timeout &&
 			(js->state == JABBER_STREAM_INITIALIZING ||
 			 js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION)) {
 		/*