changeset 26767:90d5e3b94a37

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.
author Paul Aurich <paul@darkrain42.org>
date Sun, 26 Apr 2009 00:22:21 +0000
parents 06da00c70eae
children 17379effc417 42bff519973b
files libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/parser.c libpurple/protocols/jabber/parser.h
diffstat 3 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Sun Apr 26 00:06:30 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sun Apr 26 00:22:21 2009 +0000
@@ -79,6 +79,10 @@
 						  "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)
 {
+	/* 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 @@
 	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);
 
--- a/libpurple/protocols/jabber/parser.c	Sun Apr 26 00:06:30 2009 +0000
+++ b/libpurple/protocols/jabber/parser.c	Sun Apr 26 00:22:21 2009 +0000
@@ -207,6 +207,12 @@
 	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);
--- a/libpurple/protocols/jabber/parser.h	Sun Apr 26 00:06:30 2009 +0000
+++ b/libpurple/protocols/jabber/parser.h	Sun Apr 26 00:22:21 2009 +0000
@@ -25,6 +25,7 @@
 #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);