<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Pubsub Account Management</title>
  <abstract>This specification describes a new model for handling remote pubsub services and a protocol for doing so.</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>0376</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0060</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>pam</shortname>
  
    <author>
      <firstname>Dave</firstname>
      <surname>Cridland</surname>
      <email>dave@hellopando.com</email>
      <jid>dwd@dave.cridland.net</jid>
    </author>

  <revision>
    <version>0.2</version>
    <date>2017-09-11</date>
    <initials>XEP Editor (jwi)</initials>
    <remark>Defer due to lack of activity.</remark>
  </revision>
  <revision>
    <version>0.1.1</version>
    <date>2016-07-20</date>
    <initials>dwd</initials>
    <remark><p>Added some concrete protocol around subscription tracking.</p></remark>
  </revision>
  <revision>
    <version>0.1.0</version>
    <date>2016-05-20</date>
    <initials>XEP Editor: ssw</initials>
    <remark><p>Initial version approved by the Council.</p></remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2016-01-28</date>
    <initials>dwd</initials>
    <remark><p>Initial Version</p></remark>
  </revision>
</header>
<section1 topic="Introduction">
  <p>The XMPP way is to have "disposable", or at least easily substituted, clients, maintaining long-term state on the server, and allowing it to be synchronized between clients. In particular, this can be seen on how the roster and presence fan-out operate - clients defer the operation of such things to the server, which manages the shared state and allows servers to access and manipulate it.</p>
  <p>Historically, however, we have not done this for some more recently designed services, including Multi User Chat and PubSub. In both cases, different clients may be unaware of what chatrooms (etc) are joined (etc) by which other clients. This causes practical difficulty in seamlessly switching between devices and/or clients.</p>
</section1>
<section1 topic="User Stories" anchor="stories">
  <section2 topic="Device Agility">
    <ul>
      <li>When a user subscribes to a publish-subscribe node (presumably via some higher-level abstraction), other online devices are aware of the new subscription immediately, and can choose to reflect the new subscription in their UI.</li>
      <li>Not all devices may be capable of handling the particular payload and/or service, and therefore should signal which payload and/or service types they support.</li>
      <li>The same capability as point 1 should be possible for unsubscribing.</li>
    </ul>
  </section2>
  <section2 topic="New Devices">
    <ul>
      <li>When a user brings a new device online, it should be able to quickly learn all the user's current subscriptions and present them to the user in its UI.</li>
    </ul>
  </section2>
  <section2 topic="Offline Capability">
    <ul>
      <li>When the device is offline for an extended period (beyond XEP-0198 resumption capability), it needs to be able to obtain all the events it missed, including when the events occured.</li>
      <li>It should be able to tell which of these the user is unlikely to have seen on other devices.</li>
      <li>Further, it needs to be able to tell if new subscriptions have been added, or old ones removed.</li>
    </ul>
  </section2>
  <section2 topic="PEP">
    <ul>
      <li>A one-way subscription to a user should still allow PEP.</li>
      <li>PEP should work the same way as now - users see filtered notifications about the things they care about.</li>
    </ul>
  </section2>
