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
|
|
441 if (!d)
|
|
442 return;
|
|
443
|
|
444 gc = d->gc;
|
|
445 account = gaim_connection_get_account(gc);
|
|
446 yd = gc->proto_data;
|
|
447
|
|
448 if (source < 0) {
|
|
449 gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n");
|
|
450 yahoo_buddy_icon_upload_data_free(d);
|
|
451 return;
|
|
452 }
|
|
453
|
|
454
|
|
455 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id);
|
|
456
|
|
457 size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len);
|
|
458 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */
|
|
459 yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc));
|
|
460 yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */
|
|
461 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800);
|
|
462 yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc));
|
|
463 yahoo_packet_hash_str(pkt, 28, size);
|
|
464 g_free(size);
|
|
465 yahoo_packet_hash_str(pkt, 27, d->filename);
|
|
466 yahoo_packet_hash_str(pkt, 14, "");
|
|
467
|
|
468 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt);
|
|
469
|
|
470 host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST);
|
|
471 port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT);
|
|
472 header = g_strdup_printf(
|
|
473 "POST http://%s:%d/notifyft HTTP/1.0\r\n"
|
|
474 "Content-length: %" G_GSIZE_FORMAT "\r\n"
|
|
475 "Host: %s:%d\r\n"
|
|
476 "Cookie: Y=%s; T=%s\r\n"
|
|
477 "\r\n",
|
|
478 host, port, content_length + 4 + d->str->len,
|
|
479 host, port, yd->cookie_y, yd->cookie_t);
|
|
480
|
|
481 /* There's no magic here, we just need to prepend in reverse order */
|
|
482 g_string_prepend(d->str, "29\xc0\x80");
|
|
483
|
|
484 pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf);
|
|
485 yahoo_packet_free(pkt);
|
14259
|
486 g_string_prepend_len(d->str, (char *)pkt_buf, pkt_buf_len);
|
14192
|
487 g_free(pkt_buf);
|
|
488
|
|
489 g_string_prepend(d->str, header);
|
|
490 g_free(header);
|
|
491
|
|
492 d->fd = source;
|
|
493 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d);
|
|
494
|
|
495 yahoo_buddy_icon_upload_pending(d, d->fd, GAIM_INPUT_WRITE);
|
|
496 }
|
|
497
|
|
498 void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d)
|
|
499 {
|
|
500 GaimAccount *account = gaim_connection_get_account(gc);
|
|
501 struct yahoo_data *yd = gc->proto_data;
|
|
502
|
|
503 if (yd->jp) {
|
|
504 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST),
|
|
505 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
|
|
506 yahoo_buddy_icon_upload_connected, d) == NULL)
|
|
507 {
|
|
508 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
|
|
509 yahoo_buddy_icon_upload_data_free(d);
|
|
510 }
|
|
511 } else {
|
|
512 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST),
|
|
513 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
|
|
514 yahoo_buddy_icon_upload_connected, d) == NULL)
|
|
515 {
|
|
516 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
|
|
517 yahoo_buddy_icon_upload_data_free(d);
|
|
518 }
|
|
519 }
|
|
520 }
|
|
521
|
|
522 void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile)
|
|
523 {
|
|
524 struct yahoo_data *yd = gc->proto_data;
|
|
525 GaimAccount *account = gc->account;
|
|
526 FILE *file;
|
|
527 struct stat st;
|
|
528
|
|
529 if (iconfile == NULL) {
|
|
530 if (yd->picture_url)
|
|
531 g_free(yd->picture_url);
|
|
532 yd->picture_url = NULL;
|
|
533
|
|
534 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL);
|
|
535 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0);
|
|
536 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0);
|
|
537 if (yd->logged_in)
|
|
538 yahoo_send_picture_update(gc, 0);
|
|
539 /* TODO: check if we're connected and tell everyone we ain't not one no more */
|
|
540 } else if (!g_stat(iconfile, &st)) {
|
|
541 file = g_fopen(iconfile, "rb");
|
|
542 if (file) {
|
|
543 GString *s = g_string_sized_new(st.st_size);
|
|
544 size_t len;
|
|
545 struct yahoo_buddy_icon_upload_data *d;
|
|
546 int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0);
|
|
547 int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0);
|
|
548 const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL);
|
|
549
|
|
550 g_string_set_size(s, st.st_size);
|
|
551 len = fread(s->str, 1, st.st_size, file);
|
|
552 fclose(file);
|
|
553 g_string_set_size(s, len);
|
|
554 yd->picture_checksum = g_string_hash(s);
|
|
555
|
|
556 if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) &&
|
|
557 oldcksum && expire && oldurl) {
|
|
558 gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n");
|
|
559 g_string_free(s, TRUE);
|
|
560 if (yd->picture_url)
|
|
561 g_free(yd->picture_url);
|
|
562 yd->picture_url = g_strdup(oldurl);
|
|
563 return;
|
|
564 }
|
|
565
|
|
566 d = g_new0(struct yahoo_buddy_icon_upload_data, 1);
|
|
567 d->gc = gc;
|
|
568 d->str = s;
|
|
569 d->fd = -1;
|
|
570 d->filename = g_strdup(iconfile);
|
|
571
|
|
572 if (!yd->logged_in) {
|
|
573 yd->picture_upload_todo = d;
|
|
574 return;
|
|
575 }
|
|
576
|
|
577 yahoo_buddy_icon_upload(gc, d);
|
|
578 } else
|
|
579 gaim_debug_error("yahoo",
|
|
580 "Can't open buddy icon file!\n");
|
|
581 } else
|
|
582 gaim_debug_error("yahoo",
|
|
583 "Can't stat buddy icon file!\n");
|
|
584 }
|