Update of /cvsroot/gaim/gaim/src
In directory sc8-pr-cvs1:/tmp/cvs-serv22401/src
Modified Files:
gaim.h gtkimhtml.c html.c util.c
Log Message:
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
Index: gaim.h
===================================================================
RCS file: /cvsroot/gaim/gaim/src/gaim.h,v
retrieving revision 1.385
retrieving revision 1.386
diff -u -d -r1.385 -r1.386
--- gaim.h 5 Apr 2003 10:14:21 -0000 1.385
+++ gaim.h 10 Apr 2003 06:09:25 -0000 1.386
@@ -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 */
Index: gtkimhtml.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/gtkimhtml.c,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- gtkimhtml.c 9 Apr 2003 23:35:53 -0000 1.172
+++ gtkimhtml.c 10 Apr 2003 06:09:25 -0000 1.173
@@ -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);
Index: html.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/html.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- html.c 14 Mar 2003 22:49:31 -0000 1.36
+++ html.c 10 Apr 2003 06:09:25 -0000 1.37
@@ -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, "</%s>", (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, "<!--", strlen("<!--"))) {
+ char *p = strstr(c + strlen("<!--"), "-->");
+ if(p) {
+ xhtml = g_string_append(xhtml, "<!--");
+ c += strlen("<!--");
+ continue;
+ }
+ }
+
+ xhtml = g_string_append(xhtml, "<");
+ c++;
+ }
+ } else {
+ xhtml = g_string_append_c(xhtml, *c);
+ c++;
+ }
+ }
+ tag = tags;
+ while(tag) {
+ g_string_append_printf(xhtml, "</%s>", (char *)tag->data);
+ tag = tag->next;
+ }
+ g_list_free(tags);
+ ret = g_strdup(xhtml->str);
+ g_string_free(xhtml, TRUE);
+ return ret;
+}
Index: util.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/util.c,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- util.c 8 Apr 2003 18:36:50 -0000 1.176
+++ util.c 10 Apr 2003 06:09:25 -0000 1.177
@@ -139,7 +139,7 @@
gint linkify_text(char *text)
{
- char *c, *t;
+ char *c, *t, *q = NULL;
char *cpy = g_malloc(strlen(text) * 3 + 1);
char url_buf[BUF_LEN * 4];
int cnt = 0;
@@ -149,7 +149,12 @@
cpy[strlen(text)] = 0;
c = cpy;
while (*c) {
- if (!g_ascii_strncasecmp(c, "<A", 2)) {
+ if(!q && (*c == '\"' || *c == '\'')) {
+ q = c;
+ } else if(q) {
+ if(*c == *q)
+ q = NULL;
+ } else if (!g_ascii_strncasecmp(c, "<A", 2)) {
while (1) {
if (!g_ascii_strncasecmp(c, "/A>", 3)) {
break;
|