XEP-0099: IQ Query Action Protocol

Abstract:Standardizes behavior of <iq/> <query/> actions for generic query behavior.
Author:Iain Shigeoka
Copyright:© 1999 – 2018 XMPP Standards Foundation. SEE LEGAL NOTICES.
Status:Deferred
Type:Standards Track
Version:0.1.1
Last Updated:2018-11-03

WARNING: This document has been automatically Deferred after 12 months of inactivity in its previous Experimental state. Implementation of the protocol described herein is not recommended for production systems. However, exploratory implementations are encouraged to resume the standards process.


Table of Contents


1. Introduction
2. <query/> Action Protocol
    2.1. Description
    2.2. Actions
    2.3. Elements
    2.4. Error Codes
3. Create Action
    3.1. Description
    3.2. Error Codes
    3.3. Examples
4. Read Action
    4.1. Description
    4.2. Error Codes
    4.3. Examples
5. Update Action
    5.1. Description
    5.2. Error Codes
    5.3. Examples
6. Delete Action
    6.1. Description
    6.2. Error Codes
    6.3. Examples
7. Defining an Action Protocol
    7.1. Description

Appendices
    A: Document Information
    B: Author Information
    C: Legal Notices
    D: Relation to XMPP
    E: Discussion Venue
    F: Requirements Conformance
    G: Notes
    H: Revision History


1. Introduction

There is a need for consistent query behavior amongst XMPP <iq/> protocols. Currently each protocol invents its own, slightly different behavior for conducting query behavior to create, read, update, and delete (CRUD) recipient node data. This document defines a generic query acton protocol to standardize behavior across <iq/> protocols. In addition, we hope this standard will make other protocols easier to understand and implement by using a common core protocol.

2. <query/> Action Protocol

2.1 Description

The existing XMPP core protocol defines four <iq/> types (get, set, result, and error). Unfortunately, these four types don't include a 'delete' type, and the 'set' type must do double duty for 'create' and 'update'. Many protocols can benefit from a clear separation of create and update paralleling other query languages such as SQL.

Protocols complying with the <query/> action protocol use <iq/> 'set' to initiate all request-response interactions. The particular action to be taken MUST be set as an "action" attribute in the <iq/> <query/> sub-element. The action attribute MUST have a value of 'create', 'read', 'update', or 'delete'. Responses use the standard <iq/> 'result' and 'error' types. For backward compatibility, an <iq/> 'get' query is treated as equivalent to an <iq/> 'set' query with action of 'read'. Action protocols may require all or just a subset of these actions depending on the desired outcome.

In addition to the action attribute an optional "strict" attribute may be set in the <iq/> <query/> sub-element. The only valid values for strict is "true" or "false" (case sensitive). The strict behavior of actions causes more errors to be returned which tends to make protocols more robust but also more complex. Action protocols MUST define the default value of the "strict" attribute in the context of that protocol. In addition, some protocols may not wish to allow changing the strict default, so action protocols MUST declare whether the strict behavior of the protocol may be set in the <iq/> <query/> sub-element.

2.2 Actions

Table 1: Description of Acceptable <query/> Actions

createCreates/inserts new data on the recipient node.
readRetrieves data from the recipient node.
updateUpdates existing data on the recipient node.
deleteDeletes existing data on the recipient node.

2.3 Elements

The root element is query which is in a namespace defining the protocol in use. The query element MUST have an attribute named 'action' with values given in the previous table.

2.4 Error Codes

The following error codes apply to all action codes.

Table 2: Error Codes used by Action Protocols

CodeTextDescription
406Not AcceptableThe IQ query contents are not properly formatted for the action protocol.
503Service UnavailableThe IQ query is sent to a JID that cannot handle the query.

3. Create Action

3.1 Description

The create action inserts new data on the recipient node. If the strict attribute is 'true' the create action fails if colliding data already exists on the recipient node. If the strict attribute is false, the create action will insert new data on the recipient node overwriting existing colliding data if it exists (e.g. equivalent to update).

3.2 Error Codes

Table 3: Error Codes used by Create Action

CodeTextDescription
409ConflictThe strict attribute is set to 'true' and colliding data exists on the recipient node.

3.3 Examples

Creating new data on the server using iq:private, and strict actions when no existing data is on the server.

Example 1. Client Stores New Private Data

SENDER:
<iq type="set" id="1001">
  <query xmlns="jabber:iq:private" action="create" strict="true">
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1001"/>

With strict actions enabled, conflict data will cause the create action to fail when existing data is on the recipient node. Here we show iq:private, and strict actions with existing data on the server.

Example 2. Client Stores New Private Data but Conflicts

SENDER:
<iq type="set" id="1002">
  <query xmlns="jabber:iq:private" action="create" strict="true">
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

RECIPIENT:
<iq
    type="error"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1002">
    <error code="409">Conflict</error>
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

4. Read Action

4.1 Description

The read action retrieves data on the recipient node. If the strict attribute is 'true' the read action fails if no appropriate data exists on the recipient node. If the strict attribute is false, the read action will always return with a 'result', sending an empty result in place of a 'not found' error.

4.2 Error Codes

Table 4: Error Codes used by Create Action

CodeTextDescription
404Not foundThe strict attribute is set to 'true' and no matching data exists on the recipient node.

4.3 Examples

Reading data on the server using iq:private, and strict actions when data is on the server.

Example 3. Client Reads Private Data

SENDER:
<iq type="set" id="1001">
  <query xmlns="jabber:iq:private" action="read" strict="true">
    <exodus xmlns="exodus:prefs"/>
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1001">
  <query xmlns="jabber:iq:private" action="read" strict="true">
    <exodus xmlns="exodus:prefs"/>
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

