comparison libgaim/protocols/yahoo/yahoo.c @ 14354:01daacf7b771

[gaim-migrate @ 17060] Make gaim_url_fetch() cancelable and change Yahoo! to take advantage of the changes. Other stuff can be changed later, the important thing is that the API is there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Aug 2006 21:13:30 +0000
parents b3697123b01a
children d38b0839e765
comparison
equal deleted inserted replaced
14353:33dc9f22b528 14354:01daacf7b771
50 #include "ycht.h" 50 #include "ycht.h"
51 51
52 /* #define YAHOO_DEBUG */ 52 /* #define YAHOO_DEBUG */
53 53
54 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *); 54 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *);
55 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len); 55 static void yahoo_login_page_cb(GaimUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
56 static void yahoo_set_status(GaimAccount *account, GaimStatus *status); 56 static void yahoo_set_status(GaimAccount *account, GaimStatus *status);
57 57
58 static void 58 static void
59 yahoo_add_permit(GaimConnection *gc, const char *who) 59 yahoo_add_permit(GaimConnection *gc, const char *who)
60 { 60 {
1883 case 3: 1883 case 3:
1884 msg = g_strdup(_("Invalid username.")); 1884 msg = g_strdup(_("Invalid username."));
1885 break; 1885 break;
1886 case 13: 1886 case 13:
1887 if (!yd->wm) { 1887 if (!yd->wm) {
1888 GaimUtilFetchUrlData *url_data;
1888 yd->wm = TRUE; 1889 yd->wm = TRUE;
1889 if (yd->fd >= 0) 1890 if (yd->fd >= 0)
1890 close(yd->fd); 1891 close(yd->fd);
1891 if (gc->inpa) 1892 if (gc->inpa)
1892 gaim_input_remove(gc->inpa); 1893 gaim_input_remove(gc->inpa);
1893 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE, 1894 url_data = gaim_util_fetch_url(WEBMESSENGER_URL, TRUE,
1894 yahoo_login_page_cb, gc); 1895 "Gaim/" VERSION, FALSE, yahoo_login_page_cb, gc);
1896 if (url_data != NULL)
1897 yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
1895 gaim_notify_warning(gc, NULL, _("Normal authentication failed!"), 1898 gaim_notify_warning(gc, NULL, _("Normal authentication failed!"),
1896 _("The normal authentication method has failed. " 1899 _("The normal authentication method has failed. "
1897 "This means either your password is incorrect, " 1900 "This means either your password is incorrect, "
1898 "or Yahoo!'s authentication scheme has changed. " 1901 "or Yahoo!'s authentication scheme has changed. "
1899 "Gaim will now attempt to log in using Web " 1902 "Gaim will now attempt to log in using Web "
2521 g_hash_table_insert(hash, g_strdup(name), g_strdup(value)); 2524 g_hash_table_insert(hash, g_strdup(name), g_strdup(value));
2522 } 2525 }
2523 return hash; 2526 return hash;
2524 } 2527 }
2525 2528
2526 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len) 2529 static void
2530 yahoo_login_page_cb(GaimUtilFetchUrlData *url_data, gpointer user_data,
2531 const gchar *url_text, size_t len, const gchar *error_message)
2527 { 2532 {
2528 GaimConnection *gc = (GaimConnection *)user_data; 2533 GaimConnection *gc = (GaimConnection *)user_data;
2529 GaimAccount *account = gaim_connection_get_account(gc); 2534 GaimAccount *account = gaim_connection_get_account(gc);
2530 struct yahoo_data *yd = gc->proto_data; 2535 struct yahoo_data *yd = gc->proto_data;
2531 const char *sn = gaim_account_get_username(account); 2536 const char *sn = gaim_account_get_username(account);
2532 const char *pass = gaim_connection_get_password(gc); 2537 const char *pass = gaim_connection_get_password(gc);
2533 GHashTable *hash = yahoo_login_page_hash(buf, len); 2538 GHashTable *hash = yahoo_login_page_hash(url_text, len);
2534 GString *url = g_string_new("GET http://login.yahoo.com/config/login?login="); 2539 GString *url = g_string_new("GET http://login.yahoo.com/config/login?login=");
2535 char md5[33], *hashp = md5, *chal; 2540 char md5[33], *hashp = md5, *chal;
2536 int i; 2541 int i;
2537 GaimCipher *cipher; 2542 GaimCipher *cipher;
2538 GaimCipherContext *context; 2543 GaimCipherContext *context;
2539 guchar digest[16]; 2544 guchar digest[16];
2545
2546 yd->url_datas = g_slist_remove(yd->url_datas, url_data);
2540 2547
2541 url = g_string_append(url, sn); 2548 url = g_string_append(url, sn);
2542 url = g_string_append(url, "&passwd="); 2549 url = g_string_append(url, "&passwd=");
2543 2550
2544 cipher = gaim_ciphers_find_cipher("md5"); 2551 cipher = gaim_ciphers_find_cipher("md5");
2706 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 2713 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
2707 GSList *l; 2714 GSList *l;
2708 2715
2709 if (gc->inpa) 2716 if (gc->inpa)
2710 gaim_input_remove(gc->inpa); 2717 gaim_input_remove(gc->inpa);
2718
2719 while (yd->url_datas) {
2720 gaim_util_fetch_url_cancel(yd->url_datas->data);
2721 yd->url_datas = g_slist_delete_link(yd->url_datas, yd->url_datas);
2722 }
2711 2723
2712 for (l = yd->confs; l; l = l->next) { 2724 for (l = yd->confs; l; l = l->next) {
2713 GaimConversation *conv = l->data; 2725 GaimConversation *conv = l->data;
2714 2726
2715 yahoo_conf_leave(yd, gaim_conversation_get_name(conv), 2727 yahoo_conf_leave(yd, gaim_conversation_get_name(conv),