TOC 
Network Working GroupP. Saint-Andre, Ed.
Internet-DraftXMPP Standards Foundation
Obsoletes: 3921 (if approved)July 12, 2008
Intended status: Standards Track 
Expires: January 13, 2009 


Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence
draft-saintandre-rfc3921bis-06

Status of this Memo

By submitting this Internet-Draft, each author represents that any applicable patent or other IPR claims of which he or she is aware have been or will be disclosed, and any of which he or she becomes aware will be disclosed, in accordance with Section 6 of BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet-Drafts.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as “work in progress.”

The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt.

The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html.

This Internet-Draft will expire on January 13, 2009.

Copyright Notice

Copyright © The IETF Trust (2008).

Abstract

This document defines extensions to core features of the Extensible Messaging and Presence Protocol (XMPP) that provide basic instant messaging (IM) and presence functionality in conformance with RFC 2779.

This document obsoletes RFC 3921.



Table of Contents

1.  Introduction
    1.1.  Overview
    1.2.  Requirements
    1.3.  Functional Summary
    1.4.  Conventions
    1.5.  Acknowledgements
    1.6.  Discussion Venue
2.  Managing the Roster
    2.1.  Syntax and Semantics
        2.1.1.  Roster Items
            2.1.1.1.  Ask Attribute
            2.1.1.2.  Jid Attribute
            2.1.1.3.  Name Attribute
            2.1.1.4.  Subscription Attribute
            2.1.1.5.  Group Element
        2.1.2.  Roster Get
        2.1.3.  Roster Set
        2.1.4.  Roster Push
        2.1.5.  Roster Result
        2.1.6.  Subscription Attribute
    2.2.  Retrieving the Roster on Login
    2.3.  Adding a Roster Item
        2.3.1.  Request
        2.3.2.  Success Case
        2.3.3.  Error Cases
    2.4.  Updating a Roster Item
        2.4.1.  Request
        2.4.2.  Success Case
        2.4.3.  Error Cases
    2.5.  Deleting a Roster Item
        2.5.1.  Request
        2.5.2.  Success Case
        2.5.3.  Error Cases
3.  Managing Presence Subscriptions
    3.1.  Requesting a Subscription
        3.1.1.  Client Generation of Outbound Subscription Request
        3.1.2.  Server Processing of Outbound Subscription Request
        3.1.3.  Server Processing of Inbound Subscription Request
        3.1.4.  Client Processing of Inbound Subscription Request
        3.1.5.  Server Processing of Outbound Subscription Approval
        3.1.6.  Server Processing of Inbound Subscription Approval
    3.2.  Cancelling a Subscription
        3.2.1.  Client Generation of Subscription Cancellation
        3.2.2.  Server Processing of Outbound Subscription Cancellation
        3.2.3.  Server Processing of Inbound Subscription Cancellation
    3.3.  Unsubscribing
        3.3.1.  Client Generation of Unsubscribe
        3.3.2.  Server Processing of Outbound Unsubscribe
        3.3.3.  Server Processing of Inbound Unsubscribe
4.  Exchanging Presence Information
    4.1.  Overview
    4.2.  Initial Presence
        4.2.1.  Client Generation of Initial Presence
        4.2.2.  Server Processing of Outbound Presence
        4.2.3.  Server Processing of Inbound Presence
        4.2.4.  Client Processing of Inbound Presence
    4.3.  Presence Probes
        4.3.1.  Server Generation of Outbound Presence Probe
        4.3.2.  Server Processing of Inbound Presence Probe
    4.4.  Subsequent Presence Broadcast
        4.4.1.  Client Generation of Presence Broadcast
        4.4.2.  Server Processing of Outbound Presence
        4.4.3.  Server Processing of Inbound Presence
        4.4.4.  Client Processing of Inbound Presence
    4.5.  Unavailable Presence
        4.5.1.  Client Generation of Unavailable Presence
        4.5.2.  Server Processing of Outbound Unavailable Presence
        4.5.3.  Server Processing of Inbound Unavailable Presence
        4.5.4.  Client Processing of Inbound Unavailable Presence
    4.6.  Directed Presence
        4.6.1.  Client Generation of Directed Presence
        4.6.2.  Server Processing of Outbound Directed Presence
        4.6.3.  Server Processing of Inbound Directed Presence
        4.6.4.  Client Processing of Inbound Directed Presence
    4.7.  Presence Syntax
        4.7.1.  Type Attribute
        4.7.2.  Child Elements
        4.7.3.  Show Element
        4.7.4.  Status Element
        4.7.5.  Priority Element
        4.7.6.  Extended Content
5.  Exchanging Messages
    5.1.  One-to-One Chat Sessions
    5.2.  Message Syntax
        5.2.1.  To Attribute
        5.2.2.  Type Attribute
        5.2.3.  Body Element
        5.2.4.  Subject Element
        5.2.5.  Thread Element
    5.3.  Extended Content
6.  Exchanging IQ Stanzas
7.  A Sample Session
8.  Server Rules for Processing XML Stanzas
    8.1.  No Such User
    8.2.  Full JID at Local Domain
        8.2.1.  Available Resource Matches
        8.2.2.  No Available Resource Matches
    8.3.  Bare JID at Local Domain
        8.3.1.  Available Resources
            8.3.1.1.  Message
            8.3.1.2.  Presence
            8.3.1.3.  IQ
        8.3.2.  No Available Resources
            8.3.2.1.  Message
            8.3.2.2.  Presence
            8.3.2.3.  IQ
    8.4.  Remote Domain
9.  IM and Presence Compliance Requirements
    9.1.  Servers
    9.2.  Clients
10.  Internationalization Considerations
11.  Security Considerations
12.  IANA Considerations
    12.1.  Instant Messaging SRV Protocol Label Registration
    12.2.  Presence SRV Protocol Label Registration
13.  References
    13.1.  Normative References
    13.2.  Informative References
Appendix A.  Subscription States
    A.1.  Defined States
    A.2.  Server Processing of Outbound Presence Subscription Stanzas
        A.2.1.  Subscribe
        A.2.2.  Unsubscribe
        A.2.3.  Subscribed
        A.2.4.  Unsubscribed
    A.3.  Server Processing of Inbound Presence Subscription Stanzas
        A.3.1.  Subscribe
        A.3.2.  Unsubscribe
        A.3.3.  Subscribed
        A.3.4.  Unsubscribed
Appendix B.  Blocking Communication
Appendix C.  vCards
Appendix D.  XML Schemas
    D.1.  jabber:client
    D.2.  jabber:server
    D.3.  jabber:iq:roster
Appendix E.  Differences From RFC 3921
Appendix F.  Copying Conditions
§  Index
§  Author's Address
§  Intellectual Property and Copyright Statements




 TOC 

1.  Introduction



 TOC 

1.1.  Overview

The Extensible Messaging and Presence Protocol (XMPP) is an application profile of the Extensible Markup Language [XML] (Paoli, J., Maler, E., Sperberg-McQueen, C., Yergeau, F., and T. Bray, “Extensible Markup Language (XML) 1.0 (Fourth Edition),” August 2006.) for streaming XML data in close to real time between any two (or more) network-aware entities. XMPP is typically used to exchange messages, share presence information, and engage in structured request-response interactions. The core features of XMPP defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) provide the building blocks for many types of near-real-time applications, which can be layered on top of the core by sending application-specific data qualified by particular XML namespaces (refer to [XML‑NAMES] (Bray, T., Hollander, D., and A. Layman, “Namespaces in XML,” January 1999.)). This document defines XMPP extensions that provide the basic functionality expected of an instant messaging (IM) and presence application as defined in [IMP‑REQS] (Day, M., Aggarwal, S., and J. Vincent, “Instant Messaging / Presence Protocol Requirements,” February 2000.).

