changeset 5174:376349b04123

[gaim-migrate @ 5538] made jabber xhtml stuff even better, and fixed a couple bugs in the process committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 19 Apr 2003 06:28:40 +0000
parents bfd1e4c681a1
children 591e8d9a4697
files src/gtkimhtml.c src/html.c src/protocols/jabber/jabber.c
diffstat 3 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Sat Apr 19 01:07:17 2003 +0000
+++ b/src/gtkimhtml.c	Sat Apr 19 06:28:40 2003 +0000
@@ -730,6 +730,7 @@
 
 	VALID_OPT_TAG ("SPAN");
 	VALID_TAG ("/SPAN");
+	VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */
 
 	if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) {
 		gchar *e = strstr (string + strlen("!--"), "-->");
@@ -1006,6 +1007,7 @@
 					}
 					break;
 				case 25:	/* BR */
+				case 58:	/* BR/ */
 					ws[wpos] = '\n';
 					wpos++;
 					NEW_BIT (NEW_TEXT_BIT);
@@ -1199,7 +1201,7 @@
 				case 56:	/* SPAN */
 				case 57:	/* /SPAN */
 					break;
-				case 58:	/* comment */
+				case 59:	/* comment */
 					NEW_BIT (NEW_TEXT_BIT);
 					if (imhtml->show_comments)
 						wpos = g_snprintf (ws, len, "%s", tag);
--- a/src/html.c	Sat Apr 19 01:07:17 2003 +0000
+++ b/src/html.c	Sat Apr 19 06:28:40 2003 +0000
@@ -424,7 +424,6 @@
 				ALLOW_TAG_ALT("b", "strong");
 				ALLOW_TAG("blockquote");
 				ALLOW_TAG_ALT("bold", "strong");
-				ALLOW_TAG("br");
 				ALLOW_TAG("cite");
 				ALLOW_TAG("div");
 				ALLOW_TAG("em");
@@ -434,7 +433,6 @@
 				ALLOW_TAG("h4");
 				ALLOW_TAG("h5");
 				ALLOW_TAG("h6");
-				ALLOW_TAG("hr"); /* FIXME: not valid, need to skip?? */
 				ALLOW_TAG("html");
 				ALLOW_TAG_ALT("i", "em");
 				ALLOW_TAG_ALT("italic", "em");
@@ -447,7 +445,22 @@
 				ALLOW_TAG("strong");
 				ALLOW_TAG("ul");
 
-				if(!g_ascii_strncasecmp(c, "<u>", 2) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) {
+				/* we skip <HR> because it's not legal in XHTML-IM.  However,
+				 * we still want to send something sensible, so we put a
+				 * linebreak in its place. <BR> also needs special handling
+				 * because putting a </BR> to close it would just be dumb. */
+				if((!g_ascii_strncasecmp(c, "<br", 3)
+							|| !g_ascii_strncasecmp(c, "<hr", 3))
+						&& (*(c+3) == '>' ||
+							!g_ascii_strncasecmp(c+3, "/>", 2) ||
+							!g_ascii_strncasecmp(c+3, " />", 3))) {
+					c = strchr(c, '>') + 1;
+					xhtml = g_string_append(xhtml, "<br/>");
+					if(*c != '\n')
+						plain = g_string_append_c(plain, '\n');
+					continue;
+				}
+				if(!g_ascii_strncasecmp(c, "<u>", 3) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) {
 					struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1);
 					pt->src_tag = *(c+2) == '>' ? "u" : "underline";
 					pt->dest_tag = "span";
@@ -456,7 +469,7 @@
 					xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>");
 					continue;
 				}
-				if(!g_ascii_strncasecmp(c, "<s>", 2) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) {
+				if(!g_ascii_strncasecmp(c, "<s>", 3) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) {
 					struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1);
 					pt->src_tag = *(c+2) == '>' ? "s" : "strike";
 					pt->dest_tag = "span";
--- a/src/protocols/jabber/jabber.c	Sat Apr 19 01:07:17 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Sat Apr 19 06:28:40 2003 +0000
@@ -2290,6 +2290,8 @@
 	struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
 	char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
 
+	gc->flags |= OPT_CONN_HTML;
+
 	jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
 	jd->chats = NULL;	/* we have no chats yet */
 
@@ -3381,11 +3383,18 @@
 		/* oh goody. Gaim is telling us what to do. */
 		if (message) {
 			/* Gaim wants us to be away */
+			char *stripped;
+
+			/* Jabber supports XHTML in IMs, but not in away messages. */
+			html_to_xhtml(message, NULL, &stripped);
+
 			y = xmlnode_insert_tag(x, "show");
 			xmlnode_insert_cdata(y, "away", -1);
 			y = xmlnode_insert_tag(x, "status");
-			xmlnode_insert_cdata(y, message, -1);
-			gc->away = g_strdup(message);
+			xmlnode_insert_cdata(y, stripped, -1);
+
+			gc->away = g_strdup(stripped);
+			g_free(stripped);
 		} else {
 			/* Gaim wants us to not be away */
 			/* but for Jabber, we can just send presence with no other information. */