changeset 8529:2f505651ac03

[gaim-migrate @ 9268] This strips mIRC color and formatting codes from topics and provides a generic function for stripping mirc color codes and returning plain text (irc_mirc2txt()). This should fix Bug #923672. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Tue, 30 Mar 2004 17:44:40 +0000
parents a48da599fd75
children 45e8c6cbd4a5
files src/protocols/irc/irc.h src/protocols/irc/msgs.c src/protocols/irc/parse.c
diffstat 3 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/irc/irc.h	Tue Mar 30 15:45:52 2004 +0000
+++ b/src/protocols/irc/irc.h	Tue Mar 30 17:44:40 2004 +0000
@@ -84,6 +84,7 @@
 gboolean irc_blist_timeout(struct irc_conn *irc);
 
 char *irc_mirc2html(const char *string);
+char *irc_mirc2txt(const char *string);
 
 void irc_msg_table_build(struct irc_conn *irc);
 void irc_parse_msg(struct irc_conn *irc, char *input);
--- a/src/protocols/irc/msgs.c	Tue Mar 30 15:45:52 2004 +0000
+++ b/src/protocols/irc/msgs.c	Tue Mar 30 17:44:40 2004 +0000
@@ -260,10 +260,10 @@
 
 	if (!strcmp(name, "topic")) {
 		chan = args[0];
-		topic = args[1];
+		topic = irc_mirc2txt (args[1]);
 	} else {
 		chan = args[1];
-		topic = args[2];
+		topic = irc_mirc2txt (args[2]);
 	}
 
 	convo = gaim_find_conversation_with_account(chan, irc->account);
@@ -285,6 +285,7 @@
 		g_free(msg);
 	}
 	g_free(tmp);
+	g_free(topic);
 }
 
 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args)
--- a/src/protocols/irc/parse.c	Tue Mar 30 15:45:52 2004 +0000
+++ b/src/protocols/irc/parse.c	Tue Mar 30 17:44:40 2004 +0000
@@ -35,8 +35,6 @@
 static char *irc_send_convert(struct irc_conn *irc, const char *string);
 static char *irc_recv_convert(struct irc_conn *irc, const char *string);
 
-char *irc_mirc2html(const char *string);
-
 static void irc_parse_error_cb(struct irc_conn *irc, char *input);
 
 static char *irc_mirc_colors[16] = {
@@ -269,6 +267,28 @@
 	return g_string_free(decoded, FALSE);
 }
 
+char *irc_mirc2txt (const char *string)
+{
+	char *result = g_strdup (string);
+	int i, j;
+
+	for (i = 0, j = 0; result[i]; i++) {
+		switch (result[i]) {
+		case '\002':
+		case '\003':
+		case '\007':
+		case '\017':
+		case '\026':
+		case '\037':
+			continue;
+		default:
+			result[j++] = result[i];
+		}
+	}
+	result[i] = '\0';
+        return result;
+}
+
 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice)
 {
 	GaimConnection *gc;