comparison libpurple/protocols/oscar/oscar.c @ 27771:085d0a18a7f7

propagate from branch 'im.pidgin.pidgin' (head 7bbbd3b5812df69c6884596a4343b688d73c3124) to branch 'im.pidgin.pidgin.yaz' (head 9cfa4c04679a643911c1b80123ea1e531b825074)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 28 Feb 2008 12:28:35 +0000
parents 03b2b21b4c42 969a2aeae461
children 0f3a131d23da
comparison
equal deleted inserted replaced
22346:561729870929 27771:085d0a18a7f7
302 oscar_encoding_to_utf8(PurpleAccount *account, const char *encoding, const char *text, int textlen) 302 oscar_encoding_to_utf8(PurpleAccount *account, const char *encoding, const char *text, int textlen)
303 { 303 {
304 gchar *utf8 = NULL; 304 gchar *utf8 = NULL;
305 305
306 if ((encoding == NULL) || encoding[0] == '\0') { 306 if ((encoding == NULL) || encoding[0] == '\0') {
307 purple_debug_info("oscar", "Empty encoding, assuming UTF-8\n"); 307 purple_debug_info("yaz oscar", "Empty encoding, validate as UTF-8\n");
308 if(g_utf8_validate(text, textlen, NULL)){
309 size_t newlen;
310 utf8 = sanitize_utf(text, textlen, &newlen);
311 goto done;
312 }
313 // not UTF-8
314 purple_debug_info("yaz oscar", "Empty encoding, assuming UCS-2BE\n");
315 sanitize_ucs(text, textlen);
316 utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL);
317 if(utf8){
318 if(!g_utf8_validate(utf8, strlen(utf8), NULL)){
319 purple_debug_info("yaz oscar", "Invalid conversion\n");
320 g_free(utf8);
321 utf8 = NULL;
322 }
323 } else {
324 purple_debug_info("yaz oscar", "Conversion failed\n");
325 }
308 } else if (!g_ascii_strcasecmp(encoding, "iso-8859-1")) { 326 } else if (!g_ascii_strcasecmp(encoding, "iso-8859-1")) {
309 utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL); 327 utf8 = g_convert(text, textlen, "UTF-8", "iso-8859-1", NULL, NULL, NULL);
310 } else if (!g_ascii_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || 328 } else if (!g_ascii_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") ||
311 !g_ascii_strcasecmp(encoding, "us-ascii")) 329 !g_ascii_strcasecmp(encoding, "us-ascii"))
312 { 330 {
313 utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL); 331 utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL);
314 } else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) { 332 } else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) {
333 sanitize_ucs(text, textlen);
315 /* Some official ICQ clients are apparently total crack, 334 /* Some official ICQ clients are apparently total crack,
316 * and have been known to save a UTF-8 string converted 335 * and have been known to save a UTF-8 string converted
317 * from the locale character set to UCS-2 (not from UTF-8 336 * from the locale character set to UCS-2 (not from UTF-8
318 * to UCS-2!) in the away message. This hack should find 337 * to UCS-2!) in the away message. This hack should find
319 * and do something (un)reasonable with that, and not 338 * and do something (un)reasonable with that, and not
348 && !g_utf8_validate(text, textlen, NULL)) 367 && !g_utf8_validate(text, textlen, NULL))
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.)")); 368 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.)"));
350 else 369 else
351 utf8 = g_strndup(text, textlen); 370 utf8 = g_strndup(text, textlen);
352 } 371 }
353 372 done:
354 return utf8; 373 return utf8;
355 } 374 }
356 375
357 static gchar * 376 static gchar *
358 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg) 377 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg)
504 { 523 {
505 PurpleBuddy *b; 524 PurpleBuddy *b;
506 b = purple_find_buddy(account, destsn); 525 b = purple_find_buddy(account, destsn);
507 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b))) 526 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b)))
508 { 527 {
509 *msg = g_convert(from, -1, "UCS-2BE", "UTF-8", NULL, &msglen, NULL); 528 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, NULL);
529 botch_ucs(*msg, msglen);
510 if (*msg != NULL) 530 if (*msg != NULL)
511 { 531 {
512 *charset = AIM_CHARSET_UNICODE; 532 *charset = AIM_CHARSET_UNICODE;
513 *charsubset = 0x0000; 533 *charsubset = 0x0000;
514 *msglen_int = msglen; 534 *msglen_int = msglen;
538 } 558 }
539 559
540 /* 560 /*
541 * Nothing else worked, so send as UCS-2BE. 561 * Nothing else worked, so send as UCS-2BE.
542 */ 562 */
543 *msg = g_convert(from, -1, "UCS-2BE", "UTF-8", NULL, &msglen, &err); 563 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, &msglen, &err);
564 botch_ucs(*msg, msglen);
544 if (*msg != NULL) { 565 if (*msg != NULL) {
545 *charset = AIM_CHARSET_UNICODE; 566 *charset = AIM_CHARSET_UNICODE;
546 *charsubset = 0x0000; 567 *charsubset = 0x0000;
547 *msglen_int = msglen; 568 *msglen_int = msglen;
548 return; 569 return;
2026 curpart = args->mpmsg.parts; 2047 curpart = args->mpmsg.parts;
2027 while (curpart != NULL) { 2048 while (curpart != NULL) {
2028 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset, 2049 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset,
2029 curpart->charsubset, curpart->data, curpart->datalen); 2050 curpart->charsubset, curpart->data, curpart->datalen);
2030 if (tmp != NULL) { 2051 if (tmp != NULL) {
2052 purple_str_strip_char(tmp, 0x0d); // yaz: strip CR
2053 // purple_debug_info("yaz oscar", "tmp=%s",tmp);
2031 g_string_append(message, tmp); 2054 g_string_append(message, tmp);
2032 g_free(tmp); 2055 g_free(tmp);
2033 } 2056 }
2034 2057
2035 curpart = curpart->next; 2058 curpart = curpart->next;
2128 if (args->type & OSCAR_CAPABILITY_CHAT) 2151 if (args->type & OSCAR_CAPABILITY_CHAT)
2129 { 2152 {
2130 char *encoding, *utf8name, *tmp; 2153 char *encoding, *utf8name, *tmp;
2131 GHashTable *components; 2154 GHashTable *components;
2132 2155
2156 // purple_debug_info("yaz oscar", "chat request %s\n", args->msg);
2133 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) { 2157 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) {
2134 g_free(message); 2158 g_free(message);
2135 return 1; 2159 return 1;
2136 } 2160 }
2137 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL; 2161 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL;
2150 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 2174 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
2151 g_free); 2175 g_free);
2152 g_hash_table_replace(components, g_strdup("room"), utf8name); 2176 g_hash_table_replace(components, g_strdup("room"), utf8name);
2153 g_hash_table_replace(components, g_strdup("exchange"), 2177 g_hash_table_replace(components, g_strdup("exchange"),
2154 g_strdup_printf("%d", args->info.chat.roominfo.exchange)); 2178 g_strdup_printf("%d", args->info.chat.roominfo.exchange));
2179 purple_debug_info("yaz oscar", "about to call serv_got_chat_invite\n");
2180 // purple_debug_info("yaz oscar", "name=%s message=%s\n", name ? name : args->info.chat.roominfo.name, message);
2155 serv_got_chat_invite(gc, 2181 serv_got_chat_invite(gc,
2156 utf8name, 2182 utf8name,
2157 userinfo->sn, 2183 userinfo->sn,
2158 message, 2184 message,
2159 components); 2185 components);
2385 * character in whatever encoding the message was sent in. Type 1 2411 * character in whatever encoding the message was sent in. Type 1
2386 * messages are always made up of only one part, so we can easily account 2412 * messages are always made up of only one part, so we can easily account
2387 * for this suck-ass part of the protocol by splitting the string into at 2413 * for this suck-ass part of the protocol by splitting the string into at
2388 * most 1 baby string. 2414 * most 1 baby string.
2389 */ 2415 */
2390 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); 2416 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); // \376 is 0xfe
2391 for (numtoks=0; msg1[numtoks]; numtoks++); 2417 for (numtoks=0; msg1[numtoks]; numtoks++);
2392 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); 2418 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *));
2393 for (i=0; msg1[i]; i++) { 2419 for (i=0; msg1[i]; i++) {
2394 gchar *uin = g_strdup_printf("%u", args->uin); 2420 gchar *uin = g_strdup_printf("%u", args->uin);
2395 2421
4443 int charset = 0; 4469 int charset = 0;
4444 char *encoded = NULL; 4470 char *encoded = NULL;
4445 4471
4446 charset = oscar_charset_check(str); 4472 charset = oscar_charset_check(str);
4447 if (charset == AIM_CHARSET_UNICODE) { 4473 if (charset == AIM_CHARSET_UNICODE) {
4448 encoded = g_convert(str, -1, "UCS-2BE", "UTF-8", NULL, ret_len, NULL); 4474 encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL);
4475 botch_ucs(encoded, *ret_len);
4449 *encoding = "unicode-2-0"; 4476 *encoding = "unicode-2-0";
4450 } else if (charset == AIM_CHARSET_CUSTOM) { 4477 } else if (charset == AIM_CHARSET_CUSTOM) {
4451 encoded = g_convert(str, -1, "ISO-8859-1", "UTF-8", NULL, ret_len, NULL); 4478 encoded = g_convert(str, -1, "ISO-8859-1", "UTF-8", NULL, ret_len, NULL);
4452 *encoding = "iso-8859-1"; 4479 *encoding = "iso-8859-1";
4453 } else { 4480 } else {
5566 charsetstr = "us-ascii"; 5593 charsetstr = "us-ascii";
5567 else if (charset == AIM_CHARSET_UNICODE) 5594 else if (charset == AIM_CHARSET_UNICODE)
5568 charsetstr = "unicode-2-0"; 5595 charsetstr = "unicode-2-0";
5569 else if (charset == AIM_CHARSET_CUSTOM) 5596 else if (charset == AIM_CHARSET_CUSTOM)
5570 charsetstr = "iso-8859-1"; 5597 charsetstr = "iso-8859-1";
5571 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "en"); 5598 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "JA");
5572 g_free(buf2); 5599 g_free(buf2);
5573 g_free(buf); 5600 g_free(buf);
5574 5601
5575 return 0; 5602 return 0;
5576 } 5603 }