comparison libpurple/protocols/jabber/presence.c @ 16386:e0c9a46b459f

Move the prpl icon checksum code into the core, so we can delete the checksum if the cache file disappears. See ticket #223
author Richard Laager <rlaager@wiktel.com>
date Wed, 25 Apr 2007 00:56:13 +0000
parents 84bf0f949b0b
children 24bbd7e46bfe
comparison
equal deleted inserted replaced
16385:a0df0eb75e1b 16386:e0c9a46b459f
199 } 199 }
200 200
201 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) 201 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah)
202 { 202 {
203 JabberBuddy *jb = NULL; 203 JabberBuddy *jb = NULL;
204 PurpleBuddy *b = NULL;
205 xmlnode *vcard, *photo, *binval; 204 xmlnode *vcard, *photo, *binval;
206 char *text; 205 char *text;
207 guchar *data; 206 guchar *data;
208 gsize size; 207 gsize size;
209 const char *from = xmlnode_get_attrib(packet, "from"); 208 const char *from = xmlnode_get_attrib(packet, "from");
219 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { 218 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
220 if((photo = xmlnode_get_child(vcard, "PHOTO")) && 219 if((photo = xmlnode_get_child(vcard, "PHOTO")) &&
221 (( (binval = xmlnode_get_child(photo, "BINVAL")) && 220 (( (binval = xmlnode_get_child(photo, "BINVAL")) &&
222 (text = xmlnode_get_data(binval))) || 221 (text = xmlnode_get_data(binval))) ||
223 (text = xmlnode_get_data(photo)))) { 222 (text = xmlnode_get_data(photo)))) {
223 unsigned char hashval[20];
224 char hash[41], *p;
225 int i;
226
224 data = purple_base64_decode(text, &size); 227 data = purple_base64_decode(text, &size);
225 228
226 purple_buddy_icons_set_for_user(js->gc->account, from, data, size); 229 purple_cipher_digest_region("sha1", data, size,
227 if((b = purple_find_buddy(js->gc->account, from))) { 230 sizeof(hashval), hashval, NULL);
228 unsigned char hashval[20]; 231 p = hash;
229 char hash[41], *p; 232 for(i=0; i<20; i++, p+=2)
230 int i; 233 snprintf(p, 3, "%02x", hashval[i]);
231 234
232 purple_cipher_digest_region("sha1", data, size, 235 purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash);
233 sizeof(hashval), hashval, NULL); 236
234 p = hash;
235 for(i=0; i<20; i++, p+=2)
236 snprintf(p, 3, "%02x", hashval[i]);
237 purple_blist_node_set_string((PurpleBlistNode*)b, "avatar_hash", hash);
238 }
239 g_free(data); 237 g_free(data);
240 g_free(text); 238 g_free(text);
241 } 239 }
242 } 240 }
243 } 241 }
518 g_free(status); 516 g_free(status);
519 return; 517 return;
520 } 518 }
521 519
522 if(avatar_hash) { 520 if(avatar_hash) {
523 const char *avatar_hash2 = purple_blist_node_get_string((PurpleBlistNode*)b, "avatar_hash"); 521 const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b);
524 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { 522 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) {
525 JabberIq *iq; 523 JabberIq *iq;
526 xmlnode *vcard; 524 xmlnode *vcard;
527 525
528 /* XXX this is a crappy way of trying to prevent 526 /* XXX this is a crappy way of trying to prevent