As a result of extensive implementation and deployment experience with XMPP since 2004, as well as more formal interoperability testing carried out under the auspices of the XMPP Standards Foundation (XSF), this document reflects consensus from the XMPP developer community regarding XMPP's basic instant messaging and presence features. In particular, this document incorporates the following backward-compatible changes from RFC 3921:

Therefore, this document defines the basic instant messaging and presence features of XMPP 1.0, thus obsoleting RFC 3921.



 TOC 

1.2.  Requirements

Traditionally, instant messaging applications have combined the following factors:

  1. The central point of focus is a list of one's contacts or "buddies" (in XMPP this list is called a ROSTER).
  2. The purpose of using such an application is to exchange relatively brief text messages with particular contacts in close to real time -- often relatively large numbers of such messages in rapid succession, in the form of a one-to-one CHAT SESSION as described under Section 5.1 (One-to-One Chat Sessions).
  3. The catalyst for exchanging messages is PRESENCE -- i.e., information about the network availability of particular contacts (thus knowing who is online and available for a one-to-one chat session).
  4. Presence information is provided only to contacts that one has authorized by means of an explicit agreement called a PRESENCE SUBSCRIPTION.

Thus at a high level this document assumes that a user must be able to complete the following use cases:

Detailed definitions of these functionality areas are contained in RFC 2779 [IMP‑REQS] (Day, M., Aggarwal, S., and J. Vincent, “Instant Messaging / Presence Protocol Requirements,” February 2000.), and the interested reader is referred to that document regarding the requirements addressed herein. While the XMPP instant messaging and presence extensions specified herein meet the requirements of RFC 2779, they were not designed explicitly with that specification in mind, since the base protocol evolved through an open development process within the Jabber open-source community before RFC 2779 was written. Although XMPP protocol extensions addressing many other functionality areas have been defined in the XMPP Standards Foundation's XEP series (e.g., multi-user text chat as specified in [XEP‑0045] (Saint-Andre, P., “Multi-User Chat,” January 2008.)), such extensions are not specified in this document because they are not mandated by RFC 2779.

Note: RFC 2779 stipulates that presence services must be separable from instant messaging services and vice-versa; i.e., it must be possible to use the protocol to provide a presence service, an instant messaging service, or both. Although the text of this document assumes that implementations and deployments will want to offer a unified instant messaging and presence service, there is no requirement that a service must offer both a presence service and an instant messaging service, and the protocol makes it possible to offer separate and distinct services for presence and for instant messaging. (For example, a presence-only service could return a <service-unavailable/> stanza error if a client attempt to send a <message/> stanza.)



 TOC 

1.3.  Functional Summary

This non-normative section provides a developer-friendly, functional summary of XMPP-based instant messaging and presence features; consult the sections that follow for a normative definition of these features.

[XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) specifies how an XMPP client connects to an XMPP server. In particular, it specifies the preconditions that must be fulfilled before a client is allowed to send XML stanzas (the basic unit of meaning in XMPP) to other entities on an XMPP network. These preconditions comprise negotiation of the XML stream and include XML stream establishment, optional channel encryption via Transport Layer Security [TLS] (Dierks, T. and E. Rescorla, “The Transport Layer Security (TLS) Protocol Version 1.1,” April 2006.), mandatory authentication via Simple Authentication and Security Layer [SASL] (Melnikov, A. and K. Zeilenga, “Simple Authentication and Security Layer (SASL),” June 2006.), and binding of a resource to the stream for client addressing. The reader is referred to [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) for details regarding these preconditions, and knowledge of [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) is assumed herein.

Upon fulfillment of the preconditions specified in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), an XMPP client has a long-lived XML stream with an XMPP server, which enables the user controlling that client to send and receive a potentially unlimited number of XML stanzas over the stream. Such a stream can be used to exchange messages, share presence information, and engage in structured request-response interactions in close to real time. After negotiation of the XML stream, the typical flow for an instant messaging and presence session is as follows:

  1. Retrieve one's roster. (See Section 2.2 (Retrieving the Roster on Login).)
  2. Send initial presence to the server for broadcasting to all subscribed contacts, thus "going online" from the perspective of XMPP communication. (See Section 4.2 (Initial Presence).)
  3. Exchange messages, manage presence subscriptions, perform roster updates, and in general process and generate other XML stanzas with particular semantics throughout the life of the session. (See Section 5 (Exchanging Messages), Section 3 (Managing Presence Subscriptions), Section 2 (Managing the Roster), and Section 6 (Exchanging IQ Stanzas).)
  4. Terminate the session when desired by sending unavailable presence and closing the underlying XML stream. (See Section 4.5 (Unavailable Presence).)



 TOC 

1.4.  Conventions

This document inherits the terminology defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.).

The following keywords are to be interpreted as described in [TERMS] (Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels,” March 1997.): "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".

For convenience, this document employs the term "user" to refer to the owner of an XMPP account; however, account owners need not be human persons and can be bots, devices, or other non-human applications.

Following the "XML Notation" used in [IRI] (Duerst, M. and M. Suignard, “Internationalized Resource Identifiers (IRIs),” January 2005.) to represent characters that cannot be rendered in ASCII-only documents, some examples in this document use the form "&#x...." as a notational device to represent Unicode characters (e.g., the string "&#x0159;" stands for the Unicode character LATIN SMALL LETTER R WITH CARON).

In examples, lines have been wrapped for improved readability, "[...]" means elision, and the following prepended strings are used (these prepended strings are not to be sent over the wire):



 TOC 

1.5.  Acknowledgements

The editor of this document finds it impossible to appropriately acknowledge the many individuals who have provided comments regarding the protocols defined herein. However, thanks are due to those who have who have provided implementation feedback, bug reports, requests for clarification, and suggestions for improvement since the publication of the RFC this document supersedes. The editor has endeavored to address all such feedback, but is solely responsible for any remaining errors and ambiguities.



 TOC 

1.6.  Discussion Venue

The document editor and the broader XMPP developer community welcome discussion and comments related to the topics presented in this document. The preferred forum is the <standards@xmpp.org> mailing list, for which archives and subscription information are available at http://mail.jabber.org/mailman/listinfo/standards.



 TOC 

2.  Managing the Roster

In XMPP, one's roster contains any number of specific contacts. A user's roster is stored by the user's server on the user's behalf so that the user can access roster information from any resource.



 TOC 

2.1.  Syntax and Semantics

Rosters are managed using IQ stanzas, specifically by means of a <query/> child element qualified by the 'jabber:iq:roster' namespace. The detailed syntax and semantics are defined in the following sections.



 TOC 

2.1.1.  Roster Items

The <query/> element MAY contain one or more <item/> children, each describing a unique ROSTER ITEM or "contact".

The syntax of the <item/> element is described in the following sections.



 TOC 

2.1.1.1.  Ask Attribute

The 'ask' attribute is used to specify certain subscription sub-states; for details, see Section 3.1.2 (Server Processing of Outbound Subscription Request).

Inclusion of the 'ask' attribute is OPTIONAL.



 TOC 

2.1.1.2.  Jid Attribute

The 'jid' attribute specifies the Jabber Identifier (JID) that uniquely identifies the roster item.

Inclusion of the 'jid' attribute is REQUIRED.



 TOC 

2.1.1.3.  Name Attribute

