Mercurial > pidgin.yaz
diff libpurple/protocols/oscar/oscar.c @ 25497:67ad619bd97f
propagate from branch 'im.pidgin.pidgin' (head 3d1e6b8637ff9133c8f17e9aeaeea1284c898d86)
to branch 'im.pidgin.pidgin.yaz' (head cf1ed778db33093adccaec9aa0399ac72a0b712f)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 04 Jun 2007 07:22:38 +0000 |
parents | 3d035cdd103b a79b96ba2b49 |
children | 7577706bde9c |
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c Mon Jun 04 06:57:25 2007 +0000 +++ b/libpurple/protocols/oscar/oscar.c Mon Jun 04 07:22:38 2007 +0000 @@ -303,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 (!g_ascii_strcasecmp(encoding, "iso-8859-1")) { utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL); } else if (!g_ascii_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || @@ -311,6 +329,7 @@ { utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL); } else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) { + sanitize_ucs(text, textlen); utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); } else if (g_ascii_strcasecmp(encoding, "utf-8")) { purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", " @@ -331,7 +350,7 @@ else utf8 = g_strndup(text, textlen); } - +done: return utf8; } @@ -488,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; @@ -522,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; @@ -1961,6 +1982,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); } @@ -2061,6 +2084,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; @@ -2083,6 +2107,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, @@ -2317,7 +2343,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++) { @@ -4344,6 +4370,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); @@ -5359,7 +5386,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;