changeset 2039:859e9c2c5813

[gaim-migrate @ 2049] utf8 committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 16 Jun 2001 19:16:25 +0000
parents cb4fbcdae9eb
children 64a07b9e9202
files plugins/jabber/jabber.c plugins/msn/msn.c src/gaim.h src/util.c
diffstat 4 files changed, 68 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/jabber/jabber.c	Sat Jun 16 17:55:57 2001 +0000
+++ b/plugins/jabber/jabber.c	Sat Jun 16 19:16:25 2001 +0000
@@ -1236,8 +1236,10 @@
 	xmlnode_put_attrib(x, "type", "chat");
 
 	if (message && strlen(message)) {
+		char *utf8 = str_to_utf8(message);
 		y = xmlnode_insert_tag(x, "body");
-		xmlnode_insert_cdata(y, message, -1);
+		xmlnode_insert_cdata(y, utf8, -1);
+		g_free(utf8);
 	}
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
@@ -1397,8 +1399,10 @@
 	g_free(subject);
 
 	if (message && strlen(message)) {
+		char *utf8 = str_to_utf8(message);
 		y = xmlnode_insert_tag(x, "body");
-		xmlnode_insert_cdata(y, message, -1);
+		xmlnode_insert_cdata(y, utf8, -1);
+		g_free(utf8);
 	}
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
@@ -1479,8 +1483,10 @@
 	xmlnode_put_attrib(x, "type", "groupchat");
 
 	if (message && strlen(message)) {
+		char *utf8 = str_to_utf8(message);
 		y = xmlnode_insert_tag(x, "body");
-		xmlnode_insert_cdata(y, message, -1);
+		xmlnode_insert_cdata(y, utf8, -1);
+		g_free(utf8);
 	}
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
@@ -1524,11 +1530,13 @@
 	xmlnode_put_attrib(x, "type", "groupchat");
 
 	if (topic && strlen(topic)) {
+		char *utf8 = str_to_utf8(topic);
 		y = xmlnode_insert_tag(x, "subject");
-		xmlnode_insert_cdata(y, topic, -1);
+		xmlnode_insert_cdata(y, utf8, -1);
 		y = xmlnode_insert_tag(x, "body");
-		g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", topic);
+		g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", utf8);
 		xmlnode_insert_cdata(y, buf, -1);
+		g_free(utf8);
 	}
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
@@ -1571,8 +1579,10 @@
 	xmlnode_put_attrib(x, "type", "normal");
 
 	if (message && strlen(message)) {
+		char *utf8 = str_to_utf8(message);
 		y = xmlnode_insert_tag(x, "body");
-		xmlnode_insert_cdata(y, message, -1);
+		xmlnode_insert_cdata(y, utf8, -1);
+		g_free(utf8);
 	}
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
--- a/plugins/msn/msn.c	Sat Jun 16 17:55:57 2001 +0000
+++ b/plugins/msn/msn.c	Sat Jun 16 19:16:25 2001 +0000
@@ -415,9 +415,11 @@
 			add_chat_buddy(ms->chat, user);
 		ms->total++;
 		if (ms->txqueue) {
+			char *utf8 = str_to_utf8(ms->txqueue);
 			g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
-					strlen(MIME_HEADER) + strlen(ms->txqueue),
-					MIME_HEADER, ms->txqueue);
+					strlen(MIME_HEADER) + strlen(utf8),
+					MIME_HEADER, utf8);
+			g_free(utf8);
 			g_free(ms->txqueue);
 			ms->txqueue = NULL;
 			if (msn_write(ms->fd, buf, strlen(buf)) < 0)
@@ -1125,9 +1127,11 @@
 	char buf[MSN_BUF_LEN];
 
 	if (ms) {
+		char *utf8 = str_to_utf8(message);
 		g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId,
-				strlen(MIME_HEADER) + strlen(message),
-				MIME_HEADER, message);
+				strlen(MIME_HEADER) + strlen(utf8),
+				MIME_HEADER, utf8);
+		g_free(utf8);
 		if (msn_write(ms->fd, buf, strlen(buf)) < 0)
 			msn_kill_switch(ms);
 		debug_printf("\n");
--- a/src/gaim.h	Sat Jun 16 17:55:57 2001 +0000
+++ b/src/gaim.h	Sat Jun 16 19:16:25 2001 +0000
@@ -635,6 +635,7 @@
 extern void away_on_login(char *);
 extern void system_log(enum log_event, struct gaim_connection *, struct buddy *, int);
 extern unsigned char *utf8_to_str(unsigned char *);
+extern char *str_to_utf8(unsigned char *);
 
 /* Functions in server.c */
 /* input to serv */
--- a/src/util.c	Sat Jun 16 17:55:57 2001 +0000
+++ b/src/util.c	Sat Jun 16 19:16:25 2001 +0000
@@ -1560,10 +1560,50 @@
 				n += 5;
 		}
 		n++;
-    }
-    result[i] = '\0';
+	}
+	result[i] = '\0';
+
+	return result;
+}
+
+char *str_to_utf8(unsigned char *in)
+{
+	int n = 0,i = 0;
+	int inlen;
+	char *result = NULL;
+
+	if (!in)
+		return NULL;
+
+	inlen = strlen(in);
+
+	result = g_malloc(inlen * 2 + 1);
 
-    return result;
+	while (n < inlen) {
+		long c = (long)in[n];
+		if (c == 27) {
+			n += 2;
+			if (in[n] == 'x')
+				n++;
+			if (in[n] == '3')
+				n++;
+			n += 2;
+			continue;
+		}
+		if ((c == 0x0D) || (c == 0x0A)) {
+			n++; continue;
+		}
+		if (c < 128)
+			result[i++] = (char)c;
+		else {
+			result[i++] = (char)((c>>6)|192);
+			result[i++] = (char)((c&63)|128);
+		}
+		n++;
+	}
+	result[i] = '\0';
+
+	return result;
 }
 
 time_t get_time(int year, int month, int day, int hour, int min, int sec)