Project

General

Profile

SipPayloadsApi » History » Version 1

Adrian Georgescu, 04/13/2010 10:21 AM

1 1 Adrian Georgescu
= Payloads API =
2
3
[[TOC(SipPayloadsApi*, depth=3)]]
4
5
Presence applications provide non-SIP functionality that are required for
6
implementing a feature-rich SIP SIMPLE client.  
7
8
The following modules are used for parsing and generating bodies carried using
9
SIP PUBLISH/SUBSCRIBE/NOTIFY methods that have been designed for
10
asynchronous event notifications to convey in real-time state and other
11
information between end-points. 
12
13
An example of state information is presence, which in its basic form provides user availability information based on end-user choice. In its
14
advanced form, presence can provide rich state information including but not
15
limited to user mood, geo-location, environment, noise level and type of
16
communication desired. The information can be disseminated based on a
17
granular policy which allows end-users to decide who has access to which
18
part of the published information.
19
20
These applications are used by the SIP core [wiki:SipCoreApiDocumentation#Publication Publication] and [wiki:SipCoreApiDocumentation#Subscription Subscription] classes.
21
22
== Common Policy ==
23
24
Generic data types to be used in policy applications, according to [http://tools.ietf.org/html/rfc4745 RFC 4745].
25
26
Example usage:
27
28
{{{
29
>>> alice = IdentityOne('sip:alice@example.com')
30
>>> carol = IdentityOne('tel:+1-212-555-1234')
31
>>> bob = IdentityOne('mailto:bob@example.net')
32
>>> print carol
33
tel:+1-212-555-1234
34
>>> id = Identity([alice, bob])
35
>>> print id
36
Identity([IdentityOne('sip:alice@example.com'), IdentityOne('mailto:bob@example.net')])
37
>>> id[1:1] = [carol]
38
>>> print id
39
Identity([IdentityOne('sip:alice@example.com'), IdentityOne('tel:+1-212-555-1234'), IdentityOne('mailto:bob@example.net')])
40
>>> conditions = Conditions([id])
41
>>> rule = Rule(id='f3g44r1', conditions=conditions, actions=Actions(), transformations=Transformations())
42
>>> ruleset = RuleSet()
43
>>> ruleset.append(rule)
44
>>> print ruleset.toxml(pretty_print=True)
45
<?xml version='1.0' encoding='UTF-8'?>
46
<cp:ruleset xmlns:cp="urn:ietf:params:xml:ns:common-policy">
47
  <cp:rule id="f3g44r1">
48
    <cp:conditions>
49
      <cp:identity>
50
        <cp:one id="sip:alice@example.com"/>
51
        <cp:one id="mailto:bob@example.net"/>
52
        <cp:one id="tel:+1-212-555-1234"/>
53
      </cp:identity>
54
    </cp:conditions>
55
    <cp:actions/>
56
    <cp:transformations/>
57
  </cp:rule>
58
</cp:ruleset>
59
<BLANKLINE>
60
}}}
61
62
== Pres-rules ==
63
64
Parses and produces Presence Authorization Rules documents according to [http://tools.ietf.org/html/rfc5025 RFC 5025].
65
66
Authorization rules are stored on the XCAP server. The presence rules are generated either based on user initiative or as a response to a new subscription signaled by a change in the watcherinfo application.
67
68
Example usage:
69
70
{{{
71
>>> conditions = Conditions([Identity([IdentityOne('sip:user@example.com')])])
72
>>> actions = Actions([SubHandling('allow')])
73
>>> transformations = Transformations()
74
>>> psrv = ProvideServices(provides=[ServiceURIScheme('sip'), ServiceURIScheme('mailto')])
75
>>> ppers = ProvidePersons(all=True)
76
>>> transformations[0:0] = [psrv, ppers]
77
>>> transformations.append(ProvideActivities('true'))
78
>>> transformations.append(ProvideUserInput('bare'))
79
>>> transformations.append(ProvideUnknownAttribute(ns='urn:vendor-specific:foo-namespace', name='foo', value='true'))
80
>>> rule = Rule(id='a', conditions=conditions, actions=actions, transformations=transformations)
81
>>> prules = PresRules([rule])
82
>>> print prules.toxml(pretty_print=True)
83
<?xml version='1.0' encoding='UTF-8'?>
84
<cp:ruleset xmlns:pr="urn:ietf:params:xml:ns:pres-rules" xmlns:cp="urn:ietf:params:xml:ns:common-policy">
85
  <cp:rule id="a">
86
    <cp:conditions>
87
      <cp:identity>
88
        <cp:one id="sip:user@example.com"/>
89
      </cp:identity>
90
    </cp:conditions>
91
    <cp:actions>
92
      <pr:sub-handling>allow</pr:sub-handling>
93
    </cp:actions>
94
    <cp:transformations>
95
      <pr:provide-services>
96
        <pr:service-uri-scheme>sip</pr:service-uri-scheme>
97
        <pr:service-uri-scheme>mailto</pr:service-uri-scheme>
98
      </pr:provide-services>
99
      <pr:provide-persons>
100
        <pr:all-persons/>
101
      </pr:provide-persons>
102
      <pr:provide-activities>true</pr:provide-activities>
103
      <pr:provide-user-input>bare</pr:provide-user-input>
104
      <pr:provide-unknown-attribute ns="urn:vendor-specific:foo-namespace" name="foo">true</pr:provide-unknown-attribute>
105
    </cp:transformations>
106
  </cp:rule>
107
</cp:ruleset>
108
<BLANKLINE>
109
}}}
110
111
== Resource Lists ==
112
113
This module provides convenient classes to parse and generate resource-lists documents as described in [http://tools.ietf.org/html/rfc4826 RFC 4826].
114
115
Used for server side storage of presence related buddy lists using XCAP protocol. The SIP clients maintain the resource-lists on the XCAP server which provides persisten storage and aggregation point for multiple devices.
116
117
=== Generation ===
118
119
{{{
120
>>> bill = Entry('sip:bill@example.com', display_name = 'Bill Doe')
121
>>> petri = EntryRef('some/ref')
122
>>> friends = List([bill, petri])
123
>>> rl = ResourceLists([friends])
124
>>> print rl.toxml(pretty_print=True)
125
<?xml version='1.0' encoding='UTF-8'?>
126
<rl:resource-lists xmlns:rl="urn:ietf:params:xml:ns:resource-lists">
127
  <rl:list>
128
    <rl:entry uri="sip:bill@example.com">
129
      <rl:display-name>Bill Doe</rl:display-name>
130
    </rl:entry>
131
    <rl:entry-ref ref="some/ref"/>
132
  </rl:list>
133
</rl:resource-lists>
134
<BLANKLINE>
135
}}}
136
137
toxml() wraps etree.tostring() and accepts all its arguments (like pretty_print).
138
139
=== Parsing ===
140
141
{{{
142
>>> r = ResourceLists.parse(example_from_section_3_3_rfc)
143
>>> len(r)
144
1
145
146
>>> friends = r[0]
147
>>> friends.name
148
'friends'
149
150
>>> bill = friends[0]
151
>>> bill.uri
152
'sip:bill@example.com'
153
>>> print bill.display_name
154
Bill Doe
155
156
>>> close_friends = friends[2]
157
>>> print close_friends[0]
158
"Joe Smith" <sip:joe@example.com>
159
>>> print close_friends[2].display_name
160
Marketing
161
}}}
162
163
164
== RLS Services ==
165
166
Parses and builds application/rls-services+xml documents according to [http://tools.ietf.org/html/rfc4826  RFC 4826].
167
168
Used for delegating presence related works to the server. The client build rls-services lists with buddies and instructs the server to subscribe to the sip uris indicated in the lists. This way the client can save bandwidth as the server performs the signaling for subscription and collection of notifications and provides consolidated answers to the SIP user agent.
169
170
{{{
171
>>> buddies = Service('sip:mybuddies@example.com', 'http://xcap.example.com/xxx', ['presence'])
172
>>> marketing = Service('sip:marketing@example.com')
173
>>> marketing.list = RLSList([Entry('sip:joe@example.com'), Entry('sip:sudhir@example.com')])
174
>>> marketing.packages = ['presence']
175
>>> rls = RLSServices([buddies, marketing])
176
>>> print rls.toxml(pretty_print=True)
177
<?xml version='1.0' encoding='UTF-8'?>
178
<rls-services xmlns:rl="urn:ietf:params:xml:ns:resource-lists" xmlns="urn:ietf:params:xml:ns:rls-services">
179
  <service uri="sip:mybuddies@example.com">
180
    <resource-list>http://xcap.example.com/xxx</resource-list>
181
    <packages>
182
      <package>presence</package>
183
    </packages>
184
  </service>
185
  <service uri="sip:marketing@example.com">
186
    <list>
187
      <rl:entry uri="sip:joe@example.com"/>
188
      <rl:entry uri="sip:sudhir@example.com"/>
189
    </list>
190
    <packages>
191
      <package>presence</package>
192
    </packages>
193
  </service>
194
</rls-services>
195
<BLANKLINE>
196
197
198
>>> rls = RLSServices.parse(example_from_section_4_3_rfc)
199
>>> len(rls)
200
2
201
202
>>> rls[0].uri
203
'sip:mybuddies@example.com'
204
205
>>> print rls[0].list
206
http://xcap.example.com/xxx
207
208
>>> print rls[0].packages[0]
209
presence
210
211
212
>>> rls[1].uri
213
'sip:marketing@example.com'
214
215
>>> assert len(rls[1].packages) == 1 and rls[1].packages[0] == 'presence'
216
217
}}}
218
219
220
== Presence Data Model ==
221
222
PIDF handling according to [http://tools.ietf.org/html/rfc3863 RFC 3863] and [http://tools.ietf.org/html/rfc3379 RFC 3379]. This module provides classes to parse and generate PIDF documents.
223
224
Used to parse NOTIFY body for presence event and generate state information for use with PUBLISH method and to parse the state of buddy lists entries we have subscribed to. A SIP client typically instantiates a new PIDF object for itself and for each buddy it SUBSCRIBEs to and updates each object when a NOTIFY is received. The list of buddies is maintained using the resource-lists XCAP application.
225
226
Example usage:
227
228
{{{
229
>>> from datetime import datetime
230
>>> pidf = PIDF('pres:someone@example.com')
231
>>> status = Status(basic=Basic('open'))
232
>>> contact = Contact('im:someone@mobilecarrier.net')
233
>>> contact.priority = "0.8"
234
>>> tuple1 = Service('bs35r9', notes=[ServiceNote("Don't Disturb Please!"), ServiceNote("Ne derangez pas, s'il vous plait", lang="fr")], status=status)
235
>>> tuple1.contact = contact
236
>>> tuple1.timestamp = Timestamp(datetime(2008, 9, 11, 20, 42, 03))
237
>>> tuple2 = Service('eg92n8', status=Status(basic=Basic('open')), contact=Contact('mailto:someone@example.com'))
238
>>> tuple2.contact.priority = "1.0"
239
>>> pidf.notes.add(Note("I'll be in Tokyo next week"))
240
>>> pidf.append(tuple1)
241
>>> pidf.append(tuple2)
242
>>> print pidf.toxml(pretty_print=True)
243
<?xml version='1.0' encoding='UTF-8'?>
244
<presence xmlns:rpid="urn:ietf:params:xml:ns:pidf:rpid" xmlns:dm="urn:ietf:params:xml:ns:pidf:data-model" xmlns="urn:ietf:params:xml:ns:pidf" entity="pres:someone@example.com"
245
  <tuple id="bs35r9">
246
    <status>
247
      <basic>open</basic>
248
    </status>
249
    <contact priority="0.8">im:someone@mobilecarrier.net</contact>
250
    <note>Don't Disturb Please!</note>
251
    <note xml:lang="fr">Ne derangez pas, s'il vous plait</note>
252
    <timestamp>2008-09-11T20:42:03Z</timestamp>
253
  </tuple>
254
  <tuple id="eg92n8">
255
    <status>
256
      <basic>open</basic>
257
    </status>
258
    <contact priority="1.0">mailto:someone@example.com</contact>
259
  </tuple>
260
  <note>I'll be in Tokyo next week</note>
261
</presence>
262
<BLANKLINE>
263
}}}
264
265
== Rich Presence Extension ==
266
267
RPID handling according to [http://tools.ietf.org/html/rfc4480 RFC 4480]. This module provides an extension to PIDF (module sipsimple.applications.presdm) to support rich presence.
268
269
{{{
270
__all__ = ['_rpid_namespace_',
271
           'ActivityElement',
272
           'MoodElement',
273
           'PlaceTypeElement',
274
           'PrivacyElement',
275
           'SphereElement',
276
           'RPIDNote',
277
           'Activities',
278
           'Mood',
279
           'PlaceIs',
280
           'AudioPlaceInformation',
281
           'VideoPlaceInformation',
282
           'TextPlaceInformation',
283
           'PlaceType',
284
           'AudioPrivacy',
285
           'TextPrivacy',
286
           'VideoPrivacy',
287
           'Privacy',
288
           'Relationship',
289
           'ServiceClass',
290
           'Sphere',
291
           'StatusIcon',
292
           'TimeOffset',
293
           'UserInput',
294
           'Class',
295
           'Other']
296
297
}}}
298
299
== Watcher-info ==
300
301
Parses application/watcherinfo+xml documents according to [http://tools.ietf.org/html/rfc3857 RFC 3857] and [http://tools.ietf.org/html/rfc3858 RFC3858].
302
303
Used for parsing of NOTIFY body for presence.winfo event. Used for keeping track of watchers that subscribed to our presentity. Based on this information the authorization rules can be managed using presrules.py. To retrieve this information the SIP client must subscribe to its own address for event presence.winfo.
304
305
306
Example:
307
308
{{{
309
>>> winfo_doc='''<?xml version="1.0"?>
310
... <watcherinfo xmlns="urn:ietf:params:xml:ns:watcherinfo"
311
...              version="0" state="full">
312
...   <watcher-list resource="sip:professor@example.net" package="presence">
313
...     <watcher status="active"
314
...              id="8ajksjda7s"
315
...              duration-subscribed="509"
316
...              event="approved" >sip:userA@example.net</watcher>
317
...     <watcher status="pending"
318
...              id="hh8juja87s997-ass7"
319
...              display-name="Mr. Subscriber"
320
...              event="subscribe">sip:userB@example.org</watcher>
321
...   </watcher-list>
322
... </watcherinfo>'''
323
>>> winfo = WatcherInfo()
324
325
The return value of winfo.update() is a dictionary containing WatcherList objects
326
as keys and lists of the updated watchers as values.
327
328
>>> updated = winfo.update(winfo_doc)
329
>>> len(updated['sip:professor@example.net'])
330
2
331
332
winfo.pending, winfo.terminated and winfo.active are dictionaries indexed by
333
WatcherList objects as keys and lists of Wacher objects as values.
334
335
>>> print winfo.pending['sip:professor@example.net'][0]
336
"Mr. Subscriber" <sip:userB@example.org>
337
>>> print winfo.pending['sip:professor@example.net'][1]
338
Traceback (most recent call last):
339
  File "<stdin>", line 1, in <module>
340
IndexError: list index out of range
341
>>> print winfo.active['sip:professor@example.net'][0]
342
sip:userA@example.net
343
>>> len(winfo.terminated['sip:professor@example.net'])
344
0
345
346
winfo.wlists is the list of WatcherList objects
347
348
>>> list(winfo.wlists[0].active) == list(winfo.active['sip:professor@example.net'])
349
True
350
351
See the classes for more information.
352
}}}
353
354
355
== XCAP-diff ==
356
357
This module allows parsing and building xcap-diff documents according to draft-ietf-simple-xcap-diff.
358
359
Used to parse NOTIFY body for xcap-diff event. Used to detect changes in XCAP documents changed by other device configured for the same presentity.
360
361
362
== Is-composing ==
363
364
This module parses and produces isComposing messages according to RFC3994.