<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Pubsub Subscription Storage</title>
  <abstract>This document defines an XMPP protocol extension for storing subscriptions to Pubsub nodes.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0173</number>
  <status>Deferred</status>
  <type>Historical</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0049</spec>
    <spec>XEP-0060</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>pubsubs</shortname>
  <author>
    <firstname>Magnus</firstname>
    <surname>Henoch</surname>
    <email>henoch@dtek.chalmers.se</email>
    <jid>legoscia@jabber.cd.chalmers.se</jid>
  </author>
  <revision>
    <version>0.1</version>
    <date>2006-02-09</date>
    <initials>psa</initials>
    <remark><p>Initial version; changed title to Pubsub Subscription Storage; changed namespace to storage:pubsubs for consistency with other storage XEPs.</p></remark>
  </revision>
  <revision>
    <version>0.0.4</version>
    <date>2005-12-11</date>
    <initials>mh</initials>
    <remark><p>Add resource attribute.</p></remark>
  </revision>
  <revision>
    <version>0.0.3</version>
    <date>2005-11-13</date>
    <initials>mh</initials>
    <remark><p>Add subscription attribute.</p></remark>
  </revision>
  <revision>
    <version>0.0.2</version>
    <date>2005-10-28</date>
    <initials>mh</initials>
    <remark><p>Fix typo and schema.</p></remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2005-10-25</date>
    <initials>mh</initials>
    <remark><p>First draft.</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p><span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> allows Jabber entities to subscribe to various kinds of information, but provides no way of remembering which nodes a user has subscribed to.  Other protocols (e.g. <span class="ref"><link url="https://xmpp.org/extensions/xep-0080.html">User Geolocation (XEP-0080)</link></span> <note>XEP-0080: User Geolocation &lt;<link url="https://xmpp.org/extensions/xep-0080.html">https://xmpp.org/extensions/xep-0080.html</link>&gt;.</note>, <span class="ref"><link url="https://xmpp.org/extensions/xep-0084.html">User Avatar (XEP-0084)</link></span> <note>XEP-0084: User Avatar &lt;<link url="https://xmpp.org/extensions/xep-0084.html">https://xmpp.org/extensions/xep-0084.html</link>&gt;.</note>) allow information about a certain entity to be published to a Pubsub node.  These protocols use <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note> to allow other entities to find the pubsub node used by a certain entity, but provide no way of performing the opposite mapping, from pubsub node to information source.  This document attempts to fill that void, using <span class="ref"><link url="https://xmpp.org/extensions/xep-0049.html">Private XML Storage (XEP-0049)</link></span> <note>XEP-0049: Private XML Storage &lt;<link url="https://xmpp.org/extensions/xep-0049.html">https://xmpp.org/extensions/xep-0049.html</link>&gt;.</note> for storing information about subscriptions.</p>
</section1>
<section1 topic="Requirements" anchor="reqs">
  <p>This protocol enables Jabber clients to do the following:</p>
  <ul>
    <li>Remember which pubsub nodes the entity has subscribed to, and what kind of information is available at each node</li>
    <li>Update the mappings when subscriptions are added or removed</li>
    <li>Correlate incoming pubsub events to subscriptions</li>
  </ul>
</section1>
<section1 topic="Protocol" anchor="proto">
  <p>The &lt;subscriptions/&gt; element qualified by the 'storage:pubsubs' namespace is the root element used in the jabber:iq:private transactions.  It has zero or more &lt;subscription/&gt; child elements, each of which MUST possess the following attributes:</p>

  <ul>
    <li><em>jid</em> -- The JID of the pubsub service used</li>
    <li><em>node</em> -- The pubsub node at which the data is available</li>
    <li><em>subscription</em> -- The current subscription state, one of "none", "pending", "unconfigured" and "subscribed"</li>
  </ul>

  <p>Additionally, the &lt;subscription/&gt; element MAY possess these attributes:</p>
  <ul>
    <li><em>resource</em> -- The resource that is subscribed to this pubsub node.  If the 'resource' attribute is absent, the bare JID is subscribed.</li>
    <li><em>user</em> -- The JID of the owner of this particular piece of data</li>
    <li><em>targetns</em> -- The namespace of the data in question</li>
  </ul>
</section1>
<section1 topic="Use Cases" anchor="usecases">
  <section2 topic="Retrieving Existing Subscriptions" anchor="retrieving">
    <p>In this example, the user already has a subscription to Juliet's geolocation, possibly established through another client.</p>
    <example caption="Client requests existing subscriptions"><![CDATA[
<iq type='get' id='retrieve1'>
  <query xmlns='jabber:iq:private'>
    <subscriptions xmlns='storage:pubsubs'/>
  </query>
</iq>
]]></example>
    <example caption="Server returns existing subscriptions"><![CDATA[
<iq type='result' id='retrieve1'>
  <query xmlns='jabber:iq:private'>
    <subscriptions xmlns='storage:pubsubs'>
      <subscription user='juliet@capulet.com'
		    jid='pubsub.capulet.com'
		    node='juliet/geoloc'
		    targetns='http://jabber.org/protocol/geoloc'
		    subscription='subscribed'/>
    </subscriptions>
  </query>
</iq>
]]></example>
  </section2>

  <section2 topic="Updating Subscriptions" anchor="updating">
    <p>Due to the nature of XEP-0049, incremental updates are not possible; a client MUST send the entire &lt;subscriptions/&gt; node for each update.  Before performing the update, the client SHOULD retrieve the stored subscriptions, and incorporate any changes.</p>
    <p>In this example, the user has just subscribed to Romeo's tune (see <span class="ref"><link url="https://xmpp.org/extensions/xep-0118.html">User Tune (XEP-0118)</link></span> <note>XEP-0118: User Tune &lt;<link url="https://xmpp.org/extensions/xep-0118.html">https://xmpp.org/extensions/xep-0118.html</link>&gt;.</note>).  Assuming that retrieving happened as in the previous use case, updating the subscriptions proceeds as follows:</p>
    <example caption="Client sends updated subscriptions"><![CDATA[
<iq type='set' id='update1'>
  <query xmlns='jabber:iq:private'>
    <subscriptions xmlns='storage:pubsubs'>
      <subscription user='juliet@capulet.com'
		    jid='pubsub.capulet.com'
		    node='juliet/geoloc'
		    targetns='http://jabber.org/protocol/geoloc'
		    subscription='subscribed'/>
      <subscription user='romeo@montague.net'
		    jid='pubsub.montague.net'
		    node='5017cdc9f4a3d1450445c9096064e459'
		    targetns='http://jabber.org/protocol/tune'
		    subscription='subscribed'/>
    </subscriptions>
  </query>
</iq>
]]></example>
    <example caption="Server reports success"><![CDATA[
<iq type='result' id='update1'/>
]]></example>
  </section2>

  <section2 topic="Identifying Incoming Events" anchor="identifying">
    <p>Having recorded the retrieved mappings, the client is now prepared to identify incoming pubsub events.  Assume that the following event arrives:</p>
    <example caption="Client receives pubsub event"><![CDATA[
<message
    from='pubsub.montague.net'
    to='mercutio@shakespeare.lit'>
  <event xmlns='http://jabber.org/protocol/pubsub#event'>
    <items node='5017cdc9f4a3d1450445c9096064e459'>
      <item id='current'>
        <tune xmlns='http://jabber.org/protocol/tune'>
          <artist>Yes</artist>
          <title>Heart of the Sunrise</title>
          <source>Yessongs</source>
          <track>3</track>
          <length>686</length>
        </tune>
      </item>
    </items>
  </event>
</message>
]]></example>
    <p>The client now knows that this information comes from romeo@montague.net.</p>
  </section2>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>Pubsub events offer an opportunity to spoof sender addresses e.g. through 'replyto' data (as specified by the <span class="ref"><link url="https://xmpp.org/extensions/xep-0033.html">Extended Stanza Addressing (XEP-0033)</link></span> <note>XEP-0033: Extended Stanza Addressing &lt;<link url="https://xmpp.org/extensions/xep-0033.html">https://xmpp.org/extensions/xep-0033.html</link>&gt;.</note> protocol).  This protocol attempts to close that hole.  It does so by the following rules and assumptions:</p>
  <ul>
    <li>A client MUST add mappings (i.e. associations between a publisher's JID and a pubsub node) only from trustworthy sources, i.e. published disco items (see <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note>).  This relies on disco information not being cracked or falsified.</li>
    <li>A client MUST retrieve mappings only from trustworthy sources, i.e. private XML storage.  This assumes that no-one but the user is able to change such information.</li>
  </ul>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>No namespaces or parameters need to be registered with the <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> as a result of this document.</p>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='storage:pubsubs'
    xmlns='storage:pubsubs'
    elementFormDefault='qualified'>

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

  <xs:element name='subscription'>
    <xs:complexType>
      <xs:attribute name='jid' type='xs:string' use='required'/>
      <xs:attribute name='node' type='xs:string' use='required'/>
      <xs:attribute name='subscription' use='required'>
        <xs:simpleType>
          <xs:restriction base='xs:NCName'>
            <xs:enumeration value='none'/>
            <xs:enumeration value='pending'/>
            <xs:enumeration value='subscribed'/>
            <xs:enumeration value='unconfigured'/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name='resource' type='xs:string' use='optional'/>
      <xs:attribute name='user' type='xs:string' use='optional'/>
      <xs:attribute name='targetns' type='xs:string' use='optional'/>
    </xs:complexType>
  </xs:element>

</xs:schema>
]]></code>
</section1>
</xep>
