diff libpurple/protocols/bonjour/buddy.c @ 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 f773aa054dca
children affacee881e8
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);
 }
 
 /**