Internet DRAFT - draft-saintandre-rfc3921bis

draft-saintandre-rfc3921bis






Network Working Group                                P. Saint-Andre, Ed.
Internet-Draft                                 XMPP Standards Foundation
Obsoletes: 3921 (if approved)                               June 6, 2008
Intended status: Standards Track
Expires: December 8, 2008


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

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 December 8, 2008.

Abstract

   This document describes 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.







Saint-Andre             Expires December 8, 2008                [Page 1]

Internet-Draft                   XMPP IM                       June 2008


Table of Contents

   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  5
     1.1.  Overview . . . . . . . . . . . . . . . . . . . . . . . . .  5
     1.2.  Requirements . . . . . . . . . . . . . . . . . . . . . . .  5
     1.3.  Functional Summary . . . . . . . . . . . . . . . . . . . .  6
     1.4.  Conventions  . . . . . . . . . . . . . . . . . . . . . . .  7
     1.5.  Discussion Venue . . . . . . . . . . . . . . . . . . . . .  7
   2.  Managing the Roster  . . . . . . . . . . . . . . . . . . . . .  8
     2.1.  Syntax and Semantics . . . . . . . . . . . . . . . . . . .  8
       2.1.1.  Items  . . . . . . . . . . . . . . . . . . . . . . . .  8
       2.1.2.  Roster Get . . . . . . . . . . . . . . . . . . . . . .  8
       2.1.3.  Roster Set . . . . . . . . . . . . . . . . . . . . . .  9
       2.1.4.  Roster Push  . . . . . . . . . . . . . . . . . . . . .  9
       2.1.5.  Roster Result  . . . . . . . . . . . . . . . . . . . . 10
       2.1.6.  Subscription Attribute . . . . . . . . . . . . . . . . 10
     2.2.  Retrieving the Roster on Login . . . . . . . . . . . . . . 11
     2.3.  Adding a Roster Item . . . . . . . . . . . . . . . . . . . 12
       2.3.1.  Success Case . . . . . . . . . . . . . . . . . . . . . 12
       2.3.2.  Error Cases  . . . . . . . . . . . . . . . . . . . . . 14
     2.4.  Updating a Roster Item . . . . . . . . . . . . . . . . . . 17
       2.4.1.  Success Case . . . . . . . . . . . . . . . . . . . . . 17
       2.4.2.  Error Cases  . . . . . . . . . . . . . . . . . . . . . 19
     2.5.  Deleting a Roster Item . . . . . . . . . . . . . . . . . . 19
       2.5.1.  Success Case . . . . . . . . . . . . . . . . . . . . . 19
       2.5.2.  Error Cases  . . . . . . . . . . . . . . . . . . . . . 20
   3.  Managing Presence Subscriptions  . . . . . . . . . . . . . . . 20
     3.1.  Requesting a Subscription  . . . . . . . . . . . . . . . . 21
       3.1.1.  Client Generation of Outbound Subscription Request . . 21
       3.1.2.  Server Processing of Outbound Subscription Request . . 22
       3.1.3.  Server Processing of Inbound Subscription Request  . . 23
       3.1.4.  Client Processing of Inbound Subscription Request  . . 24
       3.1.5.  Server Processing of Outbound Subscription Approval  . 25
       3.1.6.  Server Processing of Inbound Subscription Approval . . 26
     3.2.  Cancelling a Subscription  . . . . . . . . . . . . . . . . 27
       3.2.1.  Client Generation of Subscription Cancellation . . . . 27
       3.2.2.  Server Processing of Outbound Subscription
               Cancellation . . . . . . . . . . . . . . . . . . . . . 27
       3.2.3.  Server Processing of Inbound Subscription
               Cancellation . . . . . . . . . . . . . . . . . . . . . 28
     3.3.  Unsubscribing  . . . . . . . . . . . . . . . . . . . . . . 29
       3.3.1.  Client Generation of Unsubscribe . . . . . . . . . . . 29
       3.3.2.  Server Processing of Outbound Unsubscribe  . . . . . . 29
       3.3.3.  Server Processing of Inbound Unsubscribe . . . . . . . 30
   4.  Exchanging Presence Information  . . . . . . . . . . . . . . . 31
     4.1.  Overview . . . . . . . . . . . . . . . . . . . . . . . . . 31
     4.2.  Initial Presence . . . . . . . . . . . . . . . . . . . . . 31
       4.2.1.  Client Generation of Initial Presence  . . . . . . . . 31



Saint-Andre             Expires December 8, 2008                [Page 2]

Internet-Draft                   XMPP IM                       June 2008


       4.2.2.  Server Processing of Outbound Presence . . . . . . . . 32
       4.2.3.  Server Processing of Inbound Presence  . . . . . . . . 33
       4.2.4.  Client Processing of Inbound Presence  . . . . . . . . 33
     4.3.  Presence Probes  . . . . . . . . . . . . . . . . . . . . . 33
       4.3.1.  Server Generation of Outbound Presence Probe . . . . . 34
       4.3.2.  Server Processing of Inbound Presence Probe  . . . . . 34
     4.4.  Subsequent Presence Broadcast  . . . . . . . . . . . . . . 35
       4.4.1.  Client Generation of Presence Broadcast  . . . . . . . 35
       4.4.2.  Server Processing of Outbound Presence . . . . . . . . 36
       4.4.3.  Server Processing of Inbound Presence  . . . . . . . . 37
       4.4.4.  Client Processing of Inbound Presence  . . . . . . . . 37
     4.5.  Unavailable Presence . . . . . . . . . . . . . . . . . . . 37
       4.5.1.  Client Generation of Unavailable Presence  . . . . . . 37
       4.5.2.  Server Processing of Outbound Unavailable Presence . . 38
       4.5.3.  Server Processing of Inbound Unavailable Presence  . . 39
       4.5.4.  Client Processing of Inbound Unavailable Presence  . . 39
     4.6.  Directed Presence  . . . . . . . . . . . . . . . . . . . . 40
       4.6.1.  Client Generation of Directed Presence . . . . . . . . 40
       4.6.2.  Server Processing of Outbound Directed Presence  . . . 40
       4.6.3.  Server Processing of Inbound Directed Presence . . . . 41
       4.6.4.  Client Processing of Inbound Directed Presence . . . . 41
     4.7.  Presence Syntax  . . . . . . . . . . . . . . . . . . . . . 41
       4.7.1.  Type Attribute . . . . . . . . . . . . . . . . . . . . 41
       4.7.2.  Child Elements . . . . . . . . . . . . . . . . . . . . 42
       4.7.3.  Show Element . . . . . . . . . . . . . . . . . . . . . 42
       4.7.4.  Status Element . . . . . . . . . . . . . . . . . . . . 43
       4.7.5.  Priority Element . . . . . . . . . . . . . . . . . . . 44
       4.7.6.  Extended Content . . . . . . . . . . . . . . . . . . . 44
   5.  Exchanging Messages  . . . . . . . . . . . . . . . . . . . . . 45
     5.1.  Attributes . . . . . . . . . . . . . . . . . . . . . . . . 45
       5.1.1.  To Attribute . . . . . . . . . . . . . . . . . . . . . 45
       5.1.2.  Type Attribute . . . . . . . . . . . . . . . . . . . . 46
     5.2.  Child Elements . . . . . . . . . . . . . . . . . . . . . . 47
       5.2.1.  Body . . . . . . . . . . . . . . . . . . . . . . . . . 47
       5.2.2.  Subject  . . . . . . . . . . . . . . . . . . . . . . . 48
       5.2.3.  Thread . . . . . . . . . . . . . . . . . . . . . . . . 49
     5.3.  Extended Content . . . . . . . . . . . . . . . . . . . . . 50
     5.4.  One-to-One Chat Sessions . . . . . . . . . . . . . . . . . 51
   6.  Exchanging IQ Stanzas  . . . . . . . . . . . . . . . . . . . . 51
   7.  A Sample Session . . . . . . . . . . . . . . . . . . . . . . . 52
   8.  Server Rules for Processing XML Stanzas  . . . . . . . . . . . 59
     8.1.  No Such User . . . . . . . . . . . . . . . . . . . . . . . 59
     8.2.  Full JID at Local Domain . . . . . . . . . . . . . . . . . 59
       8.2.1.  Available Resource Matches . . . . . . . . . . . . . . 59
       8.2.2.  No Available Resource Matches  . . . . . . . . . . . . 60
     8.3.  Bare JID at Local Domain . . . . . . . . . . . . . . . . . 60
       8.3.1.  Available Resources  . . . . . . . . . . . . . . . . . 60
         8.3.1.1.  Message  . . . . . . . . . . . . . . . . . . . . . 60



Saint-Andre             Expires December 8, 2008                [Page 3]

Internet-Draft                   XMPP IM                       June 2008


         8.3.1.2.  Presence . . . . . . . . . . . . . . . . . . . . . 61
         8.3.1.3.  IQ . . . . . . . . . . . . . . . . . . . . . . . . 61
       8.3.2.  No Available Resources . . . . . . . . . . . . . . . . 61
         8.3.2.1.  Message  . . . . . . . . . . . . . . . . . . . . . 62
         8.3.2.2.  Presence . . . . . . . . . . . . . . . . . . . . . 62
         8.3.2.3.  IQ . . . . . . . . . . . . . . . . . . . . . . . . 62
     8.4.  Foreign Domain . . . . . . . . . . . . . . . . . . . . . . 63
   9.  IM and Presence Compliance Requirements  . . . . . . . . . . . 64
     9.1.  Servers  . . . . . . . . . . . . . . . . . . . . . . . . . 64
     9.2.  Clients  . . . . . . . . . . . . . . . . . . . . . . . . . 64
   10. Internationalization Considerations  . . . . . . . . . . . . . 65
   11. Security Considerations  . . . . . . . . . . . . . . . . . . . 65
   12. IANA Considerations  . . . . . . . . . . . . . . . . . . . . . 66
     12.1. Instant Messaging SRV Protocol Label Registration  . . . . 66
     12.2. Presence SRV Protocol Label Registration . . . . . . . . . 66
   13. References . . . . . . . . . . . . . . . . . . . . . . . . . . 67
     13.1. Normative References . . . . . . . . . . . . . . . . . . . 67
     13.2. Informative References . . . . . . . . . . . . . . . . . . 68
   Appendix A.  Subscription States . . . . . . . . . . . . . . . . . 69
     A.1.  Defined States . . . . . . . . . . . . . . . . . . . . . . 69
     A.2.  Server Processing of Outbound Presence Subscription
           Stanzas  . . . . . . . . . . . . . . . . . . . . . . . . . 70
       A.2.1.  Subscribe  . . . . . . . . . . . . . . . . . . . . . . 71
       A.2.2.  Unsubscribe  . . . . . . . . . . . . . . . . . . . . . 71
       A.2.3.  Subscribed . . . . . . . . . . . . . . . . . . . . . . 72
       A.2.4.  Unsubscribed . . . . . . . . . . . . . . . . . . . . . 72
     A.3.  Server Processing of Inbound Presence Subscription
           Stanzas  . . . . . . . . . . . . . . . . . . . . . . . . . 73
       A.3.1.  Subscribe  . . . . . . . . . . . . . . . . . . . . . . 73
       A.3.2.  Unsubscribe  . . . . . . . . . . . . . . . . . . . . . 73
       A.3.3.  Subscribed . . . . . . . . . . . . . . . . . . . . . . 74
       A.3.4.  Unsubscribed . . . . . . . . . . . . . . . . . . . . . 75
   Appendix B.  Blocking Communication  . . . . . . . . . . . . . . . 76
   Appendix C.  vCards  . . . . . . . . . . . . . . . . . . . . . . . 76
   Appendix D.  XML Schemas . . . . . . . . . . . . . . . . . . . . . 76
     D.1.  jabber:client  . . . . . . . . . . . . . . . . . . . . . . 76
     D.2.  jabber:server  . . . . . . . . . . . . . . . . . . . . . . 80
     D.3.  jabber:iq:roster . . . . . . . . . . . . . . . . . . . . . 85
   Appendix E.  Differences From RFC 3921 . . . . . . . . . . . . . . 86
   Appendix F.  Copying Conditions  . . . . . . . . . . . . . . . . . 86
   Index  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
   Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 87
   Intellectual Property and Copyright Statements . . . . . . . . . . 89








Saint-Andre             Expires December 8, 2008                [Page 4]

Internet-Draft                   XMPP IM                       June 2008


1.  Introduction

1.1.  Overview

   The Extensible Messaging and Presence Protocol (XMPP) is an
   application profile of the Extensible Markup Language [XML] 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]
   provide the building blocks for many types of near-real-time
   applications, which may be layered on top of the core by sending
   application-specific data qualified by particular XML namespaces
   (refer to [XML-NAMES]).  This document describes XMPP extensions that
   provide the basic functionality expected of an instant messaging (IM)
   and presence application as defined in [IMP-REQS].

   This document obsoletes RFC 3921.

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 each of one's contacts in
       close to real time -- often relatively large numbers of such
       messages in rapid succession, in the form of one-to-one chat
       sessions as described under Section 5.4.
   3.  The catalyst for exchanging messages is PRESENCE -- i.e.,
       information about the network availability of each of one's
       contacts (thus knowing who is online and available for a one-to-
       one chat session).
   4.  Presence information is provided only to contacts that a user has
       authorized via a presence subscription.

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

   o  Manage items in one's contact list
   o  Exchange messages with one's contacts
   o  Exchange presence information with one's contacts
   o  Manage presence subscriptions to and from one's contacts

   Detailed definitions of these functionality areas are contained in
   RFC 2779 [IMP-REQS], and the interested reader is referred to that



Saint-Andre             Expires December 8, 2008                [Page 5]

Internet-Draft                   XMPP IM                       June 2008


   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]), such extensions are not specified in this
   document because they are not required 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/> error if a client attempt to send a <message/>
   stanzas.)

1.3.  Functional Summary

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

   [XMPP-CORE] 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], mandatory authentication via Simple Authentication
   and Security Layer [SASL], and binding of a resource to the stream
   for client addressing.  The reader is referred to [XMPP-CORE] for
   details regarding these preconditions, and knowledge of [XMPP-CORE]
   is assumed herein.

   Upon fulfillment of the preconditions specified in [XMPP-CORE], an
   XMPP client has a long-lived XML stream with an XMPP server, which
   enables the user 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



Saint-Andre             Expires December 8, 2008                [Page 6]

Internet-Draft                   XMPP IM                       June 2008


   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.)
   2.  Send initial presence to the server for broadcasting to all
       subscribed contacts, thus "going online" from the perspective of
       XMPP communications.  (See Section 4.2.)
   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, Section 3, Section 2, and Section 6.)
   4.  Terminate the session when desired by sending unavailable
       presence and closing the underlying XML stream.  (See
       Section 4.5.)

1.4.  Conventions

   This document inherits the terminology defined in [XMPP-CORE].

   The following keywords are to be interpreted as described in [TERMS]:
   "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 may be bots, devices, or other non-human
   applications.

   In examples, lines have been wrapped for improved readability,
   "[...]" means elision, and the following prepended strings are used:

   o  C: = client
   o  CC: = contact's client
   o  CS: = contact's server
   o  S: = server
   o  UC: = user's client
   o  US: = user's server

