Project

General

Profile

SipPayloadsApi » History » Version 3

Adrian Georgescu, 04/13/2010 10:28 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
Generic data types to be used in policy applications, according to [http://tools.ietf.org/html/rfc4745 RFC 4745].
22
23
Example usage:
24
25
{{{
26
>>> alice = IdentityOne('sip:alice@example.com')
27
>>> carol = IdentityOne('tel:+1-212-555-1234')
28
>>> bob = IdentityOne('mailto:bob@example.net')
29
>>> print carol
30
tel:+1-212-555-1234
31
>>> id = Identity([alice, bob])
32
>>> print id
33
Identity([IdentityOne('sip:alice@example.com'), IdentityOne('mailto:bob@example.net')])
34
>>> id[1:1] = [carol]
35
>>> print id
36
Identity([IdentityOne('sip:alice@example.com'), IdentityOne('tel:+1-212-555-1234'), IdentityOne('mailto:bob@example.net')])
37
>>> conditions = Conditions([id])
38
>>> rule = Rule(id='f3g44r1', conditions=conditions, actions=Actions(), transformations=Transformations())
39
>>> ruleset = RuleSet()
40
>>> ruleset.append(rule)
41
>>> print ruleset.toxml(pretty_print=True)
42
<?xml version='1.0' encoding='UTF-8'?>
43
<cp:ruleset xmlns:cp="urn:ietf:params:xml:ns:common-policy">
44
  <cp:rule id="f3g44r1">
45
    <cp:conditions>
46
      <cp:identity>
47
        <cp:one id="sip:alice@example.com"/>
48
        <cp:one id="mailto:bob@example.net"/>
49
        <cp:one id="tel:+1-212-555-1234"/>
50
      </cp:identity>
51
    </cp:conditions>
52
    <cp:actions/>
53
    <cp:transformations/>
54
  </cp:rule>
55
</cp:ruleset>
56
<BLANKLINE>
57
}}}
58
59
== Pres-rules ==
60
61
Parses and produces Presence Authorization Rules documents according to [http://tools.ietf.org/html/rfc5025 RFC 5025].
62
63
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.
64
65
Example usage:
66
67
{{{
68
>>> conditions = Conditions([Identity([IdentityOne('sip:user@example.com')])])
69
>>> actions = Actions([SubHandling('allow')])
70
>>> transformations = Transformations()
71
>>> psrv = ProvideServices(provides=[ServiceURIScheme('sip'), ServiceURIScheme('mailto')])
72
>>> ppers = ProvidePersons(all=True)
73
>>> transformations[0:0] = [psrv, ppers]
74
>>> transformations.append(ProvideActivities('true'))
75
>>> transformations.append(ProvideUserInput('bare'))
76
>>> transformations.append(ProvideUnknownAttribute(ns='urn:vendor-specific:foo-namespace', name='foo', value='true'))
77
>>> rule = Rule(id='a', conditions=conditions, actions=actions, transformations=transformations)
78
>>> prules = PresRules([rule])
79
>>> print prules.toxml(pretty_print=True)
80
<?xml version='1.0' encoding='UTF-8'?>
81
<cp:ruleset xmlns:pr="urn:ietf:params:xml:ns:pres-rules" xmlns:cp="urn:ietf:params:xml:ns:common-policy">
82
  <cp:rule id="a">
83
    <cp:conditions>
84
      <cp:identity>
85
        <cp:one id="sip:user@example.com"/>
86
      </cp:identity>
87
    </cp:conditions>
88
    <cp:actions>
89
      <pr:sub-handling>allow</pr:sub-handling>
90
    </cp:actions>
91
    <cp:transformations>
92
      <pr:provide-services>
93
        <pr:service-uri-scheme>sip</pr:service-uri-scheme>
94
        <pr:service-uri-scheme>mailto</pr:service-uri-scheme>
95
      </pr:provide-services>
96
      <pr:provide-persons>
97
        <pr:all-persons/>
98
      </pr:provide-persons>
99
      <pr:provide-activities>true</pr:provide-activities>
100
      <pr:provide-user-input>bare</pr:provide-user-input>
101
      <pr:provide-unknown-attribute ns="urn:vendor-specific:foo-namespace" name="foo">true</pr:provide-unknown-attribute>
102
    </cp:transformations>
103
  </cp:rule>
104
</cp:ruleset>
105
<BLANKLINE>
106
}}}
107
108
== Resource Lists ==
109
110
This module provides convenient classes to parse and generate resource-lists documents as described in [http://tools.ietf.org/html/rfc4826 RFC 4826].
111
112
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.
113
114
=== Generation ===
115
116
{{{
117
>>> bill = Entry('sip:bill@example.com', display_name = 'Bill Doe')
118
>>> petri = EntryRef('some/ref')
119
>>> friends = List([bill, petri])
120
>>> rl = ResourceLists([friends])
121
>>> print rl.toxml(pretty_print=True)
122
<?xml version='1.0' encoding='UTF-8'?>
123
<rl:resource-lists xmlns:rl="urn:ietf:params:xml:ns:resource-lists">
124
  <rl:list>
125
    <rl:entry uri="sip:bill@example.com">
126
      <rl:display-name>Bill Doe</rl:display-name>
127
    </rl:entry>
128
    <rl:entry-ref ref="some/ref"/>
129
  </rl:list>
130
</rl:resource-lists>
131
<BLANKLINE>
132
}}}
133
134
toxml() wraps etree.tostring() and accepts all its arguments (like pretty_print).
135
136
=== Parsing ===
137
138
{{{
139
>>> r = ResourceLists.parse(example_from_section_3_3_rfc)
140
>>> len(r)
141
1
142
143
>>> friends = r[0]
144
>>> friends.name
145
'friends'
146
147
>>> bill = friends[0]
148
>>> bill.uri
149
'sip:bill@example.com'
150
>>> print bill.display_name
151
Bill Doe
152
153
>>> close_friends = friends[2]
154
>>> print close_friends[0]
155
"Joe Smith" <sip:joe@example.com>
156
>>> print close_friends[2].display_name
157
Marketing
158
}}}
159
160
161
== RLS Services ==
162
163
Parses and builds application/rls-services+xml documents according to [http://tools.ietf.org/html/rfc4826  RFC 4826].
164
165
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.
166
167 3 Adrian Georgescu
=== Generation ===
168
169 1 Adrian Georgescu
{{{
170
>>> buddies = Service('sip:mybuddies@example.com', 'http://xcap.example.com/xxx', ['presence'])
171
>>> marketing = Service('sip:marketing@example.com')
172
>>> marketing.list = RLSList([Entry('sip:joe@example.com'), Entry('sip:sudhir@example.com')])
173
>>> marketing.packages = ['presence']
174
>>> rls = RLSServices([buddies, marketing])
175
>>> print rls.toxml(pretty_print=True)
176
<?xml version='1.0' encoding='UTF-8'?>
177
<rls-services xmlns:rl="urn:ietf:params:xml:ns:resource-lists" xmlns="urn:ietf:params:xml:ns:rls-services">
178
  <service uri="sip:mybuddies@example.com">
179
    <resource-list>http://xcap.example.com/xxx</resource-list>
180
    <packages>
181
      <package>presence</package>
182
    </packages>
183
  </service>
184
  <service uri="sip:marketing@example.com">
185
    <list>
186
      <rl:entry uri="sip:joe@example.com"/>
187
      <rl:entry uri="sip:sudhir@example.com"/>
188
    </list>
189
    <packages>
190
      <package>presence</package>
191
    </packages>
192
  </service>
193
</rls-services>
194
<BLANKLINE>
195
196 3 Adrian Georgescu
=== Parsing ===
197 1 Adrian Georgescu
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.