Mercurial > pidgin
comparison 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 |
comparison
equal
deleted
inserted
replaced
19284:f37b493630de | 19285:2d6d936867bc |
---|---|
16 | 16 |
17 #include <glib.h> | 17 #include <glib.h> |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 | 19 |
20 #include "internal.h" | 20 #include "internal.h" |
21 #include "cipher.h" | |
22 #include "buddy.h" | 21 #include "buddy.h" |
23 #include "account.h" | 22 #include "account.h" |
24 #include "blist.h" | 23 #include "blist.h" |
25 #include "bonjour.h" | 24 #include "bonjour.h" |
26 #include "mdns_interface.h" | 25 #include "mdns_interface.h" |
202 /** | 201 /** |
203 * We got the buddy icon data; deal with it | 202 * We got the buddy icon data; deal with it |
204 */ | 203 */ |
205 void bonjour_buddy_got_buddy_icon(BonjourBuddy *buddy, gconstpointer data, gsize len) { | 204 void bonjour_buddy_got_buddy_icon(BonjourBuddy *buddy, gconstpointer data, gsize len) { |
206 /* Recalculate the hash instead of using the current phsh to make sure it is accurate for the icon. */ | 205 /* Recalculate the hash instead of using the current phsh to make sure it is accurate for the icon. */ |
207 int i; | 206 char *p, *hash; |
208 gchar *enc; | |
209 char *p, hash[41]; | |
210 unsigned char hashval[20]; | |
211 | 207 |
212 if (data == NULL || len == 0) | 208 if (data == NULL || len == 0) |
213 return; | 209 return; |
214 | 210 |
215 enc = purple_base64_encode(data, len); | 211 /* Take advantage of the fact that we use a SHA-1 hash of the data as the filename. */ |
216 | 212 hash = purple_util_get_image_filename(data, len); |
217 purple_cipher_digest_region("sha1", data, | 213 |
218 len, sizeof(hashval), | 214 /* Get rid of the extension */ |
219 hashval, NULL); | 215 if (!(p = strchr(hash, '.'))) { |
220 | 216 g_free(hash); |
221 p = hash; | 217 return; |
222 for(i=0; i<20; i++, p+=2) | 218 } |
223 snprintf(p, 3, "%02x", hashval[i]); | 219 |
220 *p = '\0'; | |
224 | 221 |
225 purple_debug_info("bonjour", "Got buddy icon for %s icon hash='%s' phsh='%s'.\n", buddy->name, | 222 purple_debug_info("bonjour", "Got buddy icon for %s icon hash='%s' phsh='%s'.\n", buddy->name, |
226 hash, buddy->phsh ? buddy->phsh : "(null)"); | 223 hash, buddy->phsh ? buddy->phsh : "(null)"); |
227 | 224 |
228 purple_buddy_icons_set_for_user(buddy->account, buddy->name, | 225 purple_buddy_icons_set_for_user(buddy->account, buddy->name, |
229 g_memdup(data, len), len, hash); | 226 g_memdup(data, len), len, hash); |
230 | 227 |
231 g_free(enc); | 228 g_free(hash); |
232 } | 229 } |
233 | 230 |
234 /** | 231 /** |
235 * Deletes a buddy from memory. | 232 * Deletes a buddy from memory. |
236 */ | 233 */ |