XCAPClient (version 1.2)

Description

XCAP (RFC 4825) is a protocol on top of HTTP which allows a client to manipulate the contents of Presence Information Data Format (PIDF) based presence documents. These documents are stored in a server in XML format and are fetched, modified, replaced or deleted by the client. The protocol allows multiple clients to manipulate the data, provided that they are authorized to do so. XCAP is already used in SIMPLE-based presence systems for manipulation of presence lists and presence authorization policies.

XCAPClient library implements the XCAP protocol in client side, allowing the applications to get, store, modify and delete XML documents in the server.

Features

The library implements the following features:

  • Fetch, create/replace and delete a XML document.

  • Fetch, create/replace and delete a XML node.

  • Fetch, create/replace and delete a XML node attribute.

  • Fetch node namespace bindings as they are used in the server (RFC 4825 Section 7.10).

  • Full configurable parameters allowing customized fields for each XCAP application, such auid, XML namespace, MIME-Type, scope (:user or :global) and default document name (“index” if not set).

  • Custom identity header (as “X-XCAP-Preferred-Identity”) required in some XCAP/XDM environments.

  • Manage of multiple documents per XCAP application.

  • Fetch the XCAP server auids, extensions and namespaces (“xcap-caps” application).

  • SSL.

  • Digest and Basic HTTP authentication.

  • Raise custom Ruby exception for each HTTP error response.

Ruby XCAPClient works in Ruby 1.8 and 1.9.

Support

The XCAPClient mailing list is available here:

The bug tracker is available here:

API

A developer interested in this library should study the following documents:

  • XCAPClient::Client

  • XCAPClient::Application

  • XCAPClient::Document

  • ERRORS.rdoc

Synopsis

require 'rubygems'
require 'xcapclient'

Create a client

xcap_conf = {
  :xcap_root => "https://xcap.myserver.org/xcap-root",
  :user => "sip:[email protected]",
  :auth_user => "me",
  :password => "xxxxxx",
  :ssl_verify_cert => true
}

xcap_apps = {
  "pres-rules" => {
    :xmlns => "urn:ietf:params:xml:ns:pres-rules",
    :mime_type => "application/auth-policy+xml",
    :scope => :user,
    :document_name => "index"
  }
}

@xcapclient = Client.new(xcap_conf, xcap_apps)

Fetch the “pres-rules” document from the server

@xcapclient.get("pres-rules")

Fetch again the “pres-rules” document (now including the stored ETag)

By default, the methods accesing the XCAP server include the ETag if it’s available. Since it was already got on the previous request, it’s included in the new request. If the document has not been modified in the server by other client, the server replies “304 Not Modified” and the method generates a XCAPClient::XCAPClientError::HTTPDocumentNotModified exception.

begin
  @xcapclient.get("pres-rules")
rescue XCAPClientError::HTTPDocumentNotModified
  puts "The document has not been modified in the server."
end

Replace the local document and upload it to the server

@xcapclient.application("pres-rules").document.reset
@xcapclient.application("pres-rules").document.plain = "<?xml version='1.0' encoding='UTF-8'?> ..."
@xcapclient.put("pres-rules")

Delete the document in the server

@xcapclient.delete("pres-rules")

Create a new document and upload it (a new “vacation-rules” document for “pres-rules” application)

my_pres_rules_2 = @xcapclient.application("pres-rules").add_document("vacation-rules")
my_pres_rules_2.plain = "<?xml version='1.0' encoding='UTF-8'?> ..."
@xcapclient.put("pres-rules", my_pres_rules_2)
  # or
@xcapclient.put("pres-rules", "vacation-rules")

Fetch a node (with “id” = “sip:[email protected]”)

@xcapclient.get_node("pres-rules", nil,
  'cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one[@id="sip:[email protected]"]',
  {"cp" => "urn:ietf:params:xml:ns:common-policy"})

Add a new node (a new allowed user in “pres-rules” document)

@xcapclient.put_node("pres-rules", nil,
  'cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one[@id="sip:[email protected]"]',
  '<cp:one id="sip:[email protected]"/>',
  {"cp"=>"urn:ietf:params:xml:ns:common-policy"})

Fetch a node attribute (node “name” from node with “id” = “sip:[email protected]”)

@xcapclient.get_attribute("pres-rules", nil,
  'cp:ruleset/cp:rule[@id="pres_whitelist"]/cp:conditions/cp:identity/cp:one[@id="sip:[email protected]"]',
  "name",
  {"cp" => "urn:ietf:params:xml:ns:common-policy"})

ToDo

  • Parse 409 error response (“application/xcap-error+xml”) as it contains the explanation of the conflict (RFC 4825 section 11).

Requeriments

Install

gem install xcapclient

Test Unit

The GEM includes a Test Unit script located in “test” directory name “test_unit_01.rb”. It performs various XCAP queries against a XCAP server using the test/PRES_RULES_EXAMPLE.xml document.

NOTE: You must edit the settings with your own values (edit the top lines of the script).

License

GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

(see LICENSE.txt)

Author

Iñaki Baz Castillo