Project

General

Profile

SipPayloadsApi » History » Version 14

Adrian Georgescu, 05/20/2010 12:59 PM

1 1 Adrian Georgescu
= Payloads API =
2
3 11 Adrian Georgescu
[[TOC(SipPayloadsApi*, depth=2)]]
4 1 Adrian Georgescu
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
== Presence Data Model ==
228
229 5 Adrian Georgescu
Implemented in [browser:sipsimple/payloads/presdm.py]
230
231 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.
232
233
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.
234
235 6 Adrian Georgescu
=== Example ===
236 1 Adrian Georgescu
237
{{{
238
>>> from datetime import datetime
239
>>> pidf = PIDF('pres:someone@example.com')
240
>>> status = Status(basic=Basic('open'))
241
>>> contact = Contact('im:someone@mobilecarrier.net')
242
>>> contact.priority = "0.8"
243
>>> tuple1 = Service('bs35r9', notes=[ServiceNote("Don't Disturb Please!"), ServiceNote("Ne derangez pas, s'il vous plait", lang="fr")], status=status)
244
>>> tuple1.contact = contact
245
>>> tuple1.timestamp = Timestamp(datetime(2008, 9, 11, 20, 42, 03))
246
>>> tuple2 = Service('eg92n8', status=Status(basic=Basic('open')), contact=Contact('mailto:someone@example.com'))
247
>>> tuple2.contact.priority = "1.0"
248
>>> pidf.notes.add(Note("I'll be in Tokyo next week"))
249
>>> pidf.append(tuple1)
250
>>> pidf.append(tuple2)
251
>>> print pidf.toxml(pretty_print=True)
252
<?xml version='1.0' encoding='UTF-8'?>
253
<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"
254
  <tuple id="bs35r9">
255
    <status>
256
      <basic>open</basic>
257
    </status>
258
    <contact priority="0.8">im:someone@mobilecarrier.net</contact>
259
    <note>Don't Disturb Please!</note>
260
    <note xml:lang="fr">Ne derangez pas, s'il vous plait</note>
261
    <timestamp>2008-09-11T20:42:03Z</timestamp>
262
  </tuple>
263
  <tuple id="eg92n8">
264
    <status>
265
      <basic>open</basic>
266
    </status>
267
    <contact priority="1.0">mailto:someone@example.com</contact>
268
  </tuple>
269
  <note>I'll be in Tokyo next week</note>
270
</presence>
271
<BLANKLINE>
272
}}}
273
274
== Rich Presence Extension ==
275
276 5 Adrian Georgescu
Implemented in [browser:sipsimple/payloads/rpid.py]
277
278 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.
279 1 Adrian Georgescu
280
{{{
281
__all__ = ['_rpid_namespace_',
282
           'ActivityElement',
283
           'MoodElement',
284
           'PlaceTypeElement',
285
           'PrivacyElement',
286
           'SphereElement',
287
           'RPIDNote',
288
           'Activities',
289
           'Mood',
290
           'PlaceIs',
291
           'AudioPlaceInformation',
292
           'VideoPlaceInformation',
293
           'TextPlaceInformation',
294
           'PlaceType',
295
           'AudioPrivacy',
296
           'TextPrivacy',
297
           'VideoPrivacy',
298
           'Privacy',
299
           'Relationship',
300
           'ServiceClass',
301
           'Sphere',
302
           'StatusIcon',
303
           'TimeOffset',
304
           'UserInput',
305
           'Class',
306
           'Other']
307
308
}}}
309
310
== Watcher-info ==
311
312 5 Adrian Georgescu
Implemented in [browser:sipsimple/payloads/watcherinfo.py]
313
314 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].
315
316
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.
317
318 6 Adrian Georgescu
=== Example ===
319 1 Adrian Georgescu
320
{{{
321
>>> winfo_doc='''<?xml version="1.0"?>
322
... <watcherinfo xmlns="urn:ietf:params:xml:ns:watcherinfo"
323
...              version="0" state="full">
324
...   <watcher-list resource="sip:professor@example.net" package="presence">
325
...     <watcher status="active"
326
...              id="8ajksjda7s"
327
...              duration-subscribed="509"
328
...              event="approved" >sip:userA@example.net</watcher>
329
...     <watcher status="pending"
330
...              id="hh8juja87s997-ass7"
331
...              display-name="Mr. Subscriber"
332
...              event="subscribe">sip:userB@example.org</watcher>
333
...   </watcher-list>
334
... </watcherinfo>'''
335
>>> winfo = WatcherInfo()
336
337
The return value of winfo.update() is a dictionary containing WatcherList objects
338
as keys and lists of the updated watchers as values.
339
340
>>> updated = winfo.update(winfo_doc)
341
>>> len(updated['sip:professor@example.net'])
342
2
343
344
winfo.pending, winfo.terminated and winfo.active are dictionaries indexed by
345
WatcherList objects as keys and lists of Wacher objects as values.
346
347
>>> print winfo.pending['sip:professor@example.net'][0]
348
"Mr. Subscriber" <sip:userB@example.org>
349
>>> print winfo.pending['sip:professor@example.net'][1]
350
Traceback (most recent call last):
351
  File "<stdin>", line 1, in <module>
352
IndexError: list index out of range
353
>>> print winfo.active['sip:professor@example.net'][0]
354
sip:userA@example.net
355
>>> len(winfo.terminated['sip:professor@example.net'])
356
0
357
358
winfo.wlists is the list of WatcherList objects
359
360
>>> list(winfo.wlists[0].active) == list(winfo.active['sip:professor@example.net'])
361
True
362
363
See the classes for more information.
364
}}}
365
366
367
== XCAP-diff ==
368
369 5 Adrian Georgescu
Implemented in [browser:sipsimple/payloads/xcapdiff.py]
370 1 Adrian Georgescu
371 14 Adrian Georgescu
This module allows parsing and building xcap-diff documents according to RFC5874.
372 1 Adrian Georgescu
373
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.
374
375 11 Adrian Georgescu
{{{
376 12 Adrian Georgescu
__all__ = ['namespace', 
377
    'XCAPDiffApplication', 
378
    'BodyNotChanged', 
379
    'Document', 
380
    'Element', 
381
    'Attribute', 
382
    'XCAPDiff']
383 11 Adrian Georgescu
}}}
384 1 Adrian Georgescu
385
== Is-composing ==
386 5 Adrian Georgescu
387
Implemented in [browser:sipsimple/payloads/iscomposing.py]
388 1 Adrian Georgescu
389
This module parses and produces isComposing messages according to RFC3994.
390
391
{{{
392 12 Adrian Georgescu
__all__ = ['namespace', 
393
    'IsComposingApplication', 
394
    'State', 
395
    'LastActive', 
396
    'ContentType', 
397
    'Refresh', 
398
    'IsComposingMessage']
399 11 Adrian Georgescu
}}}
400
401 5 Adrian Georgescu
== Message Summary ==
402
403
Implemented in [browser:sipsimple/payloads/messagesummary.py]
404
405
This module parses and produces message-summary messages according to RF3842.
406 1 Adrian Georgescu
407 11 Adrian Georgescu
408 10 Adrian Georgescu
== User Agent Capability ==
409 8 Adrian Georgescu
410
Implemented in [browser:sipsimple/payloads/caps.py]
411
412
User Agent Capability Extension handling according to RFC5196
413
414
This module provides an extension to PIDF to describe a user-agent capabilities in the PIDF documents.
415 1 Adrian Georgescu
416 11 Adrian Georgescu
{{{
417
__all__ = ['caps_namespace',
418
            'Audio',
419
            'Application',
420
            'Data',
421
            'Control',
422
            'Video',
423
            'Video',
424
            'Text',
425
            'Message',
426
            'Type',
427
            'Automata',
428
            'Class',
429
            'ClassPersonal',
430
            'ClassBusiness',
431
            'Duplex',
432
            'DuplexFull',
433
            'DuplexHalf',
434
            'DuplexReceiveOnly',
435
            'DuplexSendOnly',
436
            'Description',
437
            'EventPackages',
438
            'EventConference',
439
            'EventDialog',
440
            'EventKpml',
441
            'EventMessageSummary',
442
            'EventPocSettings',
443
            'EventPresence',
444
            'EventReg',
445
            'EventRefer',
446
            'EventSiemensRtpStats',
447
            'EventSpiritsIndps',
448
            'EventSpiritsUserProf',
449
            'EventWinfo',
450
            'Priority',
451
            'PriorityLowerthan',
452
            'PriorityHigherthan',
453
            'PriorityEquals',
454
            'PriorityRange',
455
            'Methods',
456
            'MethodAck',
457
            'MethodBye',
458
            'MethodCancel',
459
            'MethodInfo',
460
            'MethodInvite',
461
            'MethodMessage',
462
            'MethodNotify',
463
            'MethodOptions',
464
            'MethodPrack',
465
            'MethodPublish',
466
            'MethodRefer',
467
            'MethodRegister',
468
            'MethodSubscribe',
469
            'MethodUpdate',
470
            'Extensions',
471
            'ExtensionRel100',
472
            'ExtensionEarlySession',
473
            'ExtensionEventList',
474
            'ExtensionFromChange',
475
            'ExtensionGruu',
476
            'ExtensionHistinfo',
477
            'ExtensionJoin',
478
            'ExtensionNoRefSub',
479
            'ExtensionPath',
480
            'ExtensionPrecondition',
481
            'ExtensionPref',
482
            'ExtensionPrivacy',
483
            'ExtensionRecipientListInvite',
484
            'ExtensionRecipientListSubscribe',
485
            'ExtensionReplaces',
486
            'ExtensionResourcePriority',
487
            'ExtensionSdpAnat',
488
            'ExtensionSecAgree',
489
            'ExtensionTdialog',
490
            'ExtensionTimer',
491
            'Schemes',
492
            'Scheme',
493
            'Actor',
494
            'ActorPrincipal',
495
            'ActorAttendant',
496
            'ActorMsgTaker',
497
            'ActorInformation',
498
            'IsFocus',
499
            'Languages',
500
            'Language',
501
            'Servcaps',
502
            'Mobility',
503
            'MobilityFixed',
504
            'MobilityMobile',
505
            'Devcaps',
506
            'ServcapsExtension',
507
            'EventPackagesExtension',
508
            'PriorityExtension',
509
            'MethodsExtension',
510
            'ExtensionsExtension',
511
            'DevcapsExtension',
512
            'MobilityExtension']
513
}}}
514
515 8 Adrian Georgescu
== CIPID ==
516
517
Implemented in [browser:sipsimple/payloads/cipid.py]
518
519 1 Adrian Georgescu
CIPID handling according to RFC4482. This module provides an extension to PIDF to provide additional contact information about a presentity.
520 11 Adrian Georgescu
521
{{{
522 13 Adrian Georgescu
__all__ = ['cipid_namespace', 
523
    'Card', 
524
    'DisplayName', 
525
    'Homepage', 
526
    'Icon', 
527
    'Map', 
528
    'Sound']
529 11 Adrian Georgescu
}}}
530
531
== Conference ==
532
533
Implemented in [browser:sipsimple/payloads/conference.py]
534
535
Parses and produces conference-info messages according to RFC4575.
536
537
{{{
538
__all__ = ['namespace',
539
        'ConferenceApplication',
540
        'ConferenceDescription',
541
        'ConfUris',
542
        'ConfUrisEntry',
543
        'ServiceUris',
544
        'ServiceUrisEntry',
545
        'UrisTypeModified',
546
        'UrisTypeEntry',
547
        'AvailableMedia',
548
        'AvailableMediaEntry',
549
        'Users',
550
        'User',
551
        'AssociatedAors',
552
        'Roles',
553
        'Role',
554
        'Endpoint',
555
        'CallInfo',
556
        'Sip',
557
        'Referred',
558
        'JoiningInfo',
559
        'DisconnectionInfo',
560
        'HostInfo',
561
        'HostInfoUris',
562
        'ConferenceState',
563
        'SidebarsByRef',
564
        'SidebarsByVal',
565
        'Conference',
566
        'ConferenceDescriptionExtension']
567
}}}
568
569
== Dialog Info ==
570
571
Implemented in [browser:sipsimple/payloads/dialoginfo.py]
572
573
Parses and produces conference-info messages according to RFC4575.
574
575
{{{
576
577
__all__ = ['namespace',
578
        'DialogInfoApplication',
579
        'DialogState',
580
        'Replaces',
581
        'ReferredBy',
582
        'Identity',
583
        'Param',
584
        'Target',
585
        'Local',
586
        'Remote',
587
        'Dialog',
588
        'DialogInfo']
589
}}}