Mercurial > pidgin
changeset 19285:2d6d936867bc
Take advantage of the fact that our buddy icon filenames are SHA-1 hashes to avoid recalculating them in the bonjour protocol. I noticed that it wasn't calculating the hash correctly anyway while doing this.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 16 Aug 2007 00:29:17 +0000 |
parents | f37b493630de |
children | bb460965c49c |
files | libpurple/protocols/bonjour/buddy.c libpurple/protocols/bonjour/mdns_common.c |
diffstat | 2 files changed, 20 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/buddy.c Wed Aug 15 22:26:29 2007 +0000 +++ b/libpurple/protocols/bonjour/buddy.c Thu Aug 16 00:29:17 2007 +0000 @@ -18,7 +18,6 @@ #include <stdlib.h> #include "internal.h" -#include "cipher.h" #include "buddy.h" #include "account.h" #include "blist.h" @@ -204,23 +203,21 @@ */ void bonjour_buddy_got_buddy_icon(BonjourBuddy *buddy, gconstpointer data, gsize len) { /* Recalculate the hash instead of using the current phsh to make sure it is accurate for the icon. */ - int i; - gchar *enc; - char *p, hash[41]; - unsigned char hashval[20]; + char *p, *hash; if (data == NULL || len == 0) return; - enc = purple_base64_encode(data, len); + /* Take advantage of the fact that we use a SHA-1 hash of the data as the filename. */ + hash = purple_util_get_image_filename(data, len); - purple_cipher_digest_region("sha1", data, - len, sizeof(hashval), - hashval, NULL); + /* Get rid of the extension */ + if (!(p = strchr(hash, '.'))) { + g_free(hash); + return; + } - p = hash; - for(i=0; i<20; i++, p+=2) - snprintf(p, 3, "%02x", hashval[i]); + *p = '\0'; purple_debug_info("bonjour", "Got buddy icon for %s icon hash='%s' phsh='%s'.\n", buddy->name, hash, buddy->phsh ? buddy->phsh : "(null)"); @@ -228,7 +225,7 @@ purple_buddy_icons_set_for_user(buddy->account, buddy->name, g_memdup(data, len), len, hash); - g_free(enc); + g_free(hash); } /**
--- a/libpurple/protocols/bonjour/mdns_common.c Wed Aug 15 22:26:29 2007 +0000 +++ b/libpurple/protocols/bonjour/mdns_common.c Thu Aug 16 00:29:17 2007 +0000 @@ -17,7 +17,6 @@ #include <string.h> #include "internal.h" -#include "cipher.h" #include "debug.h" #include "mdns_common.h" @@ -159,25 +158,19 @@ avatar_len = purple_imgstore_get_size(img); if (_mdns_set_buddy_icon_data(data, avatar_data, avatar_len)) { - int i; - gchar *enc; - char *p, hash[41]; - unsigned char hashval[20]; - - enc = purple_base64_encode(avatar_data, avatar_len); - - purple_cipher_digest_region("sha1", avatar_data, - avatar_len, sizeof(hashval), - hashval, NULL); - - p = hash; - for(i=0; i<20; i++, p+=2) - snprintf(p, 3, "%02x", hashval[i]); + /* The filename is a SHA-1 hash of the data (conveniently what we need) */ + const char *p, *filename = purple_imgstore_get_filename(img); g_free(data->phsh); - data->phsh = g_strdup(hash); + data->phsh = NULL; - g_free(enc); + /* Get rid of the extension */ + p = strchr(filename, '.'); + if (p) + data->phsh = g_strndup(filename, p - filename); + else + purple_debug_error("bonjour", "account buddy icon returned unexpected filename (%s)" + "; unable to extract hash. Clearing buddy icon\n", filename); /* Update our TXT record */ publish_presence(data, PUBLISH_UPDATE);