diff libpurple/protocols/yahoo/util.c @ 27767:76ff0ad87964

propagate from branch 'im.pidgin.pidgin' (head 9de3934cd71a8b08f0f6da39df8f0102d36fbd2b) to branch 'im.pidgin.pidgin.yaz' (head d439d42fe8d0ee4a40486b4de12acb4116bc2e58)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 25 Feb 2008 05:45:57 +0000
parents e9cf897bd873
children c9b4fdb3fdb1
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/util.c	Mon Feb 25 00:25:51 2008 +0000
+++ b/libpurple/protocols/yahoo/util.c	Mon Feb 25 05:45:57 2008 +0000
@@ -29,6 +29,7 @@
 #include "prpl.h"
 
 #include "yahoo.h"
+#include "util.h"
 
 #include <string.h>
 /*
@@ -111,7 +112,8 @@
 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
 {
 	struct yahoo_data *yd = gc->proto_data;
-	char *ret;
+	char *ret, *strtmp;
+	int newlen;
 	const char *to_codeset;
 
 	if (yd->jp && utf8 && *utf8)
@@ -125,7 +127,13 @@
 	else
 		to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
 
-	ret = g_convert_with_fallback(str, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL);
+//	strtmp = sanitize_utf((char *)str, strlen((char *)str), &newlen);
+    strtmp = g_strdup(str);
+
+	ret = g_convert_with_fallback(strtmp, strlen(strtmp), to_codeset, "UTF-8", "?", NULL, NULL, NULL);
+
+	g_free(strtmp);
+
 	if (ret)
 		return ret;
 	else
@@ -143,8 +151,9 @@
 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8)
 {
 	struct yahoo_data *yd = gc->proto_data;
-	char *ret;
-	const char *from_codeset;
+	char *ret, *tmp;
+	char *from_codeset;
+	int newlen;
 
 	if (utf8) {
 		if (g_utf8_validate(str, -1, NULL))
@@ -156,10 +165,22 @@
 	else
 		from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
 
-	ret = g_convert_with_fallback(str, -1, "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
+	/* yaz: it's a kind of voodoo to avoid malconversion of "~". */
+	tmp = g_convert(str, strlen(str), "EUC-JP", from_codeset, NULL, NULL, NULL);
+	if(tmp) { 
+		ret = g_convert(tmp, strlen(tmp), "UTF-8", "EUC-JP", NULL, NULL, NULL);
+		g_free(tmp);
+	} else {
+		ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
+	}
 
-	if (ret)
+	if (ret){
+		tmp = ret;
+//		ret = botch_utf(tmp, strlen(tmp), &newlen);
+        ret = g_strdup(tmp);
+		g_free(tmp);
 		return ret;
+	}
 	else
 		return g_strdup("");
 }