Project

General

Profile

SipPayloadsApi » History » Version 4

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

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