</section1>
<section1 topic="Protocol" anchor="protocol">
  <section2 topic="Advertising Support" anchor="disco">
    <section3 topic="Clients">
      <p>Clients advertise support for this protocol via <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> using a Disco Feature of 'urn:xmpp:pam:0'. This is required for local servers to detect support.</p>
    </section3>
    <section3 topic="Servers">
      <p>Servers advertise this support via <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> on the user account (eg, &lt;localpart@domain.tld&gt;), using the same feature of 'urn:xmpp:pam:0'. This is used both by the local user and also remote pubsub services.</p>
    </section3>
  </section2>
  <section2 topic="Subscribing" anchor="subs">
    <p>When a client wishes to subscribe to a node, either on the local server or remotely, using this protocol it does so by sending an &lt;iq/&gt; of type "set" to its own account, containing a pam element, which in turn has a service attribute (the target service jid) and a payload of a <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> subscribe element (as described in <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> §6.1). Example 32 from <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> is thus performed in this protocol as follows:</p>
    <example caption="Client subscribes to a node"><![CDATA[
      <iq type='set' id='sub1'>
        <pam xmln='urn:xmpp:pam:0' jid='pubsub.shakespeare.lit'>
          <subscribe xmlns='http://jabber.org/protocol/pubsub'
              node='princely_musings'
              jid='francisco@denmark.lit'/>
        </pam>
      </iq>
]]>
    </example>
    <p>Note that because the <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> operation is intact within the pam element, local servers MAY interpret the operation, or MAY forward it verbatim. Note that the client SHALL always use its own bare jid (eg, &lt;localpart@domain.tld&gt;) within a subscribe, servers MUST verify this.</p>
    <p>Such a request SHALL cause the local server to send a traditional <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> request, from the account bare jid, to the remote service.</p>
    <p>When the remote service replies, the local server SHALL first notify all joined clients of the new subscription (described more in #sublist)...</p>
    <example caption="Server notifies about new subscription"><![CDATA[
      <message>
        <notify ver='aocolb' service='pubsub.shakespeare.lit' xmlns='urn:xmpp:pam:0'>
          <subscription xmlns='http://jabber.org/protocol/pubsub'
              node='princely_musings'
              jid='francisco@denmark.lit'
              subscription='subscribed'/>
       </notify>
     </message>
]]>
    </example>
    <p>... and then MUST respond to the original &lt;iq/&gt;. Since the subscription has already been notified, this is an empty result &lt;iq/&gt;.</p>
    <p>If the local server detects an error, it MUST NOT forward the request, and MUST respond with an &lt;iq/&gt; stanza of type error, which contains an error element which MAY be stamped with the local server as generator. Thus Example 34 from <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> would be very similar:</p>
    <example caption="An error generated remotely"><![CDATA[
      <iq type='error' id='sub1'>
        <error type='modify' by='francisco@denmark.lit'>
          <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
          <invalid-jid xmlns='http://jabber.org/protocol/pubsub#errors'/>
        </error>
      </iq>
]]>
    </example>
    <p>If the remote service rejects the subscription request, the local server simply forwards the response back as an &lt;iq/&gt; of type error, with the remote error copied through. The generator MUST be set to the remote service if missing. Thus Example 35 from <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> might look as follows:</p>
<example caption="An error generated remotely"><![CDATA[
  <iq type='error' id='sub1'>
    <error type='auth' by='pubsub.shakespeare.lit'>
      <not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
      <presence-subscription-required xmlns='http://jabber.org/protocol/pubsub#errors'/>
    </error>
  </iq>
]]>
    </example>
    <p>Clients MAY assume that if the generator is missing, the error is generated by the local server and not a remote service.</p>
  </section2>
  <section2 topic="Unsubscribing" anchor="unsub">
    <p>As above.</p>
  </section2>
  <section2 topic="Listing Subscriptions" anchor="sublist">
    <p>Clients obtain a current listing of the subscriptions, for example on initial connection, by sending a subscriptions request qualified by the pam namespace. If a client already has the opaque version identifier cached, it MAY include it within a "ver" attribute:</p>
    <example caption="Client requests all current subscriptions"><![CDATA[
      <iq type='get' id='subscriptions1'>
        <subscriptions xml='urn:xmpp:pam:0' ver='asdvcjkasdjb'>
      </iq>
]]>
    </example>
    <p>The local server responds with either a response containing a subscription list (such as this, similar to <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> Example 21):</p>
    <example caption="Complete subscription list"><![CDATA[
      <iq type='result' id='subscription1'>
        <subscriptions xml='urn:xmpp:pam:0' ver='kjlsadhfsd'>
          <subscription service='pubsub.shakespeare.lit' node='node1' jid='francisco@denmark.lit' subscription='subscribed'/>
          <subscription service='pubsub.marlowe.lit' node='node2' jid='francisco@denmark.lit' subscription='subscribed'/>
          <subscription service='pubsub.marlowe.lit' node='node5' jid='francisco@denmark.lit' subscription='unconfigured'/>
          <subscription service='pubsub.shakespeare.lit' node='node6' jid='francisco@denmark.lit' subscription='subscribed' subid='123-abc'/>
          <subscription service='pubsub.shakespeare.lit' node='node6' jid='francisco@denmark.lit' subscription='subscribed' subid='004-yyy'/>
        </subscriptions>
      </iq>
]]>
    </example>
    <p>Alternately, a server MAY - if the client has supplied an opaque version identifier - send a sequence of &lt;notify&gt; elements followed by an empty &lt;iq/&gt; result.</p>
    <p>Clients MAY persistently store the last "ver" attribute seen from either the &lt;subscriptions&gt; response or the last &lt;notify&gt;, whichever is later. This can then be used to minimize the volume of subscription data transferred during resync.</p>
  </section2>
  <section2 topic="Auto Subscriptions" anchor="autosub">
    <p>Servers need to subscribe to remote PEP services explicitly those nodes which are of interest. Interest needs to be detirmined by the client issuing a request; but this implies that servers would gradually acrue any node type which the user has had a capable client at any time.</p>
    <p>Perhaps timing out node types which have not been requested for over a certain period?</p>
    <p>Clients can use +notify to handle auto-subscriptions between clients and their server.</p>
    <p>Servers receiving +notify from accounts known to support this protocol ignore them.</p>
  </section2>
  <section2 topic="Filtering" anchor="filter">
    <p>Clients filter subscriptions using a specific stanza (iq, probably), containing a list of node names. This can be used instead of the odler +notify (which is broadcast).</p>
  </section2>
  <section2 topic="Interaction with MAM" anchor="mam">
    <p>We probably want to say that events are now archived by MAM, but this may imply that clients need to filter out such events (or explicitly include them). Maybe the mask above affects MAM queries?</p>
  </section2>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>I have literally no idea. I don't think anything new is introduced that couldn't be discovered by traffic monitoring, although it collects and collates information that previously would not have been so readily available.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>On publication of this specification, the XMPP Registrar will dance a little jig to the tune of the traditional hornpipe with a tea-cosy upon his or her head.</p>
</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>
</xep>
