9306
|
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_friend.h"
|
|
36 #include "yahoo_picture.h"
|
|
37
|
|
38
|
|
39 struct yahoo_fetch_picture_data {
|
|
40 GaimConnection *gc;
|
|
41 char *who;
|
|
42 int checksum;
|
|
43 };
|
|
44
|
9310
|
45
|
|
46
|
9306
|
47 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len)
|
|
48 {
|
|
49 struct yahoo_fetch_picture_data *d = user_data;
|
|
50 GaimBuddy *b;
|
|
51
|
|
52 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
|
|
53 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len);
|
|
54 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who);
|
|
55 if (b)
|
|
56 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum);
|
|
57 } else {
|
|
58 gaim_debug_error("yahoo", "Fetching buddy icon failed.\n");
|
|
59 }
|
|
60
|
|
61 g_free(d->who);
|
|
62 g_free(d);
|
|
63 }
|
|
64
|
|
65 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
66 {
|
|
67 GSList *l = pkt->hash;
|
|
68 char *who = NULL, *us = NULL;
|
|
69 gboolean got_icon_info = FALSE, send_icon_info = FALSE;
|
|
70 char *url = NULL;
|
|
71 int checksum = 0;
|
|
72
|
|
73 while (l) {
|
|
74 struct yahoo_pair *pair = l->data;
|
|
75
|
|
76 switch (pair->key) {
|
|
77 case 1:
|
|
78 case 4:
|
|
79 who = pair->value;
|
|
80 break;
|
|
81 case 5:
|
|
82 us = pair->value;
|
|
83 break;
|
|
84 case 13: {
|
|
85 int tmp;
|
|
86 tmp = strtol(pair->value, NULL, 10);
|
|
87 if (tmp == 1) {
|
|
88 send_icon_info = TRUE;
|
|
89 } else if (tmp == 2) {
|
|
90 got_icon_info = TRUE;
|
|
91 }
|
|
92 break;
|
|
93 }
|
|
94 case 20:
|
|
95 url = pair->value;
|
|
96 break;
|
|
97 case 192:
|
|
98 checksum = strtol(pair->value, NULL, 10);
|
|
99 break;
|
|
100 }
|
|
101
|
|
102 l = l->next;
|
|
103 }
|
|
104
|
|
105 if (who && got_icon_info && url) {
|
|
106 /* TODO: make this work p2p, try p2p before the url */
|
|
107 struct yahoo_fetch_picture_data *data;
|
|
108 GaimBuddy *b = gaim_find_buddy(gc->account, who);
|
|
109 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
|
|
110 return;
|
|
111
|
|
112 data = g_new0(struct yahoo_fetch_picture_data, 1);
|
|
113 data->gc = gc;
|
|
114 data->who = g_strdup(who);
|
|
115 data->checksum = checksum;
|
|
116 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
|
|
117 yahoo_fetch_picture_cb, data);
|
|
118 } else if (who && send_icon_info) {
|
|
119 yahoo_send_picture_info(gc, who);
|
|
120 }
|
|
121
|
|
122 }
|
|
123
|
|
124 void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
125 {
|
|
126 GSList *l = pkt->hash;
|
|
127 char *who = NULL;
|
|
128 int icon = 0;
|
|
129
|
|
130 while (l) {
|
|
131 struct yahoo_pair *pair = l->data;
|
|
132
|
|
133 switch (pair->key) {
|
|
134 case 4:
|
|
135 who = pair->value;
|
|
136 break;
|
|
137 case 5:
|
|
138 /* us */
|
|
139 break;
|
|
140 case 206:
|
|
141 icon = strtol(pair->value, NULL, 10);
|
|
142 break;
|
|
143 }
|
|
144 l = l->next;
|
|
145 }
|
|
146
|
|
147 if (who) {
|
|
148 if (icon == 2)
|
9310
|
149 yahoo_send_picture_request(gc, who);
|
9322
|
150 else if ((icon == 0) || (icon == 1)) {
|
9306
|
151 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0);
|
9322
|
152 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who);
|
|
153 }
|
9306
|
154 }
|
|
155 }
|
|
156
|
|
157 void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
158 {
|
|
159 GSList *l = pkt->hash;
|
|
160 char *who = NULL;
|
|
161 int checksum = 0;
|
|
162
|
|
163 while (l) {
|
|
164 struct yahoo_pair *pair = l->data;
|
|
165
|
|
166 switch (pair->key) {
|
|
167 case 4:
|
|
168 who = pair->value;
|
|
169 break;
|
|
170 case 5:
|
|
171 /* us */
|
|
172 break;
|
|
173 case 192:
|
|
174 checksum = strtol(pair->value, NULL, 10);
|
|
175 break;
|
|
176 }
|
|
177 l = l->next;
|
|
178 }
|
|
179
|
|
180 if (who) {
|
|
181 GaimBuddy *b = gaim_find_buddy(gc->account, who);
|
|
182 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
|
9310
|
183 yahoo_send_picture_request(gc, who);
|
9306
|
184 }
|
|
185 }
|
|
186
|
|
187 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
188 {
|
|
189 GaimAccount *account = gaim_connection_get_account(gc);
|
|
190 struct yahoo_data *yd = gc->proto_data;
|
|
191 GSList *l = pkt->hash;
|
|
192 char *url = NULL;
|
|
193
|
|
194 while (l) {
|
|
195 struct yahoo_pair *pair = l->data;
|
|
196
|
|
197 switch (pair->key) {
|
|
198 case 5:
|
|
199 /* us */
|
|
200 break;
|
|
201 case 27:
|
|
202 /* filename on our computer. */
|
|
203 break;
|
|
204 case 20: /* url at yahoo */
|
|
205 url = pair->value;
|
|
206 case 38: /* timestamp */
|
|
207 break;
|
|
208 }
|
|
209 l = l->next;
|
|
210 }
|
|
211
|
|
212 if (url) {
|
|
213 if (yd->picture_url)
|
|
214 g_free(yd->picture_url);
|
|
215 yd->picture_url = g_strdup(url);
|
|
216 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url);
|
|
217 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum);
|
9310
|
218 yahoo_send_picture_update(gc, 2);
|
|
219 yahoo_send_picture_checksum(gc);
|
9306
|
220 }
|
|
221 }
|
|
222
|
9322
|
223 void yahoo_send_picture_info(GaimConnection *gc, const char *who)
|
|
224 {
|
|
225 struct yahoo_data *yd = gc->proto_data;
|
|
226 struct yahoo_packet *pkt;
|
|
227 char *buf;
|
|
228
|
|
229 if (!yd->picture_url)
|
|
230 return;
|
|
231
|
|
232 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
|
|
233 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
|
|
234 yahoo_packet_hash(pkt, 4, gaim_connection_get_display_name(gc));
|
|
235 yahoo_packet_hash(pkt, 5, who);
|
|
236 yahoo_packet_hash(pkt, 13, "2");
|
|
237 yahoo_packet_hash(pkt, 20, yd->picture_url);
|
|
238 buf = g_strdup_printf("%d", yd->picture_checksum);
|
|
239 yahoo_packet_hash(pkt, 192, buf);
|
|
240
|
|
241 yahoo_send_packet(yd, pkt);
|
|
242 yahoo_packet_free(pkt);
|
|
243 g_free(buf);
|
|
244 }
|
9306
|
245
|
9310
|
246 void yahoo_send_picture_request(GaimConnection *gc, const char *who)
|
9306
|
247 {
|
|
248 struct yahoo_data *yd = gc->proto_data;
|
|
249 struct yahoo_packet *pkt;
|
|
250
|
|
251 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
|
|
252 yahoo_packet_hash(pkt, 4, gaim_connection_get_display_name(gc)); /* me */
|
|
253 yahoo_packet_hash(pkt, 5, who); /* the other guy */
|
|
254 yahoo_packet_hash(pkt, 13, "1"); /* 1 = request, 2 = reply */
|
|
255 yahoo_send_packet(yd, pkt);
|
|
256 yahoo_packet_free(pkt);
|
|
257 }
|
|
258
|
9310
|
259 void yahoo_send_picture_checksum(GaimConnection *gc)
|
|
260 {
|
|
261 struct yahoo_data *yd = gc->proto_data;
|
|
262 struct yahoo_packet *pkt;
|
|
263 char *cksum = g_strdup_printf("%d", yd->picture_checksum);
|
|
264
|
|
265 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0);
|
|
266 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
|
|
267 yahoo_packet_hash(pkt, 212, "1");
|
|
268 yahoo_packet_hash(pkt, 192, cksum);
|
|
269 yahoo_send_packet(yd, pkt);
|
|
270 yahoo_packet_free(pkt);
|
|
271 g_free(cksum);
|
|
272 }
|
|
273
|
|
274 void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type)
|
|
275 {
|
|
276 struct yahoo_data *yd = gc->proto_data;
|
|
277 struct yahoo_packet *pkt;
|
|
278 char *typestr = g_strdup_printf("%d", type);
|
|
279
|
|
280 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
|
|
281 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
|
|
282 yahoo_packet_hash(pkt, 5, who);
|
|
283 yahoo_packet_hash(pkt, 206, typestr);
|
|
284 yahoo_send_packet(yd, pkt);
|
|
285 yahoo_packet_free(pkt);
|
|
286
|
|
287 g_free(typestr);
|
|
288 }
|
|
289
|
|
290 struct yspufe {
|
|
291 GaimConnection *gc;
|
|
292 int type;
|
|
293 };
|
|
294
|
|
295 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data)
|
|
296 {
|
|
297 char *who = key;
|
|
298 YahooFriend *f = value;
|
|
299 struct yspufe *d = data;
|
|
300
|
|
301 if (f->status != YAHOO_STATUS_OFFLINE)
|
|
302 yahoo_send_picture_update_to_user(d->gc, who, d->type);
|
|
303 }
|
|
304
|
|
305 void yahoo_send_picture_update(GaimConnection *gc, int type)
|
|
306 {
|
|
307 struct yahoo_data *yd = gc->proto_data;
|
|
308 struct yspufe data;
|
|
309
|
|
310 data.gc = gc;
|
|
311 data.type = type;
|
|
312
|
|
313 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data);
|
|
314 }
|
|
315
|
9306
|
316 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d)
|
|
317 {
|
|
318 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n");
|
|
319
|
|
320 if (d->str)
|
|
321 g_string_free(d->str, TRUE);
|
|
322 if (d->filename)
|
|
323 g_free(d->filename);
|
|
324 if (d->watcher)
|
|
325 gaim_input_remove(d->watcher);
|
|
326 if (d->fd != -1)
|
|
327 close(d->fd);
|
|
328 g_free(d);
|
|
329 }
|
|
330
|
|
331 /* we could care less about the server's responce, but yahoo gets grumpy if we close before it sends it */
|
|
332 static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition)
|
|
333 {
|
|
334 struct yahoo_buddy_icon_upload_data *d = data;
|
|
335 GaimConnection *gc = d->gc;
|
|
336 char buf[1024];
|
|
337
|
|
338 if (!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
339 yahoo_buddy_icon_upload_data_free(d);
|
|
340 return;
|
|
341 }
|
|
342
|
|
343 if (read(d->fd, buf, sizeof(buf)) <= 0)
|
|
344 yahoo_buddy_icon_upload_data_free(d);
|
|
345 }
|
|
346
|
|
347 static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition)
|
|
348 {
|
|
349 struct yahoo_buddy_icon_upload_data *d = data;
|
|
350 GaimConnection *gc = d->gc;
|
|
351 ssize_t wrote;
|
|
352
|
|
353 if (!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
354 yahoo_buddy_icon_upload_data_free(d);
|
|
355 return;
|
|
356 }
|
|
357
|
|
358 wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos);
|
|
359 if (wrote <= 0) {
|
|
360 yahoo_buddy_icon_upload_data_free(d);
|
|
361 return;
|
|
362 }
|
|
363 d->pos += wrote;
|
|
364 if (d->pos >= d->str->len) {
|
|
365 gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n");
|
|
366 gaim_input_remove(d->watcher);
|
|
367 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d);
|
|
368 }
|
|
369 }
|
|
370
|
|
371 static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, GaimInputCondition condition)
|
|
372 {
|
|
373 struct yahoo_buddy_icon_upload_data *d = data;
|
|
374 struct yahoo_packet *pkt;
|
|
375 gchar *size, *post, *buf;
|
|
376 int content_length;
|
|
377 GaimConnection *gc;
|
|
378 GaimAccount *account;
|
|
379 struct yahoo_data *yd;
|
|
380
|
|
381 if (!d)
|
|
382 return;
|
|
383
|
|
384
|
|
385 gc = d->gc;
|
|
386 account = gaim_connection_get_account(gc);
|
|
387 yd = gc->proto_data;
|
|
388
|
|
389
|
|
390 if (source < 0) {
|
|
391 gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n");
|
|
392 yahoo_buddy_icon_upload_data_free(d);
|
|
393 return;
|
|
394 }
|
|
395
|
|
396 d->fd = source;
|
|
397 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d);
|
|
398
|
|
399 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id);
|
|
400
|
|
401 size = g_strdup_printf("%d", d->str->len);
|
|
402 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */
|
|
403 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc));
|
|
404 yahoo_packet_hash(pkt, 38, "604800"); /* time til expire */
|
|
405 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800);
|
|
406 yahoo_packet_hash(pkt, 0, gaim_connection_get_display_name(gc));
|
|
407 yahoo_packet_hash(pkt, 28, size);
|
|
408 yahoo_packet_hash(pkt, 27, d->filename);
|
|
409 yahoo_packet_hash(pkt, 14, "");
|
|
410
|
|
411 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt);
|
|
412
|
|
413 buf = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t);
|
|
414
|
|
415 post = g_strdup_printf("POST /notifyft HTTP/1.0\r\n"
|
|
416 "Content-length: %d\r\n"
|
|
417 "Host: %s:%d\r\n"
|
|
418 "Cookie: %s\r\n"
|
|
419 "\r\n",
|
|
420 content_length + 4 + d->str->len,
|
|
421 gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST),
|
|
422 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
|
|
423 buf);
|
|
424 write(d->fd, post, strlen(post));
|
|
425
|
|
426 yahoo_send_packet_special(d->fd, pkt, 8);
|
|
427 yahoo_packet_free(pkt);
|
|
428
|
|
429 write(d->fd, "29\xc0\x80", 4);
|
|
430
|
|
431 g_free(size);
|
|
432 g_free(post);
|
|
433 g_free(buf);
|
|
434 }
|
|
435
|
|
436 void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d)
|
|
437 {
|
|
438 GaimAccount *account = gaim_connection_get_account(gc);
|
|
439 struct yahoo_data *yd = gc->proto_data;
|
|
440
|
|
441 if (yd->jp) {
|
|
442 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST),
|
|
443 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
|
|
444 yahoo_buddy_icon_upload_connected, d) == -1)
|
|
445 {
|
|
446 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
|
|
447 yahoo_buddy_icon_upload_data_free(d);
|
|
448 }
|
|
449 } else {
|
|
450 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST),
|
|
451 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
|
|
452 yahoo_buddy_icon_upload_connected, d) == -1)
|
|
453 {
|
|
454 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
|
|
455 yahoo_buddy_icon_upload_data_free(d);
|
|
456 }
|
|
457 }
|
|
458 }
|
|
459
|
|
460 void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile)
|
|
461 {
|
|
462 struct yahoo_data *yd = gc->proto_data;
|
|
463 GaimAccount *account = gc->account;
|
|
464 FILE *file;
|
|
465 struct stat st;
|
|
466
|
|
467 if (iconfile == NULL) {
|
|
468 if (yd->picture_url)
|
|
469 g_free(yd->picture_url);
|
|
470 yd->picture_url = NULL;
|
|
471
|
|
472 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL);
|
|
473 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0);
|
|
474 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0);
|
9310
|
475 if (yd->logged_in)
|
|
476 yahoo_send_picture_update(gc, 0);
|
9306
|
477 /* TODO: check if we're connected and tell everyone we ain't not one no more */
|
|
478 } else if (!stat(iconfile, &st)) {
|
|
479 file = fopen(iconfile, "rb");
|
|
480 if (file) {
|
|
481 GString *s = g_string_sized_new(st.st_size);
|
|
482 size_t len;
|
|
483 struct yahoo_buddy_icon_upload_data *d;
|
|
484 int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0);
|
|
485 int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0);
|
|
486 const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL);
|
|
487
|
|
488 g_string_set_size(s, st.st_size);
|
|
489 len = fread(s->str, 1, st.st_size, file);
|
|
490 fclose(file);
|
|
491 g_string_set_size(s, len);
|
|
492 yd->picture_checksum = g_string_hash(s);
|
|
493
|
|
494 if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) &&
|
|
495 oldcksum && expire && oldurl) {
|
|
496 gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n");
|
|
497 g_string_free(s, TRUE);
|
|
498 if (yd->picture_url)
|
|
499 g_free(yd->picture_url);
|
|
500 yd->picture_url = g_strdup(oldurl);
|
|
501 return;
|
|
502 }
|
|
503
|
|
504 d = g_new0(struct yahoo_buddy_icon_upload_data, 1);
|
|
505 d->gc = gc;
|
|
506 d->str = s;
|
|
507 d->fd = -1;
|
|
508 d->filename = g_strdup(iconfile);
|
|
509
|
|
510 if (!yd->logged_in) {
|
|
511 yd->picture_upload_todo = d;
|
|
512 return;
|
|
513 }
|
|
514
|
|
515 yahoo_buddy_icon_upload(gc, d);
|
|
516 } else
|
|
517 gaim_debug_error("yahoo",
|
|
518 "Can't open buddy icon file!\n");
|
|
519 } else
|
|
520 gaim_debug_error("yahooo",
|
|
521 "Can't stat buddy icon file!\n");
|
|
522 }
|