# HG changeset patch # User Ethan Blanton # Date 1074739453 0 # Node ID da57fb60680aa0e0979607550a9ca05475267a51 # Parent 3273ff25b645556d15d635a3fb6b3400921a684b [gaim-migrate @ 8875] IRC quoting for HTML entities by Daniel Atallah committer: Tailor Script diff -r 3273ff25b645 -r da57fb60680a src/protocols/irc/irc.c --- a/src/protocols/irc/irc.c Wed Jan 21 20:39:00 2004 +0000 +++ b/src/protocols/irc/irc.c Thu Jan 22 02:44:13 2004 +0000 @@ -428,6 +428,7 @@ struct irc_conn *irc = gc->proto_data; GaimConversation *convo = gaim_find_chat(gc, id); const char *args[2]; + char *tmp; if (!convo) { gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); @@ -442,7 +443,10 @@ args[1] = what; irc_cmd_privmsg(irc, "msg", NULL, args); - serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, what, time(NULL)); + + tmp = gaim_escape_html(what); + serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL)); + g_free(tmp); return 0; } diff -r 3273ff25b645 -r da57fb60680a src/protocols/irc/msgs.c --- a/src/protocols/irc/msgs.c Wed Jan 21 20:39:00 2004 +0000 +++ b/src/protocols/irc/msgs.c Thu Jan 22 02:44:13 2004 +0000 @@ -798,8 +798,13 @@ g_free(nick); return; } - msg = irc_mirc2html(tmp); + + msg = gaim_escape_html(tmp); g_free(tmp); + + tmp = irc_mirc2html(msg); + g_free(msg); + msg = tmp; if (notice) { tmp = g_strdup_printf("(notice) %s", msg); g_free(msg); diff -r 3273ff25b645 -r da57fb60680a src/util.c --- a/src/util.c Wed Jan 21 20:39:00 2004 +0000 +++ b/src/util.c Thu Jan 22 02:44:13 2004 +0000 @@ -1317,6 +1317,39 @@ return tmp; } +char * +gaim_escape_html(const char *html) { + char *escaped = NULL; + + if (html != NULL) { + const char *c = html; + GString *ret = g_string_new(""); + while (*c) { + switch(*c) { + case '&': + ret = g_string_append(ret, "&"); + break; + case '<': + ret = g_string_append(ret, "<"); + break; + case '>': + ret = g_string_append(ret, ">"); + break; + case '"': + ret = g_string_append(ret, """); + break; + default: + ret = g_string_append_c(ret, *c); + } + c++; + } + + escaped = ret->str; + g_string_free(ret, FALSE); + } + return escaped; + +} /************************************************************************** * Path/Filename Functions diff -r 3273ff25b645 -r da57fb60680a src/util.h --- a/src/util.h Wed Jan 21 20:39:00 2004 +0000 +++ b/src/util.h Thu Jan 22 02:44:13 2004 +0000 @@ -266,6 +266,16 @@ */ char *gaim_markup_linkify(const char *str); +/** + * Escapes HTML special characters to be displayed literally. + * For example '&' is replaced by "&" and so on + * + * @param html The string in which to escape any HTML special characters + * + * @return the text with HTML special characters escaped + */ +char *gaim_escape_html(const char *html); + /*@}*/