There exist several proposed protocols for communicating user avatar information over Jabber/XMPP (see IQ-Based Avatars (XEP-0008)
The protocol described herein seems to have been designed with the following requirements in mind:
Before informing contacts of the user's avatar, the user's client first publishes the avatar data to the user's public vCard using the protocol defined in vcard-temp (XEP-0054)
Next, the user's client computes the SHA1 hash of the avatar image data itself (not the base64-encoded version) in accordance with RFC 3174
Note that while XML Schema defines the canonical representation of hexadecimal values to be upper-case, the historical use throughout the XMPP ecosystem has established lower-case use. Entities need to be able to process both and may prefer to emit lower-case for compatibility.
The user's server then broadcasts that presence information to all contacts who are subscribed to the user's presence information.
When the recipient's client receives the hash of the avatar image, it SHOULD check the hash to determine if it already has a cached copy of that avatar image. If not, it retrieves the sender's full vCard in accordance with the protocol flow described in XEP-0054 (note that this request is sent to the user's bare JID, not full JID):
The following rules apply to inclusion of the update child element (<x xmlns='vcard-temp:x:update'/>) in presence broadcasts:
If a client supports the protocol defined herein, it MUST include the update child element in every presence broadcast it sends and SHOULD also include the update child in directed presence stanzas (e.g., directed presence sent when joining Multi-User Chat (XEP-0045)
If a client is not yet ready to advertise an image, it MUST send an empty update child element, i.e.:
If there is no avatar image to be advertised, the photo element MUST be empty, i.e.:
If the client subsequently obtains an avatar image (e.g., by updating or retrieving the vCard), it SHOULD then publish a new <presence/> stanza with character data in the <photo/> element.
Note: This enables recipients to distinguish between the absence of an image (empty photo element) and mere support for the protocol (empty update child).
The following rules apply to downloading and uploading the vCard:
A client MUST NOT advertise an avatar image without first downloading the current vCard. Once it has done this, it MAY advertise an image. However, a client MUST advertise an image if it has just uploaded the vCard with a new avatar image. In this case, the client MAY choose not to redownload the vCard to verify its contents.
Within a given session, a client MUST NOT attempt to upload a given avatar image more than once. The client MAY upload the avatar image to the vCard on login and after that MUST NOT upload the vCard again unless the user actively changes the avatar image.
The client MUST NOT poll for new versions of the user's vCard in order to determine whether to update the avatar image hash.
Jabber/XMPP allows multiple resources to authenticate for the same JID simultaneously. This introduces the potential of conflict between the resources regarding the user's avatar image. The following rules apply when a client receives a presence broadcast from another resource of its own JID:
If the presence stanza received from the other resource does not contain the update child element, then the other resource does not support vCard-based avatars. That resource could modify the contents of the vCard (including the photo element); because polling for vCard updates is not allowed, the client MUST stop advertising the avatar image hash. However, the client MAY reset its hash if all instances of non-conforming resources have gone offline.
If the presence stanza received from the other resource contains the update child element, then the other resource conforms to the protocol for vCard-based avatars. There are three possible scenarios:
If the update child element is empty, then the other resource supports the protocol but does not have its own avatar image. Therefore the client can ignore the other resource and continue to broadcast the existing image hash.
If the update child element contains an empty photo element, then the other resource has updated the vCard with an empty BINVAL. Therefore the client MUST retrieve the vCard. If the retrieved vCard contains a photo element with an empty BINVAL, then the client MUST stop advertising the old image.
If the update child element contains a non-empty photo element, then the client MUST compare the image hashes. If the hashes are identical, then the client can ignore the other resource and continue to broadcast the existing image hash. If the hashes are different, then the client MUST NOT attempt to resolve the conflict by uploading its avatar image again. Instead, it MUST defer to the content of the retrieved vCard by resetting its image hash (see below) and providing that hash in future presence broadcasts.
Resetting the image hash consists of the following steps:
Immediately send out a presence element with an empty update child element (containing no photo element).
Download the vCard from the server.
If the BINVAL is empty or missing, advertise an empty photo element in future presence broadcasts.
If the BINVAL contains image data, calculate the hash of image and advertise that hash in future presence broadcasts.
The following rules apply to the XML syntax:
The <PHOTO/> element SHOULD contain a <BINVAL/> child whose XML character data is Base64-encoded data for the avatar image.
The <PHOTO/> element SHOULD NOT contain an <EXTVAL/> that points to a URI for the image file.
The <PHOTO/> element MUST NOT contain the avatar image itself.
The <PHOTO/> element SHOULD contain a <TYPE/> child whose XML character data specifies the content-type of the image data. The XML character data SHOULD be "image/gif", "image/jpeg", or "image/png".
The <PHOTO/> element MUST NOT possess a 'mime-type' attribute.
The following rules apply to images:
The image SHOULD use less than eight kilobytes (8k) of data; this restriction is to be enforced by the publishing client.
The image height and width SHOULD be between thirty-two (32) and ninety-six (96) pixels; the recommended size is sixty-four (64) pixels high and sixty-four (64) pixels wide.
The image SHOULD be square.
The image content type
The image data MUST conform to the base64Binary datatype
The XML character data of the <TYPE/> element is a hint. If the XML character data of the <TYPE/> specifies a content type that does not match the data provided in the <BINVAL/> element, the processing application MUST adhere to the content type of the actual image data and MUST ignore the <TYPE/>. If the <TYPE/> is something other than image/gif, image/jpeg, or image/png, it SHOULD be ignored.
If the image data exceeds the 8 KB restriction, the processing application SHOULD process the data.
This document introduces no security considerations above and beyond those described in XMPP Core
This document requires no interaction with the Internet Assigned Numbers Authority (IANA)
The XMPP Registrar
The protocol documented by this schema is defined in
XEP-0153: http://www.xmpp.org/extensions/xep-0153.html
]]>
The author wishes to thank the helpful developers who have implemented this protocol and provided feedback regarding its documentation.