Mercurial > pidgin
changeset 22295:bb124c3e668c
Fix setting vCard buddy icons when we don't have any other user info set.
Fixes #3450.
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 14 Feb 2008 13:03:34 +0000 |
parents | 33b5a0e92583 |
children | 6d3f8042f21f |
files | libpurple/protocols/jabber/buddy.c |
diffstat | 1 files changed, 45 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c Thu Feb 14 12:42:58 2008 +0000 +++ b/libpurple/protocols/jabber/buddy.c Thu Feb 14 13:03:34 2008 +0000 @@ -392,6 +392,7 @@ */ void jabber_set_info(PurpleConnection *gc, const char *info) { + PurpleStoredImage *img; JabberIq *iq; JabberStream *js = gc->proto_data; xmlnode *vc_node; @@ -410,57 +411,58 @@ */ vc_node = info ? xmlnode_from_str(info, -1) : NULL; - if(!vc_node) { - vc_node = xmlnode_new("vCard"); - for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) - xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); + if (vc_node && (!vc_node->name || + g_ascii_strncasecmp(vc_node->name, "vCard", 5))) { + xmlnode_free(vc_node); + vc_node = NULL; } - if (vc_node->name && - !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) { - PurpleStoredImage *img; - - if ((img = purple_buddy_icons_find_account_icon(gc->account))) { - gconstpointer avatar_data; - gsize avatar_len; - xmlnode *photo, *binval, *type; - gchar *enc; - int i; - unsigned char hashval[20]; - char *p, hash[41]; + if ((img = purple_buddy_icons_find_account_icon(gc->account))) { + gconstpointer avatar_data; + gsize avatar_len; + xmlnode *photo, *binval, *type; + gchar *enc; + int i; + unsigned char hashval[20]; + char *p, hash[41]; - avatar_data = purple_imgstore_get_data(img); - avatar_len = purple_imgstore_get_size(img); - /* have to get rid of the old PHOTO if it exists */ - if((photo = xmlnode_get_child(vc_node, "PHOTO"))) { - xmlnode_free(photo); - } - photo = xmlnode_new_child(vc_node, "PHOTO"); - type = xmlnode_new_child(photo, "TYPE"); - xmlnode_insert_data(type, "image/png", -1); - binval = xmlnode_new_child(photo, "BINVAL"); - enc = purple_base64_encode(avatar_data, avatar_len); - - purple_cipher_digest_region("sha1", avatar_data, - avatar_len, sizeof(hashval), - hashval, NULL); - - purple_imgstore_unref(img); - - p = hash; - for(i=0; i<20; i++, p+=2) - snprintf(p, 3, "%02x", hashval[i]); - js->avatar_hash = g_strdup(hash); - - xmlnode_insert_data(binval, enc, -1); - g_free(enc); + if(!vc_node) { + vc_node = xmlnode_new("vCard"); + for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) + xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); } + avatar_data = purple_imgstore_get_data(img); + avatar_len = purple_imgstore_get_size(img); + /* have to get rid of the old PHOTO if it exists */ + if((photo = xmlnode_get_child(vc_node, "PHOTO"))) { + xmlnode_free(photo); + } + photo = xmlnode_new_child(vc_node, "PHOTO"); + type = xmlnode_new_child(photo, "TYPE"); + xmlnode_insert_data(type, "image/png", -1); + binval = xmlnode_new_child(photo, "BINVAL"); + enc = purple_base64_encode(avatar_data, avatar_len); + + purple_cipher_digest_region("sha1", avatar_data, + avatar_len, sizeof(hashval), + hashval, NULL); + + purple_imgstore_unref(img); + + p = hash; + for(i=0; i<20; i++, p+=2) + snprintf(p, 3, "%02x", hashval[i]); + js->avatar_hash = g_strdup(hash); + + xmlnode_insert_data(binval, enc, -1); + g_free(enc); + } + + if (vc_node != NULL) { iq = jabber_iq_new(js, JABBER_IQ_SET); xmlnode_insert_child(iq->node, vc_node); jabber_iq_send(iq); - } else { - xmlnode_free(vc_node); } }