<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
  <!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
  <title>Metacontacts</title>
  <abstract>This document specifies an XMPP protocol extension for defining metacontacts and grouping member JIDs.</abstract>
  &LEGALNOTICE;
  <number>0209</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards JIG</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0049</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>NOT YET ASSIGNED</shortname>
  &ksmith;
  &remko;
  <author>
    <firstname>Yann</firstname>
    <surname>Le Boulanger</surname>
    <email>asterix@lagaule.org</email>
    <jid>asterix@jabber.lagaule.org</jid>
  </author>
  <revision>
    <version>0.1</version>
    <date>2007-04-10</date>
    <initials>psa</initials>
    <remark><p>Initial published version.</p></remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2007-03-26</date>
    <initials>kis</initials>
    <remark><p>First draft.</p></remark>
  </revision>
</header>
<section1 topic='Introduction' anchor='intro'>
  <p>It is often the case that a user will have multiple representations of a single contact, either within one account (as is often the case with contacts using legacy systems through transports) or across several accounts (particularly where a user or contact has separate work and home accounts). As these are different representations of the same logical entity, this XEP provides a method for binding them together into a single meta-contact. </p>
</section1>
<section1 topic='Requirements' anchor='reqs'>
  <p>The authors have designed the metacontacts protocol with the following requirements in mind:</p>
  <ul>
    <li>It MUST provide a method of consolidating multiple roster contacts representing the same logical entity both within an account and, if the user utilises multiple accounts, between accounts.</li>
    <li>In the case of meta-contacts spanning multiple accounts, the meta-contact data must be resilient to the failure (or simply the absence) of any combination of these accounts. Particularly it MUST NOT rely upon the private storage of one account to store data for other accounts.</li>
    <li>It MUST allow a user to order the contacts within a meta-contact in a hierarchy which clients are able to use to determine which should be the default recipient of messages where more than one is available at any time but MUST NOT require the enforcement of a hierarchy.</li>
  </ul>
</section1>
<section1 topic='Overview' anchor='overview'>
  <p>The metacontact storage is achieved through the use of private data storage. In order to achieve the resilience described above, the private storage of each account is used to store the metacontact membership of Jids in the roster of that account. The metacontacts are stored within private data storage of each account simply as an unordered collection of meta tags.</p>
  <example caption='A metacontact tag'><![CDATA[
<meta jid='romeo@montague.net' tag='d93nov' order='0'>
]]></example>
    <p>In this example, the 'jid' specifies that the roster entry 'romeo@montague.net' is a member of a metacontact. The 'tag' provides a key for a metacontact; in this example all metacontacts with a tag of 'd93nov' (across all accounts) refer to the same entity. The 'order' denotes the priority of this Jid over other Jids within the metacontact, with it being preferable to use Jids with higher priority (this is roughly analogous to the 'priority' on presence stanzas when a Jid has multiple online resources in XMPP).</p>
</section1>
<section1 topic='Use Cases' anchor='usecases'>
  <p>Below are example of setting and retrieving metacontacts for an account. When using metacontacts across multiple accounts, the steps are identical and the 'tag' attributes and used across accounts (that is: when the same tag is used for multiple contacts, all entries with the tag are merged into a single metacontact whether they reside on the same of different accounts).</p>
  <section2 topic='Retrieving the metacontact data' anchor='retrieving'>
    <p>Upon login, a client will need to know the current state of the metacontact structure and so SHOULD request the state for each account.</p>
    <example caption='Requesting metacontacts'><![CDATA[
<iq type='get' id='get1'>
  <query xmlns='jabber:iq:private'>
    <storage xmlns='storage:metacontacts'/>
  </query>
</iq>
]]></example>

    <p>The result of the query will list the metacontact membership for roster entries belonging to the queried account. </p>
    <example caption='Server returns metacontact data'><![CDATA[
<iq type='result' id='get1'>
  <query xmlns='jabber:iq:private'>
    <storage xmlns='storage:metacontacts'>
      <meta jid='mike.bolton@raplovers.org' tag='ae18f2' order='1'/>
      <meta jid='tom@jump-to-conclusions.com' tag='82a1a5' order='1'/>
      <meta jid='samir@initech.com' tag='283b94' order='2'/>
      <meta jid='mike@initech.com' tag='ae18f2' order='2'/>
    </storage>
  </query>
</iq>
]]></example>
    <p>The meta tags each represent a contact which is a member of a metacontact; as such it is likely that some roster entries for an account will not have corresponding meta tags (if they are not members of a metacontact). Each 'meta' tag MUST have a 'jid' attribute and a 'tag' attribute, an optional 'order' attribute MAY be included. </p>
    <p>The value of the 'jid' attribute MUST be the bare JID of a contact which is a member of the described metacontact and any jid MUST NOT be specified in this manner as a member of more than one metacontact within an account. A JID specified as a member of a metacontact for an account SHOULD be a member of the roster for that account. </p>
    <p>The value of the 'tag' is used as a non-human readable unique identifier for a metacontact. In the above example, there are three metacontacts; those with tags of '82a1a5' and '283b94' each have only one contact on this account, while the metacontact with tag tag='ae18f2' contains two contacts.</p>
    <p>The value of the 'order' attribute is used to suggest preference of some contacts over others within a metacontact; those contacts with a higher order are preferable to those with a lower order. In this example, 'mike@initech.com' is considered preferable to 'mike.bolton@raplovers.org' when communicating with the metacontact with tag 'ae18f2', due to their order of 2 and 1 respectively.</p>
    <p>Note: It is entirely possible for the query result for an account to indicate that, in isolation from other accounts, there exist metacontacts which contain only a single member contact, as is the case in the above example. The client MUST NOT discard such data, as other accounts belonging to the user (which the client need not have details of) may also have members of this metacontact. </p>
