Mercurial > pidgin
annotate libgaim/protocols/yahoo/yahoo_picture.c @ 14803:967c39d78bc4
[gaim-migrate @ 17568]
I'm an idiot.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 23 Oct 2006 19:43:45 +0000 |
parents | 622931ca5622 |
children | 118fd0dc5b6e |
rev | line source |
---|---|
14192 | 1 /* |
2 * gaim | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
23 | |
24 #include "internal.h" | |
25 | |
26 #include "account.h" | |
27 #include "accountopt.h" | |
28 #include "blist.h" | |
29 #include "debug.h" | |
30 #include "prpl.h" | |
31 #include "proxy.h" | |
32 #include "util.h" | |
33 | |
34 #include "yahoo.h" | |
35 #include "yahoo_packet.h" | |
36 #include "yahoo_friend.h" | |
37 #include "yahoo_picture.h" | |
38 | |
39 | |
40 struct yahoo_fetch_picture_data { | |
41 GaimConnection *gc; | |
42 char *who; | |
43 int checksum; | |
44 }; | |
45 | |
14354 | 46 static void |
47 yahoo_fetch_picture_cb(GaimUtilFetchUrlData *url_data, gpointer user_data, | |
48 const gchar *pic_data, size_t len, const gchar *error_message) | |
14192 | 49 { |
14354 | 50 struct yahoo_fetch_picture_data *d; |
51 struct yahoo_data *yd; | |
14192 | 52 GaimBuddy *b; |
53 | |
14354 | 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 { | |
14192 | 63 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len); |
64 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who); | |
65 if (b) | |
66 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); | |
67 } | |
68 | |
69 g_free(d->who); | |
70 g_free(d); | |
71 } | |
72 | |
73 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt) | |
74 { | |
14354 | 75 struct yahoo_data *yd; |
14192 | 76 GSList *l = pkt->hash; |
77 char *who = NULL, *us = NULL; | |
78 gboolean got_icon_info = FALSE, send_icon_info = FALSE; | |
79 char *url = NULL; | |
80 int checksum = 0; | |
81 | |
82 while (l) { | |
83 struct yahoo_pair *pair = l->data; | |
84 | |
85 switch (pair->key) { | |
86 case 1: | |
87 case 4: | |
88 who = pair->value; | |
89 break; | |
90 case 5: | |
91 us = pair->value; | |
92 break; | |
93 case 13: { | |
94 int tmp; | |
95 tmp = strtol(pair->value, NULL, 10); | |
96 if (tmp == 1) { | |
97 send_icon_info = TRUE; | |
98 } else if (tmp == 2) { | |
99 got_icon_info = TRUE; | |
100 } | |
101 break; | |
102 } | |
103 case 20: | |
104 url = pair->value; | |
105 break; | |
106 case 192: | |
107 checksum = strtol(pair->value, NULL, 10); | |
108 break; | |
109 } | |
110 | |
111 l = l->next; | |
112 } | |
113 | |
114 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ | |
115 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { | |
116 /* TODO: make this work p2p, try p2p before the url */ | |
14354 | 117 GaimUtilFetchUrlData *url_data; |
14192 | 118 struct yahoo_fetch_picture_data *data; |
119 GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
120 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
121 return; | |
122 | |
123 data = g_new0(struct yahoo_fetch_picture_data, 1); | |
124 data->gc = gc; | |
125 data->who = g_strdup(who); | |
126 data->checksum = checksum; | |
14354 | 127 url_data = gaim_util_fetch_url(url, FALSE, |
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 } | |
14192 | 137 } else if (who && send_icon_info) { |
138 yahoo_send_picture_info(gc, who); | |
139 } | |
140 } | |
141 | |
142 void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt) | |
143 { | |
144 GSList *l = pkt->hash; | |
145 char *who = NULL; | |
146 int icon = 0; | |
147 | |
148 while (l) { | |
149 struct yahoo_pair *pair = l->data; | |
150 | |
151 switch (pair->key) { | |
152 case 4: | |
153 who = pair->value; | |
154 break; | |
155 case 5: | |
156 /* us */ | |
157 break; | |
158 case 206: | |
159 icon = strtol(pair->value, NULL, 10); | |
160 break; | |
161 } | |
162 l = l->next; | |
163 } | |
164 | |
165 if (who) { | |
166 if (icon == 2) | |
167 yahoo_send_picture_request(gc, who); | |
168 else if ((icon == 0) || (icon == 1)) { | |
169 GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
170 YahooFriend *f; | |
171 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); | |
172 if (b) | |
173 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | |
174 if ((f = yahoo_friend_find(gc, who))) | |
175 yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
176 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); | |
177 } | |
178 } | |
179 } | |
180 | |
181 void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt) | |
182 { | |
183 GSList *l = pkt->hash; | |
184 char *who = NULL; | |
185 int checksum = 0; | |
186 | |
187 while (l) { | |
188 struct yahoo_pair *pair = l->data; | |
189 | |
190 switch (pair->key) { | |
191 case 4: | |
192 who = pair->value; | |
193 break; | |
194 case 5: | |
195 /* us */ | |
196 break; | |
197 case 192: | |
198 checksum = strtol(pair->value, NULL, 10); | |
199 break; | |
200 } | |
201 l = l->next; | |
202 } | |
203 | |
204 if (who) { | |
205 GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
206 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
207 yahoo_send_picture_request(gc, who); | |
208 } | |
209 } | |
210 | |
211 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt) | |
212 { | |
213 GaimAccount *account = gaim_connection_get_account(gc); | |
214 struct yahoo_data *yd = gc->proto_data; | |
215 GSList *l = pkt->hash; | |
216 char *url = NULL; | |
217 | |
218 while (l) { | |
219 struct yahoo_pair *pair = l->data; | |
220 | |
221 switch (pair->key) { | |
222 case 5: | |
223 /* us */ | |
224 break; | |
225 case 27: | |
226 /* filename on our computer. */ | |
227 break; | |
228 case 20: /* url at yahoo */ | |
229 url = pair->value; | |
230 case 38: /* timestamp */ | |
231 break; | |
232 } | |
233 l = l->next; | |
234 } | |
235 | |
236 if (url) { | |
237 if (yd->picture_url) | |
238 g_free(yd->picture_url); | |
239 yd->picture_url = g_strdup(url); | |
240 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url); | |
241 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); | |
242 yahoo_send_picture_update(gc, 2); | |
243 yahoo_send_picture_checksum(gc); | |
244 } | |
245 } | |
246 | |
247 void yahoo_process_avatar_update(GaimConnection *gc, struct yahoo_packet *pkt) | |
248 { | |
249 GSList *l = pkt->hash; | |
250 char *who = NULL; | |
251 int avatar = 0; | |
252 | |
253 while (l) { | |
254 struct yahoo_pair *pair = l->data; | |
255 | |
256 switch (pair->key) { | |
257 case 4: | |
258 who = pair->value; | |
259 break; | |
260 case 5: | |
261 /* us */ | |
262 break; | |
263 case 206: | |
264 /* | |
265 * 0 - No icon or avatar | |
266 * 1 - Using an avatar | |
267 * 2 - Using an icon | |
268 */ | |
269 avatar = strtol(pair->value, NULL, 10); | |
270 break; | |
271 } | |
272 l = l->next; | |
273 } | |
274 | |
275 if (who) { | |
276 if (avatar == 2) | |
277 yahoo_send_picture_request(gc, who); | |
278 else if ((avatar == 0) || (avatar == 1)) { | |
279 GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
280 YahooFriend *f; | |
281 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); | |
282 if (b) | |
283 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | |
284 if ((f = yahoo_friend_find(gc, who))) | |
285 yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
286 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); | |
287 } | |
288 } | |
289 } | |
290 | |
291 void yahoo_send_picture_info(GaimConnection *gc, const char *who) | |
292 { | |
293 struct yahoo_data *yd = gc->proto_data; | |
294 struct yahoo_packet *pkt; | |
295 | |
296 if (!yd->picture_url) { | |
297 gaim_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); | |
298 return; | |
299 } | |
300 | |
301 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
302 yahoo_packet_hash(pkt, "sssssi", 1, gaim_connection_get_display_name(gc), | |
303 4, gaim_connection_get_display_name(gc), 5, who, | |
304 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); | |
305 yahoo_packet_send_and_free(pkt, yd); | |
306 } | |
307 | |
308 void yahoo_send_picture_request(GaimConnection *gc, const char *who) | |
309 { | |
310 struct yahoo_data *yd = gc->proto_data; | |
311 struct yahoo_packet *pkt; | |
312 | |
313 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
314 yahoo_packet_hash_str(pkt, 4, gaim_connection_get_display_name(gc)); /* me */ | |
315 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ | |
316 yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | |
317 yahoo_packet_send_and_free(pkt, yd); | |
318 } | |
319 | |
320 void yahoo_send_picture_checksum(GaimConnection *gc) | |
321 { | |
322 struct yahoo_data *yd = gc->proto_data; | |
323 struct yahoo_packet *pkt; | |
324 | |
325 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | |
326 yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), | |
327 212, "1", 192, yd->picture_checksum); | |
328 yahoo_packet_send_and_free(pkt, yd); | |
329 } | |
330 | |
331 void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type) | |
332 { | |
333 struct yahoo_data *yd = gc->proto_data; | |
334 struct yahoo_packet *pkt; | |
335 | |
336 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | |
337 yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), 5, who, 206, type); | |
338 yahoo_packet_send_and_free(pkt, yd); | |
339 } | |
340 | |
341 struct yspufe { | |
342 GaimConnection *gc; | |
343 int type; | |
344 }; | |
345 | |
346 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | |
347 { | |
348 char *who = key; | |
349 YahooFriend *f = value; | |
350 struct yspufe *d = data; | |
351 | |
352 if (f->status != YAHOO_STATUS_OFFLINE) | |
353 yahoo_send_picture_update_to_user(d->gc, who, d->type); | |
354 } | |
355 | |
356 void yahoo_send_picture_update(GaimConnection *gc, int type) | |
357 { | |
358 struct yahoo_data *yd = gc->proto_data; | |
359 struct yspufe data; | |
360 | |
361 data.gc = gc; | |
362 data.type = type; | |
363 | |
364 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | |
365 } | |
366 | |
367 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) | |
368 { | |
369 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); | |
370 | |
371 if (d->str) | |
372 g_string_free(d->str, TRUE); | |
373 g_free(d->filename); | |
374 if (d->watcher) | |
375 gaim_input_remove(d->watcher); | |
376 if (d->fd != -1) | |
377 close(d->fd); | |
378 g_free(d); | |
379 } | |
380 | |
381 /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ | |
382 static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition) | |
383 { | |
384 struct yahoo_buddy_icon_upload_data *d = data; | |
385 GaimConnection *gc = d->gc; | |
386 char buf[1024]; | |
387 int ret; | |
388 | |
389 if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
390 yahoo_buddy_icon_upload_data_free(d); | |
391 return; | |
392 } | |
393 | |
394 ret = read(d->fd, buf, sizeof(buf)); | |
395 | |
396 if (ret < 0 && errno == EAGAIN) | |
397 return; | |
398 else if (ret <= 0) | |
399 yahoo_buddy_icon_upload_data_free(d); | |
400 } | |
401 | |
402 static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition) | |
403 { | |
404 struct yahoo_buddy_icon_upload_data *d = data; | |
405 GaimConnection *gc = d->gc; | |
406 ssize_t wrote; | |
407 | |
408 if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
409 yahoo_buddy_icon_upload_data_free(d); | |
410 return; | |
411 } | |
412 | |
413 wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos); | |
414 if (wrote < 0 && errno == EAGAIN) | |
415 return; | |
416 if (wrote <= 0) { | |
417 yahoo_buddy_icon_upload_data_free(d); | |
418 return; | |
419 } | |
420 d->pos += wrote; | |
421 if (d->pos >= d->str->len) { | |
422 gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n"); | |
423 gaim_input_remove(d->watcher); | |
424 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d); | |
425 } | |
426 } | |
427 | |
428 static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) | |
429 { | |
430 struct yahoo_buddy_icon_upload_data *d = data; | |
431 struct yahoo_packet *pkt; | |
432 gchar *size, *header; | |
433 guchar *pkt_buf; | |
434 const char *host; | |
435 int port; | |
436 size_t content_length, pkt_buf_len; | |
437 GaimConnection *gc; | |
438 GaimAccount *account; | |
439 struct yahoo_data *yd; | |
440 | |
14624
776615acf309
[gaim-migrate @ 17356]
Richard Laager <rlaager@wiktel.com>
parents:
14446
diff
changeset
|
441 g_return_if_fail(d != NULL); |
14192 | 442 |
443 gc = d->gc; | |
444 account = gaim_connection_get_account(gc); | |
445 yd = gc->proto_data; | |
446 | |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
447 /* Buddy icon connect is now complete; clear the GaimProxyConnectData */ |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
448 yd->buddy_icon_connect_data = NULL; |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
449 |
14192 | 450 if (source < 0) { |
451 gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n"); | |
452 yahoo_buddy_icon_upload_data_free(d); | |
453 return; | |
454 } | |
455 | |
456 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id); | |
457 | |
458 size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); | |
459 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ | |
460 yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc)); | |
461 yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ | |
462 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); | |
463 yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc)); | |
464 yahoo_packet_hash_str(pkt, 28, size); | |
465 g_free(size); | |
466 yahoo_packet_hash_str(pkt, 27, d->filename); | |
467 yahoo_packet_hash_str(pkt, 14, ""); | |
468 | |
469 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | |
470 | |
471 host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); | |
472 port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); | |
473 header = g_strdup_printf( | |
474 "POST http://%s:%d/notifyft HTTP/1.0\r\n" | |
475 "Content-length: %" G_GSIZE_FORMAT "\r\n" | |
476 "Host: %s:%d\r\n" | |
477 "Cookie: Y=%s; T=%s\r\n" | |
478 "\r\n", | |
479 host, port, content_length + 4 + d->str->len, | |
480 host, port, yd->cookie_y, yd->cookie_t); | |
481 | |
482 /* There's no magic here, we just need to prepend in reverse order */ | |
483 g_string_prepend(d->str, "29\xc0\x80"); | |
484 | |
14446
1bee09450652
[gaim-migrate @ 17160]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14354
diff
changeset
|
485 pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, yd->jp, &pkt_buf); |
14192 | 486 yahoo_packet_free(pkt); |
14259 | 487 g_string_prepend_len(d->str, (char *)pkt_buf, pkt_buf_len); |
14192 | 488 g_free(pkt_buf); |
489 | |
490 g_string_prepend(d->str, header); | |
491 g_free(header); | |
492 | |
493 d->fd = source; | |
494 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); | |
495 | |
496 yahoo_buddy_icon_upload_pending(d, d->fd, GAIM_INPUT_WRITE); | |
497 } | |
498 | |
499 void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d) | |
500 { | |
501 GaimAccount *account = gaim_connection_get_account(gc); | |
502 struct yahoo_data *yd = gc->proto_data; | |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
503 GaimProxyConnectData *connect_data = NULL; |
14192 | 504 |
14624
776615acf309
[gaim-migrate @ 17356]
Richard Laager <rlaager@wiktel.com>
parents:
14446
diff
changeset
|
505 g_return_if_fail(d != NULL); |
776615acf309
[gaim-migrate @ 17356]
Richard Laager <rlaager@wiktel.com>
parents:
14446
diff
changeset
|
506 |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
507 if (yd->buddy_icon_connect_data) { |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
508 /* Cancel any in-progress buddy icon upload */ |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
509 gaim_proxy_connect_cancel(yd->buddy_icon_connect_data); |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
510 yd->buddy_icon_connect_data = NULL; |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
511 } |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
512 |
14192 | 513 if (yd->jp) { |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
514 if ((connect_data = gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
515 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
516 yahoo_buddy_icon_upload_connected, d)) == NULL) |
14192 | 517 { |
518 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
519 yahoo_buddy_icon_upload_data_free(d); | |
520 } | |
521 } else { | |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
522 if ((connect_data = gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
523 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
524 yahoo_buddy_icon_upload_connected, d)) == NULL) |
14192 | 525 { |
526 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
527 yahoo_buddy_icon_upload_data_free(d); | |
528 } | |
529 } | |
14631
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
530 |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
531 if (connect_data) { |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
532 yd->buddy_icon_connect_data = connect_data; |
622931ca5622
[gaim-migrate @ 17377]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14624
diff
changeset
|
533 } |
14192 | 534 } |
535 | |
536 void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile) | |
537 { | |
538 struct yahoo_data *yd = gc->proto_data; | |
539 GaimAccount *account = gc->account; | |
540 FILE *file; | |
541 struct stat st; | |
542 | |
543 if (iconfile == NULL) { | |
544 if (yd->picture_url) | |
545 g_free(yd->picture_url); | |
546 yd->picture_url = NULL; | |
547 | |
548 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); | |
549 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
550 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
551 if (yd->logged_in) | |
552 yahoo_send_picture_update(gc, 0); | |
553 /* TODO: check if we're connected and tell everyone we ain't not one no more */ | |
554 } else if (!g_stat(iconfile, &st)) { | |
555 file = g_fopen(iconfile, "rb"); | |
556 if (file) { | |
557 GString *s = g_string_sized_new(st.st_size); | |
558 size_t len; | |
559 struct yahoo_buddy_icon_upload_data *d; | |
560 int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
561 int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
562 const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); | |
563 | |
564 g_string_set_size(s, st.st_size); | |
565 len = fread(s->str, 1, st.st_size, file); | |
566 fclose(file); | |
567 g_string_set_size(s, len); | |
568 yd->picture_checksum = g_string_hash(s); | |
569 | |
570 if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) && | |
571 oldcksum && expire && oldurl) { | |
572 gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); | |
573 g_string_free(s, TRUE); | |
574 if (yd->picture_url) | |
575 g_free(yd->picture_url); | |
576 yd->picture_url = g_strdup(oldurl); | |
577 return; | |
578 } | |
579 | |
580 d = g_new0(struct yahoo_buddy_icon_upload_data, 1); | |
581 d->gc = gc; | |
582 d->str = s; | |
583 d->fd = -1; | |
584 d->filename = g_strdup(iconfile); | |
585 | |
586 if (!yd->logged_in) { | |
587 yd->picture_upload_todo = d; | |
588 return; | |
589 } | |
590 | |
591 yahoo_buddy_icon_upload(gc, d); | |
592 } else | |
593 gaim_debug_error("yahoo", | |
594 "Can't open buddy icon file!\n"); | |
595 } else | |
596 gaim_debug_error("yahoo", | |
597 "Can't stat buddy icon file!\n"); | |
598 } |