Fri, 19 Jun 2009 01:18:18 +0000
Backport the parts of b859960a4a19f57f20db0536c1815a6d79e08e36 that apply to
this branch, and also apply 162a734100aafd62b7338baa81b04510c6b66921.
| 9306 | 1 | /* |
| 15884 | 2 | * purple |
| 9306 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 9306 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 9306 | 21 | * |
| 22 | */ | |
| 23 | ||
| 24 | #include "internal.h" | |
| 25 | ||
| 26 | #include "account.h" | |
| 27 | #include "accountopt.h" | |
| 28 | #include "blist.h" | |
| 29 | #include "debug.h" | |
|
23960
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
30 | #include "privacy.h" |
| 9306 | 31 | #include "prpl.h" |
| 32 | #include "proxy.h" | |
| 33 | #include "util.h" | |
| 34 | ||
| 35 | #include "yahoo.h" | |
| 10392 | 36 | #include "yahoo_packet.h" |
| 9306 | 37 | #include "yahoo_friend.h" |
| 38 | #include "yahoo_picture.h" | |
| 39 | ||
| 40 | ||
| 41 | struct yahoo_fetch_picture_data { | |
| 15884 | 42 | PurpleConnection *gc; |
| 9306 | 43 | char *who; |
| 44 | int checksum; | |
| 45 | }; | |
| 46 | ||
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
47 | static void |
| 15884 | 48 | yahoo_fetch_picture_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
49 | const gchar *pic_data, size_t len, const gchar *error_message) |
| 9306 | 50 | { |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
51 | struct yahoo_fetch_picture_data *d; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
52 | struct yahoo_data *yd; |
| 9306 | 53 | |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
54 | d = user_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
55 | yd = d->gc->proto_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
56 | yd->url_datas = g_slist_remove(yd->url_datas, url_data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
57 | |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
58 | if (error_message != NULL) { |
| 15884 | 59 | purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
60 | } else if (len == 0) { |
| 15884 | 61 | purple_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
62 | } else { |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
63 | char *checksum = g_strdup_printf("%i", d->checksum); |
|
16539
75a20ae3a527
Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents:
16538
diff
changeset
|
64 | purple_buddy_icons_set_for_user(purple_connection_get_account(d->gc), d->who, g_memdup(pic_data, len), len, checksum); |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
65 | g_free(checksum); |
| 9306 | 66 | } |
| 67 | ||
| 68 | g_free(d->who); | |
| 69 | g_free(d); | |
| 70 | } | |
| 71 | ||
| 15884 | 72 | void yahoo_process_picture(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 73 | { |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
74 | struct yahoo_data *yd; |
| 9306 | 75 | GSList *l = pkt->hash; |
| 76 | char *who = NULL, *us = NULL; | |
| 77 | gboolean got_icon_info = FALSE, send_icon_info = FALSE; | |
| 78 | char *url = NULL; | |
| 79 | int checksum = 0; | |
| 80 | ||
| 81 | while (l) { | |
| 82 | struct yahoo_pair *pair = l->data; | |
| 83 | ||
| 84 | switch (pair->key) { | |
| 85 | case 1: | |
| 86 | case 4: | |
| 87 | who = pair->value; | |
| 88 | break; | |
| 89 | case 5: | |
| 90 | us = pair->value; | |
| 91 | break; | |
| 92 | case 13: { | |
| 93 | int tmp; | |
| 94 | tmp = strtol(pair->value, NULL, 10); | |
| 95 | if (tmp == 1) { | |
| 96 | send_icon_info = TRUE; | |
| 97 | } else if (tmp == 2) { | |
| 98 | got_icon_info = TRUE; | |
| 99 | } | |
| 100 | break; | |
| 101 | } | |
| 102 | case 20: | |
| 103 | url = pair->value; | |
| 104 | break; | |
| 105 | case 192: | |
| 106 | checksum = strtol(pair->value, NULL, 10); | |
| 107 | break; | |
| 108 | } | |
| 109 | ||
| 110 | l = l->next; | |
| 111 | } | |
| 112 | ||
|
23960
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
113 | if (!purple_privacy_check(purple_connection_get_account(gc), who)) { |
|
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
114 | purple_debug_info("yahoo", "Picture packet from %s dropped.\n", who); |
|
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
115 | return; |
|
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
116 | } |
|
e57706b32d2a
Patch from "Chris G." to extend the yahoo privacy to picture requests to help
Daniel Atallah <datallah@pidgin.im>
parents:
23181
diff
changeset
|
117 | |
|
9675
127db3bbb4f2
[gaim-migrate @ 10527]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9329
diff
changeset
|
118 | /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17151
diff
changeset
|
119 | if (who && got_icon_info && url && !g_ascii_strncasecmp(url, "http://", 7)) { |
| 9306 | 120 | /* TODO: make this work p2p, try p2p before the url */ |
| 15884 | 121 | PurpleUtilFetchUrlData *url_data; |
| 9306 | 122 | struct yahoo_fetch_picture_data *data; |
| 15884 | 123 | PurpleBuddy *b = purple_find_buddy(gc->account, who); |
|
16606
b31fca4f6f60
Thanks to Bleeter, yahoo will not crash for non-existent buddyicons anymore.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16539
diff
changeset
|
124 | const char *locksum = NULL; |
|
22145
458640401515
A patch from Gideon N. Guillen, with some minor modifications from me. This
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
125 | /* use whole URL if using HTTP Proxy */ |
|
24181
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23960
diff
changeset
|
126 | gboolean use_whole_url = yahoo_account_use_http_proxy(gc); |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
127 | |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
128 | /* FIXME: Cleanup this strtol() stuff if possible. */ |
|
16606
b31fca4f6f60
Thanks to Bleeter, yahoo will not crash for non-existent buddyicons anymore.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16539
diff
changeset
|
129 | if (b && (locksum = purple_buddy_icons_get_checksum_for_user(b)) != NULL && |
|
b31fca4f6f60
Thanks to Bleeter, yahoo will not crash for non-existent buddyicons anymore.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16539
diff
changeset
|
130 | (checksum == strtol(locksum, NULL, 10))) |
| 9306 | 131 | return; |
| 132 | ||
| 133 | data = g_new0(struct yahoo_fetch_picture_data, 1); | |
| 134 | data->gc = gc; | |
| 135 | data->who = g_strdup(who); | |
| 136 | data->checksum = checksum; | |
|
25762
0c1a4287c70c
Backport the parts of b859960a4a19f57f20db0536c1815a6d79e08e36 that apply to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
25152
diff
changeset
|
137 | /* TODO: Does this need to be MSIE 5.0? */ |
|
22145
458640401515
A patch from Gideon N. Guillen, with some minor modifications from me. This
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
138 | url_data = purple_util_fetch_url(url, use_whole_url, |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
139 | "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
140 | yahoo_fetch_picture_cb, data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
141 | if (url_data != NULL) { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
142 | yd = gc->proto_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
143 | yd->url_datas = g_slist_prepend(yd->url_datas, url_data); |
|
23181
d05abf92a22a
applied changes from 9409309cfd4634425fdacbdb3d751afd0bc89a84
Daniel Atallah <datallah@pidgin.im>
parents:
23170
diff
changeset
|
144 | } else { |
|
d05abf92a22a
applied changes from 9409309cfd4634425fdacbdb3d751afd0bc89a84
Daniel Atallah <datallah@pidgin.im>
parents:
23170
diff
changeset
|
145 | g_free(data->who); |
|
d05abf92a22a
applied changes from 9409309cfd4634425fdacbdb3d751afd0bc89a84
Daniel Atallah <datallah@pidgin.im>
parents:
23170
diff
changeset
|
146 | g_free(data); |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
147 | } |
| 9306 | 148 | } else if (who && send_icon_info) { |
| 149 | yahoo_send_picture_info(gc, who); | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 15884 | 153 | void yahoo_process_picture_update(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 154 | { |
| 155 | GSList *l = pkt->hash; | |
| 156 | char *who = NULL; | |
| 157 | int icon = 0; | |
| 158 | ||
| 159 | while (l) { | |
| 160 | struct yahoo_pair *pair = l->data; | |
| 161 | ||
| 162 | switch (pair->key) { | |
| 163 | case 4: | |
| 164 | who = pair->value; | |
| 165 | break; | |
| 166 | case 5: | |
| 167 | /* us */ | |
| 168 | break; | |
|
17151
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
169 | /* NOTE: currently the server seems to only send 213; 206 was used |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
170 | * in older versions. Check whether it's still needed. */ |
| 9306 | 171 | case 206: |
|
17151
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
172 | case 213: |
| 9306 | 173 | icon = strtol(pair->value, NULL, 10); |
| 174 | break; | |
| 175 | } | |
| 176 | l = l->next; | |
| 177 | } | |
| 178 | ||
| 179 | if (who) { | |
| 180 | if (icon == 2) | |
| 9310 | 181 | yahoo_send_picture_request(gc, who); |
| 9322 | 182 | else if ((icon == 0) || (icon == 1)) { |
| 9325 | 183 | YahooFriend *f; |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
184 | purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); |
| 9325 | 185 | if ((f = yahoo_friend_find(gc, who))) |
| 186 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
| 15884 | 187 | purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
| 9322 | 188 | } |
| 9306 | 189 | } |
| 190 | } | |
| 191 | ||
| 15884 | 192 | void yahoo_process_picture_checksum(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 193 | { |
| 194 | GSList *l = pkt->hash; | |
| 195 | char *who = NULL; | |
| 196 | int checksum = 0; | |
| 197 | ||
| 198 | while (l) { | |
| 199 | struct yahoo_pair *pair = l->data; | |
| 200 | ||
| 201 | switch (pair->key) { | |
| 202 | case 4: | |
| 203 | who = pair->value; | |
| 204 | break; | |
| 205 | case 5: | |
| 206 | /* us */ | |
| 207 | break; | |
| 208 | case 192: | |
| 209 | checksum = strtol(pair->value, NULL, 10); | |
| 210 | break; | |
| 211 | } | |
| 212 | l = l->next; | |
| 213 | } | |
| 214 | ||
| 215 | if (who) { | |
| 15884 | 216 | PurpleBuddy *b = purple_find_buddy(gc->account, who); |
|
16606
b31fca4f6f60
Thanks to Bleeter, yahoo will not crash for non-existent buddyicons anymore.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16539
diff
changeset
|
217 | const char *locksum = NULL; |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
218 | |
|
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
219 | /* FIXME: Cleanup this strtol() stuff if possible. */ |
|
17151
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
220 | if (b) { |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
221 | locksum = purple_buddy_icons_get_checksum_for_user(b); |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
222 | if (!locksum || (checksum != strtol(locksum, NULL, 10))) |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
223 | yahoo_send_picture_request(gc, who); |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
224 | } |
| 9306 | 225 | } |
| 226 | } | |
| 227 | ||
| 15884 | 228 | void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 229 | { |
| 15884 | 230 | PurpleAccount *account = purple_connection_get_account(gc); |
| 9306 | 231 | struct yahoo_data *yd = gc->proto_data; |
| 232 | GSList *l = pkt->hash; | |
| 233 | char *url = NULL; | |
| 234 | ||
| 235 | while (l) { | |
| 236 | struct yahoo_pair *pair = l->data; | |
| 237 | ||
| 238 | switch (pair->key) { | |
| 239 | case 5: | |
| 240 | /* us */ | |
| 241 | break; | |
| 242 | case 27: | |
| 243 | /* filename on our computer. */ | |
| 244 | break; | |
| 245 | case 20: /* url at yahoo */ | |
| 246 | url = pair->value; | |
| 247 | case 38: /* timestamp */ | |
| 248 | break; | |
| 249 | } | |
| 250 | l = l->next; | |
| 251 | } | |
| 252 | ||
| 253 | if (url) { | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
254 | g_free(yd->picture_url); |
| 9306 | 255 | yd->picture_url = g_strdup(url); |
| 15884 | 256 | purple_account_set_string(account, YAHOO_PICURL_SETTING, url); |
| 257 | purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
258 | yahoo_send_picture_checksum(gc); |
| 9310 | 259 | yahoo_send_picture_update(gc, 2); |
| 9306 | 260 | } |
| 261 | } | |
| 262 | ||
| 15884 | 263 | void yahoo_process_avatar_update(PurpleConnection *gc, struct yahoo_packet *pkt) |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
264 | { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
265 | GSList *l = pkt->hash; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
266 | char *who = NULL; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
267 | int avatar = 0; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
268 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
269 | while (l) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
270 | struct yahoo_pair *pair = l->data; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
271 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
272 | switch (pair->key) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
273 | case 4: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
274 | who = pair->value; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
275 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
276 | case 5: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
277 | /* us */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
278 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
279 | case 206: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
280 | /* |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
281 | * 0 - No icon or avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
282 | * 1 - Using an avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
283 | * 2 - Using an icon |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
284 | */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
285 | avatar = strtol(pair->value, NULL, 10); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
286 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
287 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
288 | l = l->next; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
289 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
290 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
291 | if (who) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
292 | if (avatar == 2) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
293 | yahoo_send_picture_request(gc, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
294 | else if ((avatar == 0) || (avatar == 1)) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
295 | YahooFriend *f; |
|
16534
2ab9e23f99d9
Move the prpl icon checksum code into the core, so we can delete the
Richard Laager <rlaager@pidgin.im>
parents:
16076
diff
changeset
|
296 | purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
297 | if ((f = yahoo_friend_find(gc, who))) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
298 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
| 15884 | 299 | purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
300 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
301 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
302 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
303 | |
| 15884 | 304 | void yahoo_send_picture_info(PurpleConnection *gc, const char *who) |
| 9322 | 305 | { |
| 306 | struct yahoo_data *yd = gc->proto_data; | |
| 307 | struct yahoo_packet *pkt; | |
| 308 | ||
| 9329 | 309 | if (!yd->picture_url) { |
| 15884 | 310 | purple_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); |
| 9322 | 311 | return; |
| 9329 | 312 | } |
| 9322 | 313 | |
| 314 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 315 | yahoo_packet_hash(pkt, "sssssi", 1, purple_connection_get_display_name(gc), |
| 316 | 4, purple_connection_get_display_name(gc), 5, who, | |
| 10394 | 317 | 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); |
| 10392 | 318 | yahoo_packet_send_and_free(pkt, yd); |
| 9322 | 319 | } |
| 9306 | 320 | |
| 15884 | 321 | void yahoo_send_picture_request(PurpleConnection *gc, const char *who) |
| 9306 | 322 | { |
| 323 | struct yahoo_data *yd = gc->proto_data; | |
| 324 | struct yahoo_packet *pkt; | |
| 325 | ||
| 326 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 327 | yahoo_packet_hash_str(pkt, 4, purple_connection_get_display_name(gc)); /* me */ |
| 10394 | 328 | yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ |
| 329 | yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | |
| 10392 | 330 | yahoo_packet_send_and_free(pkt, yd); |
| 9306 | 331 | } |
| 332 | ||
| 15884 | 333 | void yahoo_send_picture_checksum(PurpleConnection *gc) |
| 9310 | 334 | { |
| 335 | struct yahoo_data *yd = gc->proto_data; | |
| 336 | struct yahoo_packet *pkt; | |
| 337 | ||
| 338 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 339 | yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), |
| 10394 | 340 | 212, "1", 192, yd->picture_checksum); |
| 10392 | 341 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 342 | } |
| 343 | ||
| 15884 | 344 | void yahoo_send_picture_update_to_user(PurpleConnection *gc, const char *who, int type) |
| 9310 | 345 | { |
| 346 | struct yahoo_data *yd = gc->proto_data; | |
| 347 | struct yahoo_packet *pkt; | |
| 348 | ||
| 349 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 350 | yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), 5, who, 206, type); |
| 10392 | 351 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 352 | } |
| 353 | ||
| 354 | struct yspufe { | |
| 15884 | 355 | PurpleConnection *gc; |
| 9310 | 356 | int type; |
| 357 | }; | |
| 358 | ||
| 359 | static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | |
| 360 | { | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
361 | const char *who = key; |
| 9310 | 362 | YahooFriend *f = value; |
| 363 | struct yspufe *d = data; | |
| 364 | ||
| 365 | if (f->status != YAHOO_STATUS_OFFLINE) | |
| 366 | yahoo_send_picture_update_to_user(d->gc, who, d->type); | |
| 367 | } | |
| 368 | ||
| 15884 | 369 | void yahoo_send_picture_update(PurpleConnection *gc, int type) |
| 9310 | 370 | { |
| 371 | struct yahoo_data *yd = gc->proto_data; | |
| 372 | struct yspufe data; | |
| 373 | ||
| 374 | data.gc = gc; | |
| 375 | data.type = type; | |
| 376 | ||
| 377 | g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | |
| 378 | } | |
| 379 | ||
| 9306 | 380 | void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) |
| 381 | { | |
| 15884 | 382 | purple_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); |
| 9306 | 383 | |
| 384 | if (d->str) | |
| 385 | g_string_free(d->str, TRUE); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
386 | g_free(d->filename); |
| 9306 | 387 | if (d->watcher) |
| 15884 | 388 | purple_input_remove(d->watcher); |
| 9306 | 389 | if (d->fd != -1) |
| 390 | close(d->fd); | |
| 391 | g_free(d); | |
| 392 | } | |
| 393 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
394 | /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ |
| 15884 | 395 | static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, PurpleInputCondition condition) |
| 9306 | 396 | { |
| 397 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 15884 | 398 | PurpleConnection *gc = d->gc; |
| 9306 | 399 | char buf[1024]; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
400 | int ret; |
| 9306 | 401 | |
| 15884 | 402 | if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
| 9306 | 403 | yahoo_buddy_icon_upload_data_free(d); |
| 404 | return; | |
| 405 | } | |
| 406 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
407 | ret = read(d->fd, buf, sizeof(buf)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
408 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
409 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
410 | return; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
411 | else if (ret <= 0) { |
|
25152
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
412 | /* There are other problems if d->str->len overflows, so shut up the |
|
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
413 | * warning on 64-bit. */ |
|
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
414 | purple_debug_info("yahoo", "Buddy icon upload response (%" G_GSIZE_FORMAT ") bytes (> ~400 indicates failure):\n%.*s\n", |
|
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
415 | d->str->len, (guint)d->str->len, d->str->str); |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
416 | |
| 9306 | 417 | yahoo_buddy_icon_upload_data_free(d); |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
418 | return; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
419 | } |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
420 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
421 | g_string_append_len(d->str, buf, ret); |
| 9306 | 422 | } |
| 423 | ||
| 15884 | 424 | static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, PurpleInputCondition condition) |
| 9306 | 425 | { |
| 426 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 15884 | 427 | PurpleConnection *gc = d->gc; |
|
23073
e731fbd84c71
Use gssize instead of ssize_t as the latter isn't available everywhere.
Daniel Atallah <datallah@pidgin.im>
parents:
22145
diff
changeset
|
428 | gssize wrote; |
| 9306 | 429 | |
| 15884 | 430 | if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
| 9306 | 431 | yahoo_buddy_icon_upload_data_free(d); |
| 432 | return; | |
| 433 | } | |
| 434 | ||
| 435 | wrote = write(d->fd, d->str->str + d->pos, d->str->len - d->pos); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
436 | if (wrote < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
437 | return; |
| 9306 | 438 | if (wrote <= 0) { |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
439 | purple_debug_info("yahoo", "Error uploading buddy icon.\n"); |
| 9306 | 440 | yahoo_buddy_icon_upload_data_free(d); |
| 441 | return; | |
| 442 | } | |
| 443 | d->pos += wrote; | |
| 444 | if (d->pos >= d->str->len) { | |
| 15884 | 445 | purple_debug_misc("yahoo", "Finished uploading buddy icon.\n"); |
| 446 | purple_input_remove(d->watcher); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
447 | /* Clean out the sent buffer and reuse it to read the result */ |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
448 | g_string_free(d->str, TRUE); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
449 | d->str = g_string_new(""); |
| 15884 | 450 | d->watcher = purple_input_add(d->fd, PURPLE_INPUT_READ, yahoo_buddy_icon_upload_reading, d); |
| 9306 | 451 | } |
| 452 | } | |
| 453 | ||
|
14182
517f4531b8a0
[gaim-migrate @ 16754]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
454 | static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) |
| 9306 | 455 | { |
| 456 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 457 | struct yahoo_packet *pkt; | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
458 | gchar *tmp, *header; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
459 | guchar *pkt_buf; |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
460 | const char *host; |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
461 | int port; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
462 | gsize pkt_buf_len; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
463 | PurpleConnection *gc = d->gc; |
| 15884 | 464 | PurpleAccount *account; |
| 9306 | 465 | struct yahoo_data *yd; |
|
24181
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23960
diff
changeset
|
466 | /* use whole URL if using HTTP Proxy */ |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23960
diff
changeset
|
467 | gboolean use_whole_url = yahoo_account_use_http_proxy(gc); |
| 9306 | 468 | |
| 15884 | 469 | account = purple_connection_get_account(gc); |
| 9306 | 470 | yd = gc->proto_data; |
| 471 | ||
| 15884 | 472 | /* Buddy icon connect is now complete; clear the PurpleProxyConnectData */ |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
473 | yd->buddy_icon_connect_data = NULL; |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
474 | |
| 9306 | 475 | if (source < 0) { |
| 15884 | 476 | purple_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message); |
| 9306 | 477 | yahoo_buddy_icon_upload_data_free(d); |
| 478 | return; | |
| 479 | } | |
| 480 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
481 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, yd->session_id); |
| 9306 | 482 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
483 | tmp = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); |
| 9306 | 484 | /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ |
| 15884 | 485 | yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc)); |
| 10394 | 486 | yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ |
| 15884 | 487 | purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); |
| 488 | yahoo_packet_hash_str(pkt, 0, purple_connection_get_display_name(gc)); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
489 | yahoo_packet_hash_str(pkt, 28, tmp); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
490 | g_free(tmp); |
| 10394 | 491 | yahoo_packet_hash_str(pkt, 27, d->filename); |
| 492 | yahoo_packet_hash_str(pkt, 14, ""); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
493 | /* 4 padding for the 29 key name */ |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
494 | pkt_buf_len = yahoo_packet_build(pkt, 4, FALSE, yd->jp, &pkt_buf); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
495 | yahoo_packet_free(pkt); |
| 9306 | 496 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
497 | /* header + packet + "29" + 0xc0 + 0x80) + pictureblob */ |
| 9306 | 498 | |
| 15884 | 499 | host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
| 500 | port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
501 | tmp = g_strdup_printf("%s:%d", host, port); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
502 | header = g_strdup_printf("POST %s%s/notifyft HTTP/1.1\r\n" |
|
25762
0c1a4287c70c
Backport the parts of b859960a4a19f57f20db0536c1815a6d79e08e36 that apply to
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
25152
diff
changeset
|
503 | "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
504 | "Cookie: T=%s; Y=%s\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
505 | "Host: %s\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
506 | "Content-Length: %" G_GSIZE_FORMAT "\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
507 | "Cache-Control: no-cache\r\n\r\n", |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
508 | use_whole_url ? "http://" : "", use_whole_url ? tmp : "", |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
509 | yd->cookie_t, yd->cookie_y, |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
510 | tmp, |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
511 | pkt_buf_len + 4 + d->str->len); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
512 | g_free(tmp); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
513 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
514 | /* There's no magic here, we just need to prepend in reverse order */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
515 | g_string_prepend(d->str, "29\xc0\x80"); |
| 9306 | 516 | |
| 14321 | 517 | g_string_prepend_len(d->str, (char *)pkt_buf, pkt_buf_len); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
518 | g_free(pkt_buf); |
| 9306 | 519 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
520 | g_string_prepend(d->str, header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
521 | g_free(header); |
| 9306 | 522 | |
|
25152
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
523 | /* There are other problems if we're uploading over 4GB of data */ |
|
128b99dfb286
Fix warnings where size_t/gsize was used for printf with the wrong format
Paul Aurich <darkrain42@pidgin.im>
parents:
24181
diff
changeset
|
524 | purple_debug_info("yahoo", "Buddy icon upload data:\n%.*s\n", (guint)d->str->len, d->str->str); |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
525 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
526 | d->fd = source; |
| 15884 | 527 | d->watcher = purple_input_add(d->fd, PURPLE_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
528 | |
| 15884 | 529 | yahoo_buddy_icon_upload_pending(d, d->fd, PURPLE_INPUT_WRITE); |
| 9306 | 530 | } |
| 531 | ||
| 15884 | 532 | void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d) |
| 9306 | 533 | { |
| 15884 | 534 | PurpleAccount *account = purple_connection_get_account(gc); |
| 9306 | 535 | struct yahoo_data *yd = gc->proto_data; |
| 536 | ||
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
537 | if (yd->buddy_icon_connect_data != NULL) { |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
538 | /* Cancel any in-progress buddy icon upload */ |
| 15884 | 539 | purple_proxy_connect_cancel(yd->buddy_icon_connect_data); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
540 | yd->buddy_icon_connect_data = NULL; |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
541 | } |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
542 | |
| 15884 | 543 | yd->buddy_icon_connect_data = purple_proxy_connect(NULL, account, |
| 544 | yd->jp ? purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST) | |
| 545 | : purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), | |
| 546 | purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
547 | yahoo_buddy_icon_upload_connected, d); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
548 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
549 | if (yd->buddy_icon_connect_data == NULL) |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
550 | { |
| 15884 | 551 | purple_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
552 | yahoo_buddy_icon_upload_data_free(d); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
553 | } |
| 9306 | 554 | } |
| 555 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
556 | static int yahoo_buddy_icon_calculate_checksum(const guchar *data, gsize len) |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
557 | { |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
558 | /* This code is borrowed from Kopete, which seems to be managing to calculate |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
559 | checksums in such a manner that Yahoo!'s servers are happy */ |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
560 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
561 | const guchar *p = data; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
562 | int checksum = 0, g, i = len; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
563 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
564 | while(i--) { |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
565 | checksum = (checksum << 4) + *p++; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
566 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
567 | if((g = (checksum & 0xf0000000)) != 0) |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
568 | checksum ^= g >> 23; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
569 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
570 | checksum &= ~g; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
571 | } |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
572 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
573 | purple_debug_misc("yahoo", "Calculated buddy icon checksum: %d", checksum); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
574 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
575 | return checksum; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
576 | } |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
577 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
578 | void yahoo_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
| 9306 | 579 | { |
| 580 | struct yahoo_data *yd = gc->proto_data; | |
| 15884 | 581 | PurpleAccount *account = gc->account; |
| 9306 | 582 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
583 | if (img == NULL) { |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
584 | g_free(yd->picture_url); |
| 9306 | 585 | yd->picture_url = NULL; |
| 586 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
587 | /* TODO: don't we have to clear it on the server too?! */ |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
588 | |
| 15884 | 589 | purple_account_set_string(account, YAHOO_PICURL_SETTING, NULL); |
| 590 | purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 591 | purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 9310 | 592 | if (yd->logged_in) |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
593 | /* Tell everyone we ain't got one no more */ |
| 9310 | 594 | yahoo_send_picture_update(gc, 0); |
| 9306 | 595 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
596 | } else { |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
597 | gconstpointer data = purple_imgstore_get_data(img); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
598 | size_t len = purple_imgstore_get_size(img); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
599 | GString *s = g_string_new_len(data, len); |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
600 | struct yahoo_buddy_icon_upload_data *d; |
| 15884 | 601 | int oldcksum = purple_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); |
| 602 | int expire = purple_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 603 | const char *oldurl = purple_account_get_string(account, YAHOO_PICURL_SETTING, NULL); | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
604 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
605 | yd->picture_checksum = yahoo_buddy_icon_calculate_checksum(data, len); |
| 9306 | 606 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
607 | if ((yd->picture_checksum == oldcksum) && |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
608 | (expire > (time(NULL) + 60*60*24)) && oldurl) |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
609 | { |
| 15884 | 610 | purple_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
611 | g_string_free(s, TRUE); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
612 | g_free(yd->picture_url); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
613 | yd->picture_url = g_strdup(oldurl); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
614 | return; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
615 | } |
| 9306 | 616 | |
|
16757
aae5c0ced2da
Update the comments about yahoo buddy icons. Only send the filename and not the whole path.
Tim Ringenbach <marv@pidgin.im>
parents:
16606
diff
changeset
|
617 | /* We use this solely for sending a filename to the server */ |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
618 | d = g_new0(struct yahoo_buddy_icon_upload_data, 1); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
619 | d->gc = gc; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
620 | d->str = s; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
621 | d->fd = -1; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
622 | d->filename = g_strdup(purple_imgstore_get_filename(img)); |
| 9306 | 623 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
624 | if (!yd->logged_in) { |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
625 | yd->picture_upload_todo = d; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
626 | return; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
627 | } |
| 9306 | 628 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
629 | yahoo_buddy_icon_upload(gc, d); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
630 | |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
631 | } |
|
15245
3abed8bd82fb
[gaim-migrate @ 17972]
Mark Doliner <markdoliner@pidgin.im>
parents:
15239
diff
changeset
|
632 | } |