RFC 7248

Interworking between the Session Initiation Protocol (SIP) and the Extensible Messaging and Presence Protocol (XMPP): Presence

πŸ“… published May 2014, from ietf

Interworking between SIP and XMPP: Presence πŸ¦‹

Okay bestie, this one is a Standards Track document from the IETF (ISSN 2070-1721), published in May 2014. The authors are P. Saint-Andre from &yet, A. Houri from IBM, and J. Hildebrand from Cisco Systems, Inc. πŸ’… It's officially RFC 7248, and the header doesn't say it obsoletes or updates anything, so it's its own little main character. πŸ‘‘

Abstract ✨

This document defines a bidirectional protocol mapping for swapping presence information between the Session Initiation Protocol (SIP) and the Extensible Messaging and Presence Protocol (XMPP). It's giving "two apps finally talking to each other" 🫢

Status of This Memo πŸŽ€

This is an Internet Standards Track document.

It's a product of the Internet Engineering Task Force (IETF), so it represents the consensus of the IETF community. It went through public review and got approved for publication by the Internet Engineering Steering Group (IESG). If you want more on Internet Standards, check Section 2 of RFC 5741.

Info about the current status, any errata, and how to give feedback lives at http://www.rfc-editor.org/info/rfc7248. 🌸

Copyright (c) 2014 IETF Trust and the persons identified as the document authors. All rights reserved.

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as they stood on the publication date. Read those carefully, because they spell out your rights and restrictions for this document. Code Components pulled out of this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come with no warranty, as the Simplified BSD License says. πŸ”₯

Table of Contents 🧚

1. Introduction ....................................................2
2. Intended Audience ...............................................3
3. Terminology .....................................................3
4. Subscriptions to Presence Information ...........................4
   4.1. Overview ...................................................4
   4.2. XMPP to SIP ................................................5
        4.2.1. Establishing a Presence Subscription ................5
        4.2.2. Refreshing a Presence Subscription ..................9
        4.2.3. Cancelling a Presence Subscription .................10
   4.3. SIP to XMPP ...............................................12
        4.3.1. Establishing a Presence Subscription ...............12
        4.3.2. Refreshing a Presence Subscription .................14
        4.3.3. Cancelling a Presence Subscription .................17
5. Notifications of Presence Information ..........................17
   5.1. Overview ..................................................17
   5.2. XMPP to SIP ...............................................19
   5.3. SIP to XMPP ...............................................22
6. Requests for Presence Information ..............................24
   6.1. XMPP to SIP ...............................................24
   6.2. SIP to XMPP ...............................................25
7. Security Considerations ........................................26
8. References .....................................................27
   8.1. Normative References ......................................27
   8.2. Informative References ....................................27
Appendix A. Acknowledgements ......................................29

1. Introduction 🌈

Okay so, to make sure presence systems that follow the instant message / presence requirements [RFC2779] can actually talk to each other, we need to clearly define protocol mappings between them. There are two presence technologies the IETF has been working on:

  • Various extensions to the Session Initiation Protocol ([RFC3261]) for presence, in particular [RFC3856]
  • The Extensible Messaging and Presence Protocol (XMPP), which is basically a formalized version of the core XML streaming protocols that the Jabber open-source community came up with. The relevant specs are [RFC6120] for the XML streaming layer and [RFC6121] for basic presence and instant-messaging extensions

One way to get these protocols interworking is to map each one to the abstract semantics in [RFC3860]. That's the approach taken by both [RFC3922] and [SIMPLE-CPIM-MAPPING], but to the best of our knowledge nobody has ever actually implemented it πŸ™ˆ So this document goes a different route and maps semantics directly from one protocol to the other (that's SIP/SIMPLE, which stands for SIP for Instant Messaging and Presence Leveraging Extensions, to XMPP and back again). The reason is simple: that's how existing systems already solve the interworking problem. ✨

The architectural assumptions behind direct mappings like this are in [RFC7247], including how addresses and error conditions get mapped. The mappings in this document cover basic presence. More advanced stuff, like so-called "rich presence," is out of scope here. πŸ’…

2. Intended Audience πŸŽ€

This document series is for software developers who already have a system built on one of these technologies (SIP, for example) and want to let that system talk to systems built on the other one (like XMPP). We assume you already know the core specs for both SIP [RFC3261] and XMPP [RFC6120], the base document for this series [RFC7247], and these presence-related specs:

  • "A Presence Event Package for the Session Initiation Protocol (SIP)" [RFC3856]
  • "Presence Information Data Format (PIDF)" [RFC3863]
  • "Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence" [RFC6121]
  • "SIP-Specific Event Notification" [RFC6665]

3. Terminology πŸ¦‹

A bunch of terms here (user, contact, subscription, notification, and so on) are explained in [RFC3261], [RFC3856], [RFC6120], and [RFC6121]. This document uses some of the terms from the Model for Presence and Instant Messaging [RFC2778], but not all of them.

In the flow diagrams, SIP traffic is drawn with arrows like ***>, and XMPP traffic is drawn with arrows like ...>. Easy to tell apart! 🌸

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. Those capitals are doing real work, so pay attention to them! πŸ‘‘

4. Subscriptions to Presence Information πŸ’–

4.1. Overview

Both XMPP and presence-aware SIP systems let entities (often, but not always, human users) subscribe to the presence of other entities. XMPP presence subscriptions are specified in [RFC6121], and presence subscriptions that use a SIP event package for presence are specified in [RFC3856]. 🫢

As [RFC6121] describes, XMPP presence subscriptions are managed with XMPP <presence/> stanzas of type "subscribe", "subscribed", "unsubscribe", and "unsubscribed". The main subscription states are:

  • "none" (neither the user nor the contact is subscribed to the other's presence information)
  • "from" (the user has a subscription from the contact)
  • "to" (the user has a subscription to the contact's presence information)
  • "both" (both the user and the contact are subscribed to each other's presence information)

As [RFC3856] describes, SIP presence subscriptions work through SIP SUBSCRIBE events sent from a SIP user agent to an intended recipient. That recipient is usually referenced by a Presence URI of the form <pres:user@domain>, but it could also be referenced by a SIP or SIPS (Session Initiation Protocol Secure) URI of the form <sip:user@domain> or <sips:user@domain>. In practice, 'pres' URIs are rarely used, which is why the examples in this document use 'sip' URIs. 🌈

The subscription models for XMPP and SIP are different, mainly because XMPP presence subscriptions are long-lived. They're permanent unless someone explicitly cancels them, so a subscription never needs refreshing during a given presence "session." SIP presence subscriptions are short-lived instead. The default time-to-live of a SIP presence subscription is 3600 seconds, as specified in Section 6.4 of [RFC3856]. That means a subscription has to be explicitly refreshed if it's going to look permanent, or even last as long as a presence "session." 😭 This difference matters for how subscription cancellations get handled in either direction and, from the SIP side, for subscription refreshes. ⭐

4.2. XMPP to SIP πŸ”₯

Okay that's the first part, bestie! 🌈 Part 2 picks up right here with XMPP to SIP.

4.2.1. Establishing a Presence Subscription ✨

Okay so this part is where the subscription actually gets set up, and it's giving main character energy πŸ¦‹. Here's the flow for an XMPP user subscribing to a SIP user. Read the diagram first, then the explanation after it, bestie πŸ’….

   XMPP       XMPP      XMPP-to-SIP    SIP-to-XMPP     SIP          SIP
   User      Server      Gateway        Gateway       Server        User
    |           |            |              |            |           |
    | (F1) XMPP |            |              |            |           |
    | subscribe |            |              |            |           |
    |..........>|            |              |            |           |
    |           | (F2) XMPP  |              |            |           |
    |           | subscribe  |              |            |           |
    |           |...........>|              |            |           |
    |           |            | (F3) SIP SUBSCRIBE        |           |
    |           |            |**************************>|           |
    |           |            |              |            | (F4) SIP  |
    |           |            |              |            | SUBSCRIBE |
    |           |            |              |            |**********>|
    |           |            |              |            | (F5) SIP  |
    |           |            |              |            | 200 OK    |
    |           |            |              | (F6) SIP   |<**********|
    |           |            |              | 200 OK     | (F7) SIP  |
    |           |            |              |<***********| NOTIFY    |
    |           |            |              |            |<**********|
    |           |            |              | (F8) SIP   |           |
    |           |            |              | NOTIFY     |           |
    |           |            |              |<***********|           |
    |           |            |              | (F9) SIP   |           |
    |           |            |              | 200 OK     |           |
    |           |            |              |***********>|           |
    |           |            |              |            | (F10) SIP |
    |           |    (F11) XMPP subscribed  |            | 200 OK    |
    |           |<..........................|            |**********>|
    |           |    (F12) XMPP presence    |            |           |
    |           |<..........................|            |           |
    | (F13) XMPP|            |              |            |           |
    | subscribed|            |              |            |           |
    |<..........|            |              |            |           |
    | (F14) XMPP|            |              |            |           |
    | presence  |            |              |            |           |
    |<..........|            |              |            |           |

So basically, an XMPP user (like juliet@example.com 🌸) starts things off by sending a subscription request to a contact (like romeo@example.net πŸ’–), and then the contact either accepts or declines. If the contact says yes, Juliet keeps a subscription to the contact's presence info until either (1) she unsubscribes or (2) the contact cancels it. The request itself is wrapped in a <presence/> stanza of type "subscribe" πŸŽ€:

Example 1: XMPP User Subscribes to SIP Contact (F1)

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

When the XMPP server Juliet connected to gets that <presence/> stanza, it has to figure out what the domainpart in the 'to' address is. It does this by following the procedures in Section 5 of [RFC7247] 🧚. If the domain turns out to be a SIP domain, the XMPP server hands the <presence/> stanza off to an associated XMPP-to-SIP gateway or connection manager, the one that natively talks to presence-aware SIP servers πŸ”₯.

Next, the XMPP-to-SIP gateway translates the XMPP subscription request into a SIP SUBSCRIBE request, going from the XMPP user to the SIP user πŸ¦‹:

Example 2: SIP Transformation of XMPP Subscription Request (F3)

   SUBSCRIBE sip:romeo@example.net SIP/2.0
   Via: SIP/2.0/TCP x2s.example.com;branch=z9hG4bKna998sk
   From: <sip:juliet@example.com>;tag=ffd2
   Call-ID: 5BCF940D-793D-43F8-8972-218F7F4EAA8C
   Event: presence
   Max-Forwards: 70
   CSeq: 123 SUBSCRIBE
   Contact: <sip:x2s.example.com;transport=tcp>
   Accept: application/pidf+xml
   Expires: 3600
   Content-Length: 0

Once the XMPP-to-SIP gateway has passed the SIP SUBSCRIBE along to the SIP server (through the SIP-to-XMPP gateway), and the SIP server has delivered it to the SIP user (that's F3 and F4, and there's no example for F4, sorry bestie πŸ™ˆ), the SIP user sends back a response saying yes, the subscription is accepted πŸ’…:

Example 3: SIP Accepts Subscription Request (F6)

   SIP/2.0 200 OK
   Via: SIP/2.0/TCP s2x.example.net;branch=z9hG4bKna998sk
   From: <sip:romeo@example.net>;tag=ffd2
   To: <sip:juliet@example.com>;tag=j89d
   Call-ID: 5BCF940D-793D-43F8-8972-218F7F4EAA8C
   CSeq: 234 SUBSCRIBE
   Contact: <sip:simple.example.net;transport=tcp>
   Expires: 3600
   Content-Length: 0

Now, following [RFC6665], the XMPP-to-SIP gateway SHOULD treat the subscription state as "neutral" until it gets a NOTIFY message 🌈. So the SIP user, or the SIP-to-XMPP gateway at the SIP user's domain, SHOULD immediately send a NOTIFY message with a Subscription-State header whose value contains the string "active" (see Section 5) ✨.

Example 4: SIP User Sends Presence Notification (F7)

   NOTIFY sip:192.0.2.1 SIP/2.0
   Via: SIP/2.0/TCP simple.example.net;branch=z9hG4bKna998sk
   From: <sip:romeo@example.net>;tag=yt66
   To: <sip:juliet@example.com>;tag=bi54
   Call-ID: 5BCF940D-793D-43F8-8972-218F7F4EAA8C
   Event: presence
   Subscription-State: active;expires=499
   Max-Forwards: 70
   CSeq: 8775 NOTIFY
   Contact: <sip:simple.example.net;transport=tcp>
   Content-Type: application/pidf+xml
   Content-Length: 193

   <?xml version='1.0' encoding='UTF-8'?>
   <presence xmlns='urn:ietf:params:xml:ns:pidf'
             entity='pres:romeo@example.net'>
     <tuple id='ID-orchard'>
       <status>
         <basic>open</basic>
         <show xmlns='jabber:client'>away</show>
       </status>
     </tuple>
   </presence>

The presence-aware SIP-to-XMPP gateway then sends a 200 OK back to the SIP user (not shown, since it doesn't get translated into an XMPP stanza, so no drama πŸ’œ).

When the XMPP-to-SIP gateway gets the first NOTIFY with a subscription state of active, it MUST generate a <presence/> stanza of type "subscribed" πŸŽ€:

Example 5: XMPP User Receives Acknowledgement from SIP Contact (F13)

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

As described in Section 5, the gateway MUST also generate a presence notification addressed to the XMPP user 🫢:

Example 6: XMPP User Receives Presence Notification from SIP Contact (F14)

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

4.2.2. Refreshing a Presence Subscription πŸ”„

Okay, this bit is all about keeping the subscription alive, and honestly it's so iconic. The XMPP-to-SIP gateway is the one in charge of setting the Expires header and renewing the subscription on the SIP side, so that to the XMPP user it looks permanent πŸ‘‘. For example, the gateway SHOULD send a new SUBSCRIBE request to the SIP user whenever the XMPP user starts a presence session with its XMPP server by sending initial presence. The gateway also SHOULD send a new SUBSCRIBE request to the SIP user whenever the SIP presence subscription is about to expire during the XMPP user's active presence session ⏰.

The rules for SIP SUBSCRIBE requests, for establishing and refreshing a presence subscription, live in [RFC6665]. Those rules apply to XMPP-to-SIP gateways too πŸ’–. Also, an XMPP-to-SIP gateway MUST consider the XMPP subscription permanently cancelled (and tell the XMPP user) if it gets a SIP response of 403, 489, or 603 πŸ’€. On the other hand, a SIP response of 423 or 481 is a transient error, so it's fine to keep the long-lived XMPP presence subscription going 🌸. [RFC6665] goes into more detail about handling SIP responses for subscription requests and refreshes πŸ“š.

Finally, check out the security considerations section (Section 7) of this document for the important info and requirements about the security implications of subscription refreshes πŸ”. Seriously, don't skip it, it's giving high stakes 😭.

4.2.3. Cancelling a Presence Subscription ✨

Okay bestie, this is the flow for when an XMPP user wants to cancel their presence subscription to a SIP user. Here's the diagram, then I'll walk you through it πŸ’…

XMPP       XMPP      XMPP-to-SIP    SIP-to-XMPP     SIP          SIP
User      Server      Gateway        Gateway       Server        User
 |           |            |              |            |           |
 | (F15) XMPP|            |              |            |           |
 |unsubscribe|            |              |            |           |
 |..........>|            |              |            |           |
 |           | (F16) XMPP |              |            |           |
 |           | unsubscribe|              |            |           |
 |           |...........>|              |            |           |
 |           |            | (F17) SIP SUBSCRIBE       |           |
 |           |            | Expires: 0   |            |           |
 |           |            |**************************>|           |
 |           |            |              |            | (F18) SIP |
 |           |            |              |            | SUBSCRIBE |
 |           |            |              |            | Expires: 0|
 |           |            |              |            |**********>|
 |           |            |              |            | (F19) SIP |
 |           |            |              |            | 200 OK    |
 |           |            |              |            |<**********|
 |           |            |              | (F20) SIP  |           |
 |           |            |              | 200 OK     |           |
 |           |            |              |<***********|           |
 |           |  (F21) XMPP unsubscribed  |            |           |
 |           |<..........................|            |           |
 | (F22) XMPP|            |              |            |           |
 | unsubscribed           |              |            |           |
 |<..........|            |              |            |           |
 |           |            |              |            |           |

At any time after subscribing, the XMPP user can unsubscribe from the contact's presence. Literally all they have to do is send a <presence/> stanza of type "unsubscribe" πŸ¦‹

Example 7: XMPP User Unsubscribes from SIP Contact (F15)

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

The XMPP-to-SIP gateway is responsible for translating the unsubscribe command into a SIP SUBSCRIBE request with the Expires header set to a value of zero. It's giving "translator with a mission" 🧚

Example 8: SIP Transformation of XMPP Unsubscribe (F17)

SUBSCRIBE sip:romeo@example.net SIP/2.0
Via: SIP/2.0/TCP s2x.example.net;branch=z9hG4bKna998sk
From: <sip:juliet@example.com>;tag=j89d
Call-ID: 9D9F00DF-FCA9-4E7E-B970-80B638D5218A
Event: presence
Max-Forwards: 70
CSeq: 789 SUBSCRIBE
Contact: <sip:x2s.example.com;transport=tcp>
Accept: application/pidf+xml
Expires: 0
Content-Length: 0

Upon sending the transformed unsubscribe, the XMPP-to-SIP gateway SHOULD send a <presence/> stanza of type "unsubscribed" addressed to the XMPP user. This is the closure moment 🫢

Example 9: XMPP User Receives Unsubscribed Notification (F22)

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

4.3. SIP to XMPP 🌸

4.3.1. Establishing a Presence Subscription πŸ’œ

Next up is the reverse trip: a SIP user subscribing to an XMPP user. Here's how the messages move between the two sides πŸŽ€

SIP        SIP      SIP-to-XMPP    XMPP-to-SIP      XMPP         XMPP
User      Server      Gateway        Gateway       Server        User
 |           |            |              |            |           |
 | (F23) SIP |            |              |            |           |
 | SUBSCRIBE |            |              |            |           |
 |**********>|            |              |            |           |
 |           | (F24) SIP  |              |            |           |
 |           | SUBSCRIBE  |              |            |           |
 |           |***********>|              |            |           |
 |           |            | (F25) XMPP subscribe      |           |
 |           |            |..........................>|           |
 |           |            |              |            | (F26) XMPP|
 |           |            |              |            | subscribe |
 |           |            |              |            |..........>|
 |           |            |              |            | (F27) XMPP|
 |           |            |              |            | subscribed|
 |           |            |              |            |<..........|
 |           |            |              | (F28) XMPP |           |
 |           |            |              | subscribed |           |
 |           |            |              |<...........|           |
 |           | (F29) SIP 200 OK          |            |           |
 |           |<**************************|            |           |
 |           | (F30) SIP |            |              |            |           |
 | 200 OK    |            |              |            |           |
 |<**********|            |              |            |           |
 |           |            |              |            |           |

A SIP user kicks things off by sending a SIP SUBSCRIBE request to the contact. Here's what that looks like πŸ’–

Example 10: SIP User Subscribes to XMPP Contact (F23)

SUBSCRIBE sip:juliet@example.com SIP/2.0
Via: SIP/2.0/TCP s2x.example.net;branch=z9hG4bKna998sk
From: <sip:romeo@example.net>;tag=xfg9
Call-ID: AA5A8BE5-CBB7-42B9-8181-6230012B1E11
Event: presence
Max-Forwards: 70
CSeq: 263 SUBSCRIBE
Contact: <sip:simple.example.net;transport=tcp>
Accept: application/pidf+xml
Content-Length: 0

Notice that the Expires header was not included in the SUBSCRIBE request. That means the default value of 3600 (i.e., 3600 seconds = 1 hour) applies. Lowkey a chill default 🌈

Upon receiving the SUBSCRIBE, the SIP server needs to determine the identity of the domain portion of the Request-URI or To header, which it does by following the procedures explained in Section 5 of [RFC7247]. If the domain is an XMPP domain, the SIP server will hand off the SUBSCRIBE to an associated SIP-to-XMPP gateway or connection manager that natively communicates with XMPP servers. Bestie, the routing is so organised πŸ“¬

The SIP-to-XMPP gateway is then responsible for translating the SUBSCRIBE into an XMPP subscription request addressed from the SIP user to the XMPP user.

Example 11: XMPP Transformation of SIP SUBSCRIBE (F25)

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

In accordance with [RFC6121], once it receives the stanza from the XMPP-to-SIP gateway, the XMPP user's server MUST deliver the presence subscription request to the XMPP user (or, if a subscription already exists in the XMPP user's roster, the XMPP server SHOULD auto-reply with a <presence/> stanza of type "subscribed"). Roster check, no cap πŸ™ˆ

If the XMPP user approves the subscription request, the XMPP server then MUST return a <presence/> stanza of type "subscribed" addressed from the XMPP user to the SIP user. The XMPP-to-SIP gateway is responsible for translating the <presence/> stanza of type "subscribed" into a SIP 200 OK response. Yasss, approved πŸ‘‘

If the XMPP user declines the subscription request, the XMPP server then MUST return a <presence/> stanza of type "unsubscribed" addressed from the XMPP user to the SIP user, and the XMPP-to-SIP gateway MUST transform that stanza into an empty SIP NOTIFY message with a Subscription-State of "terminated" and a reason of "rejected". Not me getting rejected in the protocol πŸ’€

Example 12: Subscription Request Rejected

NOTIFY sip:192.0.2.2 SIP/2.0
Via: SIP/2.0/TCP s2x.example.net;branch=z9hG4bKna998sk
From: <sip:juliet@example.com>;tag=ur93
To: <sip:romeo@example.net>;tag=pq72
Call-ID: AA5A8BE5-CBB7-42B9-8181-6230012B1E11
Event: presence
Subscription-State: terminated;reason=rejected
Max-Forwards: 70
CSeq: 232 NOTIFY
Contact: <sip:x2s.example.com;transport=tcp>
Content-Type: application/pidf+xml
Content-Length: 0

4.3.2. Refreshing a Presence Subscription πŸ”

okay so for as long as a SIP user is online and still vibing on presence updates from the XMPP contact, their SIP user agent is on refresh duty πŸ’…. It keeps sending an updated SUBSCRIBE request with a sensible value in the Expires header. Every time that happens, the presence-aware SIP-to-XMPP gateway MUST send a SIP NOTIFY back to the user agent (per [RFC6665]) πŸ’–. If the gateway actually knows the availability state of the XMPP user (say, from the core presence session on the XMPP server), then that NOTIFY MUST communicate it, like with a PIDF body [RFC3863] holding the juicy details ✨. But if the gateway has no meaningful info, the NOTIFY MUST be empty, which [RFC6665] totally allows πŸ™ˆ.

Once the SIP user ends its presence session, the presence-aware SIP-to-XMPP gateway has to handle the mismatch between short-lived SIP presence subscriptions and long-lived XMPP presence subscriptions 🧠. The gateway has two options when the SIP user's subscription expires:

  • Cancel the subscription (treat it as temporary) and send an XMPP <presence/> stanza of type "unsubscribe" to the XMPP contact. This honors the SIP semantic, but it's gonna seem kinda strange to the XMPP contact, since it'll look like the SIP user cancelled a long-lived subscription 😭.
  • Maintain the subscription (treat it as long-lived), and:
    1. send a SIP NOTIFY request to the SIP user containing a PIDF document specifying that the XMPP contact now has a basic status of "closed", including a Subscription-State of "terminated" with a reason of "timeout"
    2. send an XMPP <presence/> stanza of type "unavailable" to the XMPP contact; this violates the letter of the SIP semantic, but it'll feel more natural to the XMPP contact 🌸

Which of these options a presence-aware SIP-to-XMPP gateway chooses is up to the implementation πŸŽ€.

If the implementation picks the first option, here's the protocol it generates πŸ‘‘:

Example 13: XMPP Handling of Temporary Subscription Expiry

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

If the implementation picks the second option, here's what it generates 🧚:

Example 14: SIP Handling of Long-Lived Subscription Expiry

   |  NOTIFY sip:192.0.2.2 SIP/2.0
   |  Via: SIP/2.0/TCP s2x.example.net;branch=z9hG4bKna998sk
   |  From: <sip:juliet@example.com>;tag=ur93
   |  To: <sip:romeo@example.net>;tag=pq72
   |  Call-ID: 2B44E147-3B53-45E4-9D48-C051F3216D14
   |  Event: presence
   |  Subscription-State: terminated;reason=timeout
   |  Max-Forwards: 70
   |  CSeq: 232 NOTIFY
   |  Contact: <sip:x2s.example.com;transport=tcp>
   |  Content-Type: application/pidf+xml
   |  Content-Length: 194
   |
   |  <?xml version='1.0' encoding='UTF-8'?>
   |  <presence xmlns='urn:ietf:params:xml:ns:pidf'
   |            entity='pres:juliet@example.com'>
   |    <tuple id='ID-balcony'>
   |      <status>
   |        <basic>closed</basic>
   |      </status>
   |    </tuple>
   |  </presence>

Example 15: XMPP Handling of Long-Lived Subscription Expiry

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

4.3.3. Cancelling a Presence Subscription πŸ™…

At any time, the SIP user can cancel the subscription by sending a SUBSCRIBE message whose Expires header is set to a value of zero ("0"):

Example 16: SIP User Cancels Subscription

   |  SUBSCRIBE sip:juliet@example.com SIP/2.0
   |  Via: SIP/2.0/TCP simple.example.net;branch=z9hG4bKna998sk
   |  From: <sip:romeo@example.net>;tag=yt66
   |  Call-ID: 717B1B84-F080-4F12-9F44-0EC1ADE767B9
   |  Event: presence
   |  Max-Forwards: 70
   |  CSeq: 8775 SUBSCRIBE
   |  Contact: <sip:simple.example.net;transport=tcp>
   |  Expires: 0
   |  Content-Length: 0

As above, upon receiving such a request, the presence-aware SIP-to-XMPP gateway is responsible for doing one of the following 🫢:

  • Cancel the subscription (treat it as temporary) and send an XMPP <presence/> stanza of type "unsubscribe" to the XMPP contact.
  • Maintain the subscription (treat it as long-lived), and:
    1. send a SIP NOTIFY request to the SIP user containing a PIDF document specifying that the XMPP contact now has a basic status of "closed"
    2. send a SIP SUBSCRIBE request to the SIP user with an Expires header set to a value of "0" (zero) when it receives XMPP presence of type "unavailable" from the XMPP contact
    3. send an XMPP <presence/> stanza of type "unavailable" to the XMPP contact

5. Notifications of Presence Information πŸ“£

5.1. Overview 🌈

okay so both XMPP and presence-aware SIP systems let entities (often, but not necessarily, human users) send presence notifications to other entities πŸ’œ. At its most basic, "presence" is just info about an entity's "on/off" availability for communication on a network πŸ”₯. Usually this gets extra detail about the entity's context or status while it's available, and these availability states commonly include "away" and "do not disturb" 😌. Some systems and protocols go even further and call any relatively ephemeral info about an entity a kind of presence πŸ‘€. Categories of this "extended presence" include geographical location (e.g., GPS coordinates), user mood (e.g., grumpy), user activity (e.g., walking), and ambient environment (e.g., noisy) πŸ’€. In this document, we focus on the "least common denominator" of network availability only, although future documents might address broader notions of presence, including availability states and extended presence πŸ“.

[RFC6121] defines how XMPP <presence/> stanzas can indicate availability (via absence of a type attribute) or lack of availability (via a type attribute with a value of "unavailable") ✨. SIP presence using a SIP event package for presence is specified in [RFC3856] πŸ¦‹.

As described in [RFC6121], XMPP presence info about an entity is carried by an XML <presence/> stanza sent over an XML stream πŸŽ€. In this document we'll assume that such a <presence/> stanza is sent from an XMPP client to an XMPP server over an XML stream negotiated between the client and the server, and that a human user controls the client 🧚. In general, the user sends XMPP presence to their own server, and then the server broadcasts it to everyone subscribed to that user's presence info πŸ’–.

As described in [RFC3856], presence info about an entity is carried by a SIP NOTIFY event sent from a SIP user agent to an intended recipient. That recipient is most generally referenced by a Presence URI of the form <pres:user@domain>, but it might also be referenced by a SIP or SIPS URI of the form <sip:user@domain> or <sips:user@domain> 🌸.

This document addresses basic presence or network availability only, not the various extensions to SIP and XMPP for "rich presence" such as [RFC4480], [XEP-0107], and [XEP-0108] πŸ™ˆβœ¨.

5.2. XMPP to SIP πŸ’…

okay so when Juliet messes with her XMPP client to change her presence (or her client just auto-updates it, like with the "auto-away" thing πŸ™ˆ), her client makes an XMPP <presence/> stanza. The syntax of that stanza, including the required and optional elements and attributes, is defined in [RFC6121]. Here's one πŸ¦‹

Example 17: XMPP User Sends Presence Notification

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

When the XMPP server Juliet is connected to gets that stanza, it broadcasts it to every subscriber who's allowed to get presence notifications from Juliet πŸ’– (kinda like the SIP NOTIFY method). For each subscriber, the broadcast either delivers it to a local recipient (if the hostname in the subscriber's address matches one of the hostnames the XMPP server services) or tries to route it to the foreign domain that services the hostname in the subscriber's address. So the server needs to figure out the domainpart of the 'to' address, and it does that by following the procedures in [RFC7247]. If the domain is a SIP domain, the XMPP server hands the <presence/> stanza off to an associated XMPP-to-SIP gateway or connection manager that natively talks to presence-aware SIP servers (no example shown).

Then the XMPP-to-SIP gateway translates the XMPP <presence/> stanza into a SIP NOTIFY request, with an included PIDF document, going from the XMPP user to the SIP user ✨

Example 18: SIP Transformation of XMPP Presence Notification

NOTIFY sip:192.0.2.2 SIP/2.0
Via: SIP/2.0/TCP x2s.example.com;branch=z9hG4bKna998sk
From: <sip:juliet@example.com>;tag=gh19
To: <sip:romeo@example.net>;tag=yt66
Contact: <sip:juliet@example.com>;gr=balcony
Call-ID: 2B44E147-3B53-45E4-9D48-C051F3216D14
Event: presence
Subscription-State: active;expires=599
Max-Forwards: 70
CSeq: 157 NOTIFY
Contact: <sip:x2s.example.com;transport=tcp>
Content-Type: application/pidf+xml
Content-Length: 192

<?xml version='1.0' encoding='UTF-8'?>
<presence xmlns='urn:ietf:params:xml:ns:pidf'
          entity='pres:juliet@example.com'>
  <tuple id='ID-balcony'>
    <status>
      <basic>open</basic>
      <show xmlns='jabber:client'>away</show>
    </status>
  </tuple>
</presence>

The mapping of XMPP syntax elements to SIP syntax elements SHOULD be as shown in the following table. (Mappings for elements not mentioned are undefined.) πŸŽ€

+-----------------------------+---------------------------+
|  XMPP Element or Attribute  |  SIP Header or PIDF Data  |
+-----------------------------+---------------------------+
|  <presence/> stanza         |  "Event: presence" (1)    |
+-----------------------------+---------------------------+
|  XMPP resource identifier   |  tuple 'id' attribute (2) |
+-----------------------------+---------------------------+
|  from                       |  From                     |
+-----------------------------+---------------------------+
|  id                         |  CSeq (3)                 |
+-----------------------------+---------------------------+
|  to                         |  To                       |
+-----------------------------+---------------------------+
|  type                       |  basic status (4) (5)     |
+-----------------------------+---------------------------+
|  xml:lang                   |  Content-Language         |
+-----------------------------+---------------------------+
|  <priority/>                |  priority for tuple (6)   |
+-----------------------------+---------------------------+
|  <show/>                    |  no mapping (7)           |
+-----------------------------+---------------------------+
|  <status/>                  |  <note/>                  |
+-----------------------------+---------------------------+

     Table 1: Presence Syntax Mapping from XMPP to SIP

Note the following regarding these mappings: 🧚

(1) Only an XMPP <presence/> stanza that lacks a 'type' attribute or whose 'type' attribute has a value of "unavailable" SHOULD be mapped by an XMPP-to-SIP gateway to a SIP NOTIFY request, since those are the only <presence/> stanzas that represent notifications.

(2) The PIDF schema defines the tuple 'id' attribute as having a datatype of "xs:ID". This datatype is more restrictive than the "xs:string" datatype for XMPP resourceparts (in particular, a number is not allowed as the first character of an ID), so prepending the resourcepart with "ID-" or some other alphabetic string when mapping from XMPP to SIP is RECOMMENDED 🌸

(3) In practice, XMPP <presence/> stanzas often do not include the 'id' attribute. πŸ™ƒ

(4) Because the lack of a 'type' attribute indicates that an XMPP entity is available for communications, the gateway SHOULD map that information to a PIDF basic status of "open". Because a 'type' attribute with a value of "unavailable" indicates that an XMPP entity is not available for communications, the gateway SHOULD map that information to a PIDF basic status of "closed". ✨

(5) When the XMPP-to-SIP gateway receives XMPP presence of type "unavailable" from the XMPP contact, it SHOULD (a) send a SIP NOTIFY request to the SIP user containing a PIDF document specifying that the XMPP contact now has a basic status of "closed" and (b) send a SIP SUBSCRIBE request to the SIP user with an Expires header set to a value of "0" (zero). πŸ’€

(6) The value of the XMPP <priority/> element is an integer between -128 and +127, whereas the value of the PIDF <contact/> element's 'priority' attribute is a decimal number from zero to one inclusive, with a maximum of three decimal places. If the value of the XMPP <priority/> element is negative, an XMPP-to-SIP gateway MUST NOT map the value. If an XMPP-to-SIP gateway maps positive values, it SHOULD treat XMPP priority 0 as PIDF priority 0 and XMPP priority 127 as PIDF priority 1, mapping intermediate values appropriately so that they are unique (e.g., XMPP priority 1 to PIDF priority 0.007, XMPP priority 2 to PIDF priority 0.015, and so on up through mapping XMPP priority 126 to PIDF priority 0.992; note that this is an example only and that the exact mapping is up to the implementation). πŸ”₯

(7) Some implementations support custom extensions to encapsulate detailed information about availability. However, there is no need to standardize a PIDF extension for this purpose, since PIDF is already extensible and thus the <show/> element (qualified by the 'jabber:client' namespace) can be included directly in the PIDF XML. The examples in this document illustrate this usage, which is RECOMMENDED πŸ‘‘ The most useful values are likely "away" and "dnd", although note that the latter value merely means "busy" and does not imply that a server or client ought to block incoming traffic while the user is in that state. Naturally, a gateway can choose to translate a custom extension into an established value of the <show/> element [RFC6121] or translate a <show/> element into a custom extension that the gateway knows is supported by the user agent of the intended recipient. Unfortunately, this behavior does not guarantee that information will not be lost; to help prevent information loss, a gateway ought to include both the <show/> element and the custom extension if the gateway cannot suitably translate the custom value into a <show/> value. πŸ₯Ή

5.3. SIP to XMPP πŸ¦‹

okay so when Romeo changes his presence, his SIP user agent sends a NOTIFY request to everyone with an active subscription πŸ“£. The syntax lives in [RFC3856]. Here's what one looks like:

Example 19: SIP User Sends Presence Notification

NOTIFY sip:192.0.2.1 SIP/2.0
Via: SIP/2.0/TCP simple.example.net;branch=z9hG4bKna998sk
From: <sip:romeo@example.net>;tag=yt66
To: <sip:juliet@example.com>;tag=bi54
Contact: <sip:romeo@example.net>;gr=orchard
Call-ID: C33C6C9D-0F4A-42F9-B95C-7CE86B526B5B
Event: presence
Subscription-State: active;expires=499
Max-Forwards: 70
CSeq: 8775 NOTIFY
Contact: <sip:simple.example.net;transport=tcp>
Content-Type: application/pidf+xml
Content-Length: 193

<?xml version='1.0' encoding='UTF-8'?>
<presence xmlns='urn:ietf:params:xml:ns:pidf'
          entity='pres:romeo@example.net'>
  <tuple id='ID-orchard'>
    <status>
      <basic>closed</basic>
    </status>
  </tuple>
</presence>

When the SIP server gets that NOTIFY, it has to figure out the identity of the domain part of the Request-URI or To header πŸ”. It does that by following the procedures in [RFC7247]. If the domain is an XMPP domain, the SIP server hands the NOTIFY off to an associated SIP-to-XMPP gateway or connection manager, the thing that actually talks XMPP natively πŸ’œ

The SIP-to-XMPP gateway then turns the NOTIFY into an XMPP <presence/> stanza, sent from the SIP user to the XMPP user πŸ’Œ

Example 20: XMPP Transformation of SIP Presence Notification

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

The mapping of SIP syntax elements to XMPP syntax elements SHOULD be as shown in the following table πŸŽ€ (Mappings for elements not mentioned are undefined.)

     +---------------------------+-----------------------------+
     |  SIP Header or PIDF Data  |  XMPP Element or Attribute  |
     +---------------------------+-----------------------------+
     |  basic status             |  type (1)                   |
     +---------------------------+-----------------------------+
     |  Content-Language         |  xml:lang                   |
     +---------------------------+-----------------------------+
     |  CSeq                     |  id (2)                     |
     +---------------------------+-----------------------------+
     |  From                     |  from                       |
     +---------------------------+-----------------------------+
     |  priority for tuple       |  <priority/> (3)            |
     +---------------------------+-----------------------------+
     |  To                       |  to                         |
     +---------------------------+-----------------------------+
     |  <note/>                  |  <status/>                  |
     +---------------------------+-----------------------------+
     |  <show/>                  |  <show/> (4)                |
     +---------------------------+-----------------------------+

          Table 2: Presence Syntax Mapping from SIP to XMPP

Here are the notes that go with that table, so pay attention πŸ‘€

(1) A PIDF basic status of "open" SHOULD be mapped to no 'type' attribute, and a PIDF basic status of "closed" SHOULD be mapped to a 'type' attribute whose value is "unavailable".

(2) This mapping is OPTIONAL.

(3) See the notes following Table 1 of this document regarding mapping of presence priority.

(4) If a SIP implementation supports the <show/> element (qualified by the 'jabber:client' namespace) as a PIDF extension for availability status as described in the notes following Table 1 of this document, the SIP-to-XMPP gateway is responsible for including that element in the XMPP presence notification.


6. Requests for Presence Information 🌸

Both SIP and XMPP have methods for asking about another entity's presence. Let's get into it 🫢

6.1. XMPP to SIP 🧚

In XMPP, asking for presence info happens by sending a <presence/> stanza of type "probe" πŸ”Ž

Example 21: XMPP Server Sends Presence Probe on Behalf of XMPP User

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

Note: As described in [RFC6121], presence probes are used by XMPP servers to request presence on behalf of XMPP users. XMPP clients are discouraged from sending presence probes, since retrieving presence is a service that servers provide πŸ™ˆ

An XMPP-to-SIP gateway would turn that presence probe into its SIP equivalent, which is a SUBSCRIBE request with an Expires header value of zero πŸ”„

Example 22: SIP Transformation of XMPP Presence Probe

SUBSCRIBE sip:romeo@example.net SIP/2.0
Via: SIP/2.0/TCP x2s.example.com;branch=z9hG4bKna998sk
From: <sip:juliet@example.com>;tag=ffd2
Call-ID: 5BCF940D-793D-43F8-8972-218F7F4EAA8C
Event: presence
Max-Forwards: 70
CSeq: 123 SUBSCRIBE
Contact: <sip:x2s.example.com;transport=tcp>
Accept: application/pidf+xml
Expires: 0
Content-Length: 0

As described in [RFC3856], this cancels any subscription but causes a NOTIFY to be sent to the subscriber, just like a presence probe does. (The transformation rules for presence notifications were already covered in Section 5.2 of this document πŸ’…)

6.2. SIP to XMPP πŸ’Œ

In SIP, asking for presence info is effectively done by sending a SUBSCRIBE with an Expires header value of zero πŸ“¨

Example 23: SIP User Sends Presence Request

SUBSCRIBE sip:juliet@example.com SIP/2.0
Via: SIP/2.0/TCP simple.example.net;branch=z9hG4bKna998sk
From: <sip:romeo@example.net>;tag=yt66
Call-ID: 717B1B84-F080-4F12-9F44-0EC1ADE767B9
Event: presence
Max-Forwards: 70
CSeq: 8775 SUBSCRIBE
Contact: <sip:simple.example.net;transport=tcp>
Expires: 0
Content-Length: 0

When a presence-aware SIP-to-XMPP gateway is honoring the long-lived semantics of an XMPP presence subscription, it SHOULD translate a request like that into a <presence/> stanza of type "probe" if it doesn't already have presence info about the contact 🧠

Example 24: XMPP Transformation of SIP Presence Request

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

7. Security Considerations πŸ”

Okay bestie, this part is SERIOUS, so read it carefully 🚨

Detailed security considerations for presence protocols are in [RFC2779], for SIP-based presence in [RFC3856] (see also [RFC3261]), and for XMPP-based presence in [RFC6121] (see also [RFC6120]).

The mismatch between long-lived XMPP presence subscriptions and short-lived SIP presence subscriptions opens the door to an amplification attack launched from the XMPP network against a SIP presence server πŸ’€ Each long-lived XMPP presence subscription would typically result in multiple subscription refresh requests on the SIP side of a gateway, so this is a real risk!

Because of that, access to an XMPP-to-SIP gateway SHOULD be restricted in various ways. Among other things, only an XMPP service that carefully controls account provisioning and provides effective methods for administrators to control the behavior of registered users ought to host such a gateway (for example, not a service that offers open account registration). A gateway ought to be associated with only a single domain or trust realm. For example, a gateway hosted at simple.example.com ought to allow only users within the example.com domain to access the gateway, not users within example.org, example.net, or any other domain 🏰

If a SIP presence server gets communications through an XMPP-to-SIP gateway from users who aren't associated with a domain that's related to the gateway's hostname like that, it SHOULD (based on local service provisioning) refuse to service those users or refuse to receive traffic from the gateway 🚫

As a further check, whenever an XMPP-to-SIP gateway wants to refresh an XMPP user's long-lived subscription to a SIP user's presence, it MUST first send an XMPP <presence/> stanza of type "probe" from the address of the gateway to the "bare Jabber ID (JID)" (user@domain.tld) of the XMPP user. The user's XMPP server MUST respond in accordance with [RFC6121]. This puts an equal burden on the XMPP server and the SIP server 🀝✨


8. References πŸ“š

8.1. Normative References

  • [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
  • [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, A., Peterson, J., Sparks, R., Handley, M., and E. Schooler, "SIP: Session Initiation Protocol", RFC 3261, June 2002.
  • [RFC3856] Rosenberg, J., "A Presence Event Package for the Session Initiation Protocol (SIP)", RFC 3856, August 2004.
  • [RFC3863] Sugano, H., Fujimoto, S., Klyne, G., Bateman, A., Carr, W., and J. Peterson, "Presence Information Data Format (PIDF)", RFC 3863, August 2004.
  • [RFC6120] Saint-Andre, P., "Extensible Messaging and Presence Protocol (XMPP): Core", RFC 6120, March 2011.
  • [RFC6121] Saint-Andre, P., "Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence", RFC 6121, March 2011.
  • [RFC6665] Roach, A., "SIP-Specific Event Notification", RFC 6665, July 2012.
  • [RFC7247] Saint-Andre, P., Houri, A., and J. Hildebrand, "Interworking between the Session Initiation Protocol (SIP) and the Extensible Messaging and Presence Protocol (XMPP): Architecture, Addresses, and Error Handling", RFC 7247, May 2014.

8.2. Informative References

  • [RFC2778] Day, M., Rosenberg, J., and H. Sugano, "A Model for Presence and Instant Messaging", RFC 2778, February 2000.
  • [RFC2779] Day, M., Aggarwal, S., Mohr, G., and J. Vincent, "Instant Messaging / Presence Protocol Requirements", RFC 2779, February 2000.
  • [RFC3860] Peterson, J., "Common Profile for Instant Messaging (CPIM)", RFC 3860, August 2004.
  • [RFC3922] Saint-Andre, P., "Mapping the Extensible Messaging and Presence Protocol (XMPP) to Common Presence and Instant Messaging (CPIM)", RFC 3922, October 2004.
  • [RFC4480] Schulzrinne, H., Gurbani, V., Kyzivat, P., and J. Rosenberg, "RPID: Rich Presence Extensions to the Presence Information Data Format (PIDF)", RFC 4480, July 2006.
  • [SIMPLE-CPIM-MAPPING] Campbell, B. and J. Rosenberg, "CPIM Mapping of SIMPLE Presence and Instant Messaging", Work in Progress, June 2002.
  • [XEP-0107] Saint-Andre, P. and R. Meijer, "User Mood", XSF XEP 0107, October 2008, http://xmpp.org/extensions/xep-0107.html.
  • [XEP-0108] Meijer, R. and P. Saint-Andre, "User Activity", XSF XEP 0108, October 2008, http://xmpp.org/extensions/xep-0108.html.

Appendix A. Acknowledgements πŸŽ€βœ¨

okay bestie, the thank-you section is literally so sweet πŸ₯Ή the authors shouted out everyone who gave feedback: Chris Christou, Fabio Forno, Adrian Georgescu, Philipp Hancke, Saul Ibarra Corretge, Markus Isomaki, Olle Johansson, Paul Kyzivat, Salvatore Loreto, Michael Lundberg, Daniel-Constantin Mierla, and Tory Patnoe. the whole squad πŸ«ΆπŸ’–

Dave Crocker gave super helpful and detailed feedback on behalf of the Applications Area Directorate πŸ“ Ben Laurie did a review on behalf of the Security Directorate, and that review led to better security considerations, so iconic πŸ”πŸ’…

During IESG review, Pete Resnick caught several oversights in the document about interoperability. literally the saves we love to see πŸ˜­πŸ™Œ

The authors also gratefully acknowledge Markus Isomaki and Yana Stamcheva, who were the working group chairs, and Gonzalo Camarillo, who was the sponsoring Area Director πŸ‘‘πŸŒˆ

Some text in this document was borrowed from [RFC3922] πŸ¦‹

Peter Saint-Andre wants to acknowledge Cisco Systems, Inc., for employing him while he worked on earlier versions of this document πŸ’œ


Authors' Addresses πŸ’Œ

Peter Saint-Andre &yet

Peter Saint-Andre
&yet

EMail: ietf@stpeter.im


Avshalom Houri
IBM
Rorberg Building, Pekris 3
Rehovot  76123
Israel

EMail: avshalom@il.ibm.com


Joe Hildebrand
Cisco Systems, Inc.
1899 Wynkoop Street, Suite 600
Denver, CO  80202
USA

EMail: jhildebr@cisco.com
πŸ“¦ where this page comes from