pidgin: d34a1589: Feed a fake </stream:stream> to the XMPP..

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sat Apr 25 21:50:48 EDT 2009


-----------------------------------------------------------------
Revision: d34a15898cacf017df9190ca02741880be8dd940
Ancestor: 941a367b55f4c8881ae4cfc3f70c346d574d9af5
Author: darkrain42 at pidgin.im
Date: 2009-04-26T00:22:21
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d34a15898cacf017df9190ca02741880be8dd940

Modified files:
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/parser.c
        libpurple/protocols/jabber/parser.h

ChangeLog: 

Feed a fake </stream:stream> to the XMPP parser to silence warnings.

Upgrading to TLS and disconnecting should no longer emit
	'Extra content at the end of the document'

References #8830.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	02f9cfa39d6aaa884135867205634260064cc546
+++ libpurple/protocols/jabber/jabber.c	5e95536dd9b4bbda6dd99a741d89765b2fb7355b
@@ -79,6 +79,10 @@ static void jabber_stream_init(JabberStr
 						  "xmlns:stream='http://etherx.jabber.org/streams' "
 						  "version='1.0'>",
 						  js->user->domain);
+	if (js->reinit)
+		/* Close down the current stream to keep the XML parser happy */
+		jabber_parser_close_stream(js);
+
 	/* setup the parser fresh for each stream */
 	jabber_parser_setup(js);
 	jabber_send_raw(js, open_stream, -1);
@@ -628,6 +632,9 @@ static void tls_init(JabberStream *js)
 
 static void tls_init(JabberStream *js)
 {
+	/* Close down the current stream to keep the XML parser happy */
+	jabber_parser_close_stream(js);
+
 	purple_input_remove(js->gc->inpa);
 	js->gc->inpa = 0;
 	js->gsc = purple_ssl_connect_with_host_fd(js->gc->account, js->fd,
@@ -1335,6 +1342,16 @@ void jabber_close(PurpleConnection *gc)
 	if (!gc->disconnect_timeout)
 		jabber_send_raw(js, "</stream:stream>", -1);
 
+	if (!purple_account_get_current_error(purple_connection_get_account(gc))) {
+		/*
+		 * The common case is user-triggered, so we never receive a
+		 * </stream:stream> from the server when disconnecting, so silence the
+		 * parser's warnings. On errors, though, the server terminated the
+		 * connection, so we should have received a real </stream:stream>.
+		 */
+		jabber_parser_close_stream(js);
+	}
+
 	if (js->srv_query_data)
 		purple_srv_cancel(js->srv_query_data);
 
============================================================
--- libpurple/protocols/jabber/parser.c	157f47562332dbe377dbbb01a4488d20203c96e8
+++ libpurple/protocols/jabber/parser.c	1d02d69d0ec9be3e0e0c53d3321660bc38b2c914
@@ -207,6 +207,12 @@ jabber_parser_setup(JabberStream *js)
 	jabber_parser_free(js);
 }
 
+void
+jabber_parser_close_stream(JabberStream *js)
+{
+	xmlParseChunk(js->context, "</stream:stream>", 16 /* length */, 0);
+}
+
 void jabber_parser_free(JabberStream *js) {
 	if (js->context) {
 		xmlParseChunk(js->context, NULL,0,1);
============================================================
--- libpurple/protocols/jabber/parser.h	c526f48b9ac2937da268256ea33ef50693fcaacc
+++ libpurple/protocols/jabber/parser.h	2705491463809dd37bce24fd1404ee4c0011ff2f
@@ -25,6 +25,7 @@ void jabber_parser_setup(JabberStream *j
 #include "jabber.h"
 
 void jabber_parser_setup(JabberStream *js);
+void jabber_parser_close_stream(JabberStream *js);
 void jabber_parser_free(JabberStream *js);
 void jabber_parser_process(JabberStream *js, const char *buf, int len);
 


More information about the Commits mailing list