comparison libpurple/protocols/yahoo/libymsg.c @ 30072:60af53dd42d5

Ladies and gentlemen, I give you HTTP-based retrieval of the Yahoo CS server address, thus eliminating the need for the old "Pager server" account option. This method makes us a bit less distinguishable from the official client, as the official clients do the same HTTP request. Fixes #11555.
author John Bailey <rekkanoryo@rekkanoryo.org>
date Fri, 02 Apr 2010 06:42:32 +0000
parents c4fe6afad87a
children 51f997e2347f
comparison
equal deleted inserted replaced
30070:5b6bfea1c93d 30072:60af53dd42d5
3449 3449
3450 purple_cipher_context_destroy(context); 3450 purple_cipher_context_destroy(context);
3451 } 3451 }
3452 #endif /* TRY_WEBMESSENGER_LOGIN */ 3452 #endif /* TRY_WEBMESSENGER_LOGIN */
3453 3453
3454 static void yahoo_server_check(PurpleAccount *account)
3455 {
3456 const char *server;
3457
3458 server = purple_account_get_string(account, "server", YAHOO_PAGER_HOST);
3459
3460 if (*server == '\0' || g_str_equal(server, "scs.yahoo.com") ||
3461 g_str_equal(server, "scs.msg.yahoo.com"))
3462 purple_account_set_string(account, "server", YAHOO_PAGER_HOST);
3463 }
3464
3465 static void yahoo_picture_check(PurpleAccount *account) 3454 static void yahoo_picture_check(PurpleAccount *account)
3466 { 3455 {
3467 PurpleConnection *gc = purple_account_get_connection(account); 3456 PurpleConnection *gc = purple_account_get_connection(account);
3468 PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account); 3457 PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account);
3469 3458
3514 purple_debug_error("yahoo", "Unexpected PurpleStatus!\n"); 3503 purple_debug_error("yahoo", "Unexpected PurpleStatus!\n");
3515 return YAHOO_STATUS_AVAILABLE; 3504 return YAHOO_STATUS_AVAILABLE;
3516 } 3505 }
3517 } 3506 }
3518 3507
3508 static void yahoo_got_pager_server(PurpleUtilFetchUrlData *url_data,
3509 gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
3510 {
3511 YahooData *yd = user_data;
3512 PurpleConnection *gc = yd->gc;
3513 PurpleAccount *a = purple_connection_get_account(gc);
3514 gchar **strings = NULL, *cs_server = NULL;
3515 int port = 0;
3516
3517 if(error_message != NULL) {
3518 purple_debug_error("yahoo", "Login failed. Unable to retrieve server "
3519 "info: %s\n", error_message);
3520 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3521 _("Unable to retrieve server information"));
3522 return;
3523 }
3524
3525 if(len == 0) {
3526 purple_debug_error("yahoo", "Login failed. Unable to retrieve server "
3527 "info: Server did not return any useful data.\n");
3528 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3529 _("Unable to retrieve server information"));
3530 return;
3531 }
3532
3533 strings = g_strsplit(url_text, "\n", -1);
3534
3535 if(g_strv_length(strings) > 1) {
3536 if(g_ascii_strncasecmp(strings[1], "CS_IP_ADDRESS=", 14) == 0) {
3537 cs_server = g_strdup(&strings[1][14]);
3538 purple_debug_info("yahoo", "Got CS IP address: %s\n", cs_server);
3539 } else {
3540 purple_debug_error("yahoo", "Login failed. Unable to retrieve "
3541 "server info: The server returned information, but it was "
3542 "not in the ""expected format.\n");
3543 }
3544 } else {
3545 purple_debug_error("yahoo", "Login failed. Unable to retrieve server "
3546 "info: The server returned information, but it was not in the "
3547 "expected format.\n");
3548 }
3549
3550 g_strfreev(strings);
3551
3552 if(cs_server) { /* got an address; get on with connecting */
3553 port = purple_account_get_int(a, "port", YAHOO_PAGER_PORT);
3554
3555 if(purple_proxy_connect(gc, a, cs_server, port, yahoo_got_connected, gc) == NULL)
3556 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3557 _("Unable to connect"));
3558 } else {
3559 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3560 _("Unable to retrieve server information"));
3561 }
3562
3563 g_free(cs_server);
3564 }
3565
3519 void yahoo_login(PurpleAccount *account) { 3566 void yahoo_login(PurpleAccount *account) {
3520 PurpleConnection *gc = purple_account_get_connection(account); 3567 PurpleConnection *gc = purple_account_get_connection(account);
3521 YahooData *yd = gc->proto_data = g_new0(YahooData, 1); 3568 YahooData *yd = gc->proto_data = g_new0(YahooData, 1);
3522 PurpleStatus *status = purple_account_get_active_status(account); 3569 PurpleStatus *status = purple_account_get_active_status(account);
3523 const char *server = NULL; 3570 gboolean use_whole_url = yahoo_account_use_http_proxy(gc);
3524 int pager_port = 0;
3525 3571
3526 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC; 3572 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC;
3527 3573
3528 purple_connection_update_progress(gc, _("Connecting"), 1, 2); 3574 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
3529 3575
3530 purple_connection_set_display_name(gc, purple_account_get_username(account)); 3576 purple_connection_set_display_name(gc, purple_account_get_username(account));
3531 3577
3532 yd->gc = gc; 3578 yd->gc = gc;
3579 yd->jp = yahoo_is_japan(account);
3533 yd->yahoo_local_p2p_server_fd = -1; 3580 yd->yahoo_local_p2p_server_fd = -1;
3534 yd->fd = -1; 3581 yd->fd = -1;
3535 yd->txhandler = 0; 3582 yd->txhandler = 0;
3536 /* TODO: Is there a good grow size for the buffer? */ 3583 /* TODO: Is there a good grow size for the buffer? */
3537 yd->txbuf = purple_circ_buffer_new(0); 3584 yd->txbuf = purple_circ_buffer_new(0);
3546 yd->confs = NULL; 3593 yd->confs = NULL;
3547 yd->conf_id = 2; 3594 yd->conf_id = 2;
3548 yd->last_keepalive = yd->last_ping = time(NULL); 3595 yd->last_keepalive = yd->last_ping = time(NULL);
3549 3596
3550 yd->current_status = get_yahoo_status_from_purple_status(status); 3597 yd->current_status = get_yahoo_status_from_purple_status(status);
3551 yd->jp = yahoo_is_japan(account); 3598
3552
3553 yahoo_server_check(account);
3554 yahoo_picture_check(account); 3599 yahoo_picture_check(account);
3555 3600
3556 server = purple_account_get_string(account, "server", 3601 /* Get the pager server. Actually start connecting in the callback since we
3557 yd->jp ? YAHOOJP_PAGER_HOST : YAHOO_PAGER_HOST); 3602 * must have the contents of the HTTP response to proceed. */
3558 pager_port = purple_account_get_int(account, "port", YAHOO_PAGER_PORT); 3603 purple_util_fetch_url_request_len_with_account(
3559 3604 purple_connection_get_account(gc),
3560 if (purple_proxy_connect(gc, account, server, pager_port, yahoo_got_connected, gc) == NULL) 3605 yd->jp ? YAHOOJP_PAGER_HOST_REQ_URL : YAHOO_PAGER_HOST_REQ_URL,
3561 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 3606 use_whole_url ? TRUE : FALSE,
3562 _("Unable to connect")); 3607 YAHOO_CLIENT_USERAGENT, TRUE, NULL, FALSE, -1,
3608 yahoo_got_pager_server, yd);
3563 3609
3564 return; 3610 return;
3565 } 3611 }
3566 3612
3567 void yahoo_close(PurpleConnection *gc) { 3613 void yahoo_close(PurpleConnection *gc) {