adium: f5376d42: iChat sends direct IM messages with its ...

zacw at adiumx.com zacw at adiumx.com
Sun Nov 22 13:41:10 EST 2009


-----------------------------------------------------------------
Revision: f5376d42261b8efc3d889314df9896bb10d3fe16
Ancestor: d2a1d52b3bbf29baa53b9ddaa635d50b6332064f
Author: zacw at adiumx.com
Date: 2009-11-22T18:36:58
Branch: im.pidgin.adium
URL: http://d.pidgin.im/viewmtn/revision/info/f5376d42261b8efc3d889314df9896bb10d3fe16

Modified files:
        libpurple/protocols/oscar/oscar.c

ChangeLog: 

iChat sends direct IM messages with its encoding as 0x000d, which was being forced-interpreted as ASCII.

This change is actually from Evan Schoenberg, and adds a few debug lines for charset information being received.


-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c	f41ef1f0f7cd829184d74dd5cf3232bfda3867a1
+++ libpurple/protocols/oscar/oscar.c	b49b57bc7e89a7fa5e1fbe14d89db22f448feb83
@@ -438,10 +438,8 @@ purple_plugin_oscar_decode_im_part(Purpl
 purple_plugin_oscar_decode_im_part(PurpleAccount *account, const char *sourcebn, guint16 charset, guint16 charsubset, const gchar *data, gsize datalen)
 {
 	gchar *ret = NULL;
-	const gchar *charsetstr1, *charsetstr2;
+	const gchar *charsetstr1, *charsetstr2, *charsetstr3 = NULL;
 
-	purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT "\n", charset, charsubset, datalen);
-
 	if ((datalen == 0) || (data == NULL))
 		return NULL;
 
@@ -459,19 +457,33 @@ purple_plugin_oscar_decode_im_part(Purpl
 		charsetstr1 = "ASCII";
 		charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
 	} else if (charset == 0x000d) {
-		/* Mobile AIM client on a Nokia 3100 and an LG VX6000 */
-		charsetstr1 = "ISO-8859-1";
-		charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
+		/* iChat sending unicode over a Direct IM connection = Unicode */
+		/* Mobile AIM client on a Nokia 3100 and an LG VX6000 = ISO-8859-1 */
+		charsetstr1 = "UTF-16BE";
+		charsetstr2 = "UTF-8";
+		charsetstr3 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
 	} else {
 		/* Unknown, hope for valid UTF-8... */
 		charsetstr1 = "UTF-8";
 		charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
 	}
+	
+	purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT ", choice1=%s, choice2=%s, choise3=%s\n",
+					  charset, charsubset, datalen, charsetstr1, charsetstr2, (charsetstr3 ? charsetstr3 : ""));
 
 	ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr1, FALSE);
-	if (ret == NULL)
-		ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE);
 	if (ret == NULL) {
+		if (charsetstr3 != NULL) {
+			/* Try charsetstr2 without allowing substitutions, then fall through to charsetstr3 if needed */
+			ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, FALSE);
+			if (ret == NULL)
+				ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr3, TRUE);
+		} else {
+			/* Try charsetstr2, allowing substitutions */
+			ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE);
+		}
+	}
+	if (ret == NULL) {
 		char *str, *salvage, *tmp;
 
 		str = g_malloc(datalen + 1);
@@ -575,6 +587,9 @@ purple_plugin_oscar_convert_to_best_enco
 	 */
 	*msg = g_convert(from, -1, "UTF-16BE", "UTF-8", NULL, &msglen, &err);
 	if (*msg != NULL) {
+		purple_debug_info("oscar", "Conversion from UTF-8 to UTF-16BE results in %s.\n",
+						  *msg);
+
 		*charset = AIM_CHARSET_UNICODE;
 		*charsubset = 0x0000;
 		*msglen_int = msglen;
@@ -4552,6 +4567,8 @@ purple_odc_send_im(PeerConnection *conn,
 	}
 	g_string_free(data, TRUE);
 
+	purple_debug_info("oscar", "sending direct IM %s using charset %i", msg->str, charset);
+	
 	peer_odc_send_im(conn, msg->str, msg->len, charset,
 			imflags & PURPLE_MESSAGE_AUTO_RESP);
 	g_string_free(msg, TRUE);


More information about the Commits mailing list