Mercurial > pidgin
comparison libpurple/protocols/yahoo/yahoo_picture.c @ 32672:3828a61c44da
A boring and large patch so I can merge heads.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 23 Dec 2011 08:21:58 +0000 |
parents | 908be3822215 |
children |
comparison
equal
deleted
inserted
replaced
32671:0e69949b3e61 | 32672:3828a61c44da |
---|---|
50 { | 50 { |
51 struct yahoo_fetch_picture_data *d; | 51 struct yahoo_fetch_picture_data *d; |
52 YahooData *yd; | 52 YahooData *yd; |
53 | 53 |
54 d = user_data; | 54 d = user_data; |
55 yd = d->gc->proto_data; | 55 yd = purple_connection_get_protocol_data(d->gc); |
56 yd->url_datas = g_slist_remove(yd->url_datas, url_data); | 56 yd->url_datas = g_slist_remove(yd->url_datas, url_data); |
57 | 57 |
58 if (error_message != NULL) { | 58 if (error_message != NULL) { |
59 purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); | 59 purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); |
60 } else if (len == 0) { | 60 } else if (len == 0) { |
121 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ | 121 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ |
122 if (who && got_icon_info && url && !g_ascii_strncasecmp(url, "http://", 7)) { | 122 if (who && got_icon_info && url && !g_ascii_strncasecmp(url, "http://", 7)) { |
123 /* TODO: make this work p2p, try p2p before the url */ | 123 /* TODO: make this work p2p, try p2p before the url */ |
124 PurpleUtilFetchUrlData *url_data; | 124 PurpleUtilFetchUrlData *url_data; |
125 struct yahoo_fetch_picture_data *data; | 125 struct yahoo_fetch_picture_data *data; |
126 PurpleBuddy *b = purple_find_buddy(gc->account, who); | |
127 const char *locksum = NULL; | |
128 /* use whole URL if using HTTP Proxy */ | 126 /* use whole URL if using HTTP Proxy */ |
129 gboolean use_whole_url = yahoo_account_use_http_proxy(gc); | 127 gboolean use_whole_url = yahoo_account_use_http_proxy(gc); |
130 | |
131 /* FIXME: Cleanup this strtol() stuff if possible. */ | |
132 if (b && (locksum = purple_buddy_icons_get_checksum_for_user(b)) != NULL && | |
133 (checksum == strtol(locksum, NULL, 10))) | |
134 return; | |
135 | 128 |
136 data = g_new0(struct yahoo_fetch_picture_data, 1); | 129 data = g_new0(struct yahoo_fetch_picture_data, 1); |
137 data->gc = gc; | 130 data->gc = gc; |
138 data->who = g_strdup(who); | 131 data->who = g_strdup(who); |
139 data->checksum = checksum; | 132 data->checksum = checksum; |
140 /* TODO: Does this need to be MSIE 5.0? */ | 133 /* TODO: Does this need to be MSIE 5.0? */ |
141 url_data = purple_util_fetch_url(url, use_whole_url, | 134 url_data = purple_util_fetch_url(url, use_whole_url, |
142 "Mozilla/4.0 (compatible; MSIE 5.5)", FALSE, | 135 "Mozilla/4.0 (compatible; MSIE 5.5)", FALSE, -1, |
143 yahoo_fetch_picture_cb, data); | 136 yahoo_fetch_picture_cb, data); |
144 if (url_data != NULL) { | 137 if (url_data != NULL) { |
145 yd = gc->proto_data; | 138 yd = purple_connection_get_protocol_data(gc); |
146 yd->url_datas = g_slist_prepend(yd->url_datas, url_data); | 139 yd->url_datas = g_slist_prepend(yd->url_datas, url_data); |
147 } else { | 140 } else { |
148 g_free(data->who); | 141 g_free(data->who); |
149 g_free(data); | 142 g_free(data); |
150 } | 143 } |
175 } | 168 } |
176 l = l->next; | 169 l = l->next; |
177 } | 170 } |
178 | 171 |
179 if (who) { | 172 if (who) { |
180 PurpleBuddy *b = purple_find_buddy(gc->account, who); | 173 PurpleBuddy *b = purple_find_buddy(purple_connection_get_account(gc), who); |
181 const char *locksum = NULL; | 174 const char *locksum = NULL; |
182 | 175 |
183 /* FIXME: Cleanup this strtol() stuff if possible. */ | 176 /* FIXME: Cleanup this strtol() stuff if possible. */ |
184 if (b) { | 177 if (b) { |
185 locksum = purple_buddy_icons_get_checksum_for_user(b); | 178 locksum = purple_buddy_icons_get_checksum_for_user(b); |
190 } | 183 } |
191 | 184 |
192 void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt) | 185 void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt) |
193 { | 186 { |
194 PurpleAccount *account = purple_connection_get_account(gc); | 187 PurpleAccount *account = purple_connection_get_account(gc); |
195 YahooData *yd = gc->proto_data; | 188 YahooData *yd = purple_connection_get_protocol_data(gc); |
196 GSList *l = pkt->hash; | 189 GSList *l = pkt->hash; |
197 char *url = NULL; | 190 char *url = NULL; |
198 | 191 |
199 while (l) { | 192 while (l) { |
200 struct yahoo_pair *pair = l->data; | 193 struct yahoo_pair *pair = l->data; |
256 if (who) { | 249 if (who) { |
257 if (avatar == 2) | 250 if (avatar == 2) |
258 yahoo_send_picture_request(gc, who); | 251 yahoo_send_picture_request(gc, who); |
259 else if ((avatar == 0) || (avatar == 1)) { | 252 else if ((avatar == 0) || (avatar == 1)) { |
260 YahooFriend *f; | 253 YahooFriend *f; |
261 purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); | 254 purple_buddy_icons_set_for_user(purple_connection_get_account(gc), who, NULL, 0, NULL); |
262 if ((f = yahoo_friend_find(gc, who))) | 255 if ((f = yahoo_friend_find(gc, who))) |
263 yahoo_friend_set_buddy_icon_need_request(f, TRUE); | 256 yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
264 purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); | 257 purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
265 } | 258 } |
266 } | 259 } |
267 } | 260 } |
268 | 261 |
269 void yahoo_send_picture_info(PurpleConnection *gc, const char *who) | 262 void yahoo_send_picture_info(PurpleConnection *gc, const char *who) |
270 { | 263 { |
271 YahooData *yd = gc->proto_data; | 264 YahooData *yd = purple_connection_get_protocol_data(gc); |
272 struct yahoo_packet *pkt; | 265 struct yahoo_packet *pkt; |
273 | 266 |
274 if (!yd->picture_url) { | 267 if (!yd->picture_url) { |
275 purple_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); | 268 purple_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); |
276 return; | 269 return; |
283 yahoo_packet_send_and_free(pkt, yd); | 276 yahoo_packet_send_and_free(pkt, yd); |
284 } | 277 } |
285 | 278 |
286 void yahoo_send_picture_request(PurpleConnection *gc, const char *who) | 279 void yahoo_send_picture_request(PurpleConnection *gc, const char *who) |
287 { | 280 { |
288 YahooData *yd = gc->proto_data; | 281 YahooData *yd = purple_connection_get_protocol_data(gc); |
289 struct yahoo_packet *pkt; | 282 struct yahoo_packet *pkt; |
290 | 283 |
291 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, yd->session_id); | 284 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, yd->session_id); |
292 yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc)); /* me */ | 285 yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc)); /* me */ |
293 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ | 286 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ |
295 yahoo_packet_send_and_free(pkt, yd); | 288 yahoo_packet_send_and_free(pkt, yd); |
296 } | 289 } |
297 | 290 |
298 void yahoo_send_picture_checksum(PurpleConnection *gc) | 291 void yahoo_send_picture_checksum(PurpleConnection *gc) |
299 { | 292 { |
300 YahooData *yd = gc->proto_data; | 293 YahooData *yd = purple_connection_get_protocol_data(gc); |
301 struct yahoo_packet *pkt; | 294 struct yahoo_packet *pkt; |
302 | 295 |
303 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, yd->session_id); | 296 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, yd->session_id); |
304 yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), | 297 yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), |
305 212, "1", 192, yd->picture_checksum); | 298 212, "1", 192, yd->picture_checksum); |
306 yahoo_packet_send_and_free(pkt, yd); | 299 yahoo_packet_send_and_free(pkt, yd); |
307 } | 300 } |
308 | 301 |
309 void yahoo_send_picture_update_to_user(PurpleConnection *gc, const char *who, int type) | 302 void yahoo_send_picture_update_to_user(PurpleConnection *gc, const char *who, int type) |
310 { | 303 { |
311 YahooData *yd = gc->proto_data; | 304 YahooData *yd = purple_connection_get_protocol_data(gc); |
312 struct yahoo_packet *pkt; | 305 struct yahoo_packet *pkt; |
313 | 306 |
314 pkt = yahoo_packet_new(YAHOO_SERVICE_AVATAR_UPDATE, YAHOO_STATUS_AVAILABLE, yd->session_id); | 307 pkt = yahoo_packet_new(YAHOO_SERVICE_AVATAR_UPDATE, YAHOO_STATUS_AVAILABLE, yd->session_id); |
315 yahoo_packet_hash(pkt, "si", 3, who, 213, type); | 308 yahoo_packet_hash(pkt, "si", 3, who, 213, type); |
316 yahoo_packet_send_and_free(pkt, yd); | 309 yahoo_packet_send_and_free(pkt, yd); |
331 yahoo_send_picture_update_to_user(d->gc, who, d->type); | 324 yahoo_send_picture_update_to_user(d->gc, who, d->type); |
332 } | 325 } |
333 | 326 |
334 void yahoo_send_picture_update(PurpleConnection *gc, int type) | 327 void yahoo_send_picture_update(PurpleConnection *gc, int type) |
335 { | 328 { |
336 YahooData *yd = gc->proto_data; | 329 YahooData *yd = purple_connection_get_protocol_data(gc); |
337 struct yspufe data; | 330 struct yspufe data; |
338 | 331 |
339 data.gc = gc; | 332 data.gc = gc; |
340 data.type = type; | 333 data.type = type; |
341 | 334 |
430 YahooData *yd; | 423 YahooData *yd; |
431 /* use whole URL if using HTTP Proxy */ | 424 /* use whole URL if using HTTP Proxy */ |
432 gboolean use_whole_url = yahoo_account_use_http_proxy(gc); | 425 gboolean use_whole_url = yahoo_account_use_http_proxy(gc); |
433 | 426 |
434 account = purple_connection_get_account(gc); | 427 account = purple_connection_get_account(gc); |
435 yd = gc->proto_data; | 428 yd = purple_connection_get_protocol_data(gc); |
436 | 429 |
437 /* Buddy icon connect is now complete; clear the PurpleProxyConnectData */ | 430 /* Buddy icon connect is now complete; clear the PurpleProxyConnectData */ |
438 yd->buddy_icon_connect_data = NULL; | 431 yd->buddy_icon_connect_data = NULL; |
439 | 432 |
440 if (source < 0) { | 433 if (source < 0) { |
495 } | 488 } |
496 | 489 |
497 void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d) | 490 void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d) |
498 { | 491 { |
499 PurpleAccount *account = purple_connection_get_account(gc); | 492 PurpleAccount *account = purple_connection_get_account(gc); |
500 YahooData *yd = gc->proto_data; | 493 YahooData *yd = purple_connection_get_protocol_data(gc); |
501 | 494 |
502 if (yd->buddy_icon_connect_data != NULL) { | 495 if (yd->buddy_icon_connect_data != NULL) { |
503 /* Cancel any in-progress buddy icon upload */ | 496 /* Cancel any in-progress buddy icon upload */ |
504 purple_proxy_connect_cancel(yd->buddy_icon_connect_data); | 497 purple_proxy_connect_cancel(yd->buddy_icon_connect_data); |
505 yd->buddy_icon_connect_data = NULL; | 498 yd->buddy_icon_connect_data = NULL; |
540 return checksum; | 533 return checksum; |
541 } | 534 } |
542 | 535 |
543 void yahoo_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) | 536 void yahoo_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
544 { | 537 { |
545 YahooData *yd = gc->proto_data; | 538 YahooData *yd = purple_connection_get_protocol_data(gc); |
546 PurpleAccount *account = gc->account; | 539 PurpleAccount *account = purple_connection_get_account(gc); |
547 | 540 |
548 if (img == NULL) { | 541 if (img == NULL) { |
549 g_free(yd->picture_url); | 542 g_free(yd->picture_url); |
550 yd->picture_url = NULL; | 543 yd->picture_url = NULL; |
551 | 544 |