Project

General

Profile

SipPayloadsApi » History » Version 2

Adrian Georgescu, 04/13/2010 10:21 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
{{{
168
>>> buddies = Service('sip:mybuddies@example.com', 'http://xcap.example.com/xxx', ['presence'])
169
>>> marketing = Service('sip:marketing@example.com')
170
>>> marketing.list = RLSList([Entry('sip:joe@example.com'), Entry('sip:sudhir@example.com')])
171
>>> marketing.packages = ['presence']
172
>>> rls = RLSServices([buddies, marketing])
173
>>> print rls.toxml(pretty_print=True)
174
<?xml version='1.0' encoding='UTF-8'?>
175
<rls-services xmlns:rl="urn:ietf:params:xml:ns:resource-lists" xmlns="urn:ietf:params:xml:ns:rls-services">
176
  <service uri="sip:mybuddies@example.com">
177
    <resource-list>http://xcap.example.com/xxx</resource-list>
178
    <packages>
179
      <package>presence</package>
180
    </packages>
181
  </service>
182
  <service uri="sip:marketing@example.com">
183
    <list>
184
      <rl:entry uri="sip:joe@example.com"/>
185
      <rl:entry uri="sip:sudhir@example.com"/>
186
    </list>
187
    <packages>
188
      <package>presence</package>
189
    </packages>
190
  </service>
191
</rls-services>
192
<BLANKLINE>
193
194
195
>>> rls = RLSServices.parse(example_from_section_4_3_rfc)
196
>>> len(rls)
197
2
198
199
>>> rls[0].uri
200
'sip:mybuddies@example.com'
201
202
>>> print rls[0].list
203
http://xcap.example.com/xxx
204
205
>>> print rls[0].packages[0]
206
presence
207
208
209
>>> rls[1].uri
210
'sip:marketing@example.com'
211
212
>>> assert len(rls[1].packages) == 1 and rls[1].packages[0] == 'presence'
213
214
}}}
215
216
217
== Presence Data Model ==
218
219
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.
220
221
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.
222
223
Example usage:
224
225
{{{
226
>>> from datetime import datetime
227
>>> pidf = PIDF('pres:someone@example.com')
228
>>> status = Status(basic=Basic('open'))
229
>>> contact = Contact('im:someone@mobilecarrier.net')
230
>>> contact.priority = "0.8"
231
>>> tuple1 = Service('bs35r9', notes=[ServiceNote("Don't Disturb Please!"), ServiceNote("Ne derangez pas, s'il vous plait", lang="fr")], status=status)
232
>>> tuple1.contact = contact
233
>>> tuple1.timestamp = Timestamp(datetime(2008, 9, 11, 20, 42, 03))
234
>>> tuple2 = Service('eg92n8', status=Status(basic=Basic('open')), contact=Contact('mailto:someone@example.com'))
235
>>> tuple2.contact.priority = "1.0"
236
>>> pidf.notes.add(Note("I'll be in Tokyo next week"))
237
>>> pidf.append(tuple1)
238
>>> pidf.append(tuple2)
239
>>> print pidf.toxml(pretty_print=True)
240
<?xml version='1.0' encoding='UTF-8'?>
241
<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"
242
  <tuple id="bs35r9">
243
    <status>
244
      <basic>open</basic>
245
    </status>
246
    <contact priority="0.8">im:someone@mobilecarrier.net</contact>
247
    <note>Don't Disturb Please!</note>
248
    <note xml:lang="fr">Ne derangez pas, s'il vous plait</note>
249
    <timestamp>2008-09-11T20:42:03Z</timestamp>
250
  </tuple>
251
  <tuple id="eg92n8">
252
    <status>
253
      <basic>open</basic>
254
    </status>
255
    <contact priority="1.0">mailto:someone@example.com</contact>
256
  </tuple>
257
  <note>I'll be in Tokyo next week</note>
258
</presence>
259
<BLANKLINE>
260
}}}
261
262
== Rich Presence Extension ==
263
264
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.
265
266
{{{
267
__all__ = ['_rpid_namespace_',
268
           'ActivityElement',
269
           'MoodElement',
270
           'PlaceTypeElement',
271
           'PrivacyElement',
272
           'SphereElement',
273
           'RPIDNote',
274
           'Activities',
275
           'Mood',
276
           'PlaceIs',
277
           'AudioPlaceInformation',
278
           'VideoPlaceInformation',
279
           'TextPlaceInformation',
280
           'PlaceType',
281
           'AudioPrivacy',
282
           'TextPrivacy',
283
           'VideoPrivacy',
284
           'Privacy',
285
           'Relationship',
286
           'ServiceClass',
287
           'Sphere',
288
           'StatusIcon',
289
           'TimeOffset',
290
           'UserInput',
291
           'Class',
292
           'Other']
293
294
}}}
295
296
== Watcher-info ==
297
298
Parses application/watcherinfo+xml documents according to [http://tools.ietf.org/html/rfc3857 RFC 3857] and [http://tools.ietf.org/html/rfc3858 RFC3858].
299
300
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.
301
302
303
Example:
304
305
{{{
306
>>> winfo_doc='''<?xml version="1.0"?>
307
... <watcherinfo xmlns="urn:ietf:params:xml:ns:watcherinfo"
308
...              version="0" state="full">
309
...   <watcher-list resource="sip:professor@example.net" package="presence">
310
...     <watcher status="active"
311
...              id="8ajksjda7s"
312
...              duration-subscribed="509"
313
...              event="approved" >sip:userA@example.net</watcher>
314
...     <watcher status="pending"
315
...              id="hh8juja87s997-ass7"
316
...              display-name="Mr. Subscriber"
317
...              event="subscribe">sip:userB@example.org</watcher>
318
...   </watcher-list>
319
... </watcherinfo>'''
320
>>> winfo = WatcherInfo()
321
322
The return value of winfo.update() is a dictionary containing WatcherList objects
323
as keys and lists of the updated watchers as values.
324
325
>>> updated = winfo.update(winfo_doc)
326
>>> len(updated['sip:professor@example.net'])
327
2
328
329
winfo.pending, winfo.terminated and winfo.active are dictionaries indexed by
330
WatcherList objects as keys and lists of Wacher objects as values.
331
332
>>> print winfo.pending['sip:professor@example.net'][0]
333
"Mr. Subscriber" <sip:userB@example.org>
334
>>> print winfo.pending['sip:professor@example.net'][1]
335
Traceback (most recent call last):
336
  File "<stdin>", line 1, in <module>
337
IndexError: list index out of range
338
>>> print winfo.active['sip:professor@example.net'][0]
339
sip:userA@example.net
340
>>> len(winfo.terminated['sip:professor@example.net'])
341
0
342
343
winfo.wlists is the list of WatcherList objects
344
345
>>> list(winfo.wlists[0].active) == list(winfo.active['sip:professor@example.net'])
346
True
347
348
See the classes for more information.
349
}}}
350
351
352
== XCAP-diff ==
353
354
This module allows parsing and building xcap-diff documents according to draft-ietf-simple-xcap-diff.
355
356
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.
357
358
359
== Is-composing ==
360
361
This module parses and produces isComposing messages according to RFC3994.