1.5.  Discussion Venue

   The editor welcomes 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>>.





Saint-Andre             Expires December 8, 2008                [Page 7]

Internet-Draft                   XMPP IM                       June 2008


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 may access roster information from any resource.

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.

2.1.1.  Items

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

   The syntax of the <item/> is as follows:

   1.  The 'jid' attribute is REQUIRED; the value of this attribute is
       Jabber Identifier (JID) that uniquely identifies the roster item.
   2.  The 'name' attribute is OPTIONAL; the value of this attribute
       specifies the "handle" to be associated with the JID, as
       determined by the user (not the contact).  While the value of the
       'name' attribute may have meaning to a human user, typically it
       is opaque to the server (although it MAY be used by the server
       for matching purposes within the context of various XMPP
       extensions).
   3.  The 'subscription' attribute is OPTIONAL; see Section 2.1.6.
   4.  The 'ask' attribute is OPTIONAL and is used to specify certain
       subscription sub-states; for details, see Section 3.1.2.
   5.  The <group/> element is OPTIONAL; the XML character data of this
       element specifies a category into which the roster item should be
       grouped by a client.  The <item/> MAY contain more than one
       <group/> element.  The XML character data of the <group/> element
       is typically opaque to the server but may have meaning to a human
       user.

2.1.2.  Roster Get

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

   The <query/> element in a roster get MUST NOT contain any <item/>
   child elements.




Saint-Andre             Expires December 8, 2008                [Page 8]

Internet-Draft                   XMPP IM                       June 2008


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

2.1.3.  Roster Set

   A ROSTER SET 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.  A receiving server MUST ignore any value of the 'subscription'
       attribute other than "remove" (see Section 2.1.6).
   3.  A receiving 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'
          type='set'
          id='roster_set'>
       <query xmlns='jabber:iq:roster'>
         <item jid='nurse@example.com'/>
       </query>
     </iq>

2.1.4.  Roster Push

   A ROSTER PUSH 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 server) or it has a 'from'
       attribute whose value matches the user's bare JID <user@domain>.








Saint-Andre             Expires December 8, 2008                [Page 9]

Internet-Draft                   XMPP IM                       June 2008


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

2.1.5.  Roster Result

   A ROSTER RESULT 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 MAY contain more than one <item/>
   element.

   S: <iq to='juliet@example.com/chamber'
          type='result'
          id='roster_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'
          type='result'
          id='roster_result'>
       <query xmlns='jabber:iq:roster'/>
     </iq>

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:

   o  "none" -- the user does not have a subscription to the contact's
      presence, and the contact does not have a subscription to the
      user's presence
   o  "to" -- the user has a subscription to the contact's presence, but
      the contact does not have a subscription to the user's presence




Saint-Andre             Expires December 8, 2008               [Page 10]

Internet-Draft                   XMPP IM                       June 2008


   o  "from" -- the contact has a subscription to the user's presence,
      but the user does not have a subscription to the contact's
      presence
   o  "both" -- both the user and the contact have subscriptions to each
      other's presence (also called a "mutual subscription")

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

   In a roster push, a receiving 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
   "remove", which indicates that the item is to be removed from the
   roster; a receiving server MUST ignore all values of the
   'subscription' attribute other than "remove".

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 may not be desirable for all resources, e.g., a connection
   with limited bandwidth, the client's request for the roster is
   recommended and not required).  After a connected resource sends
   initial presence (see Section 4.2), it is referred to as an available
   resource.  If a connected resource requests the roster but does not
   send initial presence, the server MUST NOT send it presence
   subscription requests and SHOULD NOT send it associated roster
   pushes.  If an available resource does not request the roster during
   a session, the server SHOULD NOT send it presence subscription
   requests and MUST NOT send it associated roster pushes.  Therefore,
   if a client wishes to engage in the full range of interactions
   related to contact lists (rosters) and presence subscriptions, it
   SHOULD both request the roster and send initial presence.  For the
   sake of brevity, the term INTERESTED RESOURCE is used herein to refer
   to the concept of "an available resource that has requested 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' type='get' id='roster_1'>
       <query xmlns='jabber:iq:roster'/>
     </iq>





Saint-Andre             Expires December 8, 2008               [Page 11]

Internet-Draft                   XMPP IM                       June 2008


   S: <iq to='juliet@example.com/balcony' type='result' id='roster_1'>
       <query xmlns='jabber:iq:roster'>
         <item jid='romeo@example.net'
               name='Romeo'
               subscription='both'>
           <group>Friends</group>
         </item>
         <item jid='mercutio@example.org'
               name='Mercutio'
               subscription='from'/>
         <item jid='nurse@example.com'
               name='Nurse'
               subscription='to'/>
         <item jid='benvolio@example.org'
               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] (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).

2.3.  Adding a Roster Item

2.3.1.  Success Case

   At any time, a client may add an item to the roster by sending a
   roster set to the server.

   Note: When the item added represents another IM user, the value of
   the 'jid' 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.

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

   If the server can successfully process the roster set (i.e., if none



Saint-Andre             Expires December 8, 2008               [Page 12]

Internet-Draft                   XMPP IM                       June 2008


   of the error cases occurs), it MUST create the roster item in
   persistent storage and send a roster push containing the new roster
   item to all of the user's interested resources.

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

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

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

   As required by the semantics of the IQ stanza as defined in
   [XMPP-CORE], each resource that received the roster push MUST reply
   with an IQ stanza of type "result" (or "error").

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

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




Saint-Andre             Expires December 8, 2008               [Page 13]

Internet-Draft                   XMPP IM                       June 2008


2.3.2.  Error Cases

   If the server cannot successfully process the roster set, it MUST
   return an error.  The following error cases are defined (naturally,
   other stanza errors may occur, e.g., <internal-server-error/>).

   The server SHOULD return a <bad-request/> 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]).

   The server SHOULD return a <not-acceptable/> 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).




















Saint-Andre             Expires December 8, 2008               [Page 14]

Internet-Draft                   XMPP IM                       June 2008


   Error: Roster set contains more than one item

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

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














Saint-Andre             Expires December 8, 2008               [Page 15]

Internet-Draft                   XMPP IM                       June 2008


   Error: Roster set contains duplicate groups

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

   S: <iq to='juliet@example.com/balcony' type='error' id='roster_5'>
        <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' type='set' id='roster_6'>
        <query xmlns='jabber:iq:roster'>
          <item jid='nurse@example.com'
                name='Nurse'>
            <group></group>
          </item>
        </query>
      </iq>

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

















Saint-Andre             Expires December 8, 2008               [Page 16]

Internet-Draft                   XMPP IM                       June 2008


   Error: Roster set contains oversized group

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

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

   The server MUST return a <not-allowed/> 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' type='set' id='roster_8'>
        <query xmlns='jabber:iq:roster'>
          <item jid='juliet@example.com'/>
         </query>
       </iq>

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

2.4.  Updating a Roster Item

2.4.1.  Success Case

   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 shall be updated exactly as
   provided in the roster set.

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





Saint-Andre             Expires December 8, 2008               [Page 17]

Internet-Draft                   XMPP IM                       June 2008


   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 may want to add the item to
   another group.

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

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

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

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

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

   The user may then want to remove the handle altogether (note:



Saint-Andre             Expires December 8, 2008               [Page 18]

Internet-Draft                   XMPP IM                       June 2008


   including an empty 'name' attribute is equivalent to including no
   'name' attribute).

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

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

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

   As with adding a roster item, when updating a roster item 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.

2.4.2.  Error Cases

   The error cases described under Section 2.3.2 also apply to updating
   a roster item.

2.5.  Deleting a Roster Item

