Mercurial > pidgin
comparison libpurple/protocols/oscar/oscar.c @ 28611:8a90bd0a3b79
Plucked d2a1d52b3bbf29baa53b9ddaa635d50b6332064f from im.pidgin.adium
by Zac West:
Fixed sending DIM messages' encoding. Fixes #9087.
The encoding bytes were being written in the wrong location, so the messages
were being read back as ASCII and failing conversion, ending up being empty
and not being displayed.
Plucked f5376d42261b8efc3d889314df9896bb10d3fe16 from im.pidgin.adium:
iChat sends direct IM messages with its encoding as 0x000d, which was being
forced-interpreted as ASCII. Also, added better debug logging for charset
information being received.
applied changes from 212bd3655451599364562cabe553c5b7a19134ae
through d2a1d52b3bbf29baa53b9ddaa635d50b6332064f
applied changes from d2a1d52b3bbf29baa53b9ddaa635d50b6332064f
through f5376d42261b8efc3d889314df9896bb10d3fe16
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Sun, 22 Nov 2009 18:56:06 +0000 |
parents | 17617d892bc4 |
children | 10a18f1ecb66 |
comparison
equal
deleted
inserted
replaced
28610:97900b3b55ca | 28611:8a90bd0a3b79 |
---|---|
436 */ | 436 */ |
437 gchar * | 437 gchar * |
438 purple_plugin_oscar_decode_im_part(PurpleAccount *account, const char *sourcebn, guint16 charset, guint16 charsubset, const gchar *data, gsize datalen) | 438 purple_plugin_oscar_decode_im_part(PurpleAccount *account, const char *sourcebn, guint16 charset, guint16 charsubset, const gchar *data, gsize datalen) |
439 { | 439 { |
440 gchar *ret = NULL; | 440 gchar *ret = NULL; |
441 const gchar *charsetstr1, *charsetstr2; | 441 const gchar *charsetstr1, *charsetstr2, *charsetstr3 = NULL; |
442 | |
443 purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT "\n", charset, charsubset, datalen); | |
444 | 442 |
445 if ((datalen == 0) || (data == NULL)) | 443 if ((datalen == 0) || (data == NULL)) |
446 return NULL; | 444 return NULL; |
447 | 445 |
448 if (charset == AIM_CHARSET_UNICODE) { | 446 if (charset == AIM_CHARSET_UNICODE) { |
457 } else if (charset == AIM_CHARSET_ASCII) { | 455 } else if (charset == AIM_CHARSET_ASCII) { |
458 /* Should just be "ASCII" */ | 456 /* Should just be "ASCII" */ |
459 charsetstr1 = "ASCII"; | 457 charsetstr1 = "ASCII"; |
460 charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); | 458 charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); |
461 } else if (charset == 0x000d) { | 459 } else if (charset == 0x000d) { |
462 /* Mobile AIM client on a Nokia 3100 and an LG VX6000 */ | 460 /* iChat sending unicode over a Direct IM connection = Unicode */ |
463 charsetstr1 = "ISO-8859-1"; | 461 /* Mobile AIM client on a Nokia 3100 and an LG VX6000 = ISO-8859-1 */ |
464 charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); | 462 charsetstr1 = "UTF-16BE"; |
463 charsetstr2 = "UTF-8"; | |
464 charsetstr3 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); | |
465 } else { | 465 } else { |
466 /* Unknown, hope for valid UTF-8... */ | 466 /* Unknown, hope for valid UTF-8... */ |
467 charsetstr1 = "UTF-8"; | 467 charsetstr1 = "UTF-8"; |
468 charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); | 468 charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); |
469 } | 469 } |
470 | |
471 purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT ", choice1=%s, choice2=%s, choise3=%s\n", | |
472 charset, charsubset, datalen, charsetstr1, charsetstr2, (charsetstr3 ? charsetstr3 : "")); | |
470 | 473 |
471 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr1, FALSE); | 474 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr1, FALSE); |
472 if (ret == NULL) | 475 if (ret == NULL) { |
473 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE); | 476 if (charsetstr3 != NULL) { |
477 /* Try charsetstr2 without allowing substitutions, then fall through to charsetstr3 if needed */ | |
478 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, FALSE); | |
479 if (ret == NULL) | |
480 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr3, TRUE); | |
481 } else { | |
482 /* Try charsetstr2, allowing substitutions */ | |
483 ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE); | |
484 } | |
485 } | |
474 if (ret == NULL) { | 486 if (ret == NULL) { |
475 char *str, *salvage, *tmp; | 487 char *str, *salvage, *tmp; |
476 | 488 |
477 str = g_malloc(datalen + 1); | 489 str = g_malloc(datalen + 1); |
478 strncpy(str, data, datalen); | 490 strncpy(str, data, datalen); |
573 /* | 585 /* |
574 * Nothing else worked, so send as UTF-16BE. | 586 * Nothing else worked, so send as UTF-16BE. |
575 */ | 587 */ |
576 *msg = g_convert(from, -1, "UTF-16BE", "UTF-8", NULL, &msglen, &err); | 588 *msg = g_convert(from, -1, "UTF-16BE", "UTF-8", NULL, &msglen, &err); |
577 if (*msg != NULL) { | 589 if (*msg != NULL) { |
590 purple_debug_info("oscar", "Conversion from UTF-8 to UTF-16BE results in %s.\n", | |
591 *msg); | |
592 | |
578 *charset = AIM_CHARSET_UNICODE; | 593 *charset = AIM_CHARSET_UNICODE; |
579 *charsubset = 0x0000; | 594 *charsubset = 0x0000; |
580 *msglen_int = msglen; | 595 *msglen_int = msglen; |
581 return; | 596 return; |
582 } | 597 } |
4550 msg = g_string_append_len(msg, data->str, data->len); | 4565 msg = g_string_append_len(msg, data->str, data->len); |
4551 msg = g_string_append(msg, "</BINARY>"); | 4566 msg = g_string_append(msg, "</BINARY>"); |
4552 } | 4567 } |
4553 g_string_free(data, TRUE); | 4568 g_string_free(data, TRUE); |
4554 | 4569 |
4570 purple_debug_info("oscar", "sending direct IM %s using charset %i", msg->str, charset); | |
4571 | |
4555 peer_odc_send_im(conn, msg->str, msg->len, charset, | 4572 peer_odc_send_im(conn, msg->str, msg->len, charset, |
4556 imflags & PURPLE_MESSAGE_AUTO_RESP); | 4573 imflags & PURPLE_MESSAGE_AUTO_RESP); |
4557 g_string_free(msg, TRUE); | 4574 g_string_free(msg, TRUE); |
4558 } | 4575 } |
4559 | 4576 |