comparison src/protocols/yahoo/yahoo.c @ 13200:33bef17125c2

[gaim-migrate @ 15563] This is the soon-to-be-infamous nonblocking network activity patch that I've been working on. Feel free to yell at me if this makes you unhappy. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 09 Feb 2006 04:17:56 +0000
parents a0a4b44239e8
children 263c2db78f77
comparison
equal deleted inserted replaced
13199:d8f238864c88 13200:33bef17125c2
2284 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond) 2284 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond)
2285 { 2285 {
2286 GaimConnection *gc = data; 2286 GaimConnection *gc = data;
2287 GaimAccount *account = gaim_connection_get_account(gc); 2287 GaimAccount *account = gaim_connection_get_account(gc);
2288 struct yahoo_data *yd = gc->proto_data; 2288 struct yahoo_data *yd = gc->proto_data;
2289 char buf[2048], *i = buf; 2289 char bufread[2048], *i = bufread, *buf = bufread;
2290 int len; 2290 int len;
2291 GString *s; 2291 GString *s;
2292 2292
2293 len = read(source, buf, sizeof(buf)-1); 2293 len = read(source, bufread, sizeof(bufread) - 1);
2294 if (len <= 0 || (strncmp(buf, "HTTP/1.0 302", strlen("HTTP/1.0 302")) && 2294 if (len < 0 && errno == EAGAIN)
2295 return;
2296 else if (len <= 0) {
2297 gaim_connection_error(gc, _("Unable to read"));
2298 return;
2299 }
2300
2301 if (yd->rxlen > 0 || !g_strstr_len(buf, len, "\r\n\r\n")) {
2302 yd->rxqueue = g_realloc(yd->rxqueue, yd->rxlen + len + 1);
2303 memcpy(yd->rxqueue + yd->rxlen, buf, len);
2304 yd->rxlen += len;
2305 i = buf = yd->rxqueue;
2306 len = yd->rxlen;
2307 }
2308 buf[len] = '\0';
2309
2310 if ((strncmp(buf, "HTTP/1.0 302", strlen("HTTP/1.0 302")) &&
2295 strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) { 2311 strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) {
2296 gaim_connection_error(gc, _("Unable to read")); 2312 gaim_connection_error(gc, _("Unable to read"));
2297 return; 2313 return;
2298 } 2314 }
2299 2315
2300 s = g_string_sized_new(len); 2316 s = g_string_sized_new(len);
2301 buf[sizeof(buf)-1] = '\0';
2302 2317
2303 while ((i = strstr(i, "Set-Cookie: "))) { 2318 while ((i = strstr(i, "Set-Cookie: "))) {
2304 i += strlen("Set-Cookie: "); 2319 i += strlen("Set-Cookie: ");
2305 for (;*i != ';' && *i != '\0'; i++) 2320 for (;*i != ';' && *i != '\0'; i++)
2306 g_string_append_c(s, *i); 2321 g_string_append_c(s, *i);
2309 } 2324 }
2310 2325
2311 yd->auth = g_string_free(s, FALSE); 2326 yd->auth = g_string_free(s, FALSE);
2312 gaim_input_remove(gc->inpa); 2327 gaim_input_remove(gc->inpa);
2313 close(source); 2328 close(source);
2329 g_free(yd->rxqueue);
2330 yd->rxqueue = NULL;
2331 yd->rxlen = 0;
2314 /* Now we have our cookies to login with. I'll go get the milk. */ 2332 /* Now we have our cookies to login with. I'll go get the milk. */
2315 if (gaim_proxy_connect(account, "wcs2.msg.dcn.yahoo.com", 2333 if (gaim_proxy_connect(account, "wcs2.msg.dcn.yahoo.com",
2316 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), 2334 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT),
2317 yahoo_got_web_connected, gc) != 0) { 2335 yahoo_got_web_connected, gc) != 0) {
2318 gaim_connection_error(gc, _("Connection problem")); 2336 gaim_connection_error(gc, _("Connection problem"));
2322 2340
2323 static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond) 2341 static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond)
2324 { 2342 {
2325 GaimConnection *gc = data; 2343 GaimConnection *gc = data;
2326 struct yahoo_data *yd = gc->proto_data; 2344 struct yahoo_data *yd = gc->proto_data;
2345 int written, total_len;
2346
2327 if (source < 0) { 2347 if (source < 0) {
2328 gaim_connection_error(gc, _("Unable to connect.")); 2348 gaim_connection_error(gc, _("Unable to connect."));
2329 return; 2349 return;
2330 } 2350 }
2331 write(source, yd->auth, strlen(yd->auth)); 2351
2352 total_len = strlen(yd->auth) - yd->auth_written;
2353 written = write(source, yd->auth + yd->auth_written, total_len);
2354
2355 if (written < 0 && errno == EAGAIN)
2356 written = 0;
2357 else if (written <= 0) {
2358 g_free(yd->auth);
2359 yd->auth = NULL;
2360 if (gc->inpa)
2361 gaim_input_remove(gc->inpa);
2362 gc->inpa = 0;
2363 gaim_connection_error(gc, _("Unable to connect."));
2364 return;
2365 }
2366
2367 if (written < total_len) {
2368 yd->auth_written += written;
2369 if (!gc->inpa)
2370 gc->inpa = gaim_input_add(source, GAIM_INPUT_WRITE,
2371 yahoo_got_cookies, gc);
2372 return;
2373 }
2374
2332 g_free(yd->auth); 2375 g_free(yd->auth);
2376 yd->auth = NULL;
2377 yd->auth_written = 0;
2378 if (gc->inpa)
2379 gaim_input_remove(gc->inpa);
2333 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc); 2380 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc);
2334 } 2381 }
2335 2382
2336 static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url) 2383 static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url)
2337 { 2384 {
2524 gaim_connection_update_progress(gc, _("Connecting"), 1, 2); 2571 gaim_connection_update_progress(gc, _("Connecting"), 1, 2);
2525 2572
2526 gaim_connection_set_display_name(gc, gaim_account_get_username(account)); 2573 gaim_connection_set_display_name(gc, gaim_account_get_username(account));
2527 2574
2528 yd->fd = -1; 2575 yd->fd = -1;
2576 yd->txhandler = -1;
2577 /* TODO: Is there a good grow size for the buffer? */
2578 yd->txbuf = gaim_circ_buffer_new(0);
2529 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free); 2579 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free);
2530 yd->confs = NULL; 2580 yd->confs = NULL;
2531 yd->conf_id = 2; 2581 yd->conf_id = 2;
2532 2582
2533 yd->current_status = get_yahoo_status_from_gaim_status(status); 2583 yd->current_status = get_yahoo_status_from_gaim_status(status);
2577 yd->chat_online = 0; 2627 yd->chat_online = 0;
2578 if (yd->in_chat) 2628 if (yd->in_chat)
2579 yahoo_c_leave(gc, 1); /* 1 = YAHOO_CHAT_ID */ 2629 yahoo_c_leave(gc, 1); /* 1 = YAHOO_CHAT_ID */
2580 2630
2581 g_hash_table_destroy(yd->friends); 2631 g_hash_table_destroy(yd->friends);
2582 if (yd->chat_name) 2632 g_free(yd->chat_name);
2583 g_free(yd->chat_name); 2633
2584 2634 g_free(yd->cookie_y);
2585 if (yd->cookie_y) 2635 g_free(yd->cookie_t);
2586 g_free(yd->cookie_y); 2636
2587 if (yd->cookie_t) 2637 if (yd->txhandler)
2588 g_free(yd->cookie_t); 2638 gaim_input_remove(yd->txhandler);
2639
2640 gaim_circ_buffer_destroy(yd->txbuf);
2589 2641
2590 if (yd->fd >= 0) 2642 if (yd->fd >= 0)
2591 close(yd->fd); 2643 close(yd->fd);
2592 2644
2593 if (yd->rxqueue) 2645 g_free(yd->rxqueue);
2594 g_free(yd->rxqueue);
2595 yd->rxlen = 0; 2646 yd->rxlen = 0;
2596 if (yd->picture_url) 2647 g_free(yd->picture_url);
2597 g_free(yd->picture_url); 2648
2598 if (yd->picture_upload_todo) 2649 if (yd->picture_upload_todo)
2599 yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo); 2650 yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
2600 if (yd->ycht) 2651 if (yd->ycht)
2601 ycht_connection_close(yd->ycht); 2652 ycht_connection_close(yd->ycht);
2602 2653