XEP-0012: Last Activity

This specification defines an XMPP protocol extension for communicating information about the last activity associated with an XMPP entity. It is typically used by an IM client to retrieve the most recent presence information from an offline contact by sending a last activity request to the server that hosts the account controlled by the contact.


NOTICE: The protocol defined herein is a Draft Standard of the XMPP Standards Foundation. Implementations are encouraged and the protocol is appropriate for deployment in production systems, but some changes to the protocol are possible before it becomes a Final Standard.


Document Information

Series: XEP
Number: 0012
Publisher: XMPP Standards Foundation
Status: Draft
Type: Standards Track
Version: 1.3
Last Updated: 2008-07-16
Approving Body: XMPP Council
Dependencies: XMPP Core, XMPP IM
Supersedes: None
Superseded By: None
Short Name: iq-last
Schema: <http://www.xmpp.org/schemas/iq-last.xsd>
Wiki Page: <http://wiki.jabber.org/index.php/Last Activity (XEP-0012)>


Author Information

Jeremie Miller

Email: jer@jabber.org
JabberID: jer@jabber.org

Thomas Muldowney

Email: temas@jabber.org
JabberID: temas@jabber.org

Peter Saint-Andre

JabberID: stpeter@jabber.org
URI: https://stpeter.im/


Legal Notices

Copyright

This XMPP Extension Protocol is copyright (c) 1999 - 2008 by the XMPP Standards Foundation (XSF).

Permissions

Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.

Disclaimer of Warranty

## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. In no event shall the XMPP Standards Foundation or the authors of this Specification be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification. ##

Limitation of Liability

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising out of the use or inability to use the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.

IPR Conformance

This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which may be found at <http://www.xmpp.org/extensions/ipr-policy.shtml> or obtained by writing to XSF, P.O. Box 1641, Denver, CO 80201 USA).

Discussion Venue

The preferred venue for discussion of this document is the Standards discussion list: <http://mail.jabber.org/mailman/listinfo/standards>.

Errata may be sent to <editor@xmpp.org>.

Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 3920) and XMPP IM (RFC 3921) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.

Conformance Terms

The following keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".


Table of Contents


1. Introduction
2. Protocol
3. Offline User Query
4. Online User Query
5. Server and Component Query
6. Determining Support
7. Implementation Notes
8. Security Considerations
9. IANA Considerations
10. XMPP Registrar Considerations
11. XML Schema
Notes
Revision History


1. Introduction