2.5.1.  Success Case

   At any time, a client may 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' type='set' id='delete_1'>
        <query xmlns='jabber:iq:roster'>
          <item jid='nurse@example.com' subscription='remove'/>
        </query>
      </iq>

   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



Saint-Andre             Expires December 8, 2008               [Page 19]

Internet-Draft                   XMPP IM                       June 2008


   value of "remove"), and send an IQ result to the initiating resource;
   for details, see Section 2.3.

   The server MUST also generate a presence stanza of type "unsubscribe"
   and a presence stanza of type "unsubscribed" from the user to the
   contact.

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

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

2.5.2.  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/> error.

   Error: Roster item not found

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

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


3.  Managing Presence Subscriptions

   In order to protect the privacy of instant messaging users, presence
   information is disclosed only to other entities that the user has
   approved.  When a user has agreed that another entity may 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 less strict sense to
   refer to a potential contact or an item in a user's roster).



Saint-Andre             Expires December 8, 2008               [Page 20]

Internet-Draft                   XMPP IM                       June 2008


   In XMPP, a subscription lasts across 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").

   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; those details are not provided in this
   section, which simply narrates the protocol flows for common use
   cases related to presence subscriptions.

   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>.  This rule helps to prevent presence
   leaks; for details, see the security considerations of [XMPP-CORE].

3.1.  Requesting a Subscription

   A SUBSCRIPTION REQUEST 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.

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'/>

   A user's client SHOULD NOT send a presence subscription to a full JID
   <contact@domain/resource>.

   Typically the user's client prompts the user for information about
   the potential contact ("handle" and desired roster group) and
   generates a roster set with that information before sending the
   subscription request, but that behavior is recommended rather than
   required.






Saint-Andre             Expires December 8, 2008               [Page 21]

Internet-Draft                   XMPP IM                       June 2008


3.1.2.  Server Processing of Outbound Subscription Request

   As mentioned, 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'/>

   Note: If the subscription request is directed to a full JID
   <contact@domain/resource> instead of a bare JID <contact@domain>, the
   user's server MAY treat it as if the request had been directed to the
   contact's bare JID and modify the 'to' address accordingly.  This
   simplifies processing of presence subscriptions.

   If the potential contact is hosted on the same server, the server
   MUST adhere to the rules specified in the next section in processing
   the subscription request and delivering it to the (local) contact.

   If the potential contact is hosted on a different server, the user's
   server then routes the stanza to that foreign domain in accordance
   with core XMPP stanza processing rules.

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

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



Saint-Andre             Expires December 8, 2008               [Page 22]

Internet-Draft                   XMPP IM                       June 2008


   Note: Because the server must send this roster push, a client MAY
   simply wait for the roster push rather than proactively adding the
   contact to the user's roster before sending the subscription request.

   Note: 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
   may have occurred in relation to the original subscription request.

3.1.3.  Server Processing of Inbound Subscription Request

   The contact's server MUST adhere to the following rules when
   processing the inbound subscription request:

   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 interested resource(s)
       for approval or denial by the contact.
   2.  If the contact does not exist, 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 SHOULD 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), then the contact's server MAY 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
       interested resource associated with the contact when the
       subscription request is received by the contact's server, the
       contact's server MUST broadcast that subscription request to all
       interested resources in accordance with Server Rules for
       Processing XML Stanzas (Section 8).





Saint-Andre             Expires December 8, 2008               [Page 23]

Internet-Draft                   XMPP IM                       June 2008


   5.  If the contact exists, the user does not already have a
       subscription to the contact's presence, and the contact has no
       interested resources when the subscription request is received by
       the contact's server, 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 interested resource.  The
       contact's server MUST continue to deliver the subscription
       request whenever the contact creates an interested 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
       interested 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
       interested resource; this helps to prevent "subscription request
       spam".)

   Note: If the subscription request is directed to a full JID
   <contact@domain/resource> instead of a bare JID <contact@domain>, the
   contact's server MAY treat it as if the request had been directed to
   the contact's bare JID.  This simplifies processing of presence
   subscriptions.

   Note: Until and unless the contact approves the subscription request
   as described under Section 3.1.4, the contact's server MUST NOT add
   an item for the user to the contact's roster.

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'/>

   Note: Before approving a presence subscription, the contact MAY
   generate a roster set that includes a handle for the user and that
   places the user in one or more roster groups; see Section 2.3.

   A subscription request is denied by sending a presence stanza of type



Saint-Andre             Expires December 8, 2008               [Page 24]

Internet-Draft                   XMPP IM                       June 2008


   "unsubscribed", which is processed as described under Section 3.2 for
   both the contact's server and the user's server.

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

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 route or deliver 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 to='juliet@example.com/balcony'
           type='set'
           id='a78b4q6ha463'>
         <query xmlns='jabber:iq:roster'>
           <item jid='romeo@example.net'
                 subscription='from'/>
         </query>
       </iq>

   CS: <iq to='juliet@example.com/chamber'
           type='set'
           id='a78b4q6ha464'>
         <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.



Saint-Andre             Expires December 8, 2008               [Page 25]

Internet-Draft                   XMPP IM                       June 2008


   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) and the roles will be reversed.

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 a
   subscription='none' or subscription='from' and the 'ask' flag set to
   "subscribe" (i.e., a subscription states of "None + Pending Out" or
   "From + Pending Out"; see Appendix A).  If the contact is not in the
   user's roster with either of those states, the user's server MUST
   silently ignore the presence stanza of type "subscribed" (i.e., it
   MUST NOT route it to the user, modify the user's roster, or generate
   a roster push to the user's interested resources).

   If the foregoing 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".

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

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

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




Saint-Andre             Expires December 8, 2008               [Page 26]

Internet-Draft                   XMPP IM                       June 2008


   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'/>

3.2.  Cancelling a Subscription

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'/>

3.2.2.  Server Processing of Outbound Subscription Cancellation

   As mentioned, 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'/>

   If the user is hosted on the same server, the server MUST adhere to
   the rules specified in the next section when processing the
   subscription cancellation.




Saint-Andre             Expires December 8, 2008               [Page 27]

Internet-Draft                   XMPP IM                       June 2008


   If the user is hosted on a different server, the contact's server
   then routes the stanza to that foreign domain in accordance with core
   XMPP stanza processing rules.

   If the user is in the contact's roster, 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).

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

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

3.2.3.  Server Processing of Inbound Subscription Cancellation

   When the user's server receives the inbound subscription
   cancellation, it MUST modify the subscription state and send a roster
   push to the user's interested resources, where the subscription state
   is now either "none" or "from" (see Appendix A).


















Saint-Andre             Expires December 8, 2008               [Page 28]

Internet-Draft                   XMPP IM                       June 2008


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

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

3.3.  Unsubscribing

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'/>

3.3.2.  Server Processing of Outbound Unsubscribe

   As mentioned, the user's server MUST stamp the outbound unsubscribe
   with the bare JID <user@domain> of the user.

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

   If the contact is hosted on the same server, the server MUST adhere
   to the rules specified in the next section when processing the
   unsubscribe.

   If the contact is hosted on a different server, the user's server
   then routes the stanza to that foreign domain in accordance with core
   XMPP stanza processing rules.

   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).



Saint-Andre             Expires December 8, 2008               [Page 29]

Internet-Draft                   XMPP IM                       June 2008


   US: <iq to='romeo@example.net/foo'
           type='set'
           id='h37h3u1bv402'>
         <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>

3.3.3.  Server Processing of Inbound Unsubscribe

   When the contact's server receives the inbound unsubscribe, it MUST
   modify the subscription state and send a roster push to the contact's
   interested resources, where the subscription state is now either
   "none" or "to" (see Appendix A).

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

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








Saint-Andre             Expires December 8, 2008               [Page 30]

Internet-Draft                   XMPP IM                       June 2008


4.  Exchanging Presence Information

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 principal's availability is signalled
   when a client controlled by the principal 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".  In XMPP-based
   applications that combine messaging and presence functionality, the
   default type of communication for which presence signals availability
   is messaging; however, XMPP-based applications are not required 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).

   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], 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 BROADCASTED PRESENCE.  (A client MAY 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 principal's presence; see
   Section 4.6.)

   After a client completes the preconditions specified in [XMPP-CORE],
   it can establish a PRESENCE SESSION at its server by sending initial
   presence (Section 4.2).  Such a presence session is terminated by
   sending unavailable presence (Section 4.5).

4.2.  Initial Presence

4.2.1.  Client Generation of Initial Presence

   After completing the preconditions described in [XMPP-CORE]
   (REQUIRED) and requesting the roster (RECOMMENDED), a client SHOULD



Saint-Andre             Expires December 8, 2008               [Page 31]

Internet-Draft                   XMPP IM                       June 2008


   signal 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 broadcasted by the server on
   behalf of the client) and no 'type' attribute (indicating the user's
   availability).  After sending initial presence, a connected resource
   (in the terminology of [XMPP-CORE]) is said to be an AVAILABLE
   RESOURCE.

   UC: <presence/>

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".

   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.com.

   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.com'/>

   The user's server MUST also broadcast initial presence from the
   user's newly available resource to all of the user's available
   resources.

   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 SHOULD also send presence probes to the user's contacts
   on behalf of the user as specified under Section 4.3.





Saint-Andre             Expires December 8, 2008               [Page 32]

Internet-Draft                   XMPP IM                       June 2008


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'/>

4.2.4.  Client Processing of Inbound Presence

   When the contact's client receives presence from the user and the
   user is in the contact's roster, it SHOULD display the presence
   information in an appropriate roster interface.

   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 and Section 5.4).

   Otherwise, the client SHOULD ignore the presence information and not
   display it to the contact.

4.3.  Presence Probes

   A PRESENCE PROBE is a presence stanza whose 'type' attribute has a
   value of "probe".  The value of the 'from' address SHOULD be the full
   JID <user@domain/resource> of the probing user and the value of the
   'to' address SHOULD be the bare JID <contact@domain> of the contact
   whose availability the user wants to discover.

   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'



Saint-Andre             Expires December 8, 2008               [Page 33]

Internet-Draft                   XMPP IM                       June 2008


   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).

4.3.1.  Server Generation of Outbound Presence Probe

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

   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.com'
                 type='probe'/>

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

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),
       the contact's server MUST return a presence stanza of type



Saint-Andre             Expires December 8, 2008               [Page 34]

Internet-Draft                   XMPP IM                       June 2008


       "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 (but MAY 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>

4.4.  Subsequent Presence Broadcast

4.4.1.  Client Generation of Presence Broadcast

   After sending initial presence, the user's client may 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>

   Note: A user SHOULD NOT send a presence update to broadcast
   information that changes independently of the user's availability for
   communication.







Saint-Andre             Expires December 8, 2008               [Page 35]

Internet-Draft                   XMPP IM                       June 2008


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
   MAY 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 received from the contact during the
   user's presence session was of type "unavailable", the user's server
   MAY opt not to send subsequent presence notifications from the user
   to the contact.

   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.com'>
         <show>away</show>
       </presence>

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

   The user's server MUST also send the presence stanza to all of the
   user's available resources.

   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>



Saint-Andre             Expires December 8, 2008               [Page 36]

Internet-Draft                   XMPP IM                       June 2008


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>

4.4.4.  Client Processing of Inbound Presence

   When the contact's client receives presence from the user and the
   user is in the contact's roster, it SHOULD display the presence
   information in an appropriate roster interface.

   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 and Section 5.4).

   Otherwise, the client SHOULD ignore the presence information and not
   display it to the contact.

4.5.  Unavailable Presence

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 final presence stanza MAY contain one or more
   <status/> elements specifying the reason why the user is no longer
   available.



Saint-Andre             Expires December 8, 2008               [Page 37]

Internet-Draft                   XMPP IM                       June 2008


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

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 may become unavailable
   ungracefully (e.g., the resource may 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".

   As an optimization, if the subscription type is "both", the server
   MAY send the unavailable presence notification 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 received from the contact
   during the user's presence session was of type "unavailable", the
   user's server MAY opt not to send the unavailable presence
   notification from the user to the contact.

   See Section 4.6 regarding rules that supplement the foregoing.

   If the unavailable presence stanza was gracefully received from the
   client, the server MUST broadcast the full XML of the presence
   stanza.

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

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

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



Saint-Andre             Expires December 8, 2008               [Page 38]

Internet-Draft                   XMPP IM                       June 2008


   The user's server MUST also send the unavailable presence stanza to
   all of the user's remaining available resources.

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

   Note: Any presence stanza with no 'type' attribute and no 'to'
   attribute that is sent after sending broadcasted unavailable presence
   MUST be broadcasted by the server to all subscribers (i.e., MUST be
   treated as equivalent to "initial presence" for a new presence
   session).

4.5.3.  Server Processing of Inbound Unavailable Presence

   Upon receiving unavailable 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'
                 type='unavailable'/>

   [ ... to resource2 ... ]

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

   If the server is optimizing subsequent presence delivery as described
   under Section 4.4, it SHOULD also note that the user is unavailable
   and appropriately update its internal representation of which users
   are online.

4.5.4.  Client Processing of Inbound Unavailable Presence

   When the contact's client receives unavailable presence from the user
   and the user is in the contact's roster, it SHOULD display the
   unavailable presence information in an appropriate roster interface.

   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 unavailable presence information in the
   user interface for that chat session (see also Section 4.6 and
   Section 5.4).




Saint-Andre             Expires December 8, 2008               [Page 39]

Internet-Draft                   XMPP IM                       June 2008


   Otherwise, the client SHOULD ignore the unavailable presence
   information and not display it to the contact.

4.6.  Directed Presence

   This section supplements and in some respects modifies the rules
   defined above, but only for the special case of directed presence.

4.6.1.  Client Generation of Directed Presence

   As noted, directed presence is a presence stanza with a 'to'
   attribute whose value is the bare JID or full JID of the other entity
   and with either no 'type' attribute (indicating availability) or a
   'type' attribute whose value is "unavailable".

   Information about the use of directed presence in the context of a
   one-to-one chat session is provided under Section 5.4.

4.6.2.  Server Processing of Outbound Directed Presence

   When the user's server receives the directed presence stanza, it
   SHOULD process it according to the following rules.

   1.  If the user sends directed available or unavailable presence to a
       contact that is in the user's roster with a subscription type of
       "from" or "both" after having sent initial presence and before
       sending broadcasted unavailable presence (i.e., during the user's
       presence session), the user's server MUST route or deliver the
       full XML of that presence stanza but SHOULD NOT otherwise modify
       the contact's status regarding broadcasted presence (i.e., it
       SHOULD include the contact's JID in any subsequent presence
       broadcasts initiated by the user).
   2.  If the user sends directed presence to an entity that is not in
       the user's roster with a subscription type of "from" or "both"
       after having sent initial presence and before sending broadcasted
       unavailable presence (i.e., during the user's presence session),
       the user's server MUST route or deliver the full XML of that
       presence stanza to the entity but MUST NOT modify the contact's
       status regarding available presence broadcast (i.e., it MUST NOT
       include the entity's JID in any subsequent broadcasts of
       available presence initiated by the user); however, if the
       available resource from which the user sent the directed presence
       become unavailable, the user's server MUST route that unavailable
       presence to the entity (if the user has not yet sent directed
       unavailable presence to that entity).
   3.  If the user sends directed presence without first sending initial
       presence or after having sent unavailable presence broadcast
       (i.e., the resource is connected but not available), the user's



Saint-Andre             Expires December 8, 2008               [Page 40]

Internet-Draft                   XMPP IM                       June 2008


       server MUST treat the entities to which the user sends directed
       presence in the same way that it treats the entities listed in
       case #2 above.

4.6.3.  Server Processing of Inbound Directed Presence

   From the perspective of the contact's server, there is no difference
   between broadcasted presence and directed presence, so the contact's
   server follows the existing rules for processing of inbound presence.

4.6.4.  Client Processing of Inbound Directed Presence

   When the contact's client receives presence from the user and the
   user is in the contact's roster, it SHOULD display the presence
   information in an appropriate roster interface.

   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 an appropriate user
   interface.

   Otherwise, the client SHOULD ignore the presence information and not
   display it to the contact.

4.7.  Presence Syntax

4.7.1.  Type Attribute

   The absence of a 'type' attribute signals that the relevant entity is
   available for communication (see Section 4.2 and Section 4.4).

   A 'type' attribute with a value of "unavailable" signals that the
   relevant entity is not available for communication (see Section 4.5).

   The XMPP presence stanza is also used to negotiate and manage
   subscriptions to the presence of other entities.  These tasks are
   completed via presence stanzas of type "subscribe", "unsubscribe",
   "subscribed", and "unsubscribed" as described under Section 3.

   If a user and contact are associated with different XMPP servers,
   those servers also use a special presence stanza of type "probe" in
   order to determine the availability of the entity on the peer server;
   for details, see Section 4.3.  Clients SHOULD NOT send presence
   stanzas of type "probe".

   The values of the 'type' attribute can be summarized as follows:





Saint-Andre             Expires December 8, 2008               [Page 41]

Internet-Draft                   XMPP IM                       June 2008


   o  error -- An error has occurred regarding processing of a
      previously-sent presence stanza; if the presence stanza is of type
      "error", it MUST include an <error/> child element (refer to
      [XMPP-CORE]).
   o  probe -- A request for an entity's current presence; SHOULD be
      generated only by a server on behalf of a user.
   o  subscribe -- The sender wishes to subscribe to the recipient's
      presence.
   o  subscribed -- The sender has allowed the recipient to receive
      their presence.
   o  unsubscribe -- The sender is unsubscribing from another entity's
      presence.
   o  unsubscribed -- The subscription request has been denied or a
      previously-granted subscription has been cancelled.
   o  unavailable -- Signals that the entity is no longer available for
      communication.

   If the value of the 'type' attribute is not one of the foregoing
   values, the recipient or an intermediate router SHOULD return a
   stanza error of <bad-request/>.

   Note: There is no default value for the 'type' attribute of the
   <presence/> element.  Therefore if the intended recipient or
   intermediate router receives a <presence/> element whose 'type' value
   is undefined, it SHOULD return a stanza error of <bad-request/>.

4.7.2.  Child Elements

   In accordance with the default namespace declaration, a presence
   stanza is qualified by the 'jabber:client' or 'jabber:server'
   namespace, which defines certain allowable children of presence
   stanzas, in particular the <show/>, <status/>, and <priority/>
   elements.  These child elements are used to provide more detailed
   information about an entity's availability.  Typically these child
   elements are provided only if the presence stanza possesses no 'type'
   attribute, although exceptions are noted in the text that follows.

4.7.3.  Show Element

   The OPTIONAL <show/> element specifies the particular availability
   sub-state of an entity or a specific resource thereof.  A presence
   stanza MUST NOT contain more than one <show/> element.  The <show/>
   element MUST NOT possess any attributes.  The XML character data of
   the <show/> element is not human-readable.  The XML character data
   MUST be one of the following (additional availability states could be
   defined through a properly-namespaced child element of the presence
   stanza):




Saint-Andre             Expires December 8, 2008               [Page 42]

Internet-Draft                   XMPP IM                       June 2008


   o  away -- The entity or resource is temporarily away.
   o  chat -- The entity or resource is actively interested in chatting.
   o  dnd -- The entity or resource is busy (dnd = "Do Not Disturb").
   o  xa -- The entity or resource is away for an extended period (xa =
      "eXtended Away").

   If no <show/> element is provided, the entity is assumed to be online
   and available.

   Any specialized processing of availability states by recipients and
   intermediate routers is up to the implementation (e.g., incorporation
   of availability states into server routing and delivery logic).

4.7.4.  Status Element

   The OPTIONAL <status/> element contains human-readable XML character
   data specifying a natural-language description of an entity's
   availability.  It is normally used in conjunction with the show
   element to provide a detailed description of an availability state
   (e.g., "In a meeting") when the presence stanza has no 'type'
   attribute.

   <presence from='romeo@example.net/orchard'
             xml:lang='en'>
     <show>dnd</show>
     <status>Wooing Juliet</status>
   </presence>

   The <status/> element MUST NOT possess any attributes, with the
   exception of the 'xml:lang' attribute.  Multiple instances of the
   <status/> element MAY be included, but only if each instance
   possesses an 'xml:lang' attribute with a distinct language value
   (either explicitly or by inheritance from the 'xml:lang' value of an
   element farther up in the XML hierarchy, which may include the XML
   stream header as described in [XMPP-CORE]).

   <presence from='romeo@example.net/orchard'
             xml:lang='en'>
     <show>dnd</show>
     <status>Wooing Juliet</status>
     <status xml:lang='cs'>Dvo&#x0159;&#x00ED;m se Julii</status>
   </presence>

   A presence stanza of type "unavailable" MAY also include a <status/>
   element to provide detailed information about why the entity is going
   offline.





Saint-Andre             Expires December 8, 2008               [Page 43]

Internet-Draft                   XMPP IM                       June 2008


   <presence from='romeo@example.net/orchard'
             type='unavailable'>
     <status>Busy IRL</status>
   </presence>

   The <status/> child MAY also be sent in a subscription-related
   presence stanza (i.e., type "subscribe", "subscribed", "unsubscribe",
   or "unsubscribed") to provide a description of the action.  The
   receiving client MAY present this <status/> to a human user (see
   Section 11).

   <presence from='romeo@example.net'
             to='nurse@example.com'
             type='subscribe'>
     <status>Hi, Juliet said I should add you to my buddy list.</status>
   </presence>

4.7.5.  Priority Element

   The OPTIONAL <priority/> element contains non-human-readable XML
   character data that specifies the priority level of the resource.
   The value MUST be an integer between -128 and +127.  A presence
   stanza MUST NOT contain more than one <priority/> element.  The
   <priority/> element MUST NOT possess any attributes.

   <presence xml:lang='en'>
     <show>dnd</show>
     <status>Wooing Juliet</status>
     <status xml:lang='cs'>Dvo&#x0159;&#x00ED;m se Julii</status>
     <priority>1</priority>
   </presence>

   If no priority is provided, the processing server or client SHOULD
   consider the priority to be zero.

   For information regarding the semantics of priority values in stanza
   processing within instant messaging and presence applications, refer
   to Server Rules for Processing XML Stanzas (Section 8).

4.7.6.  Extended Content

   As described in [XMPP-CORE], an XML stanza MAY contain any properly-
   namespaced child element; this applies to the presence stanza as
   well.

   (In the following example, the presence stanza includes entity
   capabilities information as defined in [XEP-0115]).)




Saint-Andre             Expires December 8, 2008               [Page 44]

Internet-Draft                   XMPP IM                       June 2008


   <presence from='romeo@example.net'>
     <c xmlns='http://jabber.org/protocol/caps'
        node='http://psi-im.org/caps'
        ver='0.11'/>
   </presence>

   Any extended content included in a presence stanza SHOULD represent
   aspects of an entity's availability for communication or provide
   information about communication-related capabilities.