</section2>

  <section2 topic='Storing the metacontact data' anchor='storing'>
     <example caption=''><![CDATA[
<iq type='set' id='set2'>
  <query xmlns='jabber:iq:private'>
    <storage xmlns='storage:metacontacts'>
      <meta jid='mike.bolton@raplovers.org' tag='ae18f2' order='1'/>
      <meta jid='tom@jump-to-conclusions.com' tag='82a1a5' order='1'/>
      <meta jid='samir@initech.com' tag='283b94' order='2'/>
      <meta jid='milton@hawaii.com' tag='492ab2' order='2'/>
      <meta jid='joanna@kung-fu.org' tag='9248cc' order='1'/>
    </storage>
  </query>
</iq>
]]></example>
     <example caption='Server returns'><![CDATA[
<iq type='result' id='set2'/>
]]></example>
  </section2>

<!--As metacontacts are especially useful when used across multiple accounts, examples are also provided for actions across two accounts.
  <section2 topic='Retrieving metacontact data (account 1)' anchor='dualaccount-get1'>
     <example caption=''><![CDATA[
]]></example>
  </section2>-->
</section1>

<section1 topic='Implementation Notes' anchor='impl'>
  <!--<p>Optional.</p>-->
  <section2 topic='Creating a metacontact' anchor='creating'>
    <p>Creation of a metacontact is uncomplicated; the simple addition of meta tag with a common tag results in a new metacontact.</p>
  </section2>
  <section2 topic='Removing a metacontact' anchor='removing'>
    <p>Similarly, to remove a metacontact all that is required is to remove the meta tags which contribute to the metacontact.</p>
  </section2>
  <section2 topic='Uniqueness of order within a metacontact' anchor='uniqueness'>
		<p>Although it is unavoidable that multiple contacts within a metacontact MAY have the same order (due to potentially unavailable information from other accounts), clients SHOULD NOT apply the same order to multiple members of the same metacontact where it is possible to avoid it. If multiple members of a metacontact have the same order, the behaviour is dependent upon the client; it MAY apply rules itself to determine which member to communicate with (based upon presence, recent activity or other methods) it MAY present the user with the option to sort the members such that the orders are again unique, or it MAY employ another appropriate action.</p>
		<p>As the order attribute is optional, clients need a method for determining which member contact to use where the metacontact consists entirely of unordered members. When ordered and unordered members are present, unordered members SHOULD be considered to have the lowest order.</p>
	</section2>
</section1>
<section1 topic='Security Considerations' anchor='security'>
  <p>Security considerations related to private XML storage are described in XEP-0049; this XEP introduces no additional concerns.</p>
</section1>
<section1 topic='IANA Considerations' anchor='iana'>
  <p>No interaction with &IANA; is required as a result of this XEP.</p>
</section1>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  <p>No namespaces or parameters need to be registered with the &REGISTRAR; as a result of this XEP.</p>
</section1>
<section1 topic='XML Schema' anchor='schema'>
<code><![CDATA[
<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='storage:metacontacts'
    xmlns='storage:metacontacts'
    elementFormDefault='qualified'>

  <xs:element name='metacontacts'>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref='meta' minOccurs='0' maxOccurs='unbounded'/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name='meta'>
    <xs:complexType>
      <xs:attribute name='jid' type='xs:string' use='required'/>
      <xs:attribute name='tag' type='xs:string' use='required'/>
      <xs:attribute name='order' type='xs:xs:unsignedInt' use='optional'/>
    </xs:complexType>
  </xs:element>
</xs:schema>
]]></code>
</section1>
</xep>
