Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/buddy.c @ 25817:9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
As part of this, no longer rely on the vcard for determining a need to
publish the XEP-0084 avatar; explicitly fetch and compare it.
Closes #7734.
References #7732. That patch needs updating to apply on top of this.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 21 Jan 2009 20:16:22 +0000 |
parents | 5dd25c58b65e |
children | 370d8eba2ce0 |
comparison
equal
deleted
inserted
replaced
25816:b68ac693ae2d | 25817:9195955395b6 |
---|---|
470 xmlnode_insert_data(type, "image/png", -1); | 470 xmlnode_insert_data(type, "image/png", -1); |
471 binval = xmlnode_new_child(photo, "BINVAL"); | 471 binval = xmlnode_new_child(photo, "BINVAL"); |
472 enc = purple_base64_encode(avatar_data, avatar_len); | 472 enc = purple_base64_encode(avatar_data, avatar_len); |
473 | 473 |
474 js->avatar_hash = jabber_calculate_data_sha1sum(avatar_data, avatar_len); | 474 js->avatar_hash = jabber_calculate_data_sha1sum(avatar_data, avatar_len); |
475 | |
476 xmlnode_insert_data(binval, enc, -1); | 475 xmlnode_insert_data(binval, enc, -1); |
477 g_free(enc); | 476 g_free(enc); |
478 } else if (vc_node) { | 477 } else if (vc_node) { |
479 xmlnode *photo; | 478 xmlnode *photo; |
480 /* TODO: Remove all PHOTO children? (see above note) */ | 479 /* TODO: Remove all PHOTO children? (see above note) */ |
492 | 491 |
493 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) | 492 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
494 { | 493 { |
495 PurplePresence *gpresence; | 494 PurplePresence *gpresence; |
496 PurpleStatus *status; | 495 PurpleStatus *status; |
497 | 496 |
498 jabber_avatar_set(gc->proto_data, img); | 497 jabber_avatar_set(gc->proto_data, img); |
499 /* vCard avatars do not have an image type requirement so update our | 498 /* vCard avatars do not have an image type requirement so update our |
500 * vCard avatar regardless of image type for those poor older clients | 499 * vCard avatar regardless of image type for those poor older clients |
501 */ | 500 */ |
502 jabber_set_info(gc, purple_account_get_user_info(gc->account)); | 501 jabber_set_info(gc, purple_account_get_user_info(gc->account)); |
1044 } | 1043 } |
1045 } | 1044 } |
1046 | 1045 |
1047 static void jabber_vcard_save_mine(JabberStream *js, xmlnode *packet, gpointer data) | 1046 static void jabber_vcard_save_mine(JabberStream *js, xmlnode *packet, gpointer data) |
1048 { | 1047 { |
1049 xmlnode *vcard; | 1048 xmlnode *vcard, *photo, *binval; |
1050 char *txt; | 1049 char *txt, *vcard_hash = NULL; |
1051 PurpleStoredImage *img; | 1050 const char *current_hash; |
1052 | 1051 |
1053 if((vcard = xmlnode_get_child(packet, "vCard")) || | 1052 if((vcard = xmlnode_get_child(packet, "vCard")) || |
1054 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) | 1053 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) |
1055 { | 1054 { |
1056 txt = xmlnode_to_str(vcard, NULL); | 1055 txt = xmlnode_to_str(vcard, NULL); |
1061 /* if we have no vCard, then lets not overwrite what we might have locally */ | 1060 /* if we have no vCard, then lets not overwrite what we might have locally */ |
1062 } | 1061 } |
1063 | 1062 |
1064 js->vcard_fetched = TRUE; | 1063 js->vcard_fetched = TRUE; |
1065 | 1064 |
1066 if(NULL != (img = purple_buddy_icons_find_account_icon(js->gc->account))) { | 1065 if (vcard && (photo = xmlnode_get_child(vcard, "PHOTO")) && |
1067 jabber_set_buddy_icon(js->gc, img); | 1066 (binval = xmlnode_get_child(photo, "BINVAL"))) { |
1068 purple_imgstore_unref(img); | 1067 gsize size; |
1069 } | 1068 char *bintext = xmlnode_get_data(binval); |
1069 guchar *data = purple_base64_decode(bintext, &size); | |
1070 g_free(bintext); | |
1071 | |
1072 if (data) { | |
1073 vcard_hash = jabber_calculate_data_sha1sum(data, size); | |
1074 g_free(data); | |
1075 } | |
1076 } | |
1077 | |
1078 current_hash = purple_account_get_string(js->gc->account, | |
1079 "prpl-jabber_icon_checksum", ""); | |
1080 | |
1081 /* Republish our vcard if the photo is different than the server's */ | |
1082 if ((!vcard_hash && current_hash[0] != '\0') || | |
1083 (vcard_hash && strcmp(vcard_hash, current_hash))) { | |
1084 PurpleAccount *account = purple_connection_get_account(js->gc); | |
1085 jabber_set_info(js->gc, purple_account_get_user_info(account)); | |
1086 } else if (current_hash != '\0') { | |
1087 /* Our photo is in the vcard, so advertise vcard-temp updates */ | |
1088 js->avatar_hash = g_strdup(current_hash); | |
1089 } | |
1090 | |
1091 g_free(vcard_hash); | |
1070 } | 1092 } |
1071 | 1093 |
1072 void jabber_vcard_fetch_mine(JabberStream *js) | 1094 void jabber_vcard_fetch_mine(JabberStream *js) |
1073 { | 1095 { |
1074 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); | 1096 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); |