changeset 27769:c9b4fdb3fdb1

adapted to the transition to utf-8 of yahoo-jp.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 27 Feb 2008 14:54:42 +0000
parents 969a2aeae461
children 6ce9e29a8cdf
files libpurple/protocols/yahoo/util.c libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo_packet.h libpurple/util.c libpurple/util.h
diffstat 5 files changed, 22 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/util.c	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/protocols/yahoo/util.c	Wed Feb 27 14:54:42 2008 +0000
@@ -112,12 +112,13 @@
 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
 {
 	struct yahoo_data *yd = gc->proto_data;
-	char *ret, *strtmp;
-	int newlen;
+	char *ret = NULL;
+	size_t newlen;
 	const char *to_codeset;
 
-	if (yd->jp && utf8 && *utf8)
-		*utf8 = FALSE;
+	if (yd->jp && utf8 && *utf8) {
+		return botch_utf((gchar *)str, strlen((gchar *)str), &newlen);
+	}
 
 	if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
 		return g_strdup(str);
@@ -127,12 +128,7 @@
 	else
 		to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
 
-//	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);
+	ret = g_convert_with_fallback(str, strlen(str), to_codeset, "UTF-8", "?", NULL, NULL, NULL);
 
 	if (ret)
 		return ret;
@@ -153,14 +149,15 @@
 	struct yahoo_data *yd = gc->proto_data;
 	char *ret, *tmp;
 	char *from_codeset;
-	int newlen;
+	size_t newlen;
 
 	if (utf8) {
-		if (g_utf8_validate(str, -1, NULL))
-			return g_strdup(str);
+		ret = sanitize_utf((gchar *)str, strlen((gchar *)str), &newlen);
+		if (g_utf8_validate(ret, -1, NULL))
+			return ret;
 	}
 
-	if (yd->jp)
+	if (yd->jp && !utf8)
 		from_codeset = "SHIFT_JIS";
 	else
 		from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
@@ -176,8 +173,7 @@
 
 	if (ret){
 		tmp = ret;
-//		ret = botch_utf(tmp, strlen(tmp), &newlen);
-        ret = g_strdup(tmp);
+		ret = sanitize_utf((gchar *)tmp, strlen((gchar *)tmp), &newlen);
 		g_free(tmp);
 		return ret;
 	}
--- a/libpurple/protocols/yahoo/yahoo.c	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Wed Feb 27 14:54:42 2008 +0000
@@ -758,7 +758,8 @@
 	char *msg;
 };
 
-static void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt)
+//static void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt)
+void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt) // temporally export --yaz
 {
 	PurpleAccount *account;
 	struct yahoo_data *yd = gc->proto_data;
@@ -777,6 +778,7 @@
 				list = g_slist_append(list, im);
 				im->from = pair->value;
 				im->time = time(NULL);
+				im->utf8 = TRUE; //web messenger seems not to sent hash 97. --yaz
 			}
 			if (pair->key == 97)
 				if (im)
@@ -1280,7 +1282,7 @@
 	*n = '\0';
 
 	if (yd->jp) {
-		converted = g_convert(new, n - new, OUT_CHARSET, "SJIS", NULL, NULL, NULL);
+		converted = g_convert(new, n - new, OUT_CHARSET, "UTF-8", NULL, NULL, NULL);
 	}
 	if (!yd->jp || !converted) {
 		if (strstr(text, "\033$B"))
@@ -4443,7 +4445,7 @@
 	option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
 
-	option = purple_account_option_string_new(_("Encoding"), "local_charset", "ISO-8859-1");
+	option = purple_account_option_string_new(_("Encoding"), "local_charset", "UTF-8");
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
 
 
--- a/libpurple/protocols/yahoo/yahoo_packet.h	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_packet.h	Wed Feb 27 14:54:42 2008 +0000
@@ -123,7 +123,7 @@
 
 #define YAHOO_WEBMESSENGER_PROTO_VER 0x0065
 #define YAHOO_PROTO_VER 0x000f
-#define YAHOO_PROTO_VER_JAPAN 0x000c
+#define YAHOO_PROTO_VER_JAPAN 0x000f
 
 #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4)
 
--- a/libpurple/util.c	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/util.c	Wed Feb 27 14:54:42 2008 +0000
@@ -4796,7 +4796,7 @@
 	}
 }
 
-guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen)
+gchar *sanitize_utf(const gchar *msg, size_t len, size_t *newlen)
 {
 	gint i;
 	size_t bytes;
@@ -4868,7 +4868,7 @@
 }
 
 
-guchar *botch_utf(const void *msg, size_t len, size_t *newlen)
+gchar *botch_utf(const gchar *msg, size_t len, size_t *newlen)
 {
  	int i,bytes;
 	unsigned char *utf;
--- a/libpurple/util.h	Wed Feb 27 12:21:29 2008 +0000
+++ b/libpurple/util.h	Wed Feb 27 14:54:42 2008 +0000
@@ -1266,7 +1266,7 @@
 /* to address incompatibility with cp932. */
 void botch_ucs(gchar *ucs, gssize len);
 void sanitize_ucs(gchar *ucs, gssize len);
-guchar *botch_utf(const void *utf, size_t len, size_t *newlen);
-guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen);
+gchar *botch_utf(const gchar *utf, size_t len, size_t *newlen);
+gchar *sanitize_utf(const gchar *msg, size_t len, size_t *newlen);
 
 #endif /* _PURPLE_UTIL_H_ */