comparison libgaim/protocols/yahoo/yahoo_picture.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 0ac0f16aa006
children 1bee09450652
comparison
equal deleted inserted replaced
14353:33dc9f22b528 14354:01daacf7b771
41 GaimConnection *gc; 41 GaimConnection *gc;
42 char *who; 42 char *who;
43 int checksum; 43 int checksum;
44 }; 44 };
45 45
46 static void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len) 46 static void
47 { 47 yahoo_fetch_picture_cb(GaimUtilFetchUrlData *url_data, gpointer user_data,
48 struct yahoo_fetch_picture_data *d = user_data; 48 const gchar *pic_data, size_t len, const gchar *error_message)
49 {
50 struct yahoo_fetch_picture_data *d;
51 struct yahoo_data *yd;
49 GaimBuddy *b; 52 GaimBuddy *b;
50 53
51 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) { 54 d = user_data;
55 yd = d->gc->proto_data;
56 yd->url_datas = g_slist_remove(yd->url_datas, url_data);
57
58 if (error_message != NULL) {
59 gaim_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message);
60 } else if (len == 0) {
61 gaim_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n");
62 } else {
52 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len); 63 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len);
53 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who); 64 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who);
54 if (b) 65 if (b)
55 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); 66 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum);
56 } else {
57 gaim_debug_error("yahoo", "Fetching buddy icon failed.\n");
58 } 67 }
59 68
60 g_free(d->who); 69 g_free(d->who);
61 g_free(d); 70 g_free(d);
62 } 71 }
63 72
64 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt) 73 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt)
65 { 74 {
75 struct yahoo_data *yd;
66 GSList *l = pkt->hash; 76 GSList *l = pkt->hash;
67 char *who = NULL, *us = NULL; 77 char *who = NULL, *us = NULL;
68 gboolean got_icon_info = FALSE, send_icon_info = FALSE; 78 gboolean got_icon_info = FALSE, send_icon_info = FALSE;
69 char *url = NULL; 79 char *url = NULL;
70 int checksum = 0; 80 int checksum = 0;
102 } 112 }
103 113
104 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ 114 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */
105 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { 115 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) {
106 /* TODO: make this work p2p, try p2p before the url */ 116 /* TODO: make this work p2p, try p2p before the url */
117 GaimUtilFetchUrlData *url_data;
107 struct yahoo_fetch_picture_data *data; 118 struct yahoo_fetch_picture_data *data;
108 GaimBuddy *b = gaim_find_buddy(gc->account, who); 119 GaimBuddy *b = gaim_find_buddy(gc->account, who);
109 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) 120 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
110 return; 121 return;
111 122
112 data = g_new0(struct yahoo_fetch_picture_data, 1); 123 data = g_new0(struct yahoo_fetch_picture_data, 1);
113 data->gc = gc; 124 data->gc = gc;
114 data->who = g_strdup(who); 125 data->who = g_strdup(who);
115 data->checksum = checksum; 126 data->checksum = checksum;
116 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, 127 url_data = gaim_util_fetch_url(url, FALSE,
117 yahoo_fetch_picture_cb, data); 128 "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
129 yahoo_fetch_picture_cb, data);
130 if (url_data != NULL) {
131 yd = gc->proto_data;
132 yd->url_datas = g_slist_prepend(yd->url_datas, url_data);
133 } else {
134 g_free(data->who);
135 g_free(data);
136 }
118 } else if (who && send_icon_info) { 137 } else if (who && send_icon_info) {
119 yahoo_send_picture_info(gc, who); 138 yahoo_send_picture_info(gc, who);
120 } 139 }
121 } 140 }
122 141