The 'name' attribute specifies the "handle" to be associated with the JID, as determined by the user (not the contact). Although the value of the 'name' attribute MAY have meaning to a human user, it is opaque to the server. However, the 'name' attribute MAY be used by the server for matching purposes within the context of various XMPP extensions, in which case the values MUST be compared only after application of the Resourceprep profile of stringprep as defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.).

Inclusion of the 'name' attribute is OPTIONAL.



 TOC 

2.1.1.4.  Subscription Attribute

The 'subscription' attribute is OPTIONAL; see Section 2.1.6 (Subscription Attribute).

Inclusion of the 'subscription' attribute is OPTIONAL.



 TOC 

2.1.1.5.  Group Element

The <group/> child element specifies a category or "bucket" into which the roster item is to be grouped by a client. An <item/> element MAY contain more than one <group/> element, so that roster groups are not exclusive. Although the XML character data of the <group/> element MAY have meaning to a human user, it is opaque to the server. However, the <group/> element MAY be used by the server for matching purposes within the context of various XMPP extensions, in which case the data MUST be compared only after application of the Resourceprep profile of stringprep as defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.).

Inclusion of the <group/> child element is OPTIONAL.



 TOC 

2.1.2.  Roster Get

A ROSTER GET is a client's request for the server to send the roster; syntactically it is an IQ stanza of type "get" sent from client to server and containing a <query/> element qualified by the 'jabber:iq:roster' namespace, where the <query/> element MUST NOT contain any <item/> child elements.

C: <iq from='juliet@example.com/balcony'
       id='rg1'
       type='get'>
    <query xmlns='jabber:iq:roster'/>
  </iq>

The expected outcome of sending a roster get is for the server to return a roster result.



 TOC 

2.1.3.  Roster Set

A ROSTER SET is a client's request for the server to modify (i.e., create, update, or delete) a roster item; syntactically it is an IQ stanza of type "set" sent from client to server and containing a <query/> element qualified by the 'jabber:iq:roster' namespace.

The following rules apply to roster sets:

  1. The <query/> element MUST contain one and only one <item/> element.
  2. The server MUST ignore any value of the 'subscription' attribute other than "remove" (see Section 2.1.6 (Subscription Attribute)).
  3. The server MUST ignore any 'to' address specified on the IQ stanza and MUST handle the IQ stanza as if it included no 'to' attribute.

C: <iq from='juliet@example.com/balcony'
       id='rs1'
       type='set'>
    <query xmlns='jabber:iq:roster'>
      <item jid='nurse@example.com'/>
    </query>
  </iq>


 TOC 

2.1.4.  Roster Push

A ROSTER PUSH is a newly created, updated, or deleted roster item that is sent from the server to the client; syntactically it is an IQ stanza of type "set" sent from server to client and containing a <query/> element qualified by the 'jabber:iq:roster' namespace.

The following rules apply to roster pushes:

  1. The <query/> element in a roster push MUST contain one and only one <item/> element.
  2. A receiving client MUST ignore the stanza unless it has no 'from' attribute (i.e., implicitly from the user's bare JID) or it has a 'from' attribute whose value matches the user's bare JID <user@domain>.

S: <iq id='a78b4q6ha463'
       to='juliet@example.com/chamber'
       type='set'>
    <query xmlns='jabber:iq:roster'>
      <item jid='nurse@example.com'/>
    </query>
  </iq>

As mandated by the semantics of the IQ stanza as defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), each resource that receives a roster push MUST reply with an IQ stanza of type "result" (or "error").

C: <iq from='juliet@example.com/balcony'
       id='a78b4q6ha463'
       type='result'/>

C: <iq from='juliet@example.com/chamber'
       id='a78b4q6ha463'
       type='result'/>

Note: There is no error case for client processing of roster pushes; if the server receives an IQ of type "error" in response to a roster push it SHOULD ignore the error.



 TOC 

2.1.5.  Roster Result

A ROSTER RESULT is the server's response to a roster get; syntactically it is an IQ stanza of type "result" sent from server to client and containing a <query/> element qualified by the 'jabber:iq:roster' namespace.

The <query/> element in a roster result contains one <item/> element for each contact and therefore can contain more than one <item/> element.

S: <iq id='rg1'
       to='juliet@example.com/chamber'
       type='result'>
    <query xmlns='jabber:iq:roster'>
      <item jid='nurse@example.com'/>
      <item jid='romeo@example.net'/>
    </query>
  </iq>

If there are no contacts in the roster, the <query/> element MUST be empty.

S: <iq to='juliet@example.com/chamber'
       id='roster_result'
       type='result'>
    <query xmlns='jabber:iq:roster'/>
  </iq>


 TOC 

2.1.6.  Subscription Attribute

The state of the presence subscription in relation to a roster item is captured in the 'subscription' attribute of the <item/> element. Allowable subscription-related values for this attribute are:

In a roster result, the client MUST ignore values of the 'subscription' attribute other than "none", "to", "from", or "both".

In a roster push, the client MUST ignore values of the 'subscription' attribute other than "none", "to", "from", "both", or "remove".

In a roster set, the value of the 'subscription' attribute MAY be included with a value of "remove", which indicates that the item is to be removed from the roster; the server MUST ignore all values of the 'subscription' attribute other than "remove".



 TOC 

2.2.  Retrieving the Roster on Login

Upon authenticating with a server and binding a resource (thus becoming a connected resource), a client SHOULD request the roster before sending initial presence (however, because receiving the roster is not necessarily desirable for all resources, e.g., a connection with limited bandwidth, the client's request for the roster is not mandatory). After a connected resource sends initial presence (see Section 4.2 (Initial Presence)), it is referred to as an available resource. If a connected resource or available resource requests the roster, it is referred to as an INTERESTED RESOURCE. The server MUST send roster pushes to all interested resources.

Note: Presence subscription requests are sent to available resources, whereas the roster pushes associated with subscription state changes are sent to interested resources. Therefore if a resource wishes to receive both subscription requests and roster pushes, it MUST both send initial presence and request the roster.

A client requests the roster by sending a roster get over its stream to the server.

C: <iq from='juliet@example.com/balcony'
       id='roster_1'
       type='get'>
     <query xmlns='jabber:iq:roster'/>
   </iq>
S: <iq id='roster_1'
       to='juliet@example.com/balcony'
       type='result'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'
             name='Romeo'
             subscription='both'>
         <group>Friends</group>
       </item>
       <item jid='mercutio@example.com'
             name='Mercutio'
             subscription='from'/>
       <item jid='benvolio@example.net'
             name='Benvolio'
             subscription='both'/>
     </query>
   </iq>

If the server cannot process the roster get, it MUST return an appropriate stanza error as described in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) (such as <service-unavailable/> if the roster namespace is not supported or <internal-server-error/> if the server experiences trouble processing or returning the roster).



 TOC 

2.3.  Adding a Roster Item



 TOC 

2.3.1.  Request

At any time, a client can add an item to the roster. This is done by sending a roster set containing a new item.

C: <iq from='juliet@example.com/balcony'
       id='roster_2'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'>
         <group>Servants</group>
       </item>
     </query>
   </iq>

Note: When a user adds a contact for the purpose of tracking the user's presence subscription to a contact, the user's client MUST send a presence subscription request to the contact before generating any roster set related to the contact. This enables the user's server to enforce any policies relevant to presence subscriptions (e.g., a prohibition on presence subscriptions to full JIDs). For details, see Section 3 (Managing Presence Subscriptions).



 TOC 

2.3.2.  Success Case

If the server can successfully process the roster set (i.e., if none of the error cases occurs), it MUST create the roster item in persistent storage.

