changeset 6358:8ba58b296cc1

[gaim-migrate @ 6862] This should fix a problem I encountered when I realized again that Qt sucks and likes to crash when I have certain tags not closed. The format string conversion code in MSN was taken from the old MSN prpl, and that code didn't close tags. This should fix that problem. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 03 Aug 2003 02:16:15 +0000
parents 1fa4410d2e13
children dfde69e105ae
files src/protocols/msn/switchboard.c src/protocols/msn/utils.c src/protocols/msn/utils.h
diffstat 3 files changed, 38 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/switchboard.c	Sat Aug 02 15:27:00 2003 +0000
+++ b/src/protocols/msn/switchboard.c	Sun Aug 03 02:16:15 2003 +0000
@@ -293,7 +293,6 @@
 	MsnSwitchBoard *swboard = servconn->data;
 	char *body;
 	const char *value;
-	char *format;
 	int flags = 0;
 
 	body = g_strdup(msn_message_get_body(msg));
@@ -309,9 +308,14 @@
 	}
 
 	if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) {
-		format = msn_parse_format(value);
+		char *pre_format, *post_format;
+
+		msn_parse_format(value, &pre_format, &post_format);
 
-		body = g_strdup_printf("%s%s", format, body);
+		body = g_strdup_printf("%s%s%s", pre_format, body, post_format);
+
+		g_free(pre_format);
+		g_free(post_format);
 	}
 
 	if (swboard->chat != NULL)
--- a/src/protocols/msn/utils.c	Sat Aug 02 15:27:00 2003 +0000
+++ b/src/protocols/msn/utils.c	Sun Aug 03 02:16:15 2003 +0000
@@ -80,33 +80,38 @@
 	return buf;
 }
 
-char *
-msn_parse_format(const char *mime)
+void
+msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
 {
 	char *cur;
-	GString *ret = g_string_new(NULL);
+	GString *pre  = g_string_new(NULL);
+	GString *post = g_string_new(NULL);
 	unsigned int colors[3];
 
+	if (pre_ret  != NULL) *pre_ret  = NULL;
+	if (post_ret != NULL) *post_ret = NULL;
+
 	cur = strstr(mime, "FN=");
 
 	if (cur && (*(cur = cur + 3) != ';')) {
-		ret = g_string_append(ret, "<FONT FACE=\"");
+		pre = g_string_append(pre, "<FONT FACE=\"");
 
 		while (*cur && *cur != ';') {
-			ret = g_string_append_c(ret, *cur);
+			pre = g_string_append_c(pre, *cur);
 			cur++;
 		}
 
-		ret = g_string_append(ret, "\">");
+		pre = g_string_append(pre, "\">");
+		post = g_string_prepend(post, "</FONT>");
 	}
-	
+
 	cur = strstr(mime, "EF=");
 
 	if (cur && (*(cur = cur + 3) != ';')) {
 		while (*cur && *cur != ';') {
-			ret = g_string_append_c(ret, '<');
-			ret = g_string_append_c(ret, *cur);
-			ret = g_string_append_c(ret, '>');
+			pre = g_string_append_c(pre, '<');
+			pre = g_string_append_c(pre, *cur);
+			pre = g_string_append_c(pre, '>');
 			cur++;
 		}
 	}
@@ -136,12 +141,20 @@
 					   "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">",
 					   colors[2], colors[1], colors[0]);
 
-			ret = g_string_append(ret, tag);
+			pre = g_string_append(pre, tag);
+			post = g_string_prepend(post, "</FONT>");
 		}
 	}
 
-	cur = msn_url_decode(ret->str);
-	g_string_free(ret, TRUE);
+	cur = msn_url_decode(pre->str);
+	g_string_free(pre, TRUE);
+
+	if (pre_ret != NULL)
+		*pre_ret = cur;
 
-	return cur;
+	cur = msn_url_decode(post->str);
+	g_string_free(post, TRUE);
+
+	if (post_ret != NULL)
+		*post_ret = cur;
 }
--- a/src/protocols/msn/utils.h	Sat Aug 02 15:27:00 2003 +0000
+++ b/src/protocols/msn/utils.h	Sun Aug 03 02:16:15 2003 +0000
@@ -47,10 +47,12 @@
 /**
  * Parses the MSN message formatting into a format compatible with Gaim.
  *
- * @param mime The mime header with the formatting.
+ * @param mime     The mime header with the formatting.
+ * @param pre_ret  The returned prefix string.
+ * @param post_ret The returned postfix string.
  *
  * @return The new message.
  */
-char *msn_parse_format(const char *mime);
+void msn_parse_format(const char *mime, char **pre_ret, char **post_ret);
 
 #endif /* _MSN_UTILS_H_ */