Use a custom item value (CAP-V).
Use PubSub publish-options preconditions.
In order to atomically compare-and-publish an item, a client - sends an &IQ; with a 'pubsub' element qualified by the - 'urn:xmpp:pubsub:cap:0' namespace. The element MUST contain the same - attributes and elements as the <publish/> element defined in - &xep0060; and it MUST contain a previd attribute containing - an item ID.
+PubSub services supporting the Compare-And-Publish PubSub extension MUST include a Comapre-and-Publish value + (CAP-V) for every item in every response. The CAP-V value MUST change if the content of the item changed and + different item content under the same node MUST NOT yield the same CAP-V. A simple computation of the CAP-ID would + be to hash the String representation of the item's content.
-The PubSub service MUST only publish the item if the node's - latest item ID is equal to the ID found in the 'previd' - attribute.
+CAP-Vs are assoicated with PubSub node's items via the item ID. The maping information is placed by the PubSub + service in a <cap-v-map/> extension element, qualified by the 'urn:xmpp:pubsub:cap:0' namespace, as child + element of the <items/> element. The <cap-v-map/> element contains one or more <cap-v-map-entry/> + elements, of which each MUST have a 'item-id' and a 'cap-value' attribute. The former contains the PubSub item ID + value and the later contains the according CAP-V of the item.
-In order to atomically compare-and-publish an item, a client sends a XEP-0060 <publish/> IQ + with a 'pubsub#prev_item_cap_value' precondition publishing option, set to the value of the currently assumed CAP-V + of the latest item of the node.
+ +The PubSub service MUST only publish the item if the node's latest item CAP-V is equal to the + CAP-V found in the 'pubsub#prev_item_cap_value' field.
+ +If the 'previd' matched the latest item's ID and if the service - was able to successfully process the request then the protocol - continues as defined in XEP-0060 7.1.2.
-In case the Compare-And-Publish operation failed because the - latest node id is not the same as given in the 'previd' attribute - in the request, the server returns an &IQ; result with 'pubsub' - element qualified by the 'urn:xmpp:pubsub:cap:0' namespace which - contains a <compare-and-publish-failed/> element. The - element MUST have a 'id' attribute with the ID of the lastest - item.
+In case the Compare-And-Publish operation failed because the latest node id is not the same + as given in the 'previd' attribute in the request, the server returns an <conflict/> error + of type 'modify' which a pubsub-specific condition of <precondition-not-met/> and a + <compare-and-publish-failed/> element qualifed by the 'urn:xmpp:pubsub:cap:0' + namespace. The element MUST have a 'cap-id' attribute with the CAP-V of the lastest item.
-All other error cases are handled as specified in - XEP-0060 § 7.1.3
+Unfortunately it was not possible to re-use the PubSub item ID for the "Atomically + Compare-And-Publish" purpose. This is mostly due XEP-0060 § 12.8 stating that:
++ "If a publisher publishes an item and the ItemID + matches that of an existing item, the pubsub service MUST overwrite the existing item and generate a new event + notification." +
+Which means that the content of an item could change without its ID, rendering the item ID + unusable for CAP.
+ +Injecting a "cap"-namespaced attribute carrying the item's CAP-V into PubSub's <item/> + would be a very elegant approach to assign CAP-Vs to PubSub items (and the favored one of the + XEP's author). But the usage of namespaces attributes within XMPP is controversial. Therefore this + XEP resorts to using the <cap-v-map/> approach for now.
This extension protocol does not add any further security - considerations to the ones mentioned in XEP-0060 § - 14..
+This extension protocol does not add any further security considerations to the ones mentioned + in XEP-0060 § 14..
- urn:xmpp:pubsub:cap:0
- Indicates support for Compare-And-Publish
- XEP-XXXX
+ urn:xmpp:pubsub:cap:0
+ Indicates support for Compare-And-Publish
+ XEP-XXXX
]]>
+ This specification defines the following <publish-options/> fields:
+]]>
+
+
TODO: Add after the XEP leaves the 'experimental' state.
Thanks to Kim Alvefur and Dave Cridland for their feedback.
+ +