changeset 29050:ce29013a5f3a

oscar: Fix the parsing code from ichatballooncolors that broke receiving markup in 2.6.2. This also fixes the horrendous AIM Blast markup syntax. Closes #10234.
author Paul Aurich <paul@darkrain42.org>
date Sun, 29 Nov 2009 01:50:36 +0000
parents 23f6f80f45ed
children 39a48c780bcb
files ChangeLog libpurple/protocols/oscar/oscar.c
diffstat 2 files changed, 54 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Nov 28 23:13:55 2009 +0000
+++ b/ChangeLog	Sun Nov 29 01:50:36 2009 +0000
@@ -20,6 +20,7 @@
 	* The simultaneous login account option is respected when using
 	  the clientLogin authentication method.
 	* Fix offline message retrieval (broken in 2.6.3)
+	* Fix handling of markup on some messages (broken in 2.6.2)
 	* Fix SSL when clientLogin is enabled.
 	* Fix sending and receiving Unicode characters in a Direct IM
 
--- a/libpurple/protocols/oscar/oscar.c	Sat Nov 28 23:13:55 2009 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Sun Nov 29 01:50:36 2009 +0000
@@ -2461,42 +2461,81 @@
 	 */
 	if (purple_markup_find_tag("body", tmp, &start, &end, &attribs))
 	{
+		int len;
+		char *tmp2, *body;
 		const char *ichattextcolor, *ichatballooncolor;
-		const char *start2, *end2;
+		const char *slash_body_start, *slash_body_end = NULL; /* </body> */
 		GData *unused;
 
 		/*
 		 * Find the ending </body> so we can strip off the outer <html/>
 		 * and <body/>
 		 */
-		if (purple_markup_find_tag("/body", end + 1, &start2, &end2, &unused))
+		if (purple_markup_find_tag("/body", end + 1, &slash_body_start, &slash_body_end, &unused))
 		{
-			gchar *tmp2;
-			tmp2 = g_strndup(end + 1, (start2 - 1) - (end + 1) + 1);
-			g_free(tmp);
-			tmp = tmp2;
+			body = g_strndup(start, slash_body_end - start + 1);
 			g_datalist_clear(&unused);
 		}
+		else
+		{
+			purple_debug_warning("oscar", "Broken message contains <body> but not </body>!\n");
+			/* Take everything after <body> */
+			body = g_strdup(start);
+		}
 
 		ichattextcolor = g_datalist_get_data(&attribs, "ichattextcolor");
 		if (ichattextcolor != NULL)
 		{
-			gchar *tmp2;
-			tmp2 = g_strdup_printf("<font color=\"%s\">%s</font>", ichattextcolor, tmp);
-			g_free(tmp);
-			tmp = tmp2;
+			tmp2 = g_strdup_printf("<font color=\"%s\">%s</font>", ichattextcolor, body);
+			g_free(body);
+			body = tmp2;
 		}
 
 		ichatballooncolor = g_datalist_get_data(&attribs, "ichatballooncolor");
 		if (ichatballooncolor != NULL)
 		{
-			gchar *tmp2;
-			tmp2 = g_strdup_printf("<font back=\"%s\">%s</font>", ichatballooncolor, tmp);
-			g_free(tmp);
-			tmp = tmp2;
+			tmp2 = g_strdup_printf("<font back=\"%s\">%s</font>", ichatballooncolor, body);
+			g_free(body);
+			body = tmp2;
 		}
 
 		g_datalist_clear(&attribs);
+
+		len = start - tmp;
+		tmp2 = g_strdup_printf("%.*s%s%s", len, tmp, body, slash_body_end ? slash_body_end + 1: "</body>");
+		g_free(tmp);
+		g_free(body);
+
+		tmp = tmp2;
+	}
+
+	/*
+	 * Are there <html/> surrounding tags? If so, strip them out, too.
+	 */
+	if (purple_markup_find_tag("html", tmp, &start, &end, &attribs))
+	{
+		gchar *tmp2;
+		int len;
+
+		g_datalist_clear(&attribs);
+
+		len = start - tmp;
+		tmp2 = g_strdup_printf("%.*s%s", len, tmp, end + 1);
+		g_free(tmp);
+		tmp = tmp2;
+	}
+
+	if (purple_markup_find_tag("/html", tmp, &start, &end, &attribs))
+	{
+		gchar *tmp2;
+		int len;
+
+		g_datalist_clear(&attribs);
+
+		len = start - tmp;
+		tmp2 = g_strdup_printf("%.*s%s", len, tmp, end + 1);
+		g_free(tmp);
+		tmp = tmp2;
 	}
 
 	serv_got_im(gc, userinfo->bn, tmp, flags,