SipXCAPApi

Version 7 (Adrian Georgescu, 04/13/2010 10:14 am)

1 1 Adrian Georgescu
2 7 Adrian Georgescu
h1. XCAP API
3 7 Adrian Georgescu
4 7 Adrian Georgescu
5 7 Adrian Georgescu
6 1 Adrian Georgescu
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.
7 1 Adrian Georgescu
8 7 Adrian Georgescu
XCAP client is implemented by "python-xcaplib":http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-xcaplib;a=summary. The library provides @xcaplib.client.XCAPClient@ class which is an HTTP client with an interface better suited for XCAP servers. The library also provides
9 7 Adrian Georgescu
a version of XCAPClient (@xcaplib.green.XCAPClient@) built on top of eventlet, which may be used in twisted reactor.
10 1 Adrian Georgescu
11 1 Adrian Georgescu
12 7 Adrian Georgescu
h2. Components
13 7 Adrian Georgescu
14 7 Adrian Georgescu
15 7 Adrian Georgescu
*get*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@)
16 7 Adrian Georgescu
 Make an HTTP GET request to the resource identified by _application_ and _node_. Return a Resource instance on success.
17 1 Adrian Georgescu
 Raise HTTPError if the operation was unsuccessful.
18 1 Adrian Georgescu
19 7 Adrian Georgescu
*put*(_self_, _application_, _resource_, _node_=@None@, _etag_=@None@, _headers_=@None@)
20 7 Adrian Georgescu
 Make an HTTP PUT request to the resource identified by _application_ and _node_. Use _resource_ as a request body.
21 5 Adrian Georgescu
 Raise HTTPError is the operation was unsuccessful.
22 5 Adrian Georgescu
23 7 Adrian Georgescu
*delete*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@)
24 7 Adrian Georgescu
 Make an HTTP DELETE request to the resource identified by _application_ and _node_.
25 5 Adrian Georgescu
 Raise HTTPError if the operation was unsuccessful.
26 5 Adrian Georgescu
27 5 Adrian Georgescu
28 7 Adrian Georgescu
h2. Usage
29 7 Adrian Georgescu
30 7 Adrian Georgescu
31 7 Adrian Georgescu
<pre>
32 2 Oliver Bril
client = XCAPClient(xcap_root, xcap_user_id, password=password)
33 2 Oliver Bril
document = file('examples/resource-lists.xml').read()
34 2 Oliver Bril
35 2 Oliver Bril
# put the document on the server
36 2 Oliver Bril
client.put('resource-lists', document)
37 1 Adrian Georgescu
38 3 Oliver Bril
# read the document from the server
39 1 Adrian Georgescu
got = client.get('resource-lists')
40 3 Oliver Bril
41 4 Oliver Bril
# get a specific element within a document
42 3 Oliver Bril
element = client.get('resource-lists', '/resource-lists/list/entry/display-name')
43 3 Oliver Bril
44 3 Oliver Bril
# get an attribute:
45 3 Oliver Bril
res = client.get('resource-lists', '/resource-lists/list/entry/@uri')
46 3 Oliver Bril
47 3 Oliver Bril
# replace an element conditionally, based on the etag
48 3 Oliver Bril
client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>',
49 3 Oliver Bril
           '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag)
50 3 Oliver Bril
51 3 Oliver Bril
# delete an element
52 3 Oliver Bril
client.delete('resource-lists', node_selector, etag=res.etag)
53 7 Adrian Georgescu
</pre>