comparison libpurple/protocols/yahoo/yahoo.c @ 27829:2f05586afa12

propagate from branch 'im.pidgin.pidgin' (head 018afa661b9c72b48f2277e33e2fe55cc8b19235) to branch 'im.pidgin.pidgin.yaz' (head 0a588adc7efbf9575fd8245aa8ac7775a7e03026)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 30 Apr 2008 12:53:12 +0000
parents cc8903c59d6b 86634df8facf
children 1dd0e007514d
comparison
equal deleted inserted replaced
22770:cc8903c59d6b 27829:2f05586afa12
775 if (pair->key == 4) { 775 if (pair->key == 4) {
776 im = g_new0(struct _yahoo_im, 1); 776 im = g_new0(struct _yahoo_im, 1);
777 list = g_slist_append(list, im); 777 list = g_slist_append(list, im);
778 im->from = pair->value; 778 im->from = pair->value;
779 im->time = time(NULL); 779 im->time = time(NULL);
780 im->utf8 = 1;
780 } 781 }
781 if (pair->key == 97) 782 if (pair->key == 97)
782 if (im) 783 if (im)
783 im->utf8 = strtol(pair->value, NULL, 10); 784 im->utf8 = strtol(pair->value, NULL, 10);
784 if (pair->key == 15) 785 if (pair->key == 15)
1234 } 1235 }
1235 } 1236 }
1236 1237
1237 #define OUT_CHARSET "utf-8" 1238 #define OUT_CHARSET "utf-8"
1238 1239
1239 static char *yahoo_decode(const char *text) 1240 static char *yahoo_decode(PurpleConnection *gc, const char *text)
1240 { 1241 {
1242 struct yahoo_data *yd = gc->proto_data;
1241 char *converted = NULL; 1243 char *converted = NULL;
1242 char *n, *new; 1244 char *n, *new;
1243 const char *end, *p; 1245 const char *end, *p;
1244 int i, k; 1246 int i, k;
1245 1247
1276 *n = *p; 1278 *n = *p;
1277 } 1279 }
1278 1280
1279 *n = '\0'; 1281 *n = '\0';
1280 1282
1281 if (strstr(text, "\033$B")) 1283 if (yd->jp) {
1282 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL); 1284 converted = g_convert(new, n - new, OUT_CHARSET, "UTF-8", NULL, NULL, NULL);
1283 if (!converted) 1285 }
1284 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL); 1286 if (!yd->jp || !converted) {
1285 g_free(new); 1287 if (strstr(text, "\033$B"))
1288 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL);
1289 if (!converted)
1290 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL);
1291 g_free(new);
1292 }
1286 1293
1287 return converted; 1294 return converted;
1288 } 1295 }
1289 1296
1290 static void yahoo_process_mail(PurpleConnection *gc, struct yahoo_packet *pkt) 1297 static void yahoo_process_mail(PurpleConnection *gc, struct yahoo_packet *pkt)
1313 subj = pair->value; 1320 subj = pair->value;
1314 l = l->next; 1321 l = l->next;
1315 } 1322 }
1316 1323
1317 if (who && subj && email && *email) { 1324 if (who && subj && email && *email) {
1318 char *dec_who = yahoo_decode(who); 1325 char *dec_who = yahoo_decode(gc, who);
1319 char *dec_subj = yahoo_decode(subj); 1326 char *dec_subj = yahoo_decode(gc, subj);
1320 char *from = g_strdup_printf("%s (%s)", dec_who, email); 1327 char *from = g_strdup_printf("%s (%s)", dec_who, email);
1321 1328
1322 purple_notify_email(gc, dec_subj, from, purple_account_get_username(account), 1329 purple_notify_email(gc, dec_subj, from, purple_account_get_username(account),
1323 yahoo_mail_url, NULL, NULL); 1330 yahoo_mail_url, NULL, NULL);
1324 1331
1471 to_y64(result96, digest, 16); 1478 to_y64(result96, digest, 16);
1472 1479
1473 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); 1480 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0);
1474 1481
1475 if(yd->jp) { 1482 if(yd->jp) {
1476 yahoo_packet_hash(pack, "sssss", 1483 yahoo_packet_hash(pack, "ssssss",
1477 0, name, 1484 0, name,
1478 6, result6, 1485 6, result6,
1479 96, result96, 1486 96, result96,
1480 1, name, 1487 1, name,
1488 244, YAHOOJP_CLIENT_VERSION_ID,
1481 135, YAHOOJP_CLIENT_VERSION); 1489 135, YAHOOJP_CLIENT_VERSION);
1482 } else { 1490 } else {
1483 yahoo_packet_hash(pack, "ssssss", 1491 yahoo_packet_hash(pack, "ssssss",
1484 0, name, 1492 0, name,
1485 6, result6, 1493 6, result6,
1934 } 1942 }
1935 purple_debug_info("yahoo", "yahoo status: %d\n", yd->current_status); 1943 purple_debug_info("yahoo", "yahoo status: %d\n", yd->current_status);
1936 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->current_status, 0); 1944 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->current_status, 0);
1937 1945
1938 if(yd->jp) { 1946 if(yd->jp) {
1939 yahoo_packet_hash(pack, "sssss", 1947 yahoo_packet_hash(pack, "ssssss",
1940 0, name, 1948 0, name,
1941 6, resp_6, 1949 6, resp_6,
1942 96, resp_96, 1950 96, resp_96,
1943 1, name, 1951 1, name,
1952 244, YAHOOJP_CLIENT_VERSION_ID,
1944 135, YAHOOJP_CLIENT_VERSION); 1953 135, YAHOOJP_CLIENT_VERSION);
1945 } else { 1954 } else {
1946 yahoo_packet_hash(pack, "ssssss", 1955 yahoo_packet_hash(pack, "ssssss",
1947 0, name, 1956 0, name,
1948 6, resp_6, 1957 6, resp_6,
3533 3542
3534 /* use whole URL if using HTTP Proxy */ 3543 /* use whole URL if using HTTP Proxy */
3535 if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP)) 3544 if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP))
3536 use_whole_url = TRUE; 3545 use_whole_url = TRUE;
3537 3546
3538 url_data = purple_util_fetch_url_request(base_url, use_whole_url, 3547 if (yd->jp)
3548 url_data = NULL;
3549 else
3550 url_data = purple_util_fetch_url_request(base_url, use_whole_url,
3539 "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE, 3551 "Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
3540 yahoo_get_inbox_token_cb, gc); 3552 yahoo_get_inbox_token_cb, gc);
3541 3553
3542 g_free(request); 3554 g_free(request);
3543 3555
3726 3738
3727 return; 3739 return;
3728 } 3740 }
3729 3741
3730 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0); 3742 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
3743 if(!pkt) { // yaz
3744 purple_debug_info("yahoo", "yahoo_set_idle: pkt == NULL\n");
3745 return;
3746 }
3731 yahoo_packet_hash_int(pkt, 10, yd->current_status); 3747 yahoo_packet_hash_int(pkt, 10, yd->current_status);
3732 3748
3733 if (yd->current_status == YAHOO_STATUS_CUSTOM) { 3749 if (yd->current_status == YAHOO_STATUS_CUSTOM) {
3734 yahoo_packet_hash_str(pkt, 97, utf8 ? "1" : 0); 3750 yahoo_packet_hash_str(pkt, 97, utf8 ? "1" : 0);
3735 yahoo_packet_hash_str(pkt, 19, conv_msg); 3751 yahoo_packet_hash_str(pkt, 19, conv_msg);
3770 status = purple_presence_get_active_status(purple_account_get_presence(purple_connection_get_account(gc))); 3786 status = purple_presence_get_active_status(purple_account_get_presence(purple_connection_get_account(gc)));
3771 yd->current_status = get_yahoo_status_from_purple_status(status); 3787 yd->current_status = get_yahoo_status_from_purple_status(status);
3772 } 3788 }
3773 3789
3774 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0); 3790 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
3791 if(!pkt) {
3792 purple_debug_info("yahoo", "yahoo_set_idle: pkt == NULL\n");
3793 return;
3794 }
3775 3795
3776 yahoo_packet_hash_int(pkt, 10, yd->current_status); 3796 yahoo_packet_hash_int(pkt, 10, yd->current_status);
3777 if (yd->current_status == YAHOO_STATUS_CUSTOM) { 3797 if (yd->current_status == YAHOO_STATUS_CUSTOM) {
3778 const char *tmp; 3798 const char *tmp;
3779 if (status == NULL) 3799 if (status == NULL)
3780 status = purple_presence_get_active_status(purple_account_get_presence(purple_connection_get_account(gc))); 3800 status = purple_presence_get_active_status(purple_account_get_presence(purple_connection_get_account(gc)));
3781 tmp = purple_status_get_attr_string(status, "message"); 3801 tmp = purple_status_get_attr_string(status, "message");
3782 if (tmp != NULL) { 3802 if (tmp != NULL) {
3783 msg = yahoo_string_encode(gc, tmp, NULL); 3803 msg = yahoo_string_encode(gc, tmp, NULL);
3784 msg2 = purple_markup_strip_html(msg); 3804 msg2 = purple_markup_strip_html(msg);
3785 yahoo_packet_hash_str(pkt, 19, msg2); 3805 yahoo_packet_hash_str(pkt, 19, msg2); // yaz: pkt may be NULL.
3786 } else { 3806 } else {
3787 /* get_yahoo_status_from_purple_status() returns YAHOO_STATUS_CUSTOM for 3807 /* get_yahoo_status_from_purple_status() returns YAHOO_STATUS_CUSTOM for
3788 * the generic away state (YAHOO_STATUS_TYPE_AWAY) with no message */ 3808 * the generic away state (YAHOO_STATUS_TYPE_AWAY) with no message */
3789 yahoo_packet_hash_str(pkt, 19, _("Away")); 3809 yahoo_packet_hash_str(pkt, 19, _("Away"));
3790 } 3810 }
4447 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 4467 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
4448 4468
4449 option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE); 4469 option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
4450 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 4470 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
4451 4471
4452 option = purple_account_option_string_new(_("Encoding"), "local_charset", "ISO-8859-1"); 4472 option = purple_account_option_string_new(_("Encoding"), "local_charset", "UTF-8");
4453 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 4473 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
4454 4474
4455 4475
4456 #if 0 4476 #if 1
4457 option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL); 4477 option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
4458 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 4478 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
4459 4479
4460 option = purple_account_option_string_new(_("Yahoo Chat server"), "ycht-server", YAHOO_YCHT_HOST); 4480 option = purple_account_option_string_new(_("Yahoo Chat server"), "ycht-server", YAHOO_YCHT_HOST);
4461 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 4481 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);