Sun, 14 Dec 2008 02:58:44 +0000
Fix warnings where size_t/gsize was used for printf with the wrong format
specifier and fix some free's that should be g_free.
Fixes #7782.
committer: Elliott Sales de Andrade <qulogic@pidgin.im>
| 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; | |
|
22145
458640401515
A patch from Gideon N. Guillen, with some minor modifications from me. This
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
137 | url_data = purple_util_fetch_url(url, use_whole_url, |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
138 | "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
139 | yahoo_fetch_picture_cb, data); |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
140 | if (url_data != NULL) { |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
141 | yd = gc->proto_data; |
|
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
142 | 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
|
143 | } else { |
|
d05abf92a22a
applied changes from 9409309cfd4634425fdacbdb3d751afd0bc89a84
Daniel Atallah <datallah@pidgin.im>
parents:
23170
diff
changeset
|
144 | g_free(data->who); |
|
d05abf92a22a
applied changes from 9409309cfd4634425fdacbdb3d751afd0bc89a84
Daniel Atallah <datallah@pidgin.im>
parents:
23170
diff
changeset
|
145 | g_free(data); |
|
14416
c95ffd983a39
[gaim-migrate @ 17060]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
146 | } |
| 9306 | 147 | } else if (who && send_icon_info) { |
| 148 | yahoo_send_picture_info(gc, who); | |
| 149 | } | |
| 150 | } | |
| 151 | ||
| 15884 | 152 | void yahoo_process_picture_update(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 153 | { |
| 154 | GSList *l = pkt->hash; | |
| 155 | char *who = NULL; | |
| 156 | int icon = 0; | |
| 157 | ||
| 158 | while (l) { | |
| 159 | struct yahoo_pair *pair = l->data; | |
| 160 | ||
| 161 | switch (pair->key) { | |
| 162 | case 4: | |
| 163 | who = pair->value; | |
| 164 | break; | |
| 165 | case 5: | |
| 166 | /* us */ | |
| 167 | break; | |
|
17151
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
168 | /* 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
|
169 | * in older versions. Check whether it's still needed. */ |
| 9306 | 170 | case 206: |
|
17151
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
171 | case 213: |
| 9306 | 172 | icon = strtol(pair->value, NULL, 10); |
| 173 | break; | |
| 174 | } | |
| 175 | l = l->next; | |
| 176 | } | |
| 177 | ||
| 178 | if (who) { | |
| 179 | if (icon == 2) | |
| 9310 | 180 | yahoo_send_picture_request(gc, who); |
| 9322 | 181 | else if ((icon == 0) || (icon == 1)) { |
| 9325 | 182 | 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
|
183 | purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); |
| 9325 | 184 | if ((f = yahoo_friend_find(gc, who))) |
| 185 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
| 15884 | 186 | purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
| 9322 | 187 | } |
| 9306 | 188 | } |
| 189 | } | |
| 190 | ||
| 15884 | 191 | void yahoo_process_picture_checksum(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 192 | { |
| 193 | GSList *l = pkt->hash; | |
| 194 | char *who = NULL; | |
| 195 | int checksum = 0; | |
| 196 | ||
| 197 | while (l) { | |
| 198 | struct yahoo_pair *pair = l->data; | |
| 199 | ||
| 200 | switch (pair->key) { | |
| 201 | case 4: | |
| 202 | who = pair->value; | |
| 203 | break; | |
| 204 | case 5: | |
| 205 | /* us */ | |
| 206 | break; | |
| 207 | case 192: | |
| 208 | checksum = strtol(pair->value, NULL, 10); | |
| 209 | break; | |
| 210 | } | |
| 211 | l = l->next; | |
| 212 | } | |
| 213 | ||
| 214 | if (who) { | |
| 15884 | 215 | 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
|
216 | 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
|
217 | |
|
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 | /* 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
|
219 | if (b) { |
|
7d28dd13c4db
Patch #1038. Fix receiving of Yahoo buddy icons. Thanks, vampire!
Sean Egan <seanegan@pidgin.im>
parents:
16757
diff
changeset
|
220 | 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
|
221 | 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
|
222 | 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
|
223 | } |
| 9306 | 224 | } |
| 225 | } | |
| 226 | ||
| 15884 | 227 | void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt) |
| 9306 | 228 | { |
| 15884 | 229 | PurpleAccount *account = purple_connection_get_account(gc); |
| 9306 | 230 | struct yahoo_data *yd = gc->proto_data; |
| 231 | GSList *l = pkt->hash; | |
| 232 | char *url = NULL; | |
| 233 | ||
| 234 | while (l) { | |
| 235 | struct yahoo_pair *pair = l->data; | |
| 236 | ||
| 237 | switch (pair->key) { | |
| 238 | case 5: | |
| 239 | /* us */ | |
| 240 | break; | |
| 241 | case 27: | |
| 242 | /* filename on our computer. */ | |
| 243 | break; | |
| 244 | case 20: /* url at yahoo */ | |
| 245 | url = pair->value; | |
| 246 | case 38: /* timestamp */ | |
| 247 | break; | |
| 248 | } | |
| 249 | l = l->next; | |
| 250 | } | |
| 251 | ||
| 252 | if (url) { | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
253 | g_free(yd->picture_url); |
| 9306 | 254 | yd->picture_url = g_strdup(url); |
| 15884 | 255 | purple_account_set_string(account, YAHOO_PICURL_SETTING, url); |
| 256 | 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
|
257 | yahoo_send_picture_checksum(gc); |
| 9310 | 258 | yahoo_send_picture_update(gc, 2); |
| 9306 | 259 | } |
| 260 | } | |
| 261 | ||
| 15884 | 262 | 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
|
263 | { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
264 | GSList *l = pkt->hash; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
265 | char *who = NULL; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
266 | int avatar = 0; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
267 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
268 | while (l) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
269 | struct yahoo_pair *pair = l->data; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
270 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
271 | switch (pair->key) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
272 | case 4: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
273 | who = pair->value; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
274 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
275 | case 5: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
276 | /* us */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
277 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
278 | case 206: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
279 | /* |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
280 | * 0 - No icon or avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
281 | * 1 - Using an avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
282 | * 2 - Using an icon |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
283 | */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
284 | avatar = strtol(pair->value, NULL, 10); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
285 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
286 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
287 | l = l->next; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
288 | } |
|
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 | if (who) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
291 | if (avatar == 2) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
292 | yahoo_send_picture_request(gc, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
293 | else if ((avatar == 0) || (avatar == 1)) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
294 | 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
|
295 | 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
|
296 | if ((f = yahoo_friend_find(gc, who))) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
297 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
| 15884 | 298 | 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
|
299 | } |
|
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 | |
| 15884 | 303 | void yahoo_send_picture_info(PurpleConnection *gc, const char *who) |
| 9322 | 304 | { |
| 305 | struct yahoo_data *yd = gc->proto_data; | |
| 306 | struct yahoo_packet *pkt; | |
| 307 | ||
| 9329 | 308 | if (!yd->picture_url) { |
| 15884 | 309 | purple_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); |
| 9322 | 310 | return; |
| 9329 | 311 | } |
| 9322 | 312 | |
| 313 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 314 | yahoo_packet_hash(pkt, "sssssi", 1, purple_connection_get_display_name(gc), |
| 315 | 4, purple_connection_get_display_name(gc), 5, who, | |
| 10394 | 316 | 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); |
| 10392 | 317 | yahoo_packet_send_and_free(pkt, yd); |
| 9322 | 318 | } |
| 9306 | 319 | |
| 15884 | 320 | void yahoo_send_picture_request(PurpleConnection *gc, const char *who) |
| 9306 | 321 | { |
| 322 | struct yahoo_data *yd = gc->proto_data; | |
| 323 | struct yahoo_packet *pkt; | |
| 324 | ||
| 325 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 326 | yahoo_packet_hash_str(pkt, 4, purple_connection_get_display_name(gc)); /* me */ |
| 10394 | 327 | yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ |
| 328 | yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | |
| 10392 | 329 | yahoo_packet_send_and_free(pkt, yd); |
| 9306 | 330 | } |
| 331 | ||
| 15884 | 332 | void yahoo_send_picture_checksum(PurpleConnection *gc) |
| 9310 | 333 | { |
| 334 | struct yahoo_data *yd = gc->proto_data; | |
| 335 | struct yahoo_packet *pkt; | |
| 336 | ||
| 337 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 338 | yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), |
| 10394 | 339 | 212, "1", 192, yd->picture_checksum); |
| 10392 | 340 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 341 | } |
| 342 | ||
| 15884 | 343 | void yahoo_send_picture_update_to_user(PurpleConnection *gc, const char *who, int type) |
| 9310 | 344 | { |
| 345 | struct yahoo_data *yd = gc->proto_data; | |
| 346 | struct yahoo_packet *pkt; | |
| 347 | ||
| 348 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | |
| 15884 | 349 | yahoo_packet_hash(pkt, "ssi", 1, purple_connection_get_display_name(gc), 5, who, 206, type); |
| 10392 | 350 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 351 | } |
| 352 | ||
| 353 | struct yspufe { | |
| 15884 | 354 | PurpleConnection *gc; |
| 9310 | 355 | int type; |
| 356 | }; | |
| 357 | ||
| 358 | static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | |
| 359 | { | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
360 | const char *who = key; |
| 9310 | 361 | YahooFriend *f = value; |
| 362 | struct yspufe *d = data; | |
| 363 | ||
| 364 | if (f->status != YAHOO_STATUS_OFFLINE) | |
| 365 | yahoo_send_picture_update_to_user(d->gc, who, d->type); | |
| 366 | } | |
| 367 | ||
| 15884 | 368 | void yahoo_send_picture_update(PurpleConnection *gc, int type) |
| 9310 | 369 | { |
| 370 | struct yahoo_data *yd = gc->proto_data; | |
| 371 | struct yspufe data; | |
| 372 | ||
| 373 | data.gc = gc; | |
| 374 | data.type = type; | |
| 375 | ||
| 376 | g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | |
| 377 | } | |
| 378 | ||
| 9306 | 379 | void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) |
| 380 | { | |
| 15884 | 381 | purple_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); |
| 9306 | 382 | |
| 383 | if (d->str) | |
| 384 | g_string_free(d->str, TRUE); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
385 | g_free(d->filename); |
| 9306 | 386 | if (d->watcher) |
| 15884 | 387 | purple_input_remove(d->watcher); |
| 9306 | 388 | if (d->fd != -1) |
| 389 | close(d->fd); | |
| 390 | g_free(d); | |
| 391 | } | |
| 392 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
393 | /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ |
| 15884 | 394 | static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, PurpleInputCondition condition) |
| 9306 | 395 | { |
| 396 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 15884 | 397 | PurpleConnection *gc = d->gc; |
| 9306 | 398 | char buf[1024]; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
399 | int ret; |
| 9306 | 400 | |
| 15884 | 401 | if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
| 9306 | 402 | yahoo_buddy_icon_upload_data_free(d); |
| 403 | return; | |
| 404 | } | |
| 405 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
406 | ret = read(d->fd, buf, sizeof(buf)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
407 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
408 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
409 | return; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
410 | 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
|
411 | /* 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
|
412 | * 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
|
413 | 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
|
414 | 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
|
415 | |
| 9306 | 416 | yahoo_buddy_icon_upload_data_free(d); |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
417 | return; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
418 | } |
|
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 | g_string_append_len(d->str, buf, ret); |
| 9306 | 421 | } |
| 422 | ||
| 15884 | 423 | static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, PurpleInputCondition condition) |
| 9306 | 424 | { |
| 425 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 15884 | 426 | 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
|
427 | gssize wrote; |
| 9306 | 428 | |
| 15884 | 429 | if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
| 9306 | 430 | yahoo_buddy_icon_upload_data_free(d); |
| 431 | return; | |
| 432 | } | |
| 433 | ||
| 434 | 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
|
435 | if (wrote < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
436 | return; |
| 9306 | 437 | if (wrote <= 0) { |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
438 | purple_debug_info("yahoo", "Error uploading buddy icon.\n"); |
| 9306 | 439 | yahoo_buddy_icon_upload_data_free(d); |
| 440 | return; | |
| 441 | } | |
| 442 | d->pos += wrote; | |
| 443 | if (d->pos >= d->str->len) { | |
| 15884 | 444 | purple_debug_misc("yahoo", "Finished uploading buddy icon.\n"); |
| 445 | purple_input_remove(d->watcher); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
446 | /* 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
|
447 | g_string_free(d->str, TRUE); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
448 | d->str = g_string_new(""); |
| 15884 | 449 | d->watcher = purple_input_add(d->fd, PURPLE_INPUT_READ, yahoo_buddy_icon_upload_reading, d); |
| 9306 | 450 | } |
| 451 | } | |
| 452 | ||
|
14182
517f4531b8a0
[gaim-migrate @ 16754]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
453 | static void yahoo_buddy_icon_upload_connected(gpointer data, gint source, const gchar *error_message) |
| 9306 | 454 | { |
| 455 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 456 | struct yahoo_packet *pkt; | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
457 | gchar *tmp, *header; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
458 | guchar *pkt_buf; |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
459 | const char *host; |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
460 | int port; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
461 | gsize pkt_buf_len; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
462 | PurpleConnection *gc = d->gc; |
| 15884 | 463 | PurpleAccount *account; |
| 9306 | 464 | 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
|
465 | /* 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
|
466 | gboolean use_whole_url = yahoo_account_use_http_proxy(gc); |
| 9306 | 467 | |
| 15884 | 468 | account = purple_connection_get_account(gc); |
| 9306 | 469 | yd = gc->proto_data; |
| 470 | ||
| 15884 | 471 | /* Buddy icon connect is now complete; clear the PurpleProxyConnectData */ |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
472 | yd->buddy_icon_connect_data = NULL; |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
473 | |
| 9306 | 474 | if (source < 0) { |
| 15884 | 475 | purple_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message); |
| 9306 | 476 | yahoo_buddy_icon_upload_data_free(d); |
| 477 | return; | |
| 478 | } | |
| 479 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
480 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPLOAD, YAHOO_STATUS_AVAILABLE, yd->session_id); |
| 9306 | 481 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
482 | tmp = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); |
| 9306 | 483 | /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ |
| 15884 | 484 | yahoo_packet_hash_str(pkt, 1, purple_connection_get_display_name(gc)); |
| 10394 | 485 | yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ |
| 15884 | 486 | purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); |
| 487 | 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
|
488 | yahoo_packet_hash_str(pkt, 28, tmp); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
489 | g_free(tmp); |
| 10394 | 490 | yahoo_packet_hash_str(pkt, 27, d->filename); |
| 491 | yahoo_packet_hash_str(pkt, 14, ""); | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
492 | /* 4 padding for the 29 key name */ |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
493 | 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
|
494 | yahoo_packet_free(pkt); |
| 9306 | 495 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
496 | /* header + packet + "29" + 0xc0 + 0x80) + pictureblob */ |
| 9306 | 497 | |
| 15884 | 498 | host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
| 499 | 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
|
500 | tmp = g_strdup_printf("%s:%d", host, port); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
501 | header = g_strdup_printf("POST %s%s/notifyft HTTP/1.1\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
502 | "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5)\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
503 | "Cookie: T=%s; Y=%s\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
504 | "Host: %s\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
505 | "Content-Length: %" G_GSIZE_FORMAT "\r\n" |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
506 | "Cache-Control: no-cache\r\n\r\n", |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
507 | use_whole_url ? "http://" : "", use_whole_url ? tmp : "", |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
508 | yd->cookie_t, yd->cookie_y, |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
509 | tmp, |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
510 | pkt_buf_len + 4 + d->str->len); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
511 | g_free(tmp); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
512 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
513 | /* 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
|
514 | g_string_prepend(d->str, "29\xc0\x80"); |
| 9306 | 515 | |
| 14321 | 516 | 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
|
517 | g_free(pkt_buf); |
| 9306 | 518 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
519 | g_string_prepend(d->str, header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
520 | g_free(header); |
| 9306 | 521 | |
|
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
|
522 | /* 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
|
523 | 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
|
524 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
525 | d->fd = source; |
| 15884 | 526 | 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
|
527 | |
| 15884 | 528 | yahoo_buddy_icon_upload_pending(d, d->fd, PURPLE_INPUT_WRITE); |
| 9306 | 529 | } |
| 530 | ||
| 15884 | 531 | void yahoo_buddy_icon_upload(PurpleConnection *gc, struct yahoo_buddy_icon_upload_data *d) |
| 9306 | 532 | { |
| 15884 | 533 | PurpleAccount *account = purple_connection_get_account(gc); |
| 9306 | 534 | struct yahoo_data *yd = gc->proto_data; |
| 535 | ||
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
536 | if (yd->buddy_icon_connect_data != NULL) { |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
537 | /* Cancel any in-progress buddy icon upload */ |
| 15884 | 538 | purple_proxy_connect_cancel(yd->buddy_icon_connect_data); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
539 | yd->buddy_icon_connect_data = NULL; |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
540 | } |
|
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
541 | |
| 15884 | 542 | yd->buddy_icon_connect_data = purple_proxy_connect(NULL, account, |
| 543 | yd->jp ? purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST) | |
| 544 | : purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), | |
| 545 | purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
546 | yahoo_buddy_icon_upload_connected, d); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
547 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
548 | if (yd->buddy_icon_connect_data == NULL) |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
549 | { |
| 15884 | 550 | 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
|
551 | yahoo_buddy_icon_upload_data_free(d); |
|
14693
9e3d4f9609e1
[gaim-migrate @ 17377]
Evan Schoenberg <evands@pidgin.im>
parents:
14686
diff
changeset
|
552 | } |
| 9306 | 553 | } |
| 554 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
555 | 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
|
556 | { |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
557 | /* 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
|
558 | 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
|
559 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
560 | const guchar *p = data; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
561 | int checksum = 0, g, i = len; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
562 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
563 | while(i--) { |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
564 | checksum = (checksum << 4) + *p++; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
565 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
566 | if((g = (checksum & 0xf0000000)) != 0) |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
567 | checksum ^= g >> 23; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
568 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
569 | checksum &= ~g; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
570 | } |
|
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 | purple_debug_misc("yahoo", "Calculated buddy icon checksum: %d", checksum); |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
573 | |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
574 | return checksum; |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
575 | } |
|
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
576 | |
|
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
|
577 | void yahoo_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
| 9306 | 578 | { |
| 579 | struct yahoo_data *yd = gc->proto_data; | |
| 15884 | 580 | PurpleAccount *account = gc->account; |
| 9306 | 581 | |
|
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
|
582 | if (img == NULL) { |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
583 | g_free(yd->picture_url); |
| 9306 | 584 | yd->picture_url = NULL; |
| 585 | ||
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
586 | /* 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
|
587 | |
| 15884 | 588 | purple_account_set_string(account, YAHOO_PICURL_SETTING, NULL); |
| 589 | purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 590 | purple_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 9310 | 591 | if (yd->logged_in) |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
592 | /* Tell everyone we ain't got one no more */ |
| 9310 | 593 | yahoo_send_picture_update(gc, 0); |
| 9306 | 594 | |
|
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
|
595 | } 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
|
596 | 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
|
597 | 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
|
598 | GString *s = g_string_new_len(data, len); |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
599 | struct yahoo_buddy_icon_upload_data *d; |
| 15884 | 600 | int oldcksum = purple_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); |
| 601 | int expire = purple_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 602 | 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
|
603 | |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
604 | yd->picture_checksum = yahoo_buddy_icon_calculate_checksum(data, len); |
| 9306 | 605 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
606 | if ((yd->picture_checksum == oldcksum) && |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
607 | (expire > (time(NULL) + 60*60*24)) && oldurl) |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
608 | { |
| 15884 | 609 | 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
|
610 | g_string_free(s, TRUE); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
611 | g_free(yd->picture_url); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
612 | yd->picture_url = g_strdup(oldurl); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
613 | return; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
614 | } |
| 9306 | 615 | |
|
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
|
616 | /* 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
|
617 | d = g_new0(struct yahoo_buddy_icon_upload_data, 1); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
618 | d->gc = gc; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
619 | d->str = s; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
620 | d->fd = -1; |
|
23170
456cbed76e54
applied changes from c7504bbbe35f5bef52032c0cdf6bc7182128a469
Daniel Atallah <datallah@pidgin.im>
parents:
23156
diff
changeset
|
621 | d->filename = g_strdup(purple_imgstore_get_filename(img)); |
| 9306 | 622 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
623 | if (!yd->logged_in) { |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
624 | yd->picture_upload_todo = d; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
625 | return; |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
626 | } |
| 9306 | 627 | |
|
15239
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
628 | yahoo_buddy_icon_upload(gc, d); |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
629 | |
|
f31e2c11334e
[gaim-migrate @ 17964]
Mark Doliner <markdoliner@pidgin.im>
parents:
15042
diff
changeset
|
630 | } |
|
15245
3abed8bd82fb
[gaim-migrate @ 17972]
Mark Doliner <markdoliner@pidgin.im>
parents:
15239
diff
changeset
|
631 | } |