Project

General

Profile

SipPayloadsApi » History » Version 8

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

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