SipXcapApiDocumentation » History » Version 1
Saúl Ibarra Corretgé, 11/09/2012 01:21 PM
1 | 1 | Saúl Ibarra Corretgé | h1. XCAP API |
---|---|---|---|
2 | |||
3 | |||
4 | The @sipsimple.xcap@ module offers a high level API for managing XCAP resources to other parts of the middleware or to the applications built on top of the middleware. The XCAP resources |
||
5 | which can be managed by means of this module are: |
||
6 | * *contact list*, by means of the @resource-lists@ and @rls-services@ XCAP applications |
||
7 | * *presence policies*, by means of the @org.openmobilealliance.pres-rules@ or @pres-rules@ XCAP applications |
||
8 | * *dialoginfo policies*, by means of the @org.openxcap.dialog-rules@ XCAP application |
||
9 | * *status icon*, by means of the @org.openmobilealliance.pres-content@ XCAP application |
||
10 | * *offline status*, by means of the @pidf-manipulation@ XCAP application |
||
11 | |||
12 | The module works with OMA-compliant XCAP servers. Not all applications need to be available on the XCAP server, although it is obvious that only those that are will be managed. The required applications are: @org.openmobilealliance.pres-rules@, @resource-lists@ and @rls-services@. The central entity for XCAP resource management is the XCAPManager, whose API relies on a series of objects describing |
||
13 | the resources stored on the XCAP server. |
||
14 | |||
15 | h2. Contact |
||
16 | |||
17 | |||
18 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
19 | |||
20 | A @Contact@ is the representation of a person, containing a list of URIs with additional information stored about them, central to the XCAP contact list management. Information about a contact is stored in the @resource-lists@, @rls-services@ and @org.openmobilealliance.pres-rules@ applications mainly. |
||
21 | |||
22 | |||
23 | *attributes* |
||
24 | |||
25 | *id* |
||
26 | >A unique identifier for the contact. Should be composed of a sufficiently random string across multiple instances. |
||
27 | |||
28 | *name* |
||
29 | >A human-readable name which can be associated with the contact. This is stored using the @display-name@ standard @resource-lists@ element. |
||
30 | |||
31 | *uris* |
||
32 | >A list of @sipsimple.account.xcap.ContactURI@ instances. |
||
33 | |||
34 | *dialog* |
||
35 | > A @sipsimple.account.xcap.EventHandling@ instance which specifies the policy for this contact, and a boolean flag that indicates whether a subscription to the @dialog@ event is desired. |
||
36 | |||
37 | *presence* |
||
38 | > A @sipsimple.account.xcap.EventHandling@ instance which specifies the policy for this contact, and a boolean flag that indicates whether a subscription to the @presence@ event is desired. |
||
39 | |||
40 | *attributes* |
||
41 | >A dictionary containing additional name, value pairs which the middleware or the application can use to store any information regarding this contact. This is stored through a custom AG-Projects |
||
42 | >extension to resource-lists. |
||
43 | |||
44 | |||
45 | *methods* |
||
46 | |||
47 | |||
48 | *<notextile>__init__</notextile>*(_self_, *id*, *name*, *uris*, *presence_handling=None*, *dialog_handling=None*, ***attributes*) |
||
49 | >Initializes a new @Contact@ instance. If @presence_handling@ and @dialog_handling@ are set to None then defaults are created with a @default@ policy and the subscription boolean flag set to False. |
||
50 | |||
51 | |||
52 | h2. Policy |
||
53 | |||
54 | |||
55 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
56 | |||
57 | A @Policy@ is similar to a @Contact@ but instead of representing a physical person, it represents a policy which is applied to a single URI. |
||
58 | |||
59 | |||
60 | *attributes* |
||
61 | |||
62 | *id* |
||
63 | >A unique identifier for the policy. Should be composed of a sufficiently random string across multiple instances. |
||
64 | |||
65 | *name* |
||
66 | >A human-readable name which can be associated with the policy. |
||
67 | |||
68 | *uri* |
||
69 | >A string object representing the URI of this policy. |
||
70 | |||
71 | *dialog* |
||
72 | > A @sipsimple.account.xcap.EventHandling@ instance which specifies the policy for this policy, and a boolean flag that indicates whether a subscription to the @dialog@ event is desired. |
||
73 | |||
74 | *presence* |
||
75 | > A @sipsimple.account.xcap.EventHandling@ instance which specifies the policy for this policy, and a boolean flag that indicates whether a subscription to the @presence@ event is desired. |
||
76 | |||
77 | *attributes* |
||
78 | >A dictionary containing additional name, value pairs which the middleware or the application can use to store any information regarding this policy. This is stored through a custom AG-Projects |
||
79 | >extension to resource-lists. |
||
80 | |||
81 | |||
82 | *methods* |
||
83 | |||
84 | |||
85 | *<notextile>__init__</notextile>*(_self_, *id*, *name*, *uri*, *presence_handling=None*, *dialog_handling=None*, ***attributes*) |
||
86 | >Initializes a new @Policy@ instance. If @presence_handling@ and @dialog_handling@ are set to None then defaults are created with a @default@ policy and the subscription boolean flag set to False. |
||
87 | |||
88 | |||
89 | h2. Group |
||
90 | |||
91 | |||
92 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
93 | |||
94 | A @Group@ is a toplevel element which represents a logical entity for grouping contacts together. |
||
95 | |||
96 | |||
97 | *attributes* |
||
98 | |||
99 | *id* |
||
100 | >A unique identifier for the group. Should be composed of a sufficiently random string across multiple instances. |
||
101 | |||
102 | *name* |
||
103 | >A human-readable name which can be associated with the group. |
||
104 | |||
105 | *contacts* |
||
106 | > A list of @Contact@ objects. |
||
107 | |||
108 | *attributes* |
||
109 | >A dictionary containing additional name, value pairs which the middleware or the application can use to store any information regarding this policy. This is stored through a custom AG-Projects |
||
110 | >extension to resource-lists. |
||
111 | |||
112 | |||
113 | *methods* |
||
114 | |||
115 | |||
116 | *<notextile>__init__</notextile>*(_self_, *id*, *name*, *contacts*, ***attributes*) |
||
117 | >Initializes a new @Group@ instance. |
||
118 | |||
119 | h2. Addressbook |
||
120 | |||
121 | |||
122 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
123 | |||
124 | An @Adressbook@ is a collection of contacts, groups and policies. |
||
125 | |||
126 | |||
127 | *attributes* |
||
128 | |||
129 | *contacts* |
||
130 | > A list of @Contact@ objects. |
||
131 | |||
132 | *groups* |
||
133 | > A list of @Group@ objects. |
||
134 | |||
135 | *policies* |
||
136 | > A list of @Policy@ objects. |
||
137 | |||
138 | |||
139 | *methods* |
||
140 | |||
141 | |||
142 | *<notextile>__init__</notextile>*(_self_, *contacts*, *groups*, *policies*) |
||
143 | >Initializes a new @Addressbook@ instance. |
||
144 | |||
145 | |||
146 | h2. Icon |
||
147 | |||
148 | |||
149 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
150 | |||
151 | An @Icon@ instance represents a status icon stored using the @org.openmobilealliance.pres-content@ application. |
||
152 | |||
153 | |||
154 | *attributes* |
||
155 | |||
156 | |||
157 | *data* |
||
158 | >The binary data of the image, as a string. |
||
159 | |||
160 | *mime_type* |
||
161 | >The MIME type of the image, one of @image/jpeg@, @image/gif@ or @image/png@. |
||
162 | |||
163 | *description* |
||
164 | >An optional description of the icon. |
||
165 | |||
166 | *location* |
||
167 | >An HTTP(S) URI which can be used by other users to download the status icon of the local user. If the XCAP server returns the custom X-Alternative-Location header in its GET and PUT |
||
168 | >responses, that is used otherwise the XCAP URI of the icon is used. |
||
169 | |||
170 | |||
171 | *methods* |
||
172 | |||
173 | |||
174 | *<notextile>__init__</notextile>*(_self_, *data*, *mime_type*, *description*=@None@, *location*=@None@) |
||
175 | >Initializes a new @Icon@ instance. |
||
176 | |||
177 | h2. OfflineStatus |
||
178 | |||
179 | |||
180 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
181 | |||
182 | An @OfflineStatus@ instance represents data stored using the @pidf-manipulation@ application. |
||
183 | |||
184 | |||
185 | *attributes* |
||
186 | |||
187 | *pidf* |
||
188 | >A @sipsimple.payloads.pidf.PIDF@ instance which is stored in XCAP. |
||
189 | |||
190 | |||
191 | *methods* |
||
192 | |||
193 | |||
194 | *<notextile>__init__</notextile>*(_self_, *pidf*) |
||
195 | >Initializes a new @OfflineStatus@ instance. |
||
196 | |||
197 | h2. XCAPManager |
||
198 | |||
199 | |||
200 | Implemented in source:"sipsimple/xcap/__init__.py" |
||
201 | |||
202 | The XCAPManager is the central entity used to manage resource via the XCAP protocol. It uses a storage factory provided by @SIPApplication@ through the @Storage API@. It has state machine as described in the following diagram: |
||
203 | !{ align=center}xcap-manager-state.png! |
||
204 | |||
205 | The @load@ method needs to be called just once in order to load the data from the cache. Once this is done, the @start@ and @stop@ methods can be called as needed. Initially in the @stopped@ state, |
||
206 | the start method will result in a transition to the @initializing@ state. While in the @initializing@ state, the XCAP manager will try to connect to the XCAP server and retrieve the |
||
207 | capabilities (@xcap-caps@ application). It will then initiate a SUBSCRIBE for the @xcap-diff@ event and transition to the @fetching@ state. In the @fetching@ state, it |
||
208 | will try retrieve all the documents from the XCAP server, also specifying the ETag of the last known version. If none of the documents changed and this is not the first fetch, it transitions to the |
||
209 | @insync@ state. Otherwise, it inserts a @normalize@ operation at the beginning of the journal (described below) and transitions to the @updating@ state. In the @updating@ state, it |
||
210 | applies the operations from the journal which were not applied yet on the currently known documents and tries to push the documents, specifying the Etag of the last known version. If an operation |
||
211 | fails due to a document having been modified, it marks all the operations in the journal as not being applied and transitions to the @fetching@ state; if any other error occurs, the update is |
||
212 | retried periodically. If the update succeeds, data is extracted from the documents and the @XCAPManagerDidReloadData@ notification is sent. The XCAPManager then transitions to the @insync@ |
||
213 | state. A call to the @stop@ method will result in a transition to the @stopping@ state, termination of any existing SUBSCRIBE dialog and a transition to the @stopped@ state. |
||
214 | |||
215 | Modifications to the settings which control the XCAPManager can result in either a transition to the @initializing@ state or the termination of any previous SUBSCRIBE dialog and creation of a new |
||
216 | one. |
||
217 | |||
218 | The subscription to the @xcap-diff@ event allows the XCAPManager to be notified when the documents it manages are modified remotely. If the subscription fails, a fetch of all the documents is |
||
219 | tried and the subscription is retried in some time. This allows the XCAPManager to reload the documents when they are modified remotely even if @xcap-diff@ event is not supported by the provider. If subscription for @xcap-diff@ event fails, a fetch of all the documents will be tried every 2 minutes. |
||
220 | |||
221 | The XCAPManager keeps the documents as they are stored on the XCAP server along with their ETags in an on-disk cache. All operations are made using the conditional @If-Match@ and |
||
222 | @If-None-Match@ headers such that remote modifications the XCAPManager does not know about are not overwritten and bandwidth and processing power are not wasted by GET operations when a document |
||
223 | is not modified. |
||
224 | |||
225 | Operations which the XCAPManager can be asked to apply to modify the documents are kept in a journal. This journal is saved to disk, such that operations which cannot be applied when requested due |
||
226 | to server problems or lack of connectivity are retried even after application restarts. In addition, the high-level defined operations and the journal allow the modifications to be applied even if the |
||
227 | document stored on the XCAP server are modified. Put differently, operations do depend on a specific version of the documents and the XCAPManager will try to apply them irrespective of the format |
||
228 | of the document. |
||
229 | |||
230 | |||
231 | *configuration* |
||
232 | |||
233 | |||
234 | *Account.id*, *Account.auth.username*, *Account.auth.password* |
||
235 | >These are used both for the @xcap-diff@ subscription and the XCAP server connection. |
||
236 | |||
237 | *Account.sip.subscribe_interval* |
||
238 | >This controls the Expires header used for the subscription, although a 423 response from the server can result in a larger Expires value being used. |
||
239 | |||
240 | *Account.xcap.xcap_root* |
||
241 | >This specifies the XCAP root used for contacting the XCAP server and managing the resources. If this setting is @None@, a TXT DNS query is made for the @xcap@ subdomain of the SIP account's |
||
242 | >domain. The result is interpreted as being an XCAP root. Example record for account alice@example.org: |
||
243 | <pre> |
||
244 | xcap.example.org. IN TXT "https://xcap.example.org/xcap-root" |
||
245 | </pre> |
||
246 | |||
247 | *SIPSimpleSettings.sip.transport_list* |
||
248 | >This controls the transports which can be used for the subscription. |
||
249 | |||
250 | |||
251 | *methods* |
||
252 | |||
253 | |||
254 | *<notextile>__init__</notextile>*(_self_, *account*) |
||
255 | >Initializes an XCAPManager for the specified account. |
||
256 | |||
257 | *init*(_self_) |
||
258 | >Initializes the XCAPManager before it can be started. |
||
259 | |||
260 | *start*(_self_) |
||
261 | >Starts the XCAPManager. This will result in the subscription being started, the XCAP server being contacted and any operations in the journal being applied. This method must be called in a green |
||
262 | >thread. |
||
263 | |||
264 | *stop*(_self_) |
||
265 | >Stops the XCAPManager from performing any tasks. Waits until the @xcap-diff@ subscription, if any, is terminated. This method must be called in a green thread. |
||
266 | |||
267 | *transaction*(_self_) |
||
268 | > Return as @XCAPTransaction@ context manager object for running a piece of code within a transaction. |
||
269 | |||
270 | *start_transaction*(_self_) |
||
271 | >This allows multiple operations to be queued and not applied immediately. All operations queued after a call to this method will not be applied until the @commit_transaction@ method is called. |
||
272 | >This does not have the same meaning as a relational database transaction, since there is no @rollback@ operation. |
||
273 | |||
274 | *commit_transaction*(_self_) |
||
275 | >Applies the modifications queued after a call to @start_transaction@. This method needs to be called the exact same number of times the @start_transaction@ method was called. Does not have |
||
276 | >any effect if @start_transaction@ was not previously called. |
||
277 | |||
278 | The following methods results in XCAP operations being queued on the journal: |
||
279 | |||
280 | *add_group*(_self_, *group*) |
||
281 | >Add a group. |
||
282 | |||
283 | *update_group*(_self_, *group*, *attributes*) |
||
284 | >Update the specified group with the given attributes. |
||
285 | |||
286 | *remove_group*(_self_, *group*) |
||
287 | >Remove the specified group. |
||
288 | |||
289 | *add_contact*(_self_, *contact*) |
||
290 | >Adds a new contact, described by a @Contact@ object. Requests to add a contact to some OMA reserved presence policies (@wp_prs_unlisted@, @wp_prs_allow_unlisted@, @wp_prs_block_anonymous@, @wp_prs_allow_own@) is ignored. |
||
291 | |||
292 | *update_contact*(_self_, *contact*, *attributes*) |
||
293 | >Modifies a contact's properties. The keywords can be any of the @Contact@ attributes, with the same meaning. Requests to add a contact to some OMA reserved presence policies (@wp_prs_unlisted@, @wp_prs_allow_unlisted@, @wp_prs_block_anonymous@, @wp_prs_allow_own@) is ignored. |
||
294 | |||
295 | *remove_contact*(_self_, *contact*) |
||
296 | >Removes the specified contact. |
||
297 | |||
298 | *add_contact_uri*(_self_, *contact*, *uri*) |
||
299 | > Add the specified URI to the specified contact. |
||
300 | |||
301 | *update_contact_uri*(_self_, *contact*, *uri*, *attributes*) |
||
302 | > Update the specified URI. |
||
303 | |||
304 | *remove_contact_uri*(_self_, *contact*, *uri*) |
||
305 | > Remove the specified URI from the specified contact. |
||
306 | |||
307 | *add_group_member*(_self_, *group*, *contact*) |
||
308 | > Adds the specified contact to the specified group. A contact may be added to multiple groups. |
||
309 | |||
310 | *remove_group_member*(_self_, *group*, *contact*) |
||
311 | > Removes the specified contact from the specified group. |
||
312 | |||
313 | *add_policy*(_self_, *policy*) |
||
314 | >Adds a new policy, described by a @Policy@ object. |
||
315 | |||
316 | *update_policy*(_self_, *policy*, *attributes*) |
||
317 | >Modifies a presence policy's properties. The keywords can be any of the @PresencePolicy@ attributes, with the same meaning. |
||
318 | |||
319 | *remove_policy*(_self_, *policy*) |
||
320 | >Removes the specified policy. |
||
321 | |||
322 | *set_status_icon*(_self_, *icon*) |
||
323 | >Sets the status icon using the information from the @Icon@ object specified. The @location@ attribute is ignored. The MIME type must be one of @image/gif@, @image/png@ or @image/jpeg@. If the argument is @None@, the status icon is deleted. |
||
324 | |||
325 | *set_offline_status*(_self_, *status*) |
||
326 | >Sets the offline status using the information from the @OfflineStatus@ object specified. If the argument is @None@, the offline status document is deleted. |
||
327 | |||
328 | |||
329 | *notifications* |
||
330 | |||
331 | |||
332 | *XCAPManagerWillStart* |
||
333 | >This notification is sent just after calling the @start@ method. |
||
334 | |||
335 | *XCAPManagerDidStart* |
||
336 | >This notification is sent after the XCAPManager has started doing its tasks (contacting the XCAP server, subscribing to @xcap-diff@ event). This notification does not mean that |
||
337 | >any of these operations were successful, as the XCAPManager will retry them continuously should they fail. |
||
338 | |||
339 | *XCAPManagerWillEnd* |
||
340 | >This notification is sent just after calling the @stop@ method. |
||
341 | |||
342 | *XCAPManagerDidEnd* |
||
343 | >This notification is sent when the XCAPManager has stopped performing any tasks. This also means that any active @xcap-diff@ subscription has been terminated. |
||
344 | |||
345 | *XCAPManagerDidDiscoverServerCapabilities* |
||
346 | >This notification is sent when the XCAPManager contacts an XCAP server for the first time or after the connection is reset due to configuration changes. The data of the notification contains |
||
347 | >information about the server's capabilities (obtained using the @xcap-caps@ application). |
||
348 | |||
349 | >+_auids_+: |
||
350 | >>A list of string representing the AUIDs supported by the server. |
||
351 | |||
352 | *XCAPManagerDidReloadData* |
||
353 | >This notification is sent when the XCAPManager synchronizes with the XCAP server. The data of the notification contains objects representing the data as it is stored on the XCAP server. |
||
354 | |||
355 | >+_addressbook_+: |
||
356 | >>A @sipsimple.account.xcap.Addressbook@ object instance. |
||
357 | |||
358 | >+_presence_rules_+: |
||
359 | >>A @sipsimple.account.xcap.PresenceRules@ object. Currently it only contains the default policy. |
||
360 | |||
361 | >+_dialog_rules_+: |
||
362 | >>A @sipsimple.account.xcap.DialogRules@ object. Currently it only contains the default policy. |
||
363 | |||
364 | >+_status_icon_+: |
||
365 | >>A @StatusIcon@ object if one is stored, @None@ otherwise. |
||
366 | |||
367 | >+_offline_status_+: |
||
368 | >>A @OfflineStatus@ object if offline status information is stored, @None@ otherwise. |
||
369 | |||
370 | *XCAPManagerDidChangeState* |
||
371 | >This notification is sent when the XCAPManager transitions from one state to another. |
||
372 | |||
373 | >+_prev_state_+: |
||
374 | >>The old state of the XCAPManager, a string. |
||
375 | |||
376 | >+_state_+: |
||
377 | >>The new state of the XCAPManager, a string. |