5.  Exchanging Messages

   Once a client has authenticated with a server and bound a resource to
   an XML stream as described in [XMPP-CORE], an XMPP server will route
   XML stanzas to and from that client (if, that is, messaging
   functionality is enabled and the server is not a presence-only
   service).  One kind of stanza that may be exchanged is <message/>.
   Exchanging messages is a basic use of XMPP and occurs when a user
   generates a message stanza that is addressed to another entity.  As
   defined under Server Rules for Processing XML Stanzas (Section 8),
   the sender's server is responsible for delivering the message to the
   intended recipient (if the recipient is on the same server) or for
   routing the message to the recipient's server (if the recipient is on
   a different server).  Thus a message stanza is used to "push"
   information to another entity.

   As noted under Section 4.6, if a user exchanges messages with another
   entity but does not share presence with the entity based on a
   presence subscription, it is RECOMMENDED for the user's client to
   send directed presence to the other entity.

   The following sections describe the syntax of the <message/> stanza.

5.1.  Attributes

5.1.1.  To Attribute

   An instant messaging client SHOULD specify an intended recipient for
   a message by providing the JID of an entity other than the sender in
   the 'to' attribute of the <message/> stanza.

   If the message is being sent outside the context of any existing chat
   session or received message, the value of the 'to' address SHOULD be
   of the form <user@domain> rather than of the form
   <user@domain/resource>.





Saint-Andre             Expires December 8, 2008               [Page 45]

Internet-Draft                   XMPP IM                       June 2008


   <message
       from='juliet@example.com/balcony'
       to='romeo@example.net'
       type='chat'
       xml:lang='en'>
     <body>Art thou not Romeo, and a Montague?</body>
   </message>

   If the message is being sent in reply to a message previously
   received from an address of the form <user@domain/resource> (e.g.,
   within the context of a chat session), the value of the 'to' address
   SHOULD be of the form <user@domain/resource> rather than of the form
   <user@domain> unless the sender has knowledge (via presence) that the
   intended recipient's resource is no longer available.

   <message
       from='romeo@example.net/orchard'
       to='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <body>Neither, fair saint, if either thee dislike.</body>
   </message>

5.1.2.  Type Attribute

   Common uses of the message stanza in instant messaging applications
   include single messages, messages sent in the context of a chat
   conversation, messages sent in the context of a multi-user chat room,
   headlines and other alerts, and errors.  These uses are
   differentiated via the 'type' attribute.  Inclusion of the 'type'
   attribute is RECOMMENDED.  If included, the 'type' attribute MUST
   have one of the following values:

   o  chat -- The message is sent in the context of a one-to-one chat
      session.  A receiving client SHOULD present the message in an
      interface enabling one-to-one chat between the two parties,
      including an appropriate conversation history.  Detailed
      recommendations regarding chat sessions are provided under
      Section 5.4.
   o  error -- The message is generated by an entity that experiences an
      error in processing a message received from another entity (for
      details regarding stanza error syntax, refer to [XMPP-CORE]).  A
      client that receives a message of type "error" SHOULD present an
      appropriate interface informing the sender of the nature of the
      error.
   o  groupchat -- The message is sent in the context of a multi-user
      chat environment (similar to that of [IRC]).  A receiving client
      SHOULD present the message in an interface enabling many-to-many



Saint-Andre             Expires December 8, 2008               [Page 46]

Internet-Draft                   XMPP IM                       June 2008


      chat between the parties, including a roster of parties in the
      chatroom and an appropriate conversation history.  Full definition
      of XMPP-based groupchat protocols is out of scope for this
      document (for details, refer to [XEP-0045]).
   o  headline -- The message is probably generated by an automated
      service that delivers or broadcasts content (news, sports, market
      information, syndicated content, alerts, etc.), or the sender
      wishes the message to be delivered as if it were so generated.  No
      reply to the message is expected, and a receiving client SHOULD
      present the message in an interface that appropriately
      differentiates the message from standalone messages, chat
      sessions, or groupchat sessions (e.g., by not providing the
      recipient with the ability to reply).  The receiving server SHOULD
      deliver the message to all of the recipient's available resources.
   o  normal -- The message is a standalone message that is sent outside
      the context of a one-to-one conversation or groupchat, and to
      which it is expected that the recipient will reply.  A receiving
      client SHOULD present the message in an interface enabling the
      recipient to reply, but without a conversation history.  This is
      the default value of the 'type' attribute.

   An IM application SHOULD support all of the foregoing message types.
   If an application receives a message with no 'type' attribute or the
   application does not understand the value of the 'type' attribute
   provided, it MUST consider the message to be of type "normal" (i.e.,
   "normal" is the default).

   Although the 'type' attribute is OPTIONAL, it is considered polite to
   mirror the type in any replies to a message; furthermore, some
   specialized applications (e.g., a multi-user chat service) MAY at
   their discretion enforce the use of a particular message type (e.g.,
   type='groupchat').

5.2.  Child Elements

   An XMPP message stanza MAY contain any allowable child elements
   qualified by the 'jabber:client' (or 'jabber:server') namespace, as
   well as any other properly-namespaced child element that consists of
   extended content.  The defined payloads are described in the
   following sections and extended content payloads are described in the
   appropriate XMPP extension specifications (not herein).

5.2.1.  Body

   The <body/> element contains human-readable XML character data that
   specifies the textual contents of the message; this child element is
   normally included but is OPTIONAL.




Saint-Andre             Expires December 8, 2008               [Page 47]

Internet-Draft                   XMPP IM                       June 2008


   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <body>Wherefore art thou, Romeo?</body>
   </message>

   The <body/> element MUST NOT possess any attributes, with the
   exception of the 'xml:lang' attribute.  Multiple instances of the
   <body/> element MAY be included in a message stanza, but only if each
   instance possesses an 'xml:lang' attribute with a distinct language
   value (either explicitly or by inheritance from the 'xml:lang' value
   of an element farther up in the XML hierarchy, which may include the
   XML stream header as described in [XMPP-CORE]).

   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <body>Wherefore art thou, Romeo?</body>
     <body xml:lang='cs'>
        Pro&#x010D;e&#x017D; jsi ty, Romeo?
      </body>
   </message>

   The <body/> element MUST NOT contain mixed content (as defined in
   Section 3.2.2 of [XML]).

5.2.2.  Subject

   The <subject/> element contains human-readable XML character data
   that specifies the topic of the message.

   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <subject>I implore you!</subject>
     <body>Wherefore art thou, Romeo?</body>
   </message>

   The <subject/> element MUST NOT possess any attributes, with the
   exception of the 'xml:lang' attribute.  Multiple instances of the
   <subject/> element MAY be included for the purpose of providing
   alternate versions of the same subject, but only if each instance



Saint-Andre             Expires December 8, 2008               [Page 48]

Internet-Draft                   XMPP IM                       June 2008


   possesses an 'xml:lang' attribute with a distinct language value
   (either explicitly or by inheritance from the 'xml:lang' value of an
   element farther up in the XML hierarchy, which may include the XML
   stream header as described in [XMPP-CORE]).

   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <subject>I implore you!</subject>
     <subject xml:lang='cs'>
       &#x00DA;p&#x011B;nliv&#x011B; pros&#x00EDm!
     </subject>
     <body>Wherefore art thou, Romeo?</body>
     <body xml:lang='cs'>
        Pro&#x010D;e&#x017E; jsi ty, Romeo?
      </body>
   </message>

   The <subject/> element MUST NOT contain mixed content (as defined in
   Section 3.2.2 of [XML]).

