comparison libpurple/protocols/yahoo/libymsg.c @ 30078:51f997e2347f

Some improvements to the new CS-via-HTTP stuff, sparked by Stu's suggestion to iterate over the entire respose returned from the HTTP GET.
author John Bailey <rekkanoryo@rekkanoryo.org>
date Sat, 03 Apr 2010 05:09:28 +0000
parents 60af53dd42d5
children 6d18b6221c5e
comparison
equal deleted inserted replaced
30077:69decc147e5b 30078:51f997e2347f
3510 { 3510 {
3511 YahooData *yd = user_data; 3511 YahooData *yd = user_data;
3512 PurpleConnection *gc = yd->gc; 3512 PurpleConnection *gc = yd->gc;
3513 PurpleAccount *a = purple_connection_get_account(gc); 3513 PurpleAccount *a = purple_connection_get_account(gc);
3514 gchar **strings = NULL, *cs_server = NULL; 3514 gchar **strings = NULL, *cs_server = NULL;
3515 int port = 0; 3515 int port = 0, stringslen = 0;
3516 3516
3517 if(error_message != NULL) { 3517 if(error_message != NULL || len == 0) {
3518 purple_debug_error("yahoo", "Login failed. Unable to retrieve server " 3518 purple_debug_error("yahoo", "Unable to retrieve server info. %"
3519 "info: %s\n", error_message); 3519 G_GSIZE_FORMAT " bytes retrieved with error message: %s\n", len,
3520 error_message ? error_message : "(null)");
3520 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 3521 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3521 _("Unable to retrieve server information")); 3522 _("Unable to connect: The server returned an empty response."));
3522 return; 3523 } else {
3523 } 3524 strings = g_strsplit(url_text, "\n", -1);
3524 3525
3525 if(len == 0) { 3526 if((stringslen = g_strv_length(strings)) > 1) {
3526 purple_debug_error("yahoo", "Login failed. Unable to retrieve server " 3527 int i;
3527 "info: Server did not return any useful data.\n"); 3528
3528 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 3529 for(i = 0; i < stringslen; i++) {
3529 _("Unable to retrieve server information")); 3530 if(g_ascii_strncasecmp(strings[i], "COLO_CAPACITY=", 14) == 0) {
3530 return; 3531 purple_debug_info("yahoo", "Got COLO Capacity: %s\n", &(strings[i][14]));
3531 } 3532 } else if(g_ascii_strncasecmp(strings[i], "CS_IP_ADDRESS=", 14) == 0) {
3532 3533 cs_server = g_strdup(&strings[i][14]);
3533 strings = g_strsplit(url_text, "\n", -1); 3534 purple_debug_info("yahoo", "Got CS IP address: %s\n", cs_server);
3534 3535 }
3535 if(g_strv_length(strings) > 1) { 3536 }
3536 if(g_ascii_strncasecmp(strings[1], "CS_IP_ADDRESS=", 14) == 0) { 3537 }
3537 cs_server = g_strdup(&strings[1][14]); 3538
3538 purple_debug_info("yahoo", "Got CS IP address: %s\n", cs_server); 3539 if(cs_server) { /* got an address; get on with connecting */
3540 port = purple_account_get_int(a, "port", YAHOO_PAGER_PORT);
3541
3542 if(purple_proxy_connect(gc, a, cs_server, port, yahoo_got_connected, gc) == NULL)
3543 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3544 _("Unable to connect"));
3539 } else { 3545 } else {
3540 purple_debug_error("yahoo", "Login failed. Unable to retrieve " 3546 purple_debug_error("yahoo", "No CS address retrieved! Server "
3541 "server info: The server returned information, but it was " 3547 "response:\n%s\n", url_text ? url_text : "(null)");
3542 "not in the ""expected format.\n"); 3548 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
3543 } 3549 _("Unable to connect: The server's response did not contain "
3544 } else { 3550 "the necessary information"));
3545 purple_debug_error("yahoo", "Login failed. Unable to retrieve server " 3551 }
3546 "info: The server returned information, but it was not in the "
3547 "expected format.\n");
3548 } 3552 }
3549 3553
3550 g_strfreev(strings); 3554 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); 3555 g_free(cs_server);
3564 } 3556 }
3565 3557
3566 void yahoo_login(PurpleAccount *account) { 3558 void yahoo_login(PurpleAccount *account) {
3567 PurpleConnection *gc = purple_account_get_connection(account); 3559 PurpleConnection *gc = purple_account_get_connection(account);