Mercurial > pidgin.yaz
diff libpurple/protocols/oscar/oscar.c @ 25475:5eca30c2935b
propagate from branch 'im.pidgin.pidgin' (head 5f4a03fa07b74453c3b8312c388af42739fd16db)
to branch 'im.pidgin.pidgin.yaz' (head d3638a2d4ce4241e16b740a362d0d541c1f912b9)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 02 May 2007 12:23:38 +0000 |
parents | 9a2ec0a033b5 fb4df531105b |
children | f444605c27b6 |
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c Wed May 02 11:55:04 2007 +0000 +++ b/libpurple/protocols/oscar/oscar.c Wed May 02 12:23:38 2007 +0000 @@ -280,7 +280,8 @@ /* Make sure encoding begins with charset= */ if (strncmp(encoding, "text/aolrtf; charset=", 21) && - strncmp(encoding, "text/x-aolrtf; charset=", 23)) + strncmp(encoding, "text/x-aolrtf; charset=", 23) && + strncmp(encoding, "text/plain; charset=", 20)) /* for iChat */ { return NULL; } @@ -302,7 +303,25 @@ gchar *utf8 = NULL; if ((encoding == NULL) || encoding[0] == '\0') { - purple_debug_info("oscar", "Empty encoding, assuming UTF-8\n"); + purple_debug_info("yaz oscar", "Empty encoding, validate as UTF-8\n"); + if(g_utf8_validate(text, textlen, NULL)){ + size_t newlen; + utf8 = sanitize_utf(text, textlen, &newlen); + goto done; + } + // not UTF-8 + purple_debug_info("yaz oscar", "Empty encoding, assuming UCS-2BE\n"); + sanitize_ucs(text, textlen); + utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); + if(utf8){ + if(!g_utf8_validate(utf8, strlen(utf8), NULL)){ + purple_debug_info("yaz oscar", "Invalid conversion\n"); + g_free(utf8); + utf8 = NULL; + } + } else { + purple_debug_info("yaz oscar", "Conversion failed\n"); + } } else if (!strcasecmp(encoding, "iso-8859-1")) { utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL); } else if (!strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || @@ -310,6 +329,7 @@ { utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL); } else if (!strcasecmp(encoding, "unicode-2-0")) { + sanitize_ucs(text, textlen); utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); } else if (strcasecmp(encoding, "utf-8")) { purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", " @@ -330,7 +350,7 @@ else utf8 = g_strndup(text, textlen); } - +done: return utf8; } @@ -487,6 +507,7 @@ if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b))) { *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); + botch_ucs(*msg, msglen); if (*msg != NULL) { *charset = AIM_CHARSET_UNICODE; @@ -521,6 +542,7 @@ * Nothing else worked, so send as UCS-2BE. */ *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, &err); + botch_ucs(*msg, msglen); if (*msg != NULL) { *charset = AIM_CHARSET_UNICODE; *charsubset = 0x0000; @@ -1953,6 +1975,8 @@ tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset, curpart->charsubset, curpart->data, curpart->datalen); if (tmp != NULL) { + purple_str_strip_char(tmp, 0x0d); // yaz: strip CR +// purple_debug_info("yaz oscar", "tmp=%s",tmp); g_string_append(message, tmp); g_free(tmp); } @@ -2053,6 +2077,7 @@ char *encoding, *utf8name, *tmp; GHashTable *components; +// purple_debug_info("yaz oscar", "chat request %s\n", args->msg); if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) { g_free(message); return 1; @@ -2075,6 +2100,8 @@ g_hash_table_replace(components, g_strdup("room"), utf8name); g_hash_table_replace(components, g_strdup("exchange"), g_strdup_printf("%d", args->info.chat.roominfo.exchange)); + purple_debug_info("yaz oscar", "about to call serv_got_chat_invite\n"); +// purple_debug_info("yaz oscar", "name=%s message=%s\n", name ? name : args->info.chat.roominfo.name, message); serv_got_chat_invite(gc, utf8name, userinfo->sn, @@ -2309,7 +2336,7 @@ * for this suck-ass part of the protocol by splitting the string into at * most 1 baby string. */ - msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); + msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); // \376 is 0xfe for (numtoks=0; msg1[numtoks]; numtoks++); msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); for (i=0; msg1[i]; i++) { @@ -4335,6 +4362,7 @@ charset = oscar_charset_check(str); if (charset == AIM_CHARSET_UNICODE) { encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL); + botch_ucs(encoded, *ret_len); *encoding = "unicode-2-0"; } else if (charset == AIM_CHARSET_CUSTOM) { encoded = g_convert(str, strlen(str), "ISO-8859-1", "UTF-8", NULL, ret_len, NULL); @@ -5356,7 +5384,7 @@ charsetstr = "unicode-2-0"; else if (charset == AIM_CHARSET_CUSTOM) charsetstr = "iso-8859-1"; - aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "en"); + aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "JA"); g_free(buf2); return 0;