comparison libpurple/protocols/yahoo/libymsg.c @ 32775:75daf132caf2

Yahoo: Move the "inpa" input watcher into protocol_data.
author andrew.victor@mxit.com
date Tue, 18 Oct 2011 21:39:25 +0000
parents 50cd80d3554e
children 3e7a7e14af62
comparison
equal deleted inserted replaced
32774:f236f3fce0d8 32775:75daf132caf2
2242 if (!yd->wm) { 2242 if (!yd->wm) {
2243 PurpleUtilFetchUrlData *url_data; 2243 PurpleUtilFetchUrlData *url_data;
2244 yd->wm = TRUE; 2244 yd->wm = TRUE;
2245 if (yd->fd >= 0) 2245 if (yd->fd >= 0)
2246 close(yd->fd); 2246 close(yd->fd);
2247 if (gc->inpa) 2247 if (yd->inpa) {
2248 purple_input_remove(gc->inpa); 2248 purple_input_remove(yd->inpa);
2249 yd->inpa = 0;
2250 }
2249 url_data = purple_util_fetch_url(WEBMESSENGER_URL, TRUE, 2251 url_data = purple_util_fetch_url(WEBMESSENGER_URL, TRUE,
2250 "Purple/" VERSION, FALSE, -1, yahoo_login_page_cb, gc); 2252 "Purple/" VERSION, FALSE, -1, yahoo_login_page_cb, gc);
2251 if (url_data != NULL) 2253 if (url_data != NULL)
2252 yd->url_datas = g_slist_prepend(yd->url_datas, url_data); 2254 yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
2253 return; 2255 return;
3246 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, yd->current_status, yd->session_id); 3248 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, yd->current_status, yd->session_id);
3247 3249
3248 yahoo_packet_hash_str(pkt, 1, purple_normalize(purple_connection_get_account(gc), purple_account_get_username(purple_connection_get_account(gc)))); 3250 yahoo_packet_hash_str(pkt, 1, purple_normalize(purple_connection_get_account(gc), purple_account_get_username(purple_connection_get_account(gc))));
3249 yahoo_packet_send_and_free(pkt, yd); 3251 yahoo_packet_send_and_free(pkt, yd);
3250 3252
3251 gc->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc); 3253 yd->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc);
3252 } 3254 }
3253 3255
3254 #ifdef TRY_WEBMESSENGER_LOGIN 3256 #ifdef TRY_WEBMESSENGER_LOGIN
3255 static void yahoo_got_web_connected(gpointer data, gint source, const gchar *error_message) 3257 static void yahoo_got_web_connected(gpointer data, gint source, const gchar *error_message)
3256 { 3258 {
3276 1, purple_normalize(purple_connection_get_account(gc), purple_account_get_username(purple_connection_get_account(gc))), 3278 1, purple_normalize(purple_connection_get_account(gc), purple_account_get_username(purple_connection_get_account(gc))),
3277 6, yd->auth); 3279 6, yd->auth);
3278 yahoo_packet_send_and_free(pkt, yd); 3280 yahoo_packet_send_and_free(pkt, yd);
3279 3281
3280 g_free(yd->auth); 3282 g_free(yd->auth);
3281 gc->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc); 3283 yd->inpa = purple_input_add(yd->fd, PURPLE_INPUT_READ, yahoo_pending, gc);
3282 } 3284 }
3283 3285
3284 static void yahoo_web_pending(gpointer data, gint source, PurpleInputCondition cond) 3286 static void yahoo_web_pending(gpointer data, gint source, PurpleInputCondition cond)
3285 { 3287 {
3286 PurpleConnection *gc = data; 3288 PurpleConnection *gc = data;
3340 * It seems to work without these 3342 * It seems to work without these
3341 */ 3343 */
3342 } 3344 }
3343 3345
3344 yd->auth = g_string_free(s, FALSE); 3346 yd->auth = g_string_free(s, FALSE);
3345 purple_input_remove(gc->inpa); 3347 purple_input_remove(yd->inpa);
3348 yd->inpa = 0;
3346 close(source); 3349 close(source);
3347 g_free(yd->rxqueue); 3350 g_free(yd->rxqueue);
3348 yd->rxqueue = NULL; 3351 yd->rxqueue = NULL;
3349 yd->rxlen = 0; 3352 yd->rxlen = 0;
3350 /* Now we have our cookies to login with. I'll go get the milk. */ 3353 /* Now we have our cookies to login with. I'll go get the milk. */
3357 } 3360 }
3358 } 3361 }
3359 3362
3360 static void yahoo_got_cookies_send_cb(gpointer data, gint source, PurpleInputCondition cond) 3363 static void yahoo_got_cookies_send_cb(gpointer data, gint source, PurpleInputCondition cond)
3361 { 3364 {
3362 PurpleConnection *gc; 3365 PurpleConnection *gc = data;
3363 YahooData *yd; 3366 YahooData *yd = purple_connection_get_protocol_data(gc);
3364 int written, remaining; 3367 int written, remaining;
3365
3366 gc = data;
3367 yd = purple_connection_get_protocol_data(gc);
3368 3368
3369 remaining = strlen(yd->auth) - yd->auth_written; 3369 remaining = strlen(yd->auth) - yd->auth_written;
3370 written = write(source, yd->auth + yd->auth_written, remaining); 3370 written = write(source, yd->auth + yd->auth_written, remaining);
3371 3371
3372 if (written < 0 && errno == EAGAIN) 3372 if (written < 0 && errno == EAGAIN)
3373 written = 0; 3373 written = 0;
3374 else if (written <= 0) { 3374 else if (written <= 0) {
3375 gchar *tmp; 3375 gchar *tmp;
3376 g_free(yd->auth); 3376 g_free(yd->auth);
3377 yd->auth = NULL; 3377 yd->auth = NULL;
3378 if (gc->inpa) 3378 if (yd->inpa) {
3379 purple_input_remove(gc->inpa); 3379 purple_input_remove(yd->inpa);
3380 gc->inpa = 0; 3380 yd->inpa = 0;
3381 }
3381 tmp = g_strdup_printf(_("Lost connection with %s: %s"), 3382 tmp = g_strdup_printf(_("Lost connection with %s: %s"),
3382 "login.yahoo.com:80", g_strerror(errno)); 3383 "login.yahoo.com:80", g_strerror(errno));
3383 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 3384 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
3384 g_free(tmp); 3385 g_free(tmp);
3385 return; 3386 return;
3391 } 3392 }
3392 3393
3393 g_free(yd->auth); 3394 g_free(yd->auth);
3394 yd->auth = NULL; 3395 yd->auth = NULL;
3395 yd->auth_written = 0; 3396 yd->auth_written = 0;
3396 purple_input_remove(gc->inpa); 3397 purple_input_remove(yd->inpa);
3397 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, yahoo_web_pending, gc); 3398 yd->inpa = purple_input_add(source, PURPLE_INPUT_READ, yahoo_web_pending, gc);
3398 } 3399 }
3399 3400
3400 static void yahoo_got_cookies(gpointer data, gint source, const gchar *error_message) 3401 static void yahoo_got_cookies(gpointer data, gint source, const gchar *error_message)
3401 { 3402 {
3402 PurpleConnection *gc = data; 3403 PurpleConnection *gc = data;
3404 YahooData *yd = purple_connection_get_protocol_data(gc);
3403 3405
3404 if (source < 0) { 3406 if (source < 0) {
3405 gchar *tmp; 3407 gchar *tmp;
3406 tmp = g_strdup_printf(_("Unable to establish a connection with %s: %s"), 3408 tmp = g_strdup_printf(_("Unable to establish a connection with %s: %s"),
3407 "login.yahoo.com:80", error_message); 3409 "login.yahoo.com:80", error_message);
3408 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 3410 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
3409 g_free(tmp); 3411 g_free(tmp);
3410 return; 3412 return;
3411 } 3413 }
3412 3414
3413 if (gc->inpa == 0) 3415 if (yd->inpa == 0)
3414 { 3416 {
3415 gc->inpa = purple_input_add(source, PURPLE_INPUT_WRITE, 3417 yd->inpa = purple_input_add(source, PURPLE_INPUT_WRITE,
3416 yahoo_got_cookies_send_cb, gc); 3418 yahoo_got_cookies_send_cb, gc);
3417 yahoo_got_cookies_send_cb(gc, source, PURPLE_INPUT_WRITE); 3419 yahoo_got_cookies_send_cb(gc, source, PURPLE_INPUT_WRITE);
3418 } 3420 }
3419 } 3421 }
3420 3422
3723 3725
3724 void yahoo_close(PurpleConnection *gc) { 3726 void yahoo_close(PurpleConnection *gc) {
3725 YahooData *yd = purple_connection_get_protocol_data(gc); 3727 YahooData *yd = purple_connection_get_protocol_data(gc);
3726 GSList *l; 3728 GSList *l;
3727 3729
3728 if (gc->inpa) 3730 if (yd->inpa) {
3729 purple_input_remove(gc->inpa); 3731 purple_input_remove(yd->inpa);
3732 yd->inpa = 0;
3733 }
3730 3734
3731 while (yd->url_datas) { 3735 while (yd->url_datas) {
3732 purple_util_fetch_url_cancel(yd->url_datas->data); 3736 purple_util_fetch_url_cancel(yd->url_datas->data);
3733 yd->url_datas = g_slist_delete_link(yd->url_datas, yd->url_datas); 3737 yd->url_datas = g_slist_delete_link(yd->url_datas, yd->url_datas);
3734 } 3738 }