annotate src/protocols/yahoo/yahoo_picture.c @ 11132:a4611130e3eb

[gaim-migrate @ 13189] A bit more dewarnification. I also think I found a memleak in sametime. siege, could you please check that out sometime? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 20 Jul 2005 02:43:09 +0000
parents 8fbab42659c2
children 08bf44bcedfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
1 /*
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
2 * gaim
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
3 *
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
6 * source distribution.
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
7 *
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
12 *
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
17 *
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
21 *
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
22 */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
23
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
24 #include "internal.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
25
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
26 #include "account.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
27 #include "accountopt.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
28 #include "blist.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
29 #include "debug.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
30 #include "prpl.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
31 #include "proxy.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
32 #include "util.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
33
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
34 #include "yahoo.h"
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
35 #include "yahoo_packet.h"
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
36 #include "yahoo_friend.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
37 #include "yahoo_picture.h"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
38
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
39
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
40 struct yahoo_fetch_picture_data {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
41 GaimConnection *gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
42 char *who;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
43 int checksum;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
44 };
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
45
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
46
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
47
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
48 void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
49 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
50 struct yahoo_fetch_picture_data *d = user_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
51 GaimBuddy *b;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
52
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
53 if (GAIM_CONNECTION_IS_VALID(d->gc) && len) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
54 gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
55 b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
56 if (b)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
57 gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
58 } else {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
59 gaim_debug_error("yahoo", "Fetching buddy icon failed.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
60 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
61
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
62 g_free(d->who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
63 g_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
64 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
65
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
66 void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
67 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
68 GSList *l = pkt->hash;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
69 char *who = NULL, *us = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
70 gboolean got_icon_info = FALSE, send_icon_info = FALSE;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
71 char *url = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
72 int checksum = 0;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
73
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
74 while (l) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
75 struct yahoo_pair *pair = l->data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
76
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
77 switch (pair->key) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
78 case 1:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
79 case 4:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
80 who = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
81 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
82 case 5:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
83 us = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
84 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
85 case 13: {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
86 int tmp;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
87 tmp = strtol(pair->value, NULL, 10);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
88 if (tmp == 1) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
89 send_icon_info = TRUE;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
90 } else if (tmp == 2) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
91 got_icon_info = TRUE;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
92 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
93 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
94 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
95 case 20:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
96 url = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
97 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
98 case 192:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
99 checksum = strtol(pair->value, NULL, 10);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
100 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
101 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
102
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
103 l = l->next;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
104 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
105
9675
ba78e5a34bed [gaim-migrate @ 10527]
Mark Doliner <mark@kingant.net>
parents: 9329
diff changeset
106 /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */
ba78e5a34bed [gaim-migrate @ 10527]
Mark Doliner <mark@kingant.net>
parents: 9329
diff changeset
107 if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) {
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
108 /* TODO: make this work p2p, try p2p before the url */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
109 struct yahoo_fetch_picture_data *data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
110 GaimBuddy *b = gaim_find_buddy(gc->account, who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
111 if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
112 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
113
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
114 data = g_new0(struct yahoo_fetch_picture_data, 1);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
115 data->gc = gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
116 data->who = g_strdup(who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
117 data->checksum = checksum;
10651
8fbab42659c2 [gaim-migrate @ 12176]
Tim Ringenbach <marv@pidgin.im>
parents: 10604
diff changeset
118 gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE,
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
119 yahoo_fetch_picture_cb, data);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
120 } else if (who && send_icon_info) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
121 yahoo_send_picture_info(gc, who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
122 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
123
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
124 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
125
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
126 void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
127 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
128 GSList *l = pkt->hash;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
129 char *who = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
130 int icon = 0;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
131
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
132 while (l) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
133 struct yahoo_pair *pair = l->data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
134
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
135 switch (pair->key) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
136 case 4:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
137 who = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
138 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
139 case 5:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
140 /* us */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
141 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
142 case 206:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
143 icon = strtol(pair->value, NULL, 10);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
144 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
145 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
146 l = l->next;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
147 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
148
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
149 if (who) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
150 if (icon == 2)
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
151 yahoo_send_picture_request(gc, who);
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
152 else if ((icon == 0) || (icon == 1)) {
9325
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
153 GaimBuddy *b = gaim_find_buddy(gc->account, who);
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
154 YahooFriend *f;
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
155 gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0);
9325
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
156 if (b)
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
157 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY);
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
158 if ((f = yahoo_friend_find(gc, who)))
f40233043b5a [gaim-migrate @ 10133]
Tim Ringenbach <marv@pidgin.im>
parents: 9322
diff changeset
159 yahoo_friend_set_buddy_icon_need_request(f, TRUE);
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
160 gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who);
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
161 }
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
162 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
163 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
164
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
165 void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
166 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
167 GSList *l = pkt->hash;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
168 char *who = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
169 int checksum = 0;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
170
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
171 while (l) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
172 struct yahoo_pair *pair = l->data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
173
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
174 switch (pair->key) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
175 case 4:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
176 who = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
177 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
178 case 5:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
179 /* us */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
180 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
181 case 192:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
182 checksum = strtol(pair->value, NULL, 10);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
183 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
184 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
185 l = l->next;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
186 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
187
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
188 if (who) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
189 GaimBuddy *b = gaim_find_buddy(gc->account, who);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
190 if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)))
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
191 yahoo_send_picture_request(gc, who);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
192 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
193 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
194
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
195 void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
196 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
197 GaimAccount *account = gaim_connection_get_account(gc);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
198 struct yahoo_data *yd = gc->proto_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
199 GSList *l = pkt->hash;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
200 char *url = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
201
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
202 while (l) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
203 struct yahoo_pair *pair = l->data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
204
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
205 switch (pair->key) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
206 case 5:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
207 /* us */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
208 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
209 case 27:
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
210 /* filename on our computer. */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
211 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
212 case 20: /* url at yahoo */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
213 url = pair->value;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
214 case 38: /* timestamp */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
215 break;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
216 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
217 l = l->next;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
218 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
219
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
220 if (url) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
221 if (yd->picture_url)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
222 g_free(yd->picture_url);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
223 yd->picture_url = g_strdup(url);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
224 gaim_account_set_string(account, YAHOO_PICURL_SETTING, url);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
225 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum);
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
226 yahoo_send_picture_update(gc, 2);
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
227 yahoo_send_picture_checksum(gc);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
228 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
229 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
230
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
231 void yahoo_send_picture_info(GaimConnection *gc, const char *who)
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
232 {
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
233 struct yahoo_data *yd = gc->proto_data;
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
234 struct yahoo_packet *pkt;
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
235
9329
d42f3e4fd7ad [gaim-migrate @ 10137]
Tim Ringenbach <marv@pidgin.im>
parents: 9325
diff changeset
236 if (!yd->picture_url) {
d42f3e4fd7ad [gaim-migrate @ 10137]
Tim Ringenbach <marv@pidgin.im>
parents: 9325
diff changeset
237 gaim_debug_warning("yahoo", "Attempted to send picture info without a picture\n");
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
238 return;
9329
d42f3e4fd7ad [gaim-migrate @ 10137]
Tim Ringenbach <marv@pidgin.im>
parents: 9325
diff changeset
239 }
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
240
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
241 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
242 yahoo_packet_hash(pkt, "sssssi", 1, gaim_connection_get_display_name(gc),
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
243 4, gaim_connection_get_display_name(gc), 5, who,
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
244 13, "2", 20, yd->picture_url, 192, yd->picture_checksum);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
245 yahoo_packet_send_and_free(pkt, yd);
9322
119f8a2c00b6 [gaim-migrate @ 10130]
Tim Ringenbach <marv@pidgin.im>
parents: 9310
diff changeset
246 }
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
247
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
248 void yahoo_send_picture_request(GaimConnection *gc, const char *who)
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
249 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
250 struct yahoo_data *yd = gc->proto_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
251 struct yahoo_packet *pkt;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
252
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
253 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
254 yahoo_packet_hash_str(pkt, 4, gaim_connection_get_display_name(gc)); /* me */
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
255 yahoo_packet_hash_str(pkt, 5, who); /* the other guy */
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
256 yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
257 yahoo_packet_send_and_free(pkt, yd);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
258 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
259
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
260 void yahoo_send_picture_checksum(GaimConnection *gc)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
261 {
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
262 struct yahoo_data *yd = gc->proto_data;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
263 struct yahoo_packet *pkt;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
264
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
265 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
266 yahoo_packet_hash(pkt, "ssd", 1, gaim_connection_get_display_name(gc),
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
267 212, "1", 192, yd->picture_checksum);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
268 yahoo_packet_send_and_free(pkt, yd);
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
269 }
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
270
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
271 void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
272 {
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
273 struct yahoo_data *yd = gc->proto_data;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
274 struct yahoo_packet *pkt;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
275
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
276 pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
277 yahoo_packet_hash(pkt, "ssd", 1, gaim_connection_get_display_name(gc), 5, who, 206, type);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
278 yahoo_packet_send_and_free(pkt, yd);
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
279 }
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
280
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
281 struct yspufe {
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
282 GaimConnection *gc;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
283 int type;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
284 };
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
285
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
286 static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
287 {
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
288 char *who = key;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
289 YahooFriend *f = value;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
290 struct yspufe *d = data;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
291
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
292 if (f->status != YAHOO_STATUS_OFFLINE)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
293 yahoo_send_picture_update_to_user(d->gc, who, d->type);
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
294 }
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
295
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
296 void yahoo_send_picture_update(GaimConnection *gc, int type)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
297 {
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
298 struct yahoo_data *yd = gc->proto_data;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
299 struct yspufe data;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
300
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
301 data.gc = gc;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
302 data.type = type;
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
303
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
304 g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data);
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
305 }
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
306
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
307 void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
308 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
309 gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
310
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
311 if (d->str)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
312 g_string_free(d->str, TRUE);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
313 if (d->filename)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
314 g_free(d->filename);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
315 if (d->watcher)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
316 gaim_input_remove(d->watcher);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
317 if (d->fd != -1)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
318 close(d->fd);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
319 g_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
320 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
321
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
322 /* we could care less about the server's responce, but yahoo gets grumpy if we close before it sends it */
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
323 static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
324 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
325 struct yahoo_buddy_icon_upload_data *d = data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
326 GaimConnection *gc = d->gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
327 char buf[1024];
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
328
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
329 if (!GAIM_CONNECTION_IS_VALID(gc)) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
330 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
331 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
332 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
333
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
334 if (read(d->fd, buf, sizeof(buf)) <= 0)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
335 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
336 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
337
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
338 static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
339 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
340 struct yahoo_buddy_icon_upload_data *d = data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
341 GaimConnection *gc = d->gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
342 ssize_t wrote;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
343
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
344 if (!GAIM_CONNECTION_IS_VALID(gc)) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
345 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
346 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
347 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
348
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
349 wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
350 if (wrote <= 0) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
351 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
352 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
353 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
354 d->pos += wrote;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
355 if (d->pos >= d->str->len) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
356 gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
357 gaim_input_remove(d->watcher);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
358 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
359 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
360 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
361
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
362 static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, GaimInputCondition condition)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
363 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
364 struct yahoo_buddy_icon_upload_data *d = data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
365 struct yahoo_packet *pkt;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
366 gchar *size, *post, *buf;
10576
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
367 const char *host;
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
368 int content_length, port;
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
369 GaimConnection *gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
370 GaimAccount *account;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
371 struct yahoo_data *yd;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
372
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
373 if (!d)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
374 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
375
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
376
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
377 gc = d->gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
378 account = gaim_connection_get_account(gc);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
379 yd = gc->proto_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
380
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
381
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
382 if (source < 0) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
383 gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
384 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
385 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
386 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
387
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
388 d->fd = source;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
389 d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
390
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
391 pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
392
10111
8490f2e292a6 [gaim-migrate @ 11144]
Nathan Walp <nwalp@pidgin.im>
parents: 9779
diff changeset
393 size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
394 /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
395 yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc));
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
396 yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
397 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
398 yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc));
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
399 yahoo_packet_hash_str(pkt, 28, size);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
400 yahoo_packet_hash_str(pkt, 27, d->filename);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
401 yahoo_packet_hash_str(pkt, 14, "");
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
402
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
403 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
404
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
405 buf = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
406
10576
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
407 host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST);
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
408 port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT);
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
409 post = g_strdup_printf("POST http://%s:%d/notifyft HTTP/1.0\r\n"
10111
8490f2e292a6 [gaim-migrate @ 11144]
Nathan Walp <nwalp@pidgin.im>
parents: 9779
diff changeset
410 "Content-length: %" G_GSIZE_FORMAT "\r\n"
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
411 "Host: %s:%d\r\n"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
412 "Cookie: %s\r\n"
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
413 "\r\n",
10576
6c6772d3ea31 [gaim-migrate @ 11970]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10394
diff changeset
414 host, port, content_length + 4 + d->str->len, host, port, buf);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
415 write(d->fd, post, strlen(post));
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
416
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents: 10111
diff changeset
417 yahoo_packet_send_special(pkt, d->fd, 8);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
418 yahoo_packet_free(pkt);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
419
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
420 write(d->fd, "29\xc0\x80", 4);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
421
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
422 g_free(size);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
423 g_free(post);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
424 g_free(buf);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
425 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
426
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
427 void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
428 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
429 GaimAccount *account = gaim_connection_get_account(gc);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
430 struct yahoo_data *yd = gc->proto_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
431
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
432 if (yd->jp) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
433 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST),
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
434 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
435 yahoo_buddy_icon_upload_connected, d) == -1)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
436 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
437 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
438 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
439 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
440 } else {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
441 if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST),
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
442 gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT),
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
443 yahoo_buddy_icon_upload_connected, d) == -1)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
444 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
445 gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
446 yahoo_buddy_icon_upload_data_free(d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
447 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
448 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
449 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
450
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
451 void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
452 {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
453 struct yahoo_data *yd = gc->proto_data;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
454 GaimAccount *account = gc->account;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
455 FILE *file;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
456 struct stat st;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
457
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
458 if (iconfile == NULL) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
459 if (yd->picture_url)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
460 g_free(yd->picture_url);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
461 yd->picture_url = NULL;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
462
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
463 gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
464 gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
465 gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0);
9310
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
466 if (yd->logged_in)
085190b9dd64 [gaim-migrate @ 10118]
Tim Ringenbach <marv@pidgin.im>
parents: 9306
diff changeset
467 yahoo_send_picture_update(gc, 0);
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
468 /* TODO: check if we're connected and tell everyone we ain't not one no more */
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10576
diff changeset
469 } else if (!g_stat(iconfile, &st)) {
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10576
diff changeset
470 file = g_fopen(iconfile, "rb");
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
471 if (file) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
472 GString *s = g_string_sized_new(st.st_size);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
473 size_t len;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
474 struct yahoo_buddy_icon_upload_data *d;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
475 int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
476 int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
477 const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
478
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
479 g_string_set_size(s, st.st_size);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
480 len = fread(s->str, 1, st.st_size, file);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
481 fclose(file);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
482 g_string_set_size(s, len);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
483 yd->picture_checksum = g_string_hash(s);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
484
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
485 if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) &&
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
486 oldcksum && expire && oldurl) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
487 gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
488 g_string_free(s, TRUE);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
489 if (yd->picture_url)
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
490 g_free(yd->picture_url);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
491 yd->picture_url = g_strdup(oldurl);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
492 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
493 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
494
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
495 d = g_new0(struct yahoo_buddy_icon_upload_data, 1);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
496 d->gc = gc;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
497 d->str = s;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
498 d->fd = -1;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
499 d->filename = g_strdup(iconfile);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
500
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
501 if (!yd->logged_in) {
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
502 yd->picture_upload_todo = d;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
503 return;
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
504 }
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
505
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
506 yahoo_buddy_icon_upload(gc, d);
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
507 } else
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
508 gaim_debug_error("yahoo",
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
509 "Can't open buddy icon file!\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
510 } else
9779
2faebefa455e [gaim-migrate @ 10647]
Mark Doliner <mark@kingant.net>
parents: 9675
diff changeset
511 gaim_debug_error("yahoo",
9306
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
512 "Can't stat buddy icon file!\n");
04a3e9e869ee [gaim-migrate @ 10114]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
513 }