Mercurial > pidgin.yaz
changeset 5110:496ea7c1b77b
[gaim-migrate @ 5473]
it dawned on me that since this function is so good at validating html, it
might be pretty good at stripping html. so now we use it instead of
strip_html and jabber messages don't get stripped of valid < and > characters
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 11 Apr 2003 08:09:21 +0000 |
parents | 145587c11207 |
children | a262ecfd83bb |
files | src/gaim.h src/html.c src/protocols/jabber/jabber.c |
diffstat | 3 files changed, 30 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gaim.h Fri Apr 11 07:49:15 2003 +0000 +++ b/src/gaim.h Fri Apr 11 08:09:21 2003 +0000 @@ -371,7 +371,7 @@ extern void grab_url(char *, gboolean, void (*callback)(gpointer, char *, unsigned long), gpointer); extern gchar *strip_html(const gchar *); -extern char *html_to_xhtml(const char *); +extern void html_to_xhtml(const char *, char **, char **); struct g_url *parse_url(char *url); /* Functions in idle.c */
--- a/src/html.c Fri Apr 11 07:49:15 2003 +0000 +++ b/src/html.c Fri Apr 11 08:09:21 2003 +0000 @@ -344,6 +344,7 @@ c = p + 1; \ } else { \ xhtml = g_string_append(xhtml, "<"); \ + plain = g_string_append_c(plain, '<'); \ } \ continue; \ } \ @@ -357,29 +358,36 @@ pt->src_tag = x; \ pt->dest_tag = y; \ tags = g_list_prepend(tags, pt); \ + xhtml = g_string_append_c(xhtml, '>'); \ + } else { \ + xhtml = g_string_append(xhtml, "/>");\ } \ + c = strchr(c, '>') + 1; \ continue; \ } #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) -char *html_to_xhtml(const char *html) { +void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) { GString *xhtml = g_string_new(""); + GString *plain = g_string_new(""); GList *tags = NULL, *tag; const char *q = NULL, *c = html; - char *ret; while(*c) { if(!q && (*c == '\"' || *c == '\'')) { q = c; xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } else if(q) { if(*c == *q) { q = NULL; } else if(*c == '\\') { xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } else if(*c == '<') { if(*(c+1) == '/') { /* closing tag */ @@ -407,6 +415,7 @@ /* we tried to close a tag we never opened! escape it * and move on */ xhtml = g_string_append(xhtml, "<"); + plain = g_string_append_c(plain, '<'); c++; } } else { /* opening tag */ @@ -572,10 +581,12 @@ } xhtml = g_string_append(xhtml, "<"); + plain = g_string_append_c(plain, '<'); c++; } } else { xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } } @@ -585,7 +596,10 @@ tag = tag->next; } g_list_free(tags); - ret = g_strdup(xhtml->str); + if(xhtml_out) + *xhtml_out = g_strdup(xhtml->str); + if(plain_out) + *plain_out = g_strdup(plain->str); g_string_free(xhtml, TRUE); - return ret; + g_string_free(plain, TRUE); }
--- a/src/protocols/jabber/jabber.c Fri Apr 11 07:49:15 2003 +0000 +++ b/src/protocols/jabber/jabber.c Fri Apr 11 08:09:21 2003 +0000 @@ -2424,26 +2424,27 @@ static void insert_message(xmlnode x, const char *message, gboolean use_xhtml) { xmlnode y; - char *buf = strip_html(message); + char *buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body>%s</body></html>", message); + char *xhtml, *plain; + + html_to_xhtml(buf, &xhtml, &plain); + g_free(buf); + y = xmlnode_insert_tag(x, "body"); - xmlnode_insert_cdata(y, buf, -1); - g_free(buf); + xmlnode_insert_cdata(y, plain, -1); + g_free(plain); if(use_xhtml) { - char *buf2 = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body>%s</body></html>", message); - buf = html_to_xhtml(buf2); - g_free(buf2); - - y = xmlnode_str(buf, strlen(buf)); + y = xmlnode_str(xhtml, strlen(xhtml)); if(y) { xmlnode_insert_tag_node(x, y); xmlnode_free(y); } else { debug_printf("holy cow, html_to_xhtml didn't work right!\n"); - debug_printf("the invalid XML: %s\n", buf); + debug_printf("the invalid XML: %s\n", xhtml); } - g_free(buf); } + g_free(xhtml); } static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags)