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