comparison libpurple/protocols/oscar/oscar.c @ 25467:be098f796b32

yaz patch has been applied.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 25 Apr 2007 07:57:26 +0000
parents 569eba287c84
children bf77cf06b082
comparison
equal deleted inserted replaced
25466:46a28577399d 25467:be098f796b32
278 278
279 g_return_val_if_fail(encoding != NULL, NULL); 279 g_return_val_if_fail(encoding != NULL, NULL);
280 280
281 /* Make sure encoding begins with charset= */ 281 /* Make sure encoding begins with charset= */
282 if (strncmp(encoding, "text/aolrtf; charset=", 21) && 282 if (strncmp(encoding, "text/aolrtf; charset=", 21) &&
283 strncmp(encoding, "text/x-aolrtf; charset=", 23)) 283 strncmp(encoding, "text/x-aolrtf; charset=", 23) &&
284 strncmp(encoding, "text/plain; charset=", 20)) /* for iChat */
284 { 285 {
285 return NULL; 286 return NULL;
286 } 287 }
287 288
288 begin = strchr(encoding, '"'); 289 begin = strchr(encoding, '"');
300 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)
301 { 302 {
302 gchar *utf8 = NULL; 303 gchar *utf8 = NULL;
303 304
304 if ((encoding == NULL) || encoding[0] == '\0') { 305 if ((encoding == NULL) || encoding[0] == '\0') {
305 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 }
306 } else if (!strcasecmp(encoding, "iso-8859-1")) { 325 } else if (!strcasecmp(encoding, "iso-8859-1")) {
307 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);
308 } else if (!strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") || 327 } else if (!strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1") ||
309 !strcasecmp(encoding, "us-ascii")) 328 !strcasecmp(encoding, "us-ascii"))
310 { 329 {
311 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);
312 } else if (!strcasecmp(encoding, "unicode-2-0")) { 331 } else if (!strcasecmp(encoding, "unicode-2-0")) {
332 sanitize_ucs(text, textlen);
313 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);
314 } else if (strcasecmp(encoding, "utf-8")) { 334 } else if (strcasecmp(encoding, "utf-8")) {
315 purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", " 335 purple_debug_warning("oscar", "Unrecognized character encoding \"%s\", "
316 "attempting to convert to UTF-8 anyway\n", encoding); 336 "attempting to convert to UTF-8 anyway\n", encoding);
317 utf8 = g_convert(text, textlen, "UTF-8", encoding, NULL, NULL, NULL); 337 utf8 = g_convert(text, textlen, "UTF-8", encoding, NULL, NULL, NULL);
328 && !g_utf8_validate(text, textlen, NULL)) 348 && !g_utf8_validate(text, textlen, NULL))
329 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.)"));
330 else 350 else
331 utf8 = g_strndup(text, textlen); 351 utf8 = g_strndup(text, textlen);
332 } 352 }
333 353 done:
334 return utf8; 354 return utf8;
335 } 355 }
336 356
337 static gchar * 357 static gchar *
338 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg) 358 oscar_utf8_try_convert(PurpleAccount *account, const gchar *msg)
485 PurpleBuddy *b; 505 PurpleBuddy *b;
486 b = purple_find_buddy(account, destsn); 506 b = purple_find_buddy(account, destsn);
487 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b))) 507 if ((b != NULL) && (PURPLE_BUDDY_IS_ONLINE(b)))
488 { 508 {
489 *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);
490 if (*msg != NULL) 511 if (*msg != NULL)
491 { 512 {
492 *charset = AIM_CHARSET_UNICODE; 513 *charset = AIM_CHARSET_UNICODE;
493 *charsubset = 0x0000; 514 *charsubset = 0x0000;
494 *msglen_int = msglen; 515 *msglen_int = msglen;
519 540
520 /* 541 /*
521 * Nothing else worked, so send as UCS-2BE. 542 * Nothing else worked, so send as UCS-2BE.
522 */ 543 */
523 *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);
524 if (*msg != NULL) { 546 if (*msg != NULL) {
525 *charset = AIM_CHARSET_UNICODE; 547 *charset = AIM_CHARSET_UNICODE;
526 *charsubset = 0x0000; 548 *charsubset = 0x0000;
527 *msglen_int = msglen; 549 *msglen_int = msglen;
528 return; 550 return;
1984 curpart = args->mpmsg.parts; 2006 curpart = args->mpmsg.parts;
1985 while (curpart != NULL) { 2007 while (curpart != NULL) {
1986 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset, 2008 tmp = purple_plugin_oscar_decode_im_part(account, userinfo->sn, curpart->charset,
1987 curpart->charsubset, curpart->data, curpart->datalen); 2009 curpart->charsubset, curpart->data, curpart->datalen);
1988 if (tmp != NULL) { 2010 if (tmp != NULL) {
2011 purple_str_strip_char(tmp, 0x0d); // yaz: strip CR
2012 // purple_debug_info("yaz oscar", "tmp=%s",tmp);
1989 g_string_append(message, tmp); 2013 g_string_append(message, tmp);
1990 g_free(tmp); 2014 g_free(tmp);
1991 } 2015 }
1992 2016
1993 curpart = curpart->next; 2017 curpart = curpart->next;
2084 if (args->type & OSCAR_CAPABILITY_CHAT) 2108 if (args->type & OSCAR_CAPABILITY_CHAT)
2085 { 2109 {
2086 char *encoding, *utf8name, *tmp; 2110 char *encoding, *utf8name, *tmp;
2087 GHashTable *components; 2111 GHashTable *components;
2088 2112
2113 // purple_debug_info("yaz oscar", "chat request %s\n", args->msg);
2089 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) { 2114 if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange) {
2090 g_free(message); 2115 g_free(message);
2091 return 1; 2116 return 1;
2092 } 2117 }
2093 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL; 2118 encoding = args->encoding ? oscar_encoding_extract(args->encoding) : NULL;
2106 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 2131 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
2107 g_free); 2132 g_free);
2108 g_hash_table_replace(components, g_strdup("room"), utf8name); 2133 g_hash_table_replace(components, g_strdup("room"), utf8name);
2109 g_hash_table_replace(components, g_strdup("exchange"), 2134 g_hash_table_replace(components, g_strdup("exchange"),
2110 g_strdup_printf("%d", args->info.chat.roominfo.exchange)); 2135 g_strdup_printf("%d", args->info.chat.roominfo.exchange));
2136 purple_debug_info("yaz oscar", "about to call serv_got_chat_invite\n");
2137 // purple_debug_info("yaz oscar", "name=%s message=%s\n", name ? name : args->info.chat.roominfo.name, message);
2111 serv_got_chat_invite(gc, 2138 serv_got_chat_invite(gc,
2112 utf8name, 2139 utf8name,
2113 userinfo->sn, 2140 userinfo->sn,
2114 message, 2141 message,
2115 components); 2142 components);
2337 * character in whatever encoding the message was sent in. Type 1 2364 * character in whatever encoding the message was sent in. Type 1
2338 * messages are always made up of only one part, so we can easily account 2365 * messages are always made up of only one part, so we can easily account
2339 * for this suck-ass part of the protocol by splitting the string into at 2366 * for this suck-ass part of the protocol by splitting the string into at
2340 * most 1 baby string. 2367 * most 1 baby string.
2341 */ 2368 */
2342 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); 2369 msg1 = g_strsplit(args->msg, "\376", (args->type == 0x01 ? 1 : 0)); // \376 is 0xfe
2343 for (numtoks=0; msg1[numtoks]; numtoks++); 2370 for (numtoks=0; msg1[numtoks]; numtoks++);
2344 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); 2371 msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *));
2345 for (i=0; msg1[i]; i++) { 2372 for (i=0; msg1[i]; i++) {
2346 gchar *uin = g_strdup_printf("%u", args->uin); 2373 gchar *uin = g_strdup_printf("%u", args->uin);
2347 2374
4388 char *encoded = NULL; 4415 char *encoded = NULL;
4389 4416
4390 charset = oscar_charset_check(str); 4417 charset = oscar_charset_check(str);
4391 if (charset == AIM_CHARSET_UNICODE) { 4418 if (charset == AIM_CHARSET_UNICODE) {
4392 encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL); 4419 encoded = g_convert(str, strlen(str), "UCS-2BE", "UTF-8", NULL, ret_len, NULL);
4420 botch_ucs(encoded, *ret_len);
4393 *encoding = "unicode-2-0"; 4421 *encoding = "unicode-2-0";
4394 } else if (charset == AIM_CHARSET_CUSTOM) { 4422 } else if (charset == AIM_CHARSET_CUSTOM) {
4395 encoded = g_convert(str, strlen(str), "ISO-8859-1", "UTF-8", NULL, ret_len, NULL); 4423 encoded = g_convert(str, strlen(str), "ISO-8859-1", "UTF-8", NULL, ret_len, NULL);
4396 *encoding = "iso-8859-1"; 4424 *encoding = "iso-8859-1";
4397 } else { 4425 } else {
5408 charsetstr = "us-ascii"; 5436 charsetstr = "us-ascii";
5409 else if (charset == AIM_CHARSET_UNICODE) 5437 else if (charset == AIM_CHARSET_UNICODE)
5410 charsetstr = "unicode-2-0"; 5438 charsetstr = "unicode-2-0";
5411 else if (charset == AIM_CHARSET_CUSTOM) 5439 else if (charset == AIM_CHARSET_CUSTOM)
5412 charsetstr = "iso-8859-1"; 5440 charsetstr = "iso-8859-1";
5413 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "en"); 5441 aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "JA");
5414 g_free(buf2); 5442 g_free(buf2);
5415 5443
5416 return 0; 5444 return 0;
5417 } 5445 }
5418 5446