SipXCAPApi

Version 2 (Oliver Bril, 03/31/2009 03:35 pm)

1 1 Adrian Georgescu
= XCAP API =
2 1 Adrian Georgescu
3 1 Adrian Georgescu
[[TOC(WikiStart, Sip*, depth=3)]]
4 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.
5 2 Oliver Bril
6 2 Oliver Bril
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
7 2 Oliver Bril
a version of XCAPClient ({{{xcaplib.green.XCAPClient}}}) built on top of eventlet, which may be used in twisted reactor.
8 2 Oliver Bril
9 2 Oliver Bril
Here a few examples on how to use {{{XCAPClient}}}:
10 2 Oliver Bril
{{{
11 2 Oliver Bril
client = XCAPClient(xcap_root, xcap_user_id, password=password)
12 2 Oliver Bril
document = file('examples/resource-lists.xml').read()
13 2 Oliver Bril
14 2 Oliver Bril
# put the document on the server
15 2 Oliver Bril
client.put('resource-lists', document)
16 2 Oliver Bril
17 2 Oliver Bril
# read the document from the server
18 2 Oliver Bril
got = client.get('resource-lists')
19 2 Oliver Bril
20 2 Oliver Bril
# get a specific element within a document
21 2 Oliver Bril
element = client.get('resource-lists', '/resource-lists/list/entry/display-name')
22 2 Oliver Bril
23 2 Oliver Bril
# get an attribute:
24 2 Oliver Bril
res = client.get('resource-lists', '/resource-lists/list/entry/@uri')
25 2 Oliver Bril
26 2 Oliver Bril
# replace an element conditionally, based on the etag
27 2 Oliver Bril
client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>', '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag)
28 2 Oliver Bril
29 2 Oliver Bril
# delete an element
30 2 Oliver Bril
client.delete('resource-lists', node_selector, etag=res.etag)
31 2 Oliver Bril
}}}