The server MUST then return an IQ stanza of type "result" to the connected resource that sent the roster set.

S: <iq id='roster_2'
       to='juliet@example.com/balcony'
       type='result'/>

The server MUST also send a roster push containing the new roster item to all of the user's interested resources, including the resource that generated the roster set.

S: <iq to='juliet@example.com/balcony'
       id='a78b4q6ha463'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'
             subscription='none'>
         <group>Servants</group>
       </item>
     </query>
   </iq>

S: <iq to='juliet@example.com/chamber'
       id='a78b4q6ha464'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'
             subscription='none'>
         <group>Servants</group>
       </item>
     </query>
   </iq>

As mandated by the semantics of the IQ stanza as defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), each resource that receives a roster push MUST reply with an IQ stanza of type "result" (or "error").

C: <iq from='juliet@example.com/balcony'
       id='a78b4q6ha463'
       type='result'/>

C: <iq from='juliet@example.com/chamber'
       id='a78b4q6ha464'
       type='result'/>


 TOC 

2.3.3.  Error Cases

If the server cannot successfully process the roster set, it MUST return a stanza error. The following error cases are defined (naturally, other stanza errors can occur, such as <internal-server-error/>).

The server SHOULD return a <bad-request/> stanza error to the client if the roster set violates any of the following conditions:

  1. The <query/> element contains more than one <item/> child element.
  2. The <item/> element contains more than one <group/> element, but there are duplicate groups (where duplicates are determined using the Resourceprep profile of stringprep as defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.)).

The server SHOULD return a <not-acceptable/> stanza error to the client if the roster set violates any of the following conditions:

  1. The value of the 'name' attribute is greater than a server-configured limit.
  2. The XML character data of the <group/> element is of zero length.
  3. The XML character data of the <group/> element is greater than a server-configured limit.

Alternatively, the server MAY ignore the foregoing violations and process the roster set as best as possible (e.g., process only the first <item/> element, ignore duplicate <group/> elements, place the roster item in no group or a default group if the <group/> element is empty, and truncate 'name' attributes and <group/> elements that are too long).

Error: Roster set contains more than one item

C: <iq from='juliet@example.com/balcony'
       id='roster_3'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'>
         <group>Servants</group>
       </item>
       <item jid='mother@example.com'
             name='Mom'>
         <group>Family</group>
       </item>
     </query>
   </iq>

S: <iq id='roster_3'
       to='juliet@example.com/balcony'
       type='error'>
    <error type='modify'>
      <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
    </error>
  </iq>

Error: Roster set contains item with oversized handle

C: <iq from='juliet@example.com/balcony'
       id='roster_4'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='[ ... some-very-long-handle ... ]'>
         <group>Servants</group>
       </item>
     </query>
   </iq>

S: <iq id='roster_4'
       to='juliet@example.com/balcony'
       type='error'>
     <error type='modify'>
       <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
     </error>
   </iq>

Error: Roster set contains duplicate groups

C: <iq from='juliet@example.com/balcony'
       id='roster_5'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'>
         <group>Servants</group>
         <group>Servants</group>
       </item>
     </query>
   </iq>

S: <iq id='roster_5'
       to='juliet@example.com/balcony'
       type='error'>
     <error type='modify'>
       <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
     </error>
   </iq>

Error: Roster set contains empty group

C: <iq from='juliet@example.com/balcony'
       id='roster_6'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'>
         <group></group>
       </item>
     </query>
   </iq>

S: <iq id='roster_6'
       to='juliet@example.com/balcony'
       type='error'>
     <error type='modify'>
       <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
     </error>
   </iq>

Error: Roster set contains oversized group

C: <iq from='juliet@example.com/balcony'
       id='roster_7'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com'
             name='Nurse'>
         <group>[ ... some-very-long-group-name ... ]</group>
       </item>
     </query>
   </iq>

S: <iq id='roster_7'
       to='juliet@example.com/balcony'
       type='error'>
     <error type='modify'>
       <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
     </error>
   </iq>

The server MUST return a <not-allowed/> stanza error to the client if the value of the <item/> element's 'jid' attribute matches the bare JID <node@domain> portion of the <iq/> element's 'from' attribute (i.e., a JID MUST NOT be allowed to add itself to its own roster).

Error: Roster set contains sender's JID

C: <iq from='juliet@example.com/balcony'
       id='roster_8'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='juliet@example.com'/>
      </query>
    </iq>

S: <iq id='roster_8'
       to='juliet@example.com/balcony'
       type='error'>
      <error type='cancel'>
        <not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
      </error>
    </iq>


 TOC 

2.4.  Updating a Roster Item



 TOC 

2.4.1.  Request

Updating an existing roster item is done in the same way as adding a new roster item, i.e., by sending a roster set to the server. Because a roster item is atomic, the item MUST be updated exactly as provided in the roster set.

There are several reasons why a client might update a roster item:

  1. Adding a group
  2. Deleting a group
  3. Changing the handle
  4. Deleting the handle

Consider a roster item that is defined as follows:

    <item jid='romeo@example.net'
          name='Romeo'>
      <group>Friends</group>
    </item>

The user who has this item in her roster might want to add the item to another group.

C: <iq from='juliet@example.com/balcony'
       id='update_1'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'
             name='Romeo'>
         <group>Friends</group>
         <group>Lovers</group>
       </item>
     </query>
   </iq>

The user might then want to remove the item from the original group.

C: <iq from='juliet@example.com/balcony'
       id='update_2'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'
             name='Romeo'>
         <group>Lovers</group>
       </item>
     </query>
   </iq>

The user might then want to change the handle for the item.

C: <iq from='juliet@example.com/balcony'
       id='update_3'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'
             name='MyRomeo'>
         <group>Lovers</group>
       </item>
     </query>
   </iq>

The user might then want to remove the handle altogether (note: including an empty 'name' attribute is equivalent to including no 'name' attribute).

C: <iq from='juliet@example.com/balcony'
       id='update_4'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'
             name=''>
         <group>Lovers</group>
       </item>
     </query>
   </iq>

The user might then want to remove the item from all groups.

C: <iq from='juliet@example.com/balcony'
       id='update_5'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='romeo@example.net'/>
     </query>
   </iq>


 TOC 

2.4.2.  Success Case

As with adding a roster item, if the roster item can be successfully processed then the server MUST update the roster information in persistent storage, send a roster push to all of the user's interested resources, and send an IQ result to the initiating resource; for details, see Section 2.3 (Adding a Roster Item).



 TOC 

2.4.3.  Error Cases

The error cases described under Section 2.3.3 (Error Cases) also apply to updating a roster item.



 TOC 

2.5.  Deleting a Roster Item



 TOC 

2.5.1.  Request

At any time, a client can delete an item from his or her roster by sending a roster set and specifying the value of the 'subscription' attribute to be "remove".

C: <iq from='juliet@example.com/balcony'
       id='delete_1'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='nurse@example.com' subscription='remove'/>
     </query>
   </iq>


 TOC 

2.5.2.  Success Case

As with adding a roster item, if the server can successfully process the roster set then it MUST update the roster information in persistent storage, send a roster push to all of the user's interested resources (with the 'subscription' attribute set to a value of "remove"), and send an IQ result to the initiating resource; for details, see Section 2.3 (Adding a Roster Item).