5.2.3.  Thread

   The primary use of the XMPP <thread/> element is to uniquely identify
   a conversation thread or "chat session" between two entities
   instantiated by <message/> stanzas of type 'chat'.  However, the XMPP
   <thread/> element may also be used to uniquely identify an analogous
   thread between two entities instantiated by <message/> stanzas of
   type 'headline' or 'normal', or among multiple entities in the
   context of a multi-user chat room instantiated by <message/> stanzas
   of type 'groupchat'.  It may also be used for <message/> stanzas not
   related to a conversation, such as a game session or between plugins.
   The <thread/> element is not used to identify individual messages,
   only conversations.

   The inclusion of the <thread/> element is OPTIONAL.  Because the
   <thread/> element uniquely identifies the particular conversation
   thread to which a message belongs, a message stanza MUST NOT contain
   more than one <thread/> element.

   The value of the <thread/> element is not human-readable and MUST be
   treated as opaque by entities; no semantic meaning may be derived
   from it, and only exact comparisons may be made against it.  The
   value of the <thread/> element MUST be a universally unique
   identifier (UUID) as described in [UUID].




Saint-Andre             Expires December 8, 2008               [Page 49]

Internet-Draft                   XMPP IM                       June 2008


   The <thread/> element MAY possess a 'parent' attribute that
   identifies another thread of which the current thread is an offshoot
   or child; the value of the 'parent' MUST conform to the syntax of the
   <thread/> element itself.  The <thread/> element MUST NOT contain
   mixed content (as defined in Section 3.2.2 of [XML]).

   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <subject>I implore you!</subject>
     <subject xml:lang='cs'>
       &#x00DA;p&#x011B;nliv&#x011B; pros&#x00EDm!
     </subject>
     <body>Wherefore art thou, Romeo?</body>
     <body xml:lang='cs'>
        Pro&#x010D;e&#x017E; jsi ty, Romeo?
     </body>
     <thread parent='e0ffe42b28561960c6b12b944a092794b9683a38'>
       0e3141cd80894871a68e6fe6b1ec56fa
     </thread>
   </message>

   For detailed recommendations regarding use of the <thread/> element,
   refer to [XEP-0201].

5.3.  Extended Content

   As described in [XMPP-CORE], an XML stanza MAY contain any properly-
   namespaced child element; this applies to the message stanza as well.

   (In the following example, the message stanza includes an XHTML-
   formatted version of the message as defined in [XEP-0071]).)

   <message
       to='romeo@example.net'
       from='juliet@example.com/balcony'
       type='chat'
       xml:lang='en'>
     <body>Wherefore art thou, Romeo?</body>
     <html xmlns='http://jabber.org/protocol/xhtml-im'>
       <body xmlns='http://www.w3.org/1999/xhtml'>
         Wherefore <span style='font-style: italic'>art</span>
         thou, <span style='color:red'>Romeo</span>?
       </body>
     </html>
   </message>



Saint-Andre             Expires December 8, 2008               [Page 50]

Internet-Draft                   XMPP IM                       June 2008


5.4.  One-to-One Chat Sessions

   In practice, instant messaging activity between human users tends to
   occur in form of a conversational burst that we call a CHAT SESSION:
   the exchange of at least several messages between two parties in
   relatively rapid succession within a relatively brief period of time.

   When a human user intends to engage in such a chat session with a
   contact (rather than sending a single message to which no reply is
   expected), the user's client SHOULD send a message of type "chat" and
   the contact's client SHOULD preserve that message type in subsequent
   replies.  The user's client also SHOULD include a <thread/> element
   on its initial message, which the contact's client SHOULD also
   preserve during the life of the chat session.

   The user's client MUST address the initial message in a chat session
   to the bare JID <contact@domain> (rather than attempting to guess an
   appropriate full JID <contact@domain/resource>).  Until and unless
   the user's client receives a reply from the contact, it MUST continue
   sending any further messages to the contact's bare JID.  The
   contact's client SHOULD address its subsequent replies to the user's
   full JID <user@domain/resource> as provided in the 'from' address of
   the initial message.  Once the user's client receives a reply from
   the contact's full JID, it SHOULD address its subsequent messages to
   the contact's full JID as provided in the 'from' address of the
   contact's replies.

   If a user exchanges messages with a contact but the user does not
   normally share presence with the contact via a presence subscription,
   it is RECOMMENDED for the user's client to send directed presence to
   the contact, subject to user approval (either explicitly for this
   contact or implicitly via a configuration setting).  If a client
   supports this feature, it MUST allow the user to disable the feature
   in order to prevent presence sharing with unknown entities.

   An example of a chat session as described above is provided under
   Section 7.


6.  Exchanging IQ Stanzas

   As described in [XMPP-CORE], IQ stanzas provide a structured request-
   response mechanism.  The basic semantics of that mechanism (e.g.,
   that the 'id' attribute is required) are defined in [XMPP-CORE],
   whereas the specific semantics required to complete particular use
   cases are defined in all cases by the extended namespace that
   qualifies the direct child element of an IQ stanza of type "get" or
   "set".  The 'jabber:client' and 'jabber:server' namespaces do not



Saint-Andre             Expires December 8, 2008               [Page 51]

Internet-Draft                   XMPP IM                       June 2008


   define any children of IQ stanzas other than the <error/> common to
   all stanza types.  This document defines one such extended namespace,
   for Managing the Roster (Section 2).  However, an IQ stanza MAY
   contain structured information qualified by any extended namespace.

   As noted under Section 4.6, if a user exchanges IQ stanzas with
   another entity but does not share presence with the entity based on a
   presence subscription, it is RECOMMENDED for the user's client to
   send directed presence to the other entity.


7.  A Sample Session

   The examples in this section illustrate a possible instant messaging
   and presence session.  The user is romeo@example.net, he has an
   available resource whose resource identifier is "orchard", and he has
   the following individuals in his roster:

   o  juliet@example.com (subscription="both" and she has two available
      resources, one whose resource identifier is "chamber" and another
      whose resource identifier is "balcony")
   o  benvolio@example.org (subscription="to")
   o  mercutio@example.org (subscription="from")

   First, the user completes the preconditions (stream establishment,
   TLS and SASL negotiation, and resource binding) described in
   [XMPP-CORE]; those protocol flows are not reproduced here.

   Next, the user requests his roster.

   Example 1: User requests current roster from server:

   UC: <iq from='romeo@example.net/balcony' type='get' id='ex1'>
         <query xmlns='jabber:iq:roster'/>
       </iq>
















Saint-Andre             Expires December 8, 2008               [Page 52]

Internet-Draft                   XMPP IM                       June 2008


   Example 2: User receives roster from server:

   US: <iq to='romeo@example.net/balcony' type='result' id='ex1'>
         <query xmlns='jabber:iq:roster'>
           <item jid='romeo@example.com'
                 name='Juliet'
                 subscription='both'>
             <group>Friends</group>
           </item>
           <item jid='benvolio@example.org'
                 name='Benvolio'
                 subscription='to'/>
           <item jid='mercutio@example.org'
                 name='Mercutio'
                 subscription='from'/>
         </query>
       </iq>

   Now the user begins a presence session.

   Example 3: User sends initial presence:

   UC: <presence from='romeo@example.net/orchard'/>

   Example 4: User's server sends presence probes to contacts with
   subscription="to" and subscription="both" on behalf of the user's
   available resource:

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

   US: <presence
           type='probe'
           from='romeo@example.net/orchard'
           to='benvolio@example.org'/>

   Example 5: User's server sends initial presence to contacts with
   subscription="from" and subscription="both" on behalf of the user's
   available resource:

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

   US: <presence
           from='romeo@example.net/orchard'



Saint-Andre             Expires December 8, 2008               [Page 53]

Internet-Draft                   XMPP IM                       June 2008