Mercurial > pidgin.yaz
comparison 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 |
comparison
equal
deleted
inserted
replaced
17708:794abbe3e14e | 25497:67ad619bd97f |
---|---|
301 oscar_encoding_to_utf8(const char *encoding, const char *text, int textlen) | 301 oscar_encoding_to_utf8(const char *encoding, const char *text, int textlen) |
302 { | 302 { |
303 gchar *utf8 = NULL; | 303 gchar *utf8 = NULL; |
304 | 304 |
305 if ((encoding == NULL) || encoding[0] == '\0') { | 305 if ((encoding == NULL) || encoding[0] == '\0') { |
306 purple_debug_info("oscar", "Empty encoding, assuming UTF-8\n"); | 306 purple_debug_info("yaz oscar", "Empty encoding, validate as UTF-8\n"); |
307 if(g_utf8_validate(text, textlen, NULL)){ | |
308 size_t newlen; | |
309 utf8 = sanitize_utf(text, textlen, &newlen); | |
310 goto done; | |
311 } | |
312 // not UTF-8 | |
313 purple_debug_info("yaz oscar", "Empty encoding, assuming UCS-2BE\n"); | |
314 sanitize_ucs(text, textlen); | |
315 utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); | |
316 if(utf8){ | |
317 if(!g_utf8_validate(utf8, strlen(utf8), NULL)){ | |
318 purple_debug_info("yaz oscar", "Invalid conversion\n"); | |
319 g_free(utf8); | |
320 utf8 = NULL; | |
321 } | |
322 } else { | |
323 purple_debug_info("yaz oscar", "Conversion failed\n"); | |
324 } | |
307 } else if (!g_ascii_strcasecmp(encoding, "iso-8859-1")) { | 325 } else if (!g_ascii_strcasecmp(encoding, "iso-8859-1")) { |
308 utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL); | 326 utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL); |
309 } else if (!g_ascii_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || | 327 } else if (!g_ascii_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || |
310 !g_ascii_strcasecmp(encoding, "us-ascii")) | 328 !g_ascii_strcasecmp(encoding, "us-ascii")) |
311 { | 329 { |
312 utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL); | 330 utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL); |
313 } else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) { | 331 } else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) { |
332 sanitize_ucs(text, textlen); | |
314 utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); | 333 utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL); |
315 } else if (g_ascii_strcasecmp(encoding, "utf-8")) { | 334 } else if (g_ascii_strcasecmp(encoding, "utf-8")) { |
316 purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", " | 335 purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", " |
317 "attempting to convert to UTF-8 anyway\n", encoding); | 336 "attempting to convert to UTF-8 anyway\n", encoding); |
318 utf8 = g_convert(text, textlen, "UTF-8", encoding, NULL, NULL, NULL); | 337 utf8 = g_convert(text, textlen, "UTF-8", encoding, NULL, NULL, NULL); |
329 && !g_utf8_validate(text, textlen, NULL)) | 348 && !g_utf8_validate(text, textlen, NULL)) |
330 utf8 = g_strdup(_("(There was an error receiving this message. The buddy you are speaking with is probably using a different encoding than expected. If you know what encoding he is using, you can specify it in the advanced account options for your AIM/ICQ account.)")); | 349 utf8 = g_strdup(_("(There was an error receiving this message. The buddy you are speaking with is probably using a different encoding than expected. If you know what encoding he is using, you can specify it in the advanced account options for your AIM/ICQ account.)")); |
331 else | 350 else |
332 utf8 = g_strndup(text, textlen); | 351 utf8 = g_strndup(text, textlen); |
333 } | 352 } |
334 | 353 done: |
335 return utf8; | 354 return utf8; |
336 } | 355 } |
337 | 356 |
338 static gchar * | 357 static gchar * |
339 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg) | 358 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg) |
486 PurpleBuddy *b; | 505 PurpleBuddy *b; |
487 b = purple_find_buddy(account, destsn); | 506 b = purple_find_buddy(account, destsn); |
488 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b))) | 507 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b))) |
489 { | 508 { |
490 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); | 509 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); |
510 botch_ucs(*msg, msglen); | |
491 if (*msg != NULL) | 511 if (*msg != NULL) |
492 { | 512 { |
493 *charset = AIM_CHARSET_UNICODE; | 513 *charset = AIM_CHARSET_UNICODE; |
494 *charsubset = 0x0000; | 514 *charsubset = 0x0000; |
495 *msglen_int = msglen; | 515 *msglen_int = msglen; |
520 | 540 |
521 /* | 541 /* |
522 * Nothing else worked, so send as UCS-2BE. | 542 * Nothing else worked, so send as UCS-2BE. |
523 */ | 543 */ |
524 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, &err); | 544 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, &err); |
545 botch_ucs(*msg, msglen); | |
525 if (*msg != NULL) { | 546 if (*msg != NULL) { |
526 *charset = AIM_CHARSET_UNICODE; | 547 *charset = AIM_CHARSET_UNICODE; |
527 *charsubset = 0x0000; | 548 *charsubset = 0x0000; |
528 *msglen_int = msglen; | 549 *msglen_int = msglen; |
529 return; | 550 return; |
1959 curpart = args->mpmsg.parts; | 1980 curpart = args->mpmsg.parts; |
1960 while (curpart != NULL) { | 1981 while (curpart != NULL) { |
1961 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset, | 1982 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset, |
1962 curpart->charsubset, curpart->data, curpart->datalen); | 1983 curpart->charsubset, curpart->data, curpart->datalen); |
1963 if (tmp != NULL) { | 1984 if (tmp != NULL) { |
1985 purple_str_strip_char(tmp, 0x0d); // yaz: strip CR | |
1986 // purple_debug_info("yaz oscar", "tmp=%s",tmp); | |
1964 g_string_append(message, tmp); | 1987 g_string_append(message, tmp); |
1965 g_free(tmp); | 1988 g_free(tmp); |
1966 } | 1989 } |
1967 | 1990 |
1968 curpart = curpart->next; | 1991 curpart = curpart->next; |
2059 if (args->type & OSCAR_CAPABILITY_CHAT) | 2082 if (args->type & OSCAR_CAPABILITY_CHAT) |
2060 { | 2083 { |
2061 char *encoding, *utf8name, *tmp; | 2084 char *encoding, *utf8name, *tmp; |
2062 GHashTable *components; | 2085 GHashTable *components; |
2063 | 2086 |
2087 // purple_debug_info("yaz oscar", "chat request %s\n", args->msg); | |
2064 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) { | 2088 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) { |
2065 g_free(message); | 2089 g_free(message); |
2066 return 1; | 2090 return 1; |
2067 } | 2091 } |
2068 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL; | 2092 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL; |
2081 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | 2105 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
2082 g_free); | 2106 g_free); |
2083 g_hash_table_replace(components, g_strdup("room"), utf8name); | 2107 g_hash_table_replace(components, g_strdup("room"), utf8name); |
2084 g_hash_table_replace(components, g_strdup("exchange"), | 2108 g_hash_table_replace(components, g_strdup("exchange"), |
2085 g_strdup_printf("%d", args->info.chat.roominfo.exchange)); | 2109 g_strdup_printf("%d", args->info.chat.roominfo.exchange)); |
2110 purple_debug_info("yaz oscar", "about to call serv_got_chat_invite\n"); | |
2111 // purple_debug_info("yaz oscar", "name=%s message=%s\n", name ? name : args->info.chat.roominfo.name, message); | |
2086 serv_got_chat_invite(gc, | 2112 serv_got_chat_invite(gc, |
2087 utf8name, | 2113 utf8name, |
2088 userinfo->sn, | 2114 userinfo->sn, |
2089 message, | 2115 message, |
2090 components); | 2116 components); |
2315 * character in whatever encoding the message was sent in. Type 1 | 2341 * character in whatever encoding the message was sent in. Type 1 |
2316 * messages are always made up of only one part, so we can easily account | 2342 * messages are always made up of only one part, so we can easily account |
2317 * for this suck-ass part of the protocol by splitting the string into at | 2343 * for this suck-ass part of the protocol by splitting the string into at |
2318 * most 1 baby string. | 2344 * most 1 baby string. |
2319 */ | 2345 */ |
2320 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); | 2346 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); // \376 is 0xfe |
2321 for (numtoks=0; msg1[numtoks]; numtoks++); | 2347 for (numtoks=0; msg1[numtoks]; numtoks++); |
2322 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); | 2348 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); |
2323 for (i=0; msg1[i]; i++) { | 2349 for (i=0; msg1[i]; i++) { |
2324 gchar *uin = g_strdup_printf("%u", args->uin); | 2350 gchar *uin = g_strdup_printf("%u", args->uin); |
2325 | 2351 |
4342 char *encoded = NULL; | 4368 char *encoded = NULL; |
4343 | 4369 |
4344 charset = oscar_charset_check(str); | 4370 charset = oscar_charset_check(str); |
4345 if (charset == AIM_CHARSET_UNICODE) { | 4371 if (charset == AIM_CHARSET_UNICODE) { |
4346 encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL); | 4372 encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL); |
4373 botch_ucs(encoded, *ret_len); | |
4347 *encoding = "unicode-2-0"; | 4374 *encoding = "unicode-2-0"; |
4348 } else if (charset == AIM_CHARSET_CUSTOM) { | 4375 } else if (charset == AIM_CHARSET_CUSTOM) { |
4349 encoded = g_convert(str, strlen(str), "ISO-8859-1", "UTF-8", NULL, ret_len, NULL); | 4376 encoded = g_convert(str, strlen(str), "ISO-8859-1", "UTF-8", NULL, ret_len, NULL); |
4350 *encoding = "iso-8859-1"; | 4377 *encoding = "iso-8859-1"; |
4351 } else { | 4378 } else { |
5357 charsetstr = "us-ascii"; | 5384 charsetstr = "us-ascii"; |
5358 else if (charset == AIM_CHARSET_UNICODE) | 5385 else if (charset == AIM_CHARSET_UNICODE) |
5359 charsetstr = "unicode-2-0"; | 5386 charsetstr = "unicode-2-0"; |
5360 else if (charset == AIM_CHARSET_CUSTOM) | 5387 else if (charset == AIM_CHARSET_CUSTOM) |
5361 charsetstr = "iso-8859-1"; | 5388 charsetstr = "iso-8859-1"; |
5362 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "en"); | 5389 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "JA"); |
5363 g_free(buf2); | 5390 g_free(buf2); |
5364 | 5391 |
5365 return 0; | 5392 return 0; |
5366 } | 5393 } |
5367 | 5394 |