comparison libpurple/protocols/jabber/presence.c @ 31526:b2f6fec7b98e

jabber: Correctly handle the unsetting case for a contact's vCard avatar. Patch from Matthew (mentor) W.S. Bell. Closes #13370 committer: Paul Aurich <paul@darkrain42.org>
author matthew@bells23.org.uk
date Tue, 03 May 2011 05:02:00 +0000
parents 58d9bcd75866
children c832d481d021
comparison
equal deleted inserted replaced
31525:db082e0421f6 31526:b2f6fec7b98e
448 if (nickname) { 448 if (nickname) {
449 serv_got_alias(js->gc, from, nickname); 449 serv_got_alias(js->gc, from, nickname);
450 g_free(nickname); 450 g_free(nickname);
451 } 451 }
452 452
453 if ((photo = xmlnode_get_child(vcard, "PHOTO")) && 453 if ((photo = xmlnode_get_child(vcard, "PHOTO"))) {
454 (binval = xmlnode_get_child(photo, "BINVAL")) && 454 guchar *data = NULL;
455 (text = xmlnode_get_data(binval))) { 455 gchar *hash = NULL;
456 guchar *data; 456 gsize size = 0;
457 gsize size; 457
458 458 if ((binval = xmlnode_get_child(photo, "BINVAL")) &&
459 data = purple_base64_decode(text, &size); 459 (text = xmlnode_get_data(binval))) {
460 if (data) { 460 data = purple_base64_decode(text, &size);
461 gchar *hash = jabber_calculate_data_hash(data, size, "sha1"); 461 g_free(text);
462 purple_buddy_icons_set_for_user(js->gc->account, from, data, 462
463 size, hash); 463 if (data)
464 g_free(hash); 464 hash = jabber_calculate_data_hash(data, size, "sha1");
465 } 465 }
466 466
467 g_free(text); 467 purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash);
468
469 g_free(hash);
468 } 470 }
469 } 471 }
470 } 472 }
471 473
472 typedef struct _JabberPresenceCapabilities { 474 typedef struct _JabberPresenceCapabilities {
838 } else { 840 } else {
839 /* this is a different resource of our own account. Resume even when this account isn't on our blist */ 841 /* this is a different resource of our own account. Resume even when this account isn't on our blist */
840 } 842 }
841 } 843 }
842 844
843 if(b && presence->vcard_avatar_hash) { 845 if (b && presence->vcard_avatar_hash) {
844 const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b); 846 const char *ah = presence->vcard_avatar_hash[0] != '\0' ?
845 if(!avatar_hash2 || strcmp(presence->vcard_avatar_hash, avatar_hash2)) { 847 presence->vcard_avatar_hash : NULL;
846 JabberIq *iq; 848 const char *ah2 = purple_buddy_icons_get_checksum_for_user(b);
847 xmlnode *vcard; 849 if (!purple_strequal(ah, ah2)) {
848
849 /* XXX this is a crappy way of trying to prevent 850 /* XXX this is a crappy way of trying to prevent
850 * someone from spamming us with presence packets 851 * someone from spamming us with presence packets
851 * and causing us to DoS ourselves...what we really 852 * and causing us to DoS ourselves...what we really
852 * need is a queue system that can throttle itself, 853 * need is a queue system that can throttle itself,
853 * but i'm too tired to write that right now */ 854 * but i'm too tired to write that right now */
854 if(!g_slist_find(js->pending_avatar_requests, presence->jb)) { 855 if(!g_slist_find(js->pending_avatar_requests, presence->jb)) {
855 856 JabberIq *iq;
856 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, presence->jb); 857 xmlnode *vcard;
858
859 js->pending_avatar_requests =
860 g_slist_prepend(js->pending_avatar_requests, presence->jb);
857 861
858 iq = jabber_iq_new(js, JABBER_IQ_GET); 862 iq = jabber_iq_new(js, JABBER_IQ_GET);
859 xmlnode_set_attrib(iq->node, "to", buddy_name); 863 xmlnode_set_attrib(iq->node, "to", buddy_name);
860 vcard = xmlnode_new_child(iq->node, "vCard"); 864 vcard = xmlnode_new_child(iq->node, "vCard");
861 xmlnode_set_namespace(vcard, "vcard-temp"); 865 xmlnode_set_namespace(vcard, "vcard-temp");
1204 1208
1205 static void 1209 static void
1206 parse_vcard_avatar(JabberStream *js, JabberPresence *presence, xmlnode *x) 1210 parse_vcard_avatar(JabberStream *js, JabberPresence *presence, xmlnode *x)
1207 { 1211 {
1208 xmlnode *photo = xmlnode_get_child(x, "photo"); 1212 xmlnode *photo = xmlnode_get_child(x, "photo");
1213 char *hash_tmp;
1214
1209 if (photo) { 1215 if (photo) {
1210 g_free(presence->vcard_avatar_hash); 1216 g_free(presence->vcard_avatar_hash);
1211 presence->vcard_avatar_hash = xmlnode_get_data(photo); 1217 hash_tmp = xmlnode_get_data(photo);
1218 presence->vcard_avatar_hash =
1219 hash_tmp ? hash_tmp : g_strdup("");
1212 } 1220 }
1213 } 1221 }
1214 1222
1215 static void 1223 static void
1216 parse_muc_user(JabberStream *js, JabberPresence *presence, xmlnode *x) 1224 parse_muc_user(JabberStream *js, JabberPresence *presence, xmlnode *x)