📄 yahoo_picture.c
字号:
/* * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#include "internal.h"#include "account.h"#include "accountopt.h"#include "blist.h"#include "debug.h"#include "prpl.h"#include "proxy.h"#include "util.h"#include "yahoo.h"#include "yahoo_packet.h"#include "yahoo_friend.h"#include "yahoo_picture.h"struct yahoo_fetch_picture_data { PurpleConnection *gc; char *who; int checksum;};static voidyahoo_fetch_picture_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *pic_data, size_t len, const gchar *error_message){ struct yahoo_fetch_picture_data *d; struct yahoo_data *yd; d = user_data; yd = d->gc->proto_data; yd->url_datas = g_slist_remove(yd->url_datas, url_data); if (error_message != NULL) { purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); } else if (len == 0) { purple_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); } else { char *checksum = g_strdup_printf("%i", d->checksum); purple_buddy_icons_set_for_user(purple_connection_get_account(d->gc), d->who, g_memdup(pic_data, len), len, checksum); g_free(checksum); } g_free(d->who); g_free(d);}void yahoo_process_picture(PurpleConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd; GSList *l = pkt->hash; char *who = NULL, *us = NULL; gboolean got_icon_info = FALSE, send_icon_info = FALSE; char *url = NULL; int checksum = 0; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 1: case 4: who = pair->value; break; case 5: us = pair->value; break; case 13: { int tmp; tmp = strtol(pair->value, NULL, 10); if (tmp == 1) { send_icon_info = TRUE; } else if (tmp == 2) { got_icon_info = TRUE; } break; } case 20: url = pair->value; break; case 192: checksum = strtol(pair->value, NULL, 10); break; } l = l->next; } /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ if (who && got_icon_info && url && !strncasecmp(url, "http://", 7)) { /* TODO: make this work p2p, try p2p before the url */ PurpleUtilFetchUrlData *url_data; struct yahoo_fetch_picture_data *data; PurpleBuddy *b = purple_find_buddy(gc->account, who); const char *locksum = NULL; /* FIXME: Cleanup this strtol() stuff if possible. */ if (b && (locksum = purple_buddy_icons_get_checksum_for_user(b)) != NULL && (checksum == strtol(locksum, NULL, 10))) return; data = g_new0(struct yahoo_fetch_picture_data, 1); data->gc = gc; data->who = g_strdup(who); data->checksum = checksum; url_data = purple_util_fetch_url(url, FALSE, "Mozilla/4.0 (compatible; MSIE 5.0)", FALSE, yahoo_fetch_picture_cb, data); if (url_data != NULL) { yd = gc->proto_data; yd->url_datas = g_slist_prepend(yd->url_datas, url_data); } else { g_free(data->who); g_free(data); } } else if (who && send_icon_info) { yahoo_send_picture_info(gc, who); }}void yahoo_process_picture_update(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l = pkt->hash; char *who = NULL; int icon = 0; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 4: who = pair->value; break; case 5: /* us */ break; /* NOTE: currently the server seems to only send 213; 206 was used * in older versions. Check whether it's still needed. */ case 206: case 213: icon = strtol(pair->value, NULL, 10); break; } l = l->next; } if (who) { if (icon == 2) yahoo_send_picture_request(gc, who); else if ((icon == 0) || (icon == 1)) { YahooFriend *f; purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); if ((f = yahoo_friend_find(gc, who))) yahoo_friend_set_buddy_icon_need_request(f, TRUE); purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); } }}void yahoo_process_picture_checksum(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l = pkt->hash; char *who = NULL; int checksum = 0; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 4: who = pair->value; break; case 5: /* us */ break; case 192: checksum = strtol(pair->value, NULL, 10); break; } l = l->next; } if (who) { PurpleBuddy *b = purple_find_buddy(gc->account, who); const char *locksum = NULL; /* FIXME: Cleanup this strtol() stuff if possible. */ if (b) { locksum = purple_buddy_icons_get_checksum_for_user(b); if (!locksum || (checksum != strtol(locksum, NULL, 10))) yahoo_send_picture_request(gc, who); } }}void yahoo_process_picture_upload(PurpleConnection *gc, struct yahoo_packet *pkt){ PurpleAccount *account = purple_connection_get_account(gc); struct yahoo_data *yd = gc->proto_data; GSList *l = pkt->hash; char *url = NULL; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 5: /* us */ break; case 27: /* filename on our computer. */ break; case 20: /* url at yahoo */ url = pair->value; case 38: /* timestamp */ break; } l = l->next; } if (url) { if (yd->picture_url) g_free(yd->picture_url); yd->picture_url = g_strdup(url); purple_account_set_string(account, YAHOO_PICURL_SETTING, url); purple_account_set_int(account, YAHOO_PICCKSUM_SETTING, yd->picture_checksum); yahoo_send_picture_update(gc, 2); yahoo_send_picture_checksum(gc); }}void yahoo_process_avatar_update(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l = pkt->hash; char *who = NULL; int avatar = 0; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 4: who = pair->value; break; case 5: /* us */ break; case 206: /* * 0 - No icon or avatar * 1 - Using an avatar * 2 - Using an icon */ avatar = strtol(pair->value, NULL, 10); break; } l = l->next; } if (who) { if (avatar == 2) yahoo_send_picture_request(gc, who); else if ((avatar == 0) || (avatar == 1)) { YahooFriend *f; purple_buddy_icons_set_for_user(gc->account, who, NULL, 0, NULL); if ((f = yahoo_friend_find(gc, who))) yahoo_friend_set_buddy_icon_need_request(f, TRUE); purple_debug_misc("yahoo", "Setting user %s's icon to NULL.\n", who); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -