Mercurial > pidgin.yaz
changeset 8163:da57fb60680a
[gaim-migrate @ 8875]
IRC quoting for HTML entities by Daniel Atallah
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Thu, 22 Jan 2004 02:44:13 +0000 |
parents | 3273ff25b645 |
children | 2c7b0e44c565 |
files | src/protocols/irc/irc.c src/protocols/irc/msgs.c src/util.c src/util.h |
diffstat | 4 files changed, 54 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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);
--- 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
--- 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); + /*@}*/