Sat, 12 Aug 2006 10:12:43 +0000
[gaim-migrate @ 16712]
Pretty large commit here. Basically I got sick of having to verify
that gc is still valid on all the callback functions for
gaim_proxy_connect(). The fix for this for gaim_proxy_connect() to
return something that allows the connection attempt to be canceled.
It's not quite there yet, but this is a good first step. I changed
gaim_proxy_connect() to return a reference to a new
GaimProxyConnectInfo (this used to be called PHB). Eventually this
can be passed to a function that'll cancel the connection attempt.
I also decided to add an error_cb instead of using connect_cb and
passing a file descriptor of -1. And proxy.c will also pass an
error message to callers which should explain the reason that the
connection attempt failed.
Oh, and proxy.c now never calls gaim_connection_error()
| 9306 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | */ | |
| 23 | ||
| 24 | #include "internal.h" | |
| 25 | ||
| 26 | #include "account.h" | |
| 27 | #include "accountopt.h" | |
| 28 | #include "blist.h" | |
| 29 | #include "debug.h" | |
| 30 | #include "prpl.h" | |
| 31 | #include "proxy.h" | |
| 32 | #include "util.h" | |
| 33 | ||
| 34 | #include "yahoo.h" | |
| 10392 | 35 | #include "yahoo_packet.h" |
| 9306 | 36 | #include "yahoo_friend.h" |
| 37 | #include "yahoo_picture.h" | |
| 38 | ||
| 39 | ||
| 40 | struct yahoo_fetch_picture_data { | |
| 41 | GaimConnection *gc; | |
| 42 | char *who; | |
| 43 | int checksum; | |
| 44 | }; | |
| 45 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
11644
diff
changeset
|
46 | static void yahoo_fetch_picture_cb(void *user_data, const char *pic_data, size_t len) |
| 9306 | 47 | { |
| 48 | struct yahoo_fetch_picture_data *d = user_data; | |
| 49 | GaimBuddy *b; | |
| 50 | ||
| 51 | if (GAIM_CONNECTION_IS_VALID(d->gc) && len) { | |
| 52 | gaim_buddy_icons_set_for_user(gaim_connection_get_account(d->gc), d->who, (void *)pic_data, len); | |
| 53 | b = gaim_find_buddy(gaim_connection_get_account(d->gc), d->who); | |
| 54 | if (b) | |
| 55 | gaim_blist_node_set_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY, d->checksum); | |
| 56 | } else { | |
| 57 | gaim_debug_error("yahoo", "Fetching buddy icon failed.\n"); | |
| 58 | } | |
| 59 | ||
| 60 | g_free(d->who); | |
| 61 | g_free(d); | |
| 62 | } | |
| 63 | ||
| 64 | void yahoo_process_picture(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 65 | { | |
| 66 | GSList *l = pkt->hash; | |
| 67 | char *who = NULL, *us = NULL; | |
| 68 | gboolean got_icon_info = FALSE, send_icon_info = FALSE; | |
| 69 | char *url = NULL; | |
| 70 | int checksum = 0; | |
| 71 | ||
| 72 | while (l) { | |
| 73 | struct yahoo_pair *pair = l->data; | |
| 74 | ||
| 75 | switch (pair->key) { | |
| 76 | case 1: | |
| 77 | case 4: | |
| 78 | who = pair->value; | |
| 79 | break; | |
| 80 | case 5: | |
| 81 | us = pair->value; | |
| 82 | break; | |
| 83 | case 13: { | |
| 84 | int tmp; | |
| 85 | tmp = strtol(pair->value, NULL, 10); | |
| 86 | if (tmp == 1) { | |
| 87 | send_icon_info = TRUE; | |
| 88 | } else if (tmp == 2) { | |
| 89 | got_icon_info = TRUE; | |
| 90 | } | |
| 91 | break; | |
| 92 | } | |
| 93 | case 20: | |
| 94 | url = pair->value; | |
| 95 | break; | |
| 96 | case 192: | |
| 97 | checksum = strtol(pair->value, NULL, 10); | |
| 98 | break; | |
| 99 | } | |
| 100 | ||
| 101 | l = l->next; | |
| 102 | } | |
| 103 | ||
|
9675
127db3bbb4f2
[gaim-migrate @ 10527]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9329
diff
changeset
|
104 | /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ |
|
127db3bbb4f2
[gaim-migrate @ 10527]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9329
diff
changeset
|
105 | if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { |
| 9306 | 106 | /* TODO: make this work p2p, try p2p before the url */ |
| 107 | struct yahoo_fetch_picture_data *data; | |
| 108 | GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
| 109 | if (b && (checksum == gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
| 110 | return; | |
| 111 | ||
| 112 | data = g_new0(struct yahoo_fetch_picture_data, 1); | |
| 113 | data->gc = gc; | |
| 114 | data->who = g_strdup(who); | |
| 115 | data->checksum = checksum; | |
| 10651 | 116 | gaim_url_fetch(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, |
| 9306 | 117 | yahoo_fetch_picture_cb, data); |
| 118 | } else if (who && send_icon_info) { | |
| 119 | yahoo_send_picture_info(gc, who); | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | void yahoo_process_picture_update(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 124 | { | |
| 125 | GSList *l = pkt->hash; | |
| 126 | char *who = NULL; | |
| 127 | int icon = 0; | |
| 128 | ||
| 129 | while (l) { | |
| 130 | struct yahoo_pair *pair = l->data; | |
| 131 | ||
| 132 | switch (pair->key) { | |
| 133 | case 4: | |
| 134 | who = pair->value; | |
| 135 | break; | |
| 136 | case 5: | |
| 137 | /* us */ | |
| 138 | break; | |
| 139 | case 206: | |
| 140 | icon = strtol(pair->value, NULL, 10); | |
| 141 | break; | |
| 142 | } | |
| 143 | l = l->next; | |
| 144 | } | |
| 145 | ||
| 146 | if (who) { | |
| 147 | if (icon == 2) | |
| 9310 | 148 | yahoo_send_picture_request(gc, who); |
| 9322 | 149 | else if ((icon == 0) || (icon == 1)) { |
| 9325 | 150 | GaimBuddy *b = gaim_find_buddy(gc->account, who); |
| 151 | YahooFriend *f; | |
| 9306 | 152 | gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
| 9325 | 153 | if (b) |
| 154 | gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); | |
| 155 | if ((f = yahoo_friend_find(gc, who))) | |
| 156 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); | |
| 9322 | 157 | gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
| 158 | } | |
| 9306 | 159 | } |
| 160 | } | |
| 161 | ||
| 162 | void yahoo_process_picture_checksum(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 163 | { | |
| 164 | GSList *l = pkt->hash; | |
| 165 | char *who = NULL; | |
| 166 | int checksum = 0; | |
| 167 | ||
| 168 | while (l) { | |
| 169 | struct yahoo_pair *pair = l->data; | |
| 170 | ||
| 171 | switch (pair->key) { | |
| 172 | case 4: | |
| 173 | who = pair->value; | |
| 174 | break; | |
| 175 | case 5: | |
| 176 | /* us */ | |
| 177 | break; | |
| 178 | case 192: | |
| 179 | checksum = strtol(pair->value, NULL, 10); | |
| 180 | break; | |
| 181 | } | |
| 182 | l = l->next; | |
| 183 | } | |
| 184 | ||
| 185 | if (who) { | |
| 186 | GaimBuddy *b = gaim_find_buddy(gc->account, who); | |
| 187 | if (b && (checksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))) | |
| 9310 | 188 | yahoo_send_picture_request(gc, who); |
| 9306 | 189 | } |
| 190 | } | |
| 191 | ||
| 192 | void yahoo_process_picture_upload(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 193 | { | |
| 194 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 195 | struct yahoo_data *yd = gc->proto_data; | |
| 196 | GSList *l = pkt->hash; | |
| 197 | char *url = NULL; | |
| 198 | ||
| 199 | while (l) { | |
| 200 | struct yahoo_pair *pair = l->data; | |
| 201 | ||
| 202 | switch (pair->key) { | |
| 203 | case 5: | |
| 204 | /* us */ | |
| 205 | break; | |
| 206 | case 27: | |
| 207 | /* filename on our computer. */ | |
| 208 | break; | |
| 209 | case 20: /* url at yahoo */ | |
| 210 | url = pair->value; | |
| 211 | case 38: /* timestamp */ | |
| 212 | break; | |
| 213 | } | |
| 214 | l = l->next; | |
| 215 | } | |
| 216 | ||
| 217 | if (url) { | |
| 218 | if (yd->picture_url) | |
| 219 | g_free(yd->picture_url); | |
| 220 | yd->picture_url = g_strdup(url); | |
| 221 | gaim_account_set_string(account, YAHOO_PICURL_SETTING, url); | |
| 222 | gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); | |
| 9310 | 223 | yahoo_send_picture_update(gc, 2); |
| 224 | yahoo_send_picture_checksum(gc); | |
| 9306 | 225 | } |
| 226 | } | |
| 227 | ||
|
14030
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
228 | void yahoo_process_avatar_update(GaimConnection *gc, struct yahoo_packet *pkt) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
229 | { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
230 | GSList *l = pkt->hash; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
231 | char *who = NULL; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
232 | int avatar = 0; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
233 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
234 | while (l) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
235 | struct yahoo_pair *pair = l->data; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
236 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
237 | switch (pair->key) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
238 | case 4: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
239 | who = pair->value; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
240 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
241 | case 5: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
242 | /* us */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
243 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
244 | case 206: |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
245 | /* |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
246 | * 0 - No icon or avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
247 | * 1 - Using an avatar |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
248 | * 2 - Using an icon |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
249 | */ |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
250 | avatar = strtol(pair->value, NULL, 10); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
251 | break; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
252 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
253 | l = l->next; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
254 | } |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
255 | |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
256 | if (who) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
257 | if (avatar == 2) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
258 | yahoo_send_picture_request(gc, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
259 | else if ((avatar == 0) || (avatar == 1)) { |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
260 | GaimBuddy *b = gaim_find_buddy(gc->account, who); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
261 | YahooFriend *f; |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
262 | gaim_buddy_icons_set_for_user(gc->account, who, NULL, 0); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
263 | if (b) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
264 | gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
265 | if ((f = yahoo_friend_find(gc, who))) |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
266 | yahoo_friend_set_buddy_icon_need_request(f, TRUE); |
|
23144f1dc950
[gaim-migrate @ 16525]
Mark Doliner <markdoliner@pidgin.im>
parents:
13277
diff
changeset
|
267 | gaim_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); |
|
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 | } |
|
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 | |
| 9322 | 272 | void yahoo_send_picture_info(GaimConnection *gc, const char *who) |
| 273 | { | |
| 274 | struct yahoo_data *yd = gc->proto_data; | |
| 275 | struct yahoo_packet *pkt; | |
| 276 | ||
| 9329 | 277 | if (!yd->picture_url) { |
| 278 | gaim_debug_warning("yahoo", "Attempted to send picture info without a picture\n"); | |
| 9322 | 279 | return; |
| 9329 | 280 | } |
| 9322 | 281 | |
| 282 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 10394 | 283 | yahoo_packet_hash(pkt, "sssssi", 1, gaim_connection_get_display_name(gc), |
| 284 | 4, gaim_connection_get_display_name(gc), 5, who, | |
| 285 | 13, "2", 20, yd->picture_url, 192, yd->picture_checksum); | |
| 10392 | 286 | yahoo_packet_send_and_free(pkt, yd); |
| 9322 | 287 | } |
| 9306 | 288 | |
| 9310 | 289 | void yahoo_send_picture_request(GaimConnection *gc, const char *who) |
| 9306 | 290 | { |
| 291 | struct yahoo_data *yd = gc->proto_data; | |
| 292 | struct yahoo_packet *pkt; | |
| 293 | ||
| 294 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YAHOO_STATUS_AVAILABLE, 0); | |
| 10394 | 295 | yahoo_packet_hash_str(pkt, 4, gaim_connection_get_display_name(gc)); /* me */ |
| 296 | yahoo_packet_hash_str(pkt, 5, who); /* the other guy */ | |
| 297 | yahoo_packet_hash_str(pkt, 13, "1"); /* 1 = request, 2 = reply */ | |
| 10392 | 298 | yahoo_packet_send_and_free(pkt, yd); |
| 9306 | 299 | } |
| 300 | ||
| 9310 | 301 | void yahoo_send_picture_checksum(GaimConnection *gc) |
| 302 | { | |
| 303 | struct yahoo_data *yd = gc->proto_data; | |
| 304 | struct yahoo_packet *pkt; | |
| 305 | ||
| 306 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, YAHOO_STATUS_AVAILABLE, 0); | |
|
11384
aa52418a603f
[gaim-migrate @ 13611]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
10651
diff
changeset
|
307 | yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), |
| 10394 | 308 | 212, "1", 192, yd->picture_checksum); |
| 10392 | 309 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 310 | } |
| 311 | ||
| 312 | void yahoo_send_picture_update_to_user(GaimConnection *gc, const char *who, int type) | |
| 313 | { | |
| 314 | struct yahoo_data *yd = gc->proto_data; | |
| 315 | struct yahoo_packet *pkt; | |
| 316 | ||
| 317 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | |
|
11384
aa52418a603f
[gaim-migrate @ 13611]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
10651
diff
changeset
|
318 | yahoo_packet_hash(pkt, "ssi", 1, gaim_connection_get_display_name(gc), 5, who, 206, type); |
| 10392 | 319 | yahoo_packet_send_and_free(pkt, yd); |
| 9310 | 320 | } |
| 321 | ||
| 322 | struct yspufe { | |
| 323 | GaimConnection *gc; | |
| 324 | int type; | |
| 325 | }; | |
| 326 | ||
| 327 | static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) | |
| 328 | { | |
| 329 | char *who = key; | |
| 330 | YahooFriend *f = value; | |
| 331 | struct yspufe *d = data; | |
| 332 | ||
| 333 | if (f->status != YAHOO_STATUS_OFFLINE) | |
| 334 | yahoo_send_picture_update_to_user(d->gc, who, d->type); | |
| 335 | } | |
| 336 | ||
| 337 | void yahoo_send_picture_update(GaimConnection *gc, int type) | |
| 338 | { | |
| 339 | struct yahoo_data *yd = gc->proto_data; | |
| 340 | struct yspufe data; | |
| 341 | ||
| 342 | data.gc = gc; | |
| 343 | data.type = type; | |
| 344 | ||
| 345 | g_hash_table_foreach(yd->friends, yahoo_send_picture_update_foreach, &data); | |
| 346 | } | |
| 347 | ||
| 9306 | 348 | void yahoo_buddy_icon_upload_data_free(struct yahoo_buddy_icon_upload_data *d) |
| 349 | { | |
| 350 | gaim_debug_misc("yahoo", "In yahoo_buddy_icon_upload_data_free()\n"); | |
| 351 | ||
| 352 | if (d->str) | |
| 353 | g_string_free(d->str, TRUE); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
354 | g_free(d->filename); |
| 9306 | 355 | if (d->watcher) |
| 356 | gaim_input_remove(d->watcher); | |
| 357 | if (d->fd != -1) | |
| 358 | close(d->fd); | |
| 359 | g_free(d); | |
| 360 | } | |
| 361 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
362 | /* we couldn't care less about the server's response, but yahoo gets grumpy if we close before it sends it */ |
| 9306 | 363 | static void yahoo_buddy_icon_upload_reading(gpointer data, gint source, GaimInputCondition condition) |
| 364 | { | |
| 365 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 366 | GaimConnection *gc = d->gc; | |
| 367 | char buf[1024]; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
368 | int ret; |
| 9306 | 369 | |
| 370 | if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
| 371 | yahoo_buddy_icon_upload_data_free(d); | |
| 372 | return; | |
| 373 | } | |
| 374 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
375 | ret = read(d->fd, buf, sizeof(buf)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
376 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
377 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
378 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
379 | else if (ret <= 0) |
| 9306 | 380 | yahoo_buddy_icon_upload_data_free(d); |
| 381 | } | |
| 382 | ||
| 383 | static void yahoo_buddy_icon_upload_pending(gpointer data, gint source, GaimInputCondition condition) | |
| 384 | { | |
| 385 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 386 | GaimConnection *gc = d->gc; | |
| 387 | ssize_t wrote; | |
| 388 | ||
| 389 | if (!GAIM_CONNECTION_IS_VALID(gc)) { | |
| 390 | yahoo_buddy_icon_upload_data_free(d); | |
| 391 | return; | |
| 392 | } | |
| 393 | ||
| 394 | 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
|
395 | if (wrote < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
396 | return; |
| 9306 | 397 | if (wrote <= 0) { |
| 398 | yahoo_buddy_icon_upload_data_free(d); | |
| 399 | return; | |
| 400 | } | |
| 401 | d->pos += wrote; | |
| 402 | if (d->pos >= d->str->len) { | |
| 403 | gaim_debug_misc("yahoo", "Finished uploading buddy icon.\n"); | |
| 404 | gaim_input_remove(d->watcher); | |
| 405 | d->watcher = gaim_input_add(d->fd, GAIM_INPUT_READ, yahoo_buddy_icon_upload_reading, d); | |
| 406 | } | |
| 407 | } | |
| 408 | ||
|
14151
34427f138b1f
[gaim-migrate @ 16712]
Mark Doliner <markdoliner@pidgin.im>
parents:
14030
diff
changeset
|
409 | static void yahoo_buddy_icon_upload_connected(gpointer data, gint source) |
| 9306 | 410 | { |
| 411 | struct yahoo_buddy_icon_upload_data *d = data; | |
| 412 | struct yahoo_packet *pkt; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
413 | gchar *size, *header; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
414 | guchar *pkt_buf; |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
415 | const char *host; |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
416 | int port; |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13272
diff
changeset
|
417 | size_t content_length, pkt_buf_len; |
| 9306 | 418 | GaimConnection *gc; |
| 419 | GaimAccount *account; | |
| 420 | struct yahoo_data *yd; | |
| 421 | ||
| 422 | if (!d) | |
| 423 | return; | |
| 424 | ||
| 425 | gc = d->gc; | |
| 426 | account = gaim_connection_get_account(gc); | |
| 427 | yd = gc->proto_data; | |
| 428 | ||
| 429 | if (source < 0) { | |
| 430 | gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n"); | |
| 431 | yahoo_buddy_icon_upload_data_free(d); | |
| 432 | return; | |
| 433 | } | |
| 434 | ||
| 435 | ||
| 436 | pkt = yahoo_packet_new(0xc2, YAHOO_STATUS_AVAILABLE, yd->session_id); | |
| 437 | ||
| 10111 | 438 | size = g_strdup_printf("%" G_GSIZE_FORMAT, d->str->len); |
| 9306 | 439 | /* 1 = me, 38 = expire time(?), 0 = me, 28 = size, 27 = filename, 14 = NULL, 29 = data */ |
| 10394 | 440 | yahoo_packet_hash_str(pkt, 1, gaim_connection_get_display_name(gc)); |
| 441 | yahoo_packet_hash_str(pkt, 38, "604800"); /* time til expire */ | |
| 9306 | 442 | gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, time(NULL) + 604800); |
| 10394 | 443 | yahoo_packet_hash_str(pkt, 0, gaim_connection_get_display_name(gc)); |
| 444 | yahoo_packet_hash_str(pkt, 28, size); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
445 | g_free(size); |
| 10394 | 446 | yahoo_packet_hash_str(pkt, 27, d->filename); |
| 447 | yahoo_packet_hash_str(pkt, 14, ""); | |
| 9306 | 448 | |
| 449 | content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | |
| 450 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
451 | host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
452 | port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
453 | header = g_strdup_printf( |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
454 | "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
455 | "Content-length: %" G_GSIZE_FORMAT "\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
456 | "Host: %s:%d\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
457 | "Cookie: Y=%s; T=%s\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
458 | "\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
459 | host, port, content_length + 4 + d->str->len, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
460 | host, port, yd->cookie_y, yd->cookie_t); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
461 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
462 | /* 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
|
463 | g_string_prepend(d->str, "29\xc0\x80"); |
| 9306 | 464 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
465 | pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf); |
| 9306 | 466 | yahoo_packet_free(pkt); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
467 | g_string_prepend_len(d->str, pkt_buf, pkt_buf_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
468 | g_free(pkt_buf); |
| 9306 | 469 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
470 | g_string_prepend(d->str, header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
471 | g_free(header); |
| 9306 | 472 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
473 | d->fd = source; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
474 | d->watcher = gaim_input_add(d->fd, GAIM_INPUT_WRITE, yahoo_buddy_icon_upload_pending, d); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
475 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12412
diff
changeset
|
476 | yahoo_buddy_icon_upload_pending(d, d->fd, GAIM_INPUT_WRITE); |
| 9306 | 477 | } |
| 478 | ||
| 479 | void yahoo_buddy_icon_upload(GaimConnection *gc, struct yahoo_buddy_icon_upload_data *d) | |
| 480 | { | |
| 481 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 482 | struct yahoo_data *yd = gc->proto_data; | |
| 483 | ||
| 484 | if (yd->jp) { | |
| 485 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), | |
| 486 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
14151
34427f138b1f
[gaim-migrate @ 16712]
Mark Doliner <markdoliner@pidgin.im>
parents:
14030
diff
changeset
|
487 | yahoo_buddy_icon_upload_connected, NULL, d) == NULL) |
| 9306 | 488 | { |
| 489 | gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
| 490 | yahoo_buddy_icon_upload_data_free(d); | |
| 491 | } | |
| 492 | } else { | |
| 493 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), | |
| 494 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), | |
|
14151
34427f138b1f
[gaim-migrate @ 16712]
Mark Doliner <markdoliner@pidgin.im>
parents:
14030
diff
changeset
|
495 | yahoo_buddy_icon_upload_connected, NULL, d) == NULL) |
| 9306 | 496 | { |
| 497 | gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); | |
| 498 | yahoo_buddy_icon_upload_data_free(d); | |
| 499 | } | |
| 500 | } | |
| 501 | } | |
| 502 | ||
| 503 | void yahoo_set_buddy_icon(GaimConnection *gc, const char *iconfile) | |
| 504 | { | |
| 505 | struct yahoo_data *yd = gc->proto_data; | |
| 506 | GaimAccount *account = gc->account; | |
| 507 | FILE *file; | |
| 508 | struct stat st; | |
| 509 | ||
| 510 | if (iconfile == NULL) { | |
| 511 | if (yd->picture_url) | |
| 512 | g_free(yd->picture_url); | |
| 513 | yd->picture_url = NULL; | |
| 514 | ||
| 515 | gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); | |
| 516 | gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 517 | gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 9310 | 518 | if (yd->logged_in) |
| 519 | yahoo_send_picture_update(gc, 0); | |
| 9306 | 520 | /* TODO: check if we're connected and tell everyone we ain't not one no more */ |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10576
diff
changeset
|
521 | } else if (!g_stat(iconfile, &st)) { |
|
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10576
diff
changeset
|
522 | file = g_fopen(iconfile, "rb"); |
| 9306 | 523 | if (file) { |
| 524 | GString *s = g_string_sized_new(st.st_size); | |
| 525 | size_t len; | |
| 526 | struct yahoo_buddy_icon_upload_data *d; | |
| 527 | int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); | |
| 528 | int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); | |
| 529 | const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); | |
| 530 | ||
| 531 | g_string_set_size(s, st.st_size); | |
| 532 | len = fread(s->str, 1, st.st_size, file); | |
| 533 | fclose(file); | |
| 534 | g_string_set_size(s, len); | |
| 535 | yd->picture_checksum = g_string_hash(s); | |
| 536 | ||
| 537 | if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) && | |
| 538 | oldcksum && expire && oldurl) { | |
| 539 | gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); | |
| 540 | g_string_free(s, TRUE); | |
| 541 | if (yd->picture_url) | |
| 542 | g_free(yd->picture_url); | |
| 543 | yd->picture_url = g_strdup(oldurl); | |
| 544 | return; | |
| 545 | } | |
| 546 | ||
| 547 | d = g_new0(struct yahoo_buddy_icon_upload_data, 1); | |
| 548 | d->gc = gc; | |
| 549 | d->str = s; | |
| 550 | d->fd = -1; | |
| 551 | d->filename = g_strdup(iconfile); | |
| 552 | ||
| 553 | if (!yd->logged_in) { | |
| 554 | yd->picture_upload_todo = d; | |
| 555 | return; | |
| 556 | } | |
| 557 | ||
| 558 | yahoo_buddy_icon_upload(gc, d); | |
| 559 | } else | |
| 560 | gaim_debug_error("yahoo", | |
| 561 | "Can't open buddy icon file!\n"); | |
| 562 | } else | |
|
9779
ddbddc8d6081
[gaim-migrate @ 10647]
Peter Lawler <pidgin@bleeter.id.au>
parents:
9675
diff
changeset
|
563 | gaim_debug_error("yahoo", |
| 9306 | 564 | "Can't stat buddy icon file!\n"); |
| 565 | } |