# HG changeset patch # User Paul Aurich # Date 1268375115 0 # Node ID 6e598ca344b3c2a2c0b2e7c05c224072f1ce2551 # Parent f5f3c5134eb73f7fa9c9323561111e4036f0878a jabber: Clear the stream header when restarting a stream, and be much stricter about the first tag in a stream. diff -r f5f3c5134eb7 -r 6e598ca344b3 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Fri Mar 12 06:16:43 2010 +0000 +++ b/libpurple/protocols/jabber/jabber.c Fri Mar 12 06:25:15 2010 +0000 @@ -86,6 +86,11 @@ { char *open_stream; + if (js->stream_id) { + g_free(js->stream_id); + js->stream_id = NULL; + } + open_stream = g_strdup_printf(" tag. This being NULL is treated + * as a special condition in the parsing code (signifying the next + * stanza started is an opening stream tag), and its being missing on + * the stream header is treated as a fatal error. + */ char *stream_id; JabberStreamState state; diff -r f5f3c5134eb7 -r 6e598ca344b3 libpurple/protocols/jabber/parser.c --- a/libpurple/protocols/jabber/parser.c Fri Mar 12 06:16:43 2010 +0000 +++ b/libpurple/protocols/jabber/parser.c Fri Mar 12 06:25:15 2010 +0000 @@ -43,10 +43,25 @@ if(!element_name) { return; - } else if(!xmlStrcmp(element_name, (xmlChar*) "stream")) { + } else if (js->stream_id == NULL) { + /* Sanity checking! */ + if (0 != xmlStrcmp(element_name, (xmlChar *) "stream") || + 0 != xmlStrcmp(namespace, (xmlChar *) NS_XMPP_STREAMS)) { + /* We were expecting a opening stanza, but + * didn't get it. Bad! + */ + purple_debug_error("jabber", "Expecting stream header, got %s with " + "xmlns %s\n", element_name, namespace); + purple_connection_error_reason(js->gc, + PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, + _("XMPP stream header missing")); + return; + } + js->protocol_version.major = 0; js->protocol_version.minor = 9; - for(i=0; i < nb_attributes * 5; i += 5) { + + 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); @@ -56,11 +71,14 @@ js->protocol_version.major = atoi(attrib); js->protocol_version.minor = dot ? atoi(dot + 1) : 0; - if (js->protocol_version.major > 1) + if (js->protocol_version.major > 1) { /* TODO: Send error */ purple_connection_error_reason(js->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, _("XMPP Version Mismatch")); + g_free(attrib); + return; + } if (js->protocol_version.major == 0 && js->protocol_version.minor != 9) { purple_debug_warning("jabber", "Treating version %s as 0.9 for backward " @@ -74,6 +92,11 @@ g_free(attrib); } } + + if (js->stream_id == NULL) + purple_connection_error_reason(js->gc, + PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, + _("XMPP stream missing ID")); } else { if(js->current)