It is often helpful to know the time of the last activity associated with a entity. The canonical usage is to discover when a disconnected user last accessed the server. The 'jabber:iq:last' namespace provides a method for retrieving that information. The 'jabber:iq:last' namespace can also be used to discover when a connected user was last active on the server (i.e., the user's idle time) or to query servers and components about their current uptime.

2. Protocol

In order to request last activity information regarding another entity, the requesting entity shall send an <iq/> stanza of type "get" to the target entity, containing a <query/> element qualified by the 'jabber:iq:last' namespace:

Example 1. Last Activity Query

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com' type='get' id='last1'>
  <query xmlns='jabber:iq:last'/>
</iq>
  

The target entity MUST return either an IQ-result or an IQ-error. When returning an IQ-result, the target entity sends an <iq/> stanza of type='result' containing a <query/> element with a REQUIRED 'seconds' attribute and OPTIONAL XML character data.

Example 2. Last Activity Response

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <query xmlns='jabber:iq:last' seconds='903'/>
</iq>
  

The requesting entity must interpret the IQ-result based on the responding entity's JID type in order to determine the meaning of the information. Specifically, the information means something different depending on whether the responding entity has a JID of the form 'host', 'user@host', or 'user@host/resource'. These differences are explained more fully below.

3. Offline User Query

The primary usage of the 'jabber:iq:last' namespace is to find out how long ago a user logged out (and, additionally, what their status message was at that time). This primary usage assumes that the IQ-get is sent to a bare JID (<localpart@domain.tld> or <domain.tld>). When used in this way, the <query/> element contained in the IQ-result has a 'seconds' attribute, which is the number of seconds that have passed since the user last logged out. In addition, the element MAY contain XML character data that specifies the status message of the last unavailable presence received from the user. An example is shown below:

Example 3. Last Activity Query

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com' type='get' id='last1'>
  <query xmlns='jabber:iq:last'/>
</iq>
  

As specified in XMPP Core [1] and XMPP IM [2], an IQ stanza of type "get" sent to a bare JID <localpart@domain.tld> is handled by the user's server on the user's behalf, not delivered to one or more active resources.

If the requesting entity is not authorized to view the user's presence information (normally via a presence subscription as defined in XMPP-IM), the user's server MUST NOT return last activity information but instead MUST return a <forbidden/> error in response to the last activity request.

Example 4. Requesting Entity is Not Authorized to Retrieve Last Activity Information

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <error type='auth'>
    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
  

If the requesting entity is authorized to view the user's presence information, the server shall return information about the last presence activity recorded by the server for that user.

Example 5. Last Activity Response by Server

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>
</iq>
  

In this example, the user logged out fifteen minutes and three seconds ago, and when they logged out they sent a presence stanza of type='unavailable' whose <status/> element contained the text "Heading Home".

If the user has at least one available resource when the server receives the request, the response SHOULD contain an empty <query/> element whose 'seconds' attribute is set to a value of '0'.

4. Online User Query

A requesting entity may send a last activity query to a full JID <localpart@domain.tld/resource>.

Example 6. Last Activity Query Sent to Full JID

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' type='get' id='last2'>
  <query xmlns='jabber:iq:last'/>
</iq>
  

In this case, the user's server shall either deliver the IQ to an available resource or respond on behalf of the user.

In particular, as with the offline query use case above, if the requesting entity is not authorized to view the user's presence information (normally via a presence subscription as defined in XMPP IM), the user's server MUST NOT deliver the IQ-get to an available resource but instead MUST return a <forbidden/> error in response to the last activity request.

Example 7. Requesting Entity is Not Authorized to Retrieve Last Activity Information

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <error type='auth'>
    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
  

If the user's server delivers the IQ-get to one of the user's available resources, the user's client MAY respond with the idle time of the user (i.e., the last time that the user interacted with the client application).

Example 8. Last Activity Response by Client

<iq from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' type='result' id='last2'>
  <query xmlns='jabber:iq:last' seconds='123'/>
</iq>
  

In this example, the user has been idle for about two minutes.

Support for this functionality is OPTIONAL. A client that does not support the protocol, or that does not wish to divulge this information, MUST return a <service-unavailable/> error.

Example 9. Service Unavailable Error

<iq from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' type='error' id='last2'>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
  

If there is no available resource matching the user@host/resource in the 'to' attribute of the request, the server MUST follow the rules in XMPP IM in order to determine what error stanza to return.

5. Server and Component Query

When the last activity query is sent to a server or component (i.e., to a JID of the form <domain.tld>), the information contained in the IQ reply reflects the uptime of the JID sending the reply. The seconds attribute specifies how long the host has been up and running. The <query/> element SHOULD NOT contain XML character data.

Example 10. Last Activity Query Sent to Server or Service

<iq from='romeo@montague.net/orchard' to='capulet.com' type='get' id='last3'>
  <query xmlns='jabber:iq:last'/>
</iq>

<iq from='capulet.com' to='romeo@montague.net/orchard' type='result' id='last3'>
  <query xmlns='jabber:iq:last' seconds='123456'/>
</iq>
  

In this example, the server has been up for a little more than 34 hours.

6. Determining Support

In order for a requesting entity to determine if a responding entity supports the last activity protocol, it SHOULD send a Service Discovery [3] information request to the responding entity:

Example 11. Requesting entity queries responding entity regarding protocol support

<iq from='stpeter@jabber.org/roundabout'
    to='jabber.org'
    id='disco1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
  

Example 12. Responding entity communicates protocol support

<iq from='jabber.org'
    to='stpeter@jabber.org/roundabout'
    id='disco1'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    ...
    <feature var='jabber:iq:last'/>
    ...
  </query>
</iq>
  

7. Implementation Notes

The information contained in an IQ reply for this namespace is inherently ambiguous. Specifically, for a bare JID <localpart@domain.tld> the information is the time since the JID was last connected to its server; for a full JID <localpart@domain.tld/resource> the information is the time since the resource was last active in the context of an existing session; and for a bare domain the information is the uptime for the server or component. An application must take these differences into account when presenting the information to a human user.

8. Security Considerations

A server MUST NOT allow an unauthorized entity to learn a user's network availability by sending a Last Activity request to a JID of the form user@host or user@host/resource; i.e., Last Activity information MAY be divulged only to those entities that have permission to view the user's presence via a presence subscription (potentially as restricted by Server-Based Privacy Rules [4] or Simple Communications Blocking [5]).

A client MUST provide a way for a human user to disable sending of Last Activity responses from the client's full JID <localpart@domain.tld/resource>.

9. IANA Considerations

This document requires no interaction with the Internet Assigned Numbers Authority (IANA) [6].

10. XMPP Registrar Considerations

No action on the part of the XMPP Registrar [7] is necessary as a result of this document, since 'jabber:iq:last' is already registered in the protocol namespaces registry located at <http://www.xmpp.org/registrar/namespaces.html>.

11. XML Schema

<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='jabber:iq:last'
    xmlns='jabber:iq:last'
    elementFormDefault='qualified'>

  <xs:annotation>
    <xs:documentation>
      The protocol documented by this schema is defined in
      XEP-0012: http://www.xmpp.org/extensions/xep-0012.html
    </xs:documentation>
  </xs:annotation>

  <xs:element name='query'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base='xs:string'>
          <xs:attribute
              name='seconds'
              type='xs:unsignedLong'
              use='optional'/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

</xs:schema>
    

Notes

1. RFC 3920: Extensible Messaging and Presence Protocol (XMPP): Core <http://tools.ietf.org/html/rfc3920>.

2. RFC 3921: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence <http://tools.ietf.org/html/rfc3921>.

3. XEP-0030: Service Discovery <http://www.xmpp.org/extensions/xep-0030.html>.

4. XEP-0016: Server-Based Privacy Rules <http://www.xmpp.org/extensions/xep-0016.html>.

5. XEP-0191: Simple Communications Blocking <http://www.xmpp.org/extensions/xep-0191.html>.

6. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.

7. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see <http://www.xmpp.org/registrar/>.


Revision History

Version 1.3 (2008-07-16)

Corrected server processing rules to block queries to a full JID when the requesting entity is not authorized to view the presence of the user.

(psa)

Version 1.2 (2007-02-15)

Per a vote of the XMPP Council, changed from Historical and Active to Standards Track and Draft; added Implementation Notes and clarified text throughout; added proviso to security considerations regarding client support; added section on Service Discovery.

(psa)

Version 1.1 (2004-01-22)

Editorial revisions.

(psa)

Version 1.0 (2002-01-22)

Changed status to Active.

(psa)

Version 0.3 (2002-01-14)

Made appropriate changes to reflect status as informational.

(psa)

Version 0.2 (2002-01-04)

Converted to XML format.

(tjm)

Version 0.1 (2001-01-25)

Initial version from website.

(jm)

END