# HG changeset patch # User Nathan Walp # Date 1049954966 0 # Node ID 89c0c811befa17545904fc701c4518cd59fd8b55 # Parent a4ad609ee6b31d48eba701daac673035f7a39749 [gaim-migrate @ 5455] jabber XHTML support. since people tend to not like to write valid XHTML all of the time, we now have html_to_xhtml() which does its best to figure out what you meant. i'm tired, hope this works for everyone committer: Tailor Script diff -r a4ad609ee6b3 -r 89c0c811befa ChangeLog --- a/ChangeLog Thu Apr 10 00:57:06 2003 +0000 +++ b/ChangeLog Thu Apr 10 06:09:26 2003 +0000 @@ -3,6 +3,7 @@ version 0.62 * Keyboard shortcuts in the buddy list work again (Thanks Joe Clarke). + * Support for Jabber XHTML messages version 0.61 (04/07/2003): * Split the buddy pounce core and UI, and rewrote the UI for it. diff -r a4ad609ee6b3 -r 89c0c811befa src/gaim.h --- a/src/gaim.h Thu Apr 10 00:57:06 2003 +0000 +++ b/src/gaim.h Thu Apr 10 06:09:26 2003 +0000 @@ -371,6 +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 *); struct g_url *parse_url(char *url); /* Functions in idle.c */ diff -r a4ad609ee6b3 -r 89c0c811befa src/gtkimhtml.c --- a/src/gtkimhtml.c Thu Apr 10 00:57:06 2003 +0000 +++ b/src/gtkimhtml.c Thu Apr 10 06:09:26 2003 +0000 @@ -632,6 +632,9 @@ } else if (!g_ascii_strncasecmp (string, "®", 5)) { *replace = '®'; /* was: '®' */ *length = 5; + } else if (!g_ascii_strncasecmp (string, "'", 6)) { + *replace = '\''; + *length = 6; } else if (*(string + 1) == '#') { guint pound = 0; if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { @@ -703,7 +706,7 @@ VALID_TAG ("/HEAD"); VALID_TAG ("BINARY"); VALID_TAG ("/BINARY"); - + VALID_OPT_TAG ("HR"); VALID_OPT_TAG ("FONT"); VALID_OPT_TAG ("BODY"); @@ -711,6 +714,7 @@ VALID_OPT_TAG ("IMG"); VALID_OPT_TAG ("P"); VALID_OPT_TAG ("H3"); + VALID_OPT_TAG ("HTML"); if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { gchar *e = strstr (string + strlen("!--"), "-->"); @@ -1170,8 +1174,9 @@ } case 47: /* P (opt) */ case 48: /* H3 (opt) */ + case 49: /* HTML (opt) */ break; - case 49: /* comment */ + case 50: /* comment */ NEW_BIT (NEW_TEXT_BIT); if (imhtml->show_comments) wpos = g_snprintf (ws, len, "%s", tag); diff -r a4ad609ee6b3 -r 89c0c811befa src/html.c --- a/src/html.c Thu Apr 10 00:57:06 2003 +0000 +++ b/src/html.c Thu Apr 10 06:09:26 2003 +0000 @@ -322,3 +322,138 @@ callback(data, g_strdup(_("g003: Error opening connection.\n")), 0); } } + +#define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ + char *o = strchr(c+1, '<'); \ + char *p = strchr(c+1, '>'); \ + if(p && (!o || p < o)) { \ + if(*(p-1) != '/') \ + tags = g_list_prepend(tags, y); \ + xhtml = g_string_append(xhtml, "<" y); \ + c += strlen("<" x ); \ + xhtml = g_string_append_len(xhtml, c, (p - c) + 1); \ + c = p + 1; \ + } else { \ + xhtml = g_string_append(xhtml, "<"); \ + } \ + continue; \ + } \ + if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ + (*(c+strlen("<" x)) == '>' || \ + !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ + xhtml = g_string_append(xhtml, "<" y); \ + c += strlen("<" x); \ + if(*c != '/') \ + tags = g_list_prepend(tags, y); \ + continue; \ + } +#define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) + +char *html_to_xhtml(const char *html) { + GString *xhtml = 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); + c++; + } else if(q) { + if(*c == *q) { + q = NULL; + } else if(*c == '\\') { + xhtml = g_string_append_c(xhtml, *c); + c++; + } + xhtml = g_string_append_c(xhtml, *c); + c++; + } else if(*c == '<') { + if(*(c+1) == '/') { /* closing tag */ + tag = tags; + while(tag) { + if(!g_ascii_strncasecmp((c+2), tag->data, strlen(tag->data)) && *(c+strlen(tag->data)+2) == '>') { + c += strlen(tag->data) + 3; + break; + } + tag = tag->next; + } + if(tag) { + while(tags) { + g_string_append_printf(xhtml, "", (char *)tags->data); + if(tags == tag) + break; + tags = g_list_remove(tags, tags->data); + } + tags = g_list_remove(tags, tag->data); + } else { + /* we tried to close a tag we never opened! escape it + * and move on */ + xhtml = g_string_append(xhtml, "<"); + c++; + } + } else { /* opening tag */ + ALLOW_TAG("a"); + ALLOW_TAG("b"); + ALLOW_TAG("blockquote"); + ALLOW_TAG("body"); + ALLOW_TAG_ALT("bold", "b"); + ALLOW_TAG("br"); + ALLOW_TAG("cite"); + ALLOW_TAG("div"); + ALLOW_TAG("em"); + ALLOW_TAG("font"); + ALLOW_TAG("h1"); + ALLOW_TAG("h2"); + ALLOW_TAG("h3"); + ALLOW_TAG("h4"); + ALLOW_TAG("h5"); + ALLOW_TAG("h6"); + ALLOW_TAG("head"); + ALLOW_TAG("hr"); + ALLOW_TAG("html"); + ALLOW_TAG("i"); + ALLOW_TAG_ALT("italic", "i"); + ALLOW_TAG("li"); + ALLOW_TAG("ol"); + ALLOW_TAG("p"); + ALLOW_TAG("pre"); + ALLOW_TAG("q"); + ALLOW_TAG_ALT("s", "strike"); + ALLOW_TAG("span"); + ALLOW_TAG("strike"); + ALLOW_TAG("strong"); + ALLOW_TAG("sub"); + ALLOW_TAG("sup"); + ALLOW_TAG("title"); + ALLOW_TAG("u"); + ALLOW_TAG_ALT("underline","u"); + ALLOW_TAG("ul"); + + if(!g_ascii_strncasecmp(c, ""); + if(p) { + xhtml = g_string_append(xhtml, "