pidgin: 1e788884: jabber: Treat the version properly.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Mar 9 20:06:17 EST 2010


-----------------------------------------------------------------
Revision: 1e788884681d69417de33d28d010a08ffa88bd9d
Ancestor: 505674b244fa23228640a82d339318c5587b8397
Author: darkrain42 at pidgin.im
Date: 2010-03-09T23:09:54
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1e788884681d69417de33d28d010a08ffa88bd9d

Modified 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

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	4d708e04e0b7835167e16055dd9d3dac6545be36
+++ libpurple/protocols/jabber/bosh.c	25556796bdf49f7ae7fc5743f962a2cbdbd1189a
@@ -521,7 +521,7 @@ static void boot_response_cb(PurpleBOSHC
 	}
 
 	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);
============================================================
--- libpurple/protocols/jabber/buddy.c	e3293d5f903f1046066b48ed47257c83f53a520a
+++ libpurple/protocols/jabber/buddy.c	c6d13a010fa20db9a6447694c76544f1f7f080fd
@@ -1824,7 +1824,8 @@ static GList *jabber_buddy_menu(PurpleBu
 	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),
============================================================
--- libpurple/protocols/jabber/jabber.c	edd80ebd2f05028f86941f3c478d47608ce2c46f
+++ libpurple/protocols/jabber/jabber.c	d594709af5c36b8b29c8cc0316eed014981caeb8
@@ -870,7 +870,8 @@ jabber_stream_new(PurpleAccount *account
 	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;
============================================================
--- libpurple/protocols/jabber/jabber.h	5327fd1d04f5c286717593a06f25b4a9d3faee65
+++ libpurple/protocols/jabber/jabber.h	32b19839964f9c88391314585dc9b0d919bb9d87
@@ -105,9 +105,9 @@ struct _JabberStream
 	xmlParserCtxt *context;
 	xmlnode *current;
 
-	enum {
-		JABBER_PROTO_0_9,
-		JABBER_PROTO_1_0
+	struct {
+		guint8 major;
+		guint8 minor;
 	} protocol_version;
 
 	JabberSaslMech *auth_mech;
============================================================
--- libpurple/protocols/jabber/parser.c	58c4da2571d7be0486bbf851b13ca7c204c05469
+++ libpurple/protocols/jabber/parser.c	6a1e8e4083ad4c58c7ef6e06e502eefa9c0e22b0
@@ -44,15 +44,26 @@ jabber_parser_element_start_libxml(void 
 	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 @@ void jabber_parser_process(JabberStream 
 		}
 	}
 
-	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)) {
 		/*


More information about the Commits mailing list