If the user has a presence subscription to the contact or the contact has a presence subscription to the user, the user's server MUST also generate a presence stanza of type "unsubscribe" (to unsubscribe from the contact's presence) or a presence stanza of type "unsubscribed" (to cancel the contact's subscription to the user), or both.

S: <presence from='juliet@example.com'
             to='nurse@example.com'
             type='unsubscribe'/>

S: <presence from='juliet@example.com'
             to='nurse@example.com'
             type='unsubscribed'/>


 TOC 

2.5.3.  Error Cases

If the value of the 'jid' attribute specifies an item that is not in the roster, the server MUST return an <item-not-found/> stanza error.

Error: Roster item not found

C: <iq from='juliet@example.com/balcony'
       id='delete_2'
       type='set'>
     <query xmlns='jabber:iq:roster'>
       <item jid='[ ... non-existent-jid ... ]'
             subscription='remove'/>
     </query>
   </iq>

S: <iq id='delete_2'
       to='juliet@example.com/balcony'
       type='error'>
     <error type='modify'>
       <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
     </error>
   </iq>


 TOC 

3.  Managing Presence Subscriptions

In order to protect the privacy of instant messaging users, presence information is disclosed only to other entities that a user has approved. When a user has agreed that another entity is allowed to view its presence, the entity is said to have a SUBSCRIPTION to the user's presence. An entity that has a subscription to a user's presence or to which a user has a presence subscription is called a CONTACT (in this document the term "contact" is also used in a less strict sense to refer to a potential contact or an item in a user's roster).

In XMPP, a subscription lasts across presence sessions; indeed, it lasts until the contact unsubscribes or the user cancels the previously-granted subscription.

Subscriptions are managed within XMPP by sending presence stanzas containing specially-defined attributes ("subscribe", "unsubscribe", "subscribed", and "unsubscribed").

Note: When a server processes or generates an outbound presence stanza of type "subscribe", "subscribed", "unsubscribe", or "unsubscribed", the server MUST stamp the outgoing presence stanza with the bare JID <node@domain> of the sending entity, not the full JID <node@domain/resource>. Enforcement of this rule simplifies the presence subscription model and helps to prevent presence leaks; for information about presence leaks, refer to the security considerations of [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.).

Subscription states are reflected in the rosters of both the user and the contact. Complete details regarding these subscription states can be found Appendix A (Subscription States); those details are not provided in this section, which simply narrates the protocol flows for common use cases related to presence subscriptions.



 TOC 

3.1.  Requesting a Subscription

A SUBSCRIPTION REQUEST is a request from a user for authorization to permanently subscribe to a contact's presence information; syntactically it is a presence stanza whose 'type' attribute has a value of "subscribe". A subscription request is generated by a user's client, processed by the (potential) contact's server, and acted on by the contact via the contact's client. The workflow is described in the following sections.

Note: Presence subscription requests are sent to available resources, whereas the roster pushes associated with subscription state changes are sent to interested resources. Therefore if a resource wishes to receive both subscription requests and roster pushes, it MUST both send initial presence and request the roster.



 TOC 

3.1.1.  Client Generation of Outbound Subscription Request

A user's client generates a subscription request by sending a presence stanza of type "subscribe" and specifying a 'to' address of the potential contact's bare JID <contact@domain>.

UC: <presence to='juliet@example.com' type='subscribe'/>

When a user sends a presence subscription request to a potential instant messaging and presence contact, the value of the 'to' attribute MUST be a bare JID <contact@domain> rather a full JID <contact@domain/resource>, since the desired result is for the user to receive presence from all of the contact's resources, not merely the particular resource specified in the 'to' attribute. Use of bare JIDs also simplifies subscription processing, presence probes, and presence notifications by the user's server and the contact's server.

Although many XMPP clients prompt the user for information about the potential contact (e.g., "handle" and desired roster group) when generating an outbound presence subscription request, the client MUST NOT send a roster set before sending the presence subscription request, but instead MUST wait until receiving the initial roster push from the server. This enables the user's server to enforce any policies relevant to presence subscriptions (e.g., a prohibition on presence subscriptions to full JIDs).



 TOC 

3.1.2.  Server Processing of Outbound Subscription Request

Upon receiving the outbound presence subscription request, the user's server MUST proceed as follows.

  1. Before processing the request, the user's server SHOULD check the syntax of the JID contained in the 'to' attribute. If the JID is of the form <contact@domain/resource> instead of <contact@domain>, the user's server SHOULD treat it as if the request had been directed to the contact's bare JID and modify the 'to' address accordingly. The server MAY also verify that the JID adheres to the format defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), including checking against the relevant stringprep profiles.
  2. If the potential contact is hosted on the same server as the user, the server MUST adhere to the rules specified in the next section in processing the subscription request and delivering it to the (local) contact.
  3. If the potential contact is hosted on a remote server, subject to local service policies the user's server MUST then route the stanza to that remote domain in accordance with core XMPP stanza processing rules. (This can result in returning an appropriate stanza error to the user, such as <remote-server-timeout/>.)

As mentioned, before locally delivering or remotely routing the presence subscription request, the user's server MUST stamp the outbound subscription request with the bare JID <user@domain> of the user.

US: <presence from='romeo@example.net'
              to='juliet@example.com'
              type='subscribe'/>

After locally delivering or remotely routing the presence subscription request, the user's server MUST then send a roster push to all of the user's interested resources, containing the potential contact with a subscription state of "none" and with notation that the subscription is pending (via an 'ask' attribute whose value is "subscribe").

US: <iq id='b89c5r7ib574'
        to='romeo@example.net/foo'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item ask='subscribe'
              jid='juliet@example.com'
              subscription='none'/>
      </query>
    </iq>

US: <iq id='b89c5r7ib575'
        to='romeo@example.net/bar'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item ask='subscribe'
              jid='juliet@example.com'
              subscription='none'/>
        </item>
      </query>
    </iq>

If the contact does not approve or deny the subscription request within some configurable amount of time, the user's server SHOULD re-send the subscription request to the contact based on an implementation-specific algorithm (e.g., whenever a new resource becomes available for the user, or after a certain amount of time has elapsed); this helps to recover from transient, silent errors that might have occurred in relation to the original subscription request.



 TOC 

3.1.3.  Server Processing of Inbound Subscription Request

Before processing the inbound presence subscription request, the contact's server SHOULD check the syntax of the JID contained in the 'to' attribute. If the JID is of the form <contact@domain/resource> instead of <contact@domain>, the contact's server SHOULD treat it as if the request had been directed to the contact's bare JID and modify the 'to' address accordingly. The server MAY also verify that the JID adheres to the format defined in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), including checking against the relevant stringprep profiles.

When processing the inbound presence subscription request, the contact's server MUST adhere to the following rules:

  1. Above all, the contact's server MUST NOT automatically approve subscription requests on the contact's behalf; instead, if a subscription request requires approval then the contact's server MUST deliver that request to the contact's available resource(s) for approval or denial by the contact.
  2. If the contact does not exist, then the contact's server MUST automatically return a presence stanza of type "unsubscribed" to the user.
    CS: <presence from='juliet@example.com'
                  to='romeo@example.net'
                  type='unsubscribed'/>
    
  3. If the contact exists and the user already has a subscription to the user's presence, then the contact's server MUST auto-reply on behalf of the contact by sending a presence stanza of type "subscribed" from the contact's bare JID to the user's bare JID. If the contact previously sent a presence stanza of type "subscribed" and the contact's server treated that as indicating "pre-approval" for the user's presence subscription (see Appendix A (Subscription States)), then the contact's server SHOULD also auto-reply on behalf of the contact.
  4. If the contact exists, the user does not already have a subscription to the contact's presence, and there is at least one available resource associated with the contact when the subscription request is received by the contact's server, then the contact's server MUST broadcast that subscription request to all available resources in accordance with Section 8 (Server Rules for Processing XML Stanzas).
  5. If the contact exists, the user does not already have a subscription to the contact's presence, and the contact has no available resources when the subscription request is received by the contact's server, then the contact's server MUST keep a record of the complete presence stanza comprising the subscription request, including any extended content contained therein, and deliver the request when the contact next has an available resource. The contact's server MUST continue to deliver the subscription request whenever the contact creates an available resource, until the contact either approves or denies the request. (Note: The contact's server MUST NOT deliver more than one subscription request from any given user when the contact next has an available resource; e.g., if the user sends multiple subscription requests to the contact while the contact is offline, the contact's server SHOULD store only one of those requests, such as the first request or last request, and MUST deliver only one of the requests when the contact next has an available resource; this helps to prevent "subscription request spam".)

Note: Until and unless the contact approves the subscription request as described under Section 3.1.4 (Client Processing of Inbound Subscription Request), the contact's server MUST NOT add an item for the user to the contact's roster.



 TOC 

3.1.4.  Client Processing of Inbound Subscription Request

When the contact's client receives a subscription request from the user, it MUST present the request to the contact for approval (unless the contact has explicitly configured the client to automatically approve or deny some or all subscription requests).

A subscription request is approved by sending a presence stanza of type "subscribed", which is processed as described in the following sections for both the contact's server and the user's server.

CC: <presence to='romeo@example.net' type='subscribed'/>

A subscription request is denied by sending a presence stanza of type "unsubscribed", which is processed as described under Section 3.2 (Cancelling a Subscription) for both the contact's server and the user's server.

CC: <presence to='romeo@example.net' type='unsubscribed'/>


 TOC 

3.1.5.  Server Processing of Outbound Subscription Approval

When the contact's client sends the subscription approval, the contact's server MUST stamp the outbound stanza with the bare JID <contact@domain> of the contact and locally deliver or remotely route the stanza to the user.

CS: <presence from='juliet@example.com'
              to='romeo@example.net'
              type='subscribed'/>

The contact's server then MUST send a roster push to all of the contact's interested resources.

CS: <iq id='a78b4q6ha463'
        to='juliet@example.com/balcony'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='from'/>
      </query>
    </iq>

CS: <iq id='a78b4q6ha464'
        to='juliet@example.com/chamber'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='from'/>
      </query>
    </iq>

The contact's server MUST then also send current presence to the user from each of the contact's available resources.

CS: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

CS: <presence from='juliet@example.com/chamber'
              to='romeo@example.net'/>

From the perspective of the contact, there now exists a subscription from the user.

In order to subscribe to the user's presence, the contact would then send a subscription request to the user. (XMPP clients will often automatically send the subscription request instead of requiring the contact to initiate the subscription request, since it is assumed that the desired end state is a mutual subscription.) Naturally, when the contact sends a subscription request to the user, the subscription states will be different from those shown in the foregoing examples (see Appendix A (Subscription States)) and the roles will be reversed.



 TOC 

3.1.6.  Server Processing of Inbound Subscription Approval

When the user's server receives the subscription approval, it MUST first check if the contact is in the user's roster with subscription='none' or subscription='from' and the 'ask' flag set to "subscribe" (i.e., a subscription state of "None + Pending Out", "None + Pending Out+In", or "From + Pending Out"; see Appendix A (Subscription States)). If this check is successful, the user's server MUST initiate a roster push to all of the user's interested resources, containing an updated roster item for the contact with the 'subscription' attribute set to a value of "to" (if the subscription state was "None + Pending Out" or "None + Pending Out+In") or "both" (if the subscription state was "From + Pending Out").

US: <iq id='b89c5r7ib576'
        to='romeo@example.net/foo'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='to'/>
      </query>
    </iq>

US: <iq id='b89c5r7ib577'
        to='romeo@example.net/bar'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='to'/>
        </item>
      </query>
    </iq>

(Otherwise -- that is, if the user does not exist, if the contact is not in the user's roster, or if the contact is in the user's roster with a subscription state other than those described in the foregoing check -- then the user's server MUST silently ignore the stanza by not delivering it to the user, not modifying the user's roster, and not generating a roster push to the user's interested resources.)

From the perspective of the user, there now exists a subscription to the contact's presence.

The user's server MUST also deliver the available presence stanza received from each of the contact's available resources to each of the user's available resources.

[ ... to resource1 ... ]

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

[ ... to resource2 ... ]

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

[ ... to resource1 ... ]

US: <presence from='juliet@example.com/chamber'
              to='romeo@example.net'/>

[ ... to resource2 ... ]

US: <presence from='juliet@example.com/chamber'
              to='romeo@example.net'/>


 TOC 

3.2.  Cancelling a Subscription



 TOC 

3.2.1.  Client Generation of Subscription Cancellation

If a contact would like to cancel a subscription that it has previously granted to a user (or deny a subscription request), it sends a presence stanza of type "unsubscribed".

CC: <presence to='romeo@example.net' type='unsubscribed'/>


 TOC 

3.2.2.  Server Processing of Outbound Subscription Cancellation

Upon receiving the outound subscription cancellation, the contact's server MUST proceed as follows.

  1. If the user is hosted on the same server as the contact, the server MUST adhere to the rules specified in the next section in processing the subscription cancellation.
  2. If the user is hosted on a remote server, subject to local service policies the contact's server MUST then route the stanza to that remote domain in accordance with core XMPP stanza processing rules. (This can result in returning an appropriate stanza error to the contact, such as <remote-server-timeout/>.)

As mentioned, before locally delivering or remotely routing the stanza, the contact's server MUST stamp the outbound subscription cancellation with the bare JID <contact@domain> of the contact.

CS: <presence from='juliet@example.com'
              to='romeo@example.net'
              type='unsubscribed'/>

The contact's server then MUST send a roster push with the updated roster item to all of the contact's interested resources, where the subscription state is now either "none" or "to" (see Appendix A (Subscription States)).

CS: <iq id='a78b4q6ha465'
        to='juliet@example.com/balcony'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='none'/>
      </query>
    </iq>

CS: <iq id='a78b4q6ha466'
        to='juliet@example.com/chamber'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='none'/>
      </query>
    </iq>


 TOC 

3.2.3.  Server Processing of Inbound Subscription Cancellation

When the user's server receives the inbound subscription cancellation, it MUST first check if the contact is in the user's roster with subscription='to' or subscription='both' (see Appendix A (Subscription States)). If this check is successful, the user's server MUST initiate a roster push to all of the user's interested resources, containing an updated roster item for the contact with the 'subscription' attribute set to a value of "none" (if the subscription state was "To" or "To + Pending In") or "from" (if the subscription state was "Both").

US: <iq id='h37h3u1bv400'
        to='romeo@example.net/foo'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='none'/>
      </query>
    </iq>

US: <iq id='h37h3u1bv401'
        to='romeo@example.net/bar'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='none'/>
        </item>
      </query>
    </iq>

(Otherwise -- that is, if the user does not exist, if the contact is not in the user's roster, or if the contact is in the user's roster with a subscription state other than those described in the foregoing check -- then the user's server MUST silently ignore the stanza by not delivering it to the user, not modifying the user's roster, and not generating a roster push to the user's interested resources.)



 TOC 

3.3.  Unsubscribing



 TOC 

3.3.1.  Client Generation of Unsubscribe

If a user would like to unsubscribe from a contact's presence, it sends a presence stanza of type "unsubscribe".

UC: <presence to='juliet@example.com' type='unsubscribe'/>


 TOC 

3.3.2.  Server Processing of Outbound Unsubscribe

Upon receiving the outbound unsubscribe, the user's server MUST proceed as follows.

  1. If the contact is hosted on the same server as the user, the server MUST adhere to the rules specified in the next section in processing the subscription request.
  2. If the contact is hosted on a remote server, subject to local service policies the user's server MUST then route the stanza to that remote domain in accordance with core XMPP stanza processing rules. (This can result in returning an appropriate stanza error to the user, such as <remote-server-timeout/>.)

As mentioned, before locally delivering or remotely routing the unsubscrbe, the user's server MUST stamp the stanza with the bare JID <user@domain> of the user.

US: <presence from='romeo@example.net'
              to='juliet@example.com'
              type='unsubscribe'/>

The user's server then MUST send a roster push with the updated roster item to all of the user's interested resources, where the subscription state is now either "none" or "from" (see Appendix A (Subscription States)).

US: <iq id='h37h3u1bv402'
        to='romeo@example.net/foo'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='none'/>
      </query>
    </iq>

US: <iq to='romeo@example.net/bar'
        type='set'
        id='h37h3u1bv403'>
      <query xmlns='jabber:iq:roster'>
        <item jid='juliet@example.com'
              subscription='none'/>
        </item>
      </query>
    </iq>


 TOC 

3.3.3.  Server Processing of Inbound Unsubscribe

When the contact's server receives the subscription approval, it MUST first check if the user is in the contact's roster with subscription='from' or subscription='both' (i.e., a subscription state of "From", "From + Pending Out", or "Both"; see Appendix A (Subscription States)). If this check is successful, the contact's server MUST initiate a roster push to all of the contact's interested resources, containing an updated roster item for the contact with the 'subscription' attribute set to a value of "none" (if the subscription state was "From" or "From + Pending Out") or "to" (if the subscription state was "Both").

CS: <iq id='a78b4q6ha467'
        to='juliet@example.com/balcony'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='none'/>
      </query>
    </iq>

CS: <iq id='a78b4q6ha468'
        to='juliet@example.com/chamber'
        type='set'>
      <query xmlns='jabber:iq:roster'>
        <item jid='romeo@example.net'
              subscription='none'/>
      </query>
    </iq>

(Otherwise -- that is, if the contact does not exist, if the user is not in the contact's roster, or if the user is in the contact's roster with a subscription state other than those described in the foregoing check -- then the contact's server MUST silently ignore the stanza by not delivering it to the contact, not modifying the contact's roster, and not generating a roster push to the contact's interested resources.)



 TOC 

4.  Exchanging Presence Information



 TOC 

4.1.  Overview

The concept of presence refers to an entity's availability for communication over a network. At the most basic level, presence is a boolean "on/off" variable that signals whether an entity is available or unavailable for communication (the terms "online" and "offline" are also used). In XMPP, a user's availability is signalled when a client controlled by the user generates a <presence/> stanza with no 'type' attribute, and an entity's lack of availability is signalled when a client generates a <presence/> stanza whose 'type' attribute has a value of "unavailable".

XMPP presence typically follows a "publish-subscribe" or "observer" pattern, wherein an entity sends presence to its server, and its server then broadcasts that information to all of the entity's contacts who have a subscription to the entity's presence (in the terminology of [IMP‑MODEL] (Day, M., Rosenberg, J., and H. Sugano, “A Model for Presence and Instant Messaging,” February 2000.), an entity that generates presence is a "presentity" and the entities that receive presence are "subscribers"). A client generates presence for broadcasting to all subscribed entities by sending a presence stanza to its server with no 'to' address, where the presence stanza has either no 'type' attribute or a 'type' attribute whose value is "unavailable". This kind of presence is called BROADCAST PRESENCE. (A client can also send DIRECTED PRESENCE, i.e., a presence stanza with a 'to' address; this is less common but is sometimes used to send presence to entities that are not subscribed to the user's presence; see Section 4.6 (Directed Presence).)

After a client completes the preconditions specified in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.), it can establish a PRESENCE SESSION at its server by sending initial presence (Initial Presence), where the presence session is terminated by sending unavailable presence (Unavailable Presence). For the duration of its presence session, a connected resource (in the terminology of [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.)) is said to be an AVAILABLE RESOURCE.

In XMPP-based applications that combine messaging and presence functionality, the default type of communication for which presence signals availability is messaging; however, it is not necessary for XMPP-based applications to combine messaging and presence functionality, and can provide standalone presence features without messaging (in addition, XMPP servers do not require information about network availability in order to successfully route message and IQ stanzas).

Note: In the following examples, the "user" is juliet@example.com and the user has three contacts in her roster with a subscription state of "from" or "both": romeo@example.net, mercutio@example.com, and benvolio@example.net.



 TOC 

4.2.  Initial Presence



 TOC 

4.2.1.  Client Generation of Initial Presence

After completing the preconditions described in [XMPP‑CORE] (Saint-Andre, P., “Extensible Messaging and Presence Protocol (XMPP): Core,” October 2007.) (REQUIRED) and requesting the roster (RECOMMENDED), a client signals its availability for communication by sending INITIAL PRESENCE to its server, i.e., a presence stanza with no 'to' address (indicating that it is meant to be broadcast by the server on behalf of the client) and no 'type' attribute (indicating the user's availability).

UC: <presence/>

The initial presence stanza MAY contain the <priority/> element, the <show/> element, and one or more instances of the <status/> element, as well as extended content.



 TOC 

4.2.2.  Server Processing of Outbound Presence

Upon receiving initial presence from a client, the user's server MUST send the initial presence stanza from the full JID <user@domain/resource> of the user to all contacts that are subscribed to the user's presence; such contacts are those for which a JID is present in the user's roster with the 'subscription' attribute set to a value of "from" or "both".

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

US: <presence from='juliet@example.com/balcony'
              to='mercutio@example.com'/>

US: <presence from='juliet@example.com/balcony'
              to='benvolio@example.net'/>

The user's server MUST also broadcast initial presence from the user's newly available resource to all of the user's available resources (including the resource that generated the presence notification in the first place).

US: <presence from='juliet@example.com/balcony'
              to='juliet@example.com/balcony'/>

US: <presence from='juliet@example.com/balcony'
              to='juliet@example.com/chamber'/>

In the absence of presence information about the user's contacts, the user's server MUST also send presence probes to the user's contacts on behalf of the user as specified under Section 4.3 (Presence Probes).



 TOC 

4.2.3.  Server Processing of Inbound Presence

Upon receiving presence from the user, the contact's server MUST deliver the user's presence stanza to all of the contact's available resources.

[ ... to resource1 ... ]

CS: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

[ ... to resource2 ... ]

CS: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'/>

If there is no such contact, the contact's server MUST silently ignore the presence stanza.



 TOC 

4.2.4.  Client Processing of Inbound Presence

When the contact's client receives presence from the user, it SHOULD proceed as follows:

  1. If the user is in the contact's roster, the client MUST display the presence information in an appropriate roster interface.
  2. If the user is not in the contact's roster but the contact and the user are actively exchanging message or IQ stanzas, the contact's client SHOULD display the presence information in the user interface for that chat session (see also Section 4.6 (Directed Presence) and Section 5.1 (One-to-One Chat Sessions)).
  3. Otherwise, the client MUST ignore the presence information and not display it to the contact.



 TOC 

4.3.  Presence Probes

A PRESENCE PROBE is a request for a contact's current presence information, sent on behalf of a user by the user's server; syntactically it is a presence stanza whose 'type' attribute has a value of "probe". The value of the 'from' address MUST be the full JID <user@domain/resource> of the user and the value of the 'to' address MUST be the bare JID <contact@domain> of the contact to which the user is subscribed.

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'
              type='probe'/>

A presence probe SHOULD NOT be sent by a client. Instead, it is designed to be sent by a user's server on the user's behalf in order to discover the availability of the user's contacts.

If a server receives a presence probe intended for a full JID <contact@domain/resource>, it SHOULD treat the probe as if the 'to' address was a bare JID, but MAY instead handle it on behalf of the connected resource by returning only the presence information for that particular resources (and in any case MUST NOT deliver it to the resource).



 TOC 

4.3.1.  Server Generation of Outbound Presence Probe

When a server needs to discover the availability of a user's contact, it sends a presence probe from the full JID <user@domain/resource> of the user to the bare JID <contact@domain> of the contact. The server MUST NOT send a probe to a contact if the user is not subscribed to the contact's presence (i.e., if the contact is not in the user's roster with the 'subscription' attribute set to a value of "to" or "both".

The user's server SHOULD send a presence probe whenever the user starts a new presence session by sending initial presence; however, the server MAY choose not to send the probe at that point if it has what it deems to be reliable and up-to-date presence information about the user's contacts (e.g., because the user has another available resource or because the user briefly logged off and on before the new presence session began). In addition, a server MAY periodically send a presence probe to a contact if it has not received presence information or other traffic from the contact in some configurable amount of time; this can help to prevent "ghost" contacts who appear to be online but in fact are not.

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'
              type='probe'/>

US: <presence from='juliet@example.com/balcony'
              to='benvolio@example.net'
              type='probe'/>

Naturally, the user's server does not need to send a presence probe to a contact if the contact's account resides on the same server as the user, since the server possesses contact's information locally.



 TOC 

4.3.2.  Server Processing of Inbound Presence Probe

Upon receiving a presence probe from the user's server on behalf of the user, the contact's server SHOULD reply as follows:

  1. If the contact account does not exist or the user is in the contact's roster with a subscription state other than "From", "From + Pending Out", or "Both" (as defined under Appendix A (Subscription States)), the contact's server MUST return a presence stanza of type "unsubscribed" in response to the presence probe (however, if a server receives a presence probe from a configured hostname of the server itself or another such trusted service, it MAY provide presence information about the user to that entity).
    CS: <presence from='mercutio@example.com'
                  to='juliet@example.com'
                  type='unsubscribed'/>
    
  2. Else, if the contact has no available resources, the server SHOULD reply to the presence probe by sending to the user the full XML of the last presence stanza of type "unavailable" received by the server from the contact (however, the server MAY opt to not reply at all).
  3. Else, if the contact has at least one available resource, the server MUST reply to the presence probe by sending to the user the full XML of the last presence stanza with no 'to' attribute received by the server from each of the contact's available resources.
    CS: <presence from='romeo@example.net/foo'
                  to='juliet@example.com'/>
    
    CS: <presence from='romeo@example.net/bar'
                  to='juliet@example.com'>
          <show>away</show>
        </presence>
    



 TOC 

4.4.  Subsequent Presence Broadcast



 TOC 

4.4.1.  Client Generation of Presence Broadcast

After sending initial presence, the user's client can update its availability for broadcasting at any time during its session by sending a presence stanza with no 'to' address and no 'type' attribute.

UC: <presence>
      <show>away</show>
    </presence>

The presence broadcast MAY contain the <priority/> element, the <show/> element, and one or more instances of the <status/> element, as well as extended content.

However, a user SHOULD send a presence update only to broadcast information that is relevant to the user's availability for communication or the communication capabilities of the connected resource. Information that is not relevant in this way can be of interest to the user's contacts but SHOULD be sent via other means, such as the XMPP message stanza.



 TOC 

4.4.2.  Server Processing of Outbound Presence

Upon receiving a presence stanza expressing updated availability, the user's server MUST broadcast the full XML of that presence stanza to the contacts who meet all of the following criteria:

  1. The contact is in the user's roster with a subscription type of "from" or "both".
  2. The last presence stanza received from the contact during the user's presence session was not of type "error" or "unsubscribe".

As an optimization, if the subscription type is "both", the server SHOULD send subsequent presence notifications to a contact only if the contact is online according to the user's server. That is, if the user's server never received a positive indication that the contact is online in response to the presence probe it sent to the contact or if the last presence stanza it received from the contact during the user's presence session was of type "unavailable", the user's server SHOULD NOT send subsequent presence notifications from the user to the contact. This optimization helps to save bandwidth, since most presence subscriptions are bidirectional and many contacts will not be online at any given time.

US: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'>
      <show>away</show>
    </presence>

US: <presence from='juliet@example.com/balcony'
              to='benvolio@example.net'>
      <show>away</show>
    </presence>

US: <presence from='juliet@example.com/balcony'
              to='mercutio@example.com'>
      <show>away</show>
    </presence>

See Section 4.6 (Directed Presence) regarding rules that supplement the foregoing for handling of directed presence.

The user's server MUST also send the presence stanza to all of the user's available resources (including the resource that generated the presence notification in the first place).

US: <presence from='juliet@example.com/balcony'
              to='juliet@example.com/chamber'>
      <show>away</show>
    </presence>

US: <presence from='juliet@example.com/balcony'
              to='juliet@example.com/balcony'>
      <show>away</show>
    </presence>


 TOC 

4.4.3.  Server Processing of Inbound Presence

Upon receiving presence from the user, the contact's server MUST deliver the user's presence stanza to all of the contact's available resources.

[ ... to resource1 ... ]

CS: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'>
      <show>away</show>
    </presence>

[ ... to resource2 ... ]

CS: <presence from='juliet@example.com/balcony'
              to='romeo@example.net'>
      <show>away</show>
    </presence>


 TOC 

4.4.4.  Client Processing of Inbound Presence

When the contact's client receives presence from the user, it SHOULD proceed as follows:

  1. If the user is in the contact's roster, the client MUST display the presence information in an appropriate roster interface.
  2. If the user is not in the contact's roster but the contact and the user are actively exchanging message or IQ stanzas, the contact's client SHOULD display the presence information in the user interface for that chat session (see also Section 4.6 (Directed Presence) and Section 5.1 (One-to-One Chat Sessions)).
  3. Otherwise, the client MUST ignore the presence information and not display it to the contact.



 TOC 

4.5.  Unavailable Presence



 TOC 

4.5.1.  Client Generation of Unavailable Presence

Before ending its presence session with a server, the user's client SHOULD gracefully become unavailable by sending UNAVAILABLE PRESENCE, i.e., a presence stanza that possesses no 'to' attribute and that possesses a 'type' attribute whose value is "unavailable".

UC: <presence type='unavailable'/>

Optionally, the unavailable presence stanza MAY contain one or more <status/> elements specifying the reason why the user is no longer available.

US: <presence type='unavailable'>
      <status>going on vacation</status>
    </presence>

However, the unavailable presence stanza MUST NOT contain the <priority/≫ element or the <show/> element, since these elements apply only to available presence.



 TOC 

4.5.2.  Server Processing of Outbound Unavailable Presence

The user's server MUST NOT depend on receiving unavailable presence from an available resource, since the resource can become unavailable ungracefully (e.g., the resource can be timed out by the server because of inactivity).

If an available resource becomes unavailable for any reason (either gracefully or ungracefully), the user's server MUST broadcast unavailable presence to all contacts that meet all of the following criteria:

  1. The contact is in the user's roster with a subscription type of "from" or "both".
  2. The last presence stanza received from the contact during the user's presence session was not of type "error" or "unsubscribe".

See Section&n