« Previous - Version 6/8 (diff) - Next » - Current version
Adrian Georgescu, 04/13/2010 10:14 am


= XCAP API =

<acronym title="WikiStart, Sip*, depth=3">TOC</acronym>
XCAP protocol allows a client to read, write, and modify application configuration data stored in XML format on a server. XCAP maps XML document sub-trees and element attributes to HTTP URIs, so that these components can be directly accessed by clients using HTTP protocol. An XCAP server is used by XCAP clients to store data like buddy lists and presence policy in combination with a SIP Presence server that supports PUBLISH, SUBSCRIBE and NOTIFY methods to provide a complete SIP SIMPLE solution.

XCAP client is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-xcaplib;a=summary python-xcaplib]. The library provides {{{xcaplib.client.XCAPClient}}} class which is an HTTP client with an interface better suited for XCAP servers. The library also provides
a version of XCAPClient ({{{xcaplib.green.XCAPClient}}}) built on top of eventlet, which may be used in twisted reactor.

Components '''get'''(''self'', ''application'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}})::
Make an HTTP GET request to the resource identified by ''application'' and ''node''. Return a Resource instance on success.
Raise HTTPError if the operation was unsuccessful. '''put'''(''self'', ''application'', ''resource'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}})::
Make an HTTP PUT request to the resource identified by ''application'' and ''node''. Use ''resource'' as a request body.
Raise HTTPError is the operation was unsuccessful. '''delete'''(''self'', ''application'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}})::
Make an HTTP DELETE request to the resource identified by ''application'' and ''node''.
Raise HTTPError if the operation was unsuccessful. Usage

{{{
client = XCAPClient(xcap_root, xcap_user_id, password=password)
document = file('examples/resource-lists.xml').read()

  1. put the document on the server
    client.put('resource-lists', document)
  1. read the document from the server
    got = client.get('resource-lists')
  1. get a specific element within a document
    element = client.get('resource-lists', '/resource-lists/list/entry/display-name')
  1. get an attribute:
    res = client.get('resource-lists', '/resource-lists/list/entry/@uri')
  1. replace an element conditionally, based on the etag
    client.put('resource-lists', '<entry uri="sip:"><display-name>The Bob</display-name></entry>',
    '/resource-lists/list/entry[@uri="sip:"]', etag=stored_etag)
  1. delete an element
    client.delete('resource-lists', node_selector, etag=res.etag)
    }}}