With strict actions enabled, the absence of matching data will cause the read action to fail. Here we show iq:private, and strict actions with no matching data on the server.

Example 4. Client Reads Private Data but Not Found (strict)

SENDER:
<iq type="set" id="1002">
  <query xmlns="jabber:iq:private" action="read" strict="true">
    <data xmlns="imaginary"/>
  </query>
</iq>

RECIPIENT:
<iq
    type="error"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1002">
    <error code="404">Not Found</error>
    <data xmlns="imaginary"/>
  </query>
</iq>

With strict actions disabled, the absence of matching data will cause the read action to return an 'empty' result. Here we show iq:private, and strict actions disabled with no matching data on the server.

Example 5. Client Reads Private Data but Not Found (not strict)

SENDER:
<iq type="set" id="1003">
  <query xmlns="jabber:iq:private" action="read" strict="false">
    <data xmlns="imaginary"/>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1003">
    <data xmlns="imaginary"/>
  </query>
</iq>

5. Update Action

5.1 Description

The update action edits existing data on the recipient node. If the strict attribute is 'true' the update action fails if matching data does not already exists on the recipient node. If the strict attribute is false, the update action will edit existing data, inserting the data on the recipient node if necessary.

5.2 Error Codes

Table 5: Error Codes used by Create Action

CodeTextDescription
404Not FoundThe strict attribute is set to 'true' and matching data does NOT already exist on the recipient node.

5.3 Examples

Updating existing new data on the server using iq:private, and strict actions when existing data is on the server.

Example 6. Client Updates Existing Private Data

SENDER:
<iq type="set" id="1001">
  <query xmlns="jabber:iq:private" action="update" strict="true">
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1001"/>

With strict actions enabled, the absence of existing data will cause the update action to fail. Here we show iq:private, and strict actions with no existing data on the server.

Example 7. Client Updates Private Data but None Found

SENDER:
<iq type="set" id="1002">
  <query xmlns="jabber:iq:private" action="update" strict="true">
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

RECIPIENT:
<iq
    type="error"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1002">
    <error code="404">Not Found</error>
    <exodus xmlns="exodus:prefs">
      <defaultnick>Hamlet</defaultnick>
    </exodus>
  </query>
</iq>

6. Delete Action

6.1 Description

The delete action deletes existing data on the recipient node. If the strict attribute is 'true' the delete action fails if matching data does not already exists on the recipient node. If the strict attribute is false, the delete action will delete any existing data on the recipient node (if any) and return successful..

6.2 Error Codes

Table 6: Error Codes used by Create Action

CodeTextDescription
404Not FoundThe strict attribute is set to 'true' and matching data does NOT already exist on the recipient node.

6.3 Examples

Deleting existing new data on the server using iq:private, and strict actions when existing data is on the server.

Example 8. Client Deletes Existing Private Data

SENDER:
<iq type="set" id="1001">
  <query xmlns="jabber:iq:private" action="delete" strict="true">
    <exodus xmlns="exodus:prefs"/>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1001"/>

With strict actions enabled, the absence of existing data will cause the delete action to fail. Here we show iq:private, and strict actions with no existing data on the server.

Example 9. Client Deletes Private Data but None Found (strict)

SENDER:
<iq type="set" id="1002">
  <query xmlns="jabber:iq:private" action="delete" strict="true">
    <data xmlns="imaginary"/>
  </query>
</iq>

RECIPIENT:
<iq
    type="error"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1002">
    <error code="404">Not Found</error>
    <data xmlns="imaginary"/>
  </query>
</iq>

With strict actions disabled, the absence of existing data will not cause the delete action to fail. Here we show iq:private, and strict actions with no existing data on the server.

Example 10. Client Deletes Private Data but None Found (not strict)

SENDER:
<iq type="set" id="1003">
  <query xmlns="jabber:iq:private" action="delete" strict="false">
    <data xmlns="imaginary"/>
  </query>
</iq>

RECIPIENT:
<iq
    type="result"
    from="hamlet@shakespeare.lit/denmark"
    to="hamlet@shakespeare.lit/denmark"
    id="1003"/>

7. Defining an Action Protocol

7.1 Description

In order to define an action protocol that uses the <query/> behavior defined in this document, you must specify the following:


Appendices


Appendix A: Document Information

Series: XEP
Number: 0099
Publisher: XMPP Standards Foundation
Status: Deferred
Type: Standards Track
Version: 0.1.1
Last Updated: 2018-11-03
Approving Body: XMPP Council
Dependencies: None
Supersedes: None
Superseded By: None
Short Name: Not yet assigned
Source Control: HTML
This document in other formats: XML  PDF


Appendix B: Author Information

Iain Shigeoka

Email: iain@jivesoftware.com
JabberID: smirk@jabber.com


Appendix C: Legal Notices

Copyright

This XMPP Extension Protocol is copyright © 1999 – 2018 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. ##

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 from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.

IPR Conformance

This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at <https://xmpp.org/about/xsf/ipr-policy> or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).

Appendix D: Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) 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.


Appendix E: Discussion Venue

The primary venue for discussion of XMPP Extension Protocols is the <standards@xmpp.org> discussion list.

Discussion on other xmpp.org discussion lists might also be appropriate; see <http://xmpp.org/about/discuss.shtml> for a complete list.

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


Appendix F: Requirements Conformance

The following requirements 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".


Appendix G: Notes


Appendix H: Revision History

Note: Older versions of this specification might be available at http://xmpp.org/extensions/attic/

Version 0.1.1 (2018-11-03)

Fix a bunch of typos, batch-style. (pep)

Version 0.1 (2003-06-25)

Initial version. (iss)

END