SipMSRPApi

Version 58 (Adrian Georgescu, 04/16/2010 09:13 am)

1 1 Adrian Georgescu
= MSRP API =
2 1 Adrian Georgescu
3 48 Luci Stanescu
[[TOC(SipMSRPApi, SipDeveloperGuide, depth=2)]]
4 1 Adrian Georgescu
5 57 Adrian Georgescu
Message Session Relay Protocol (MSRP) is a protocol for transmitting a series of related Instant Messages in the context of a session. Message sessions are treated like any other media stream when set up via a rendezvous or session creation protocol such as the Session Initiation Protocol (SIP).  MSRP can be used for any application that requires a reliable stream of data, for example File Transfer or Desktop Sharing.
6 1 Adrian Georgescu
7 25 Adrian Georgescu
 * MSRP sessions are defined in [http://tools.ietf.org/html/rfc4975 RFC 4975]
8 54 Adrian Georgescu
 * MSRP relay extension for NAT traversal is defined in [http://tools.ietf.org/html/rfc4976 RFC 4976]
9 1 Adrian Georgescu
10 56 Adrian Georgescu
The MSRP protocol stack is implemented by [http://download.ag-projects.com/SipClient python-msrplib] package. 
11 4 Oliver Bril
12 33 Adrian Georgescu
{{{msrplib}}} is based upon [http://twistedmatrix.com twisted] and [http://download.ag-projects.com/SipClient/ eventlet] and provides a set of classes for establishing and managing MSRP connections.
13 1 Adrian Georgescu
14 28 Adrian Georgescu
The library consists of the following modules:
15 1 Adrian Georgescu
16 1 Adrian Georgescu
 '''msrplib.transport'''::
17 27 Adrian Georgescu
 Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connections.
18 2 Redmine Admin
19 1 Adrian Georgescu
 '''msrplib.connect'''::
20 1 Adrian Georgescu
 Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance.
21 1 Adrian Georgescu
22 1 Adrian Georgescu
 '''msrplib.session'''::
23 1 Adrian Georgescu
 Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection.
24 1 Adrian Georgescu
25 1 Adrian Georgescu
 '''msrplib.protocol'''::
26 42 Luci Stanescu
 Provides representation and parsing of MSRP entities - chunks and MSRP URIs.  
27 1 Adrian Georgescu
28 48 Luci Stanescu
== URI ==
29 39 Luci Stanescu
30 44 Luci Stanescu
This class is implemented in the {{{msrplib.protocol}}} module and is used to represent an MSRP URI.
31 1 Adrian Georgescu
32 49 Adrian Georgescu
==== methods ====
33 1 Adrian Georgescu
34 39 Luci Stanescu
 '''!__init!__'''(''self'', '''host'''={{{None}}}, '''use_tls'''={{{False}}}, '''user'''={{{None}}}, '''port'''={{{None}}}, '''session_id'''={{{None}}}, '''parameters'''={{{None}}}, '''credentials'''={{{None}}})::
35 39 Luci Stanescu
  Constructs a new {{{URI}}}. All the arguments specified here are also attributes on the object. For more information on these attributes, see RFC4975.
36 39 Luci Stanescu
  [[BR]]''host'':[[BR]]
37 39 Luci Stanescu
  The hostname or IP address which forms the URI.
38 39 Luci Stanescu
  [[BR]]''use_tls'':[[BR]]
39 39 Luci Stanescu
  Whether this identifies an msrps or msrp URI.
40 39 Luci Stanescu
  [[BR]]''user'':[[BR]]
41 39 Luci Stanescu
  The user part of the URI.
42 39 Luci Stanescu
  [[BR]]''port'':[[BR]]
43 39 Luci Stanescu
  The port in the URI.
44 39 Luci Stanescu
  [[BR]]''session_id'':[[BR]]
45 39 Luci Stanescu
  The session identifier part of the URI.
46 1 Adrian Georgescu
  [[BR]]''parameters'':[[BR]]
47 39 Luci Stanescu
  A {{{dict}}} containing the parameters which will be appended to the URI.
48 39 Luci Stanescu
  [[BR]]''credentials'':[[BR]]
49 1 Adrian Georgescu
  A {{{gnutls.interfaces.twisted.X509Credentials}}} object which will be used if this identifies a TLS URI to authenticate to the other endpoint.
50 39 Luci Stanescu
51 48 Luci Stanescu
== MSRPRelaySettings ==
52 1 Adrian Georgescu
53 45 Luci Stanescu
This class is implemented in the {{{msrplib.connect}}} module and is used to specify the MSRP relay which will be used when connecting via a relay (using the {{{ConnectorRelay}}} or {{{AcceptorRelay}}} classes).
54 39 Luci Stanescu
55 49 Adrian Georgescu
==== methods ====
56 39 Luci Stanescu
57 39 Luci Stanescu
 '''!__init!__'''(''self'', '''domain''', '''username''', '''password''', '''host'''={{{None}}}, '''use_tls'''={{{False}}}, '''port'''={{{None}}}, '''credentials'''={{{None}}})::
58 39 Luci Stanescu
  Constructs a new {{{URI}}}. All the arguments specified here are also attributes on the object. For more information on these attributes, see RFC4975.
59 39 Luci Stanescu
  [[BR]]''domain'':[[BR]]
60 39 Luci Stanescu
  The DNS domain in which to search for a MSRP relay using SRV queries.
61 39 Luci Stanescu
  [[BR]]''username'':[[BR]]
62 39 Luci Stanescu
  The username which will be used to authenticate to the relay.
63 39 Luci Stanescu
  [[BR]]''password'':[[BR]]
64 39 Luci Stanescu
  The password which will be used to authenticate to the relay.
65 39 Luci Stanescu
  [[BR]]''host'':[[BR]]
66 39 Luci Stanescu
  The hostname or IP address of the MSRP relay.
67 1 Adrian Georgescu
  [[BR]]''use_tls'':[[BR]]
68 39 Luci Stanescu
  Whether this identifies an msrps or msrp URI.
69 39 Luci Stanescu
  [[BR]]''port'':[[BR]]
70 1 Adrian Georgescu
  The port in the URI.
71 39 Luci Stanescu
  [[BR]]''credentials'':[[BR]]
72 39 Luci Stanescu
  A {{{gnutls.interfaces.twisted.X509Credentials}}} object which will be used to authenticate to the relay if TLS is used.
73 39 Luci Stanescu
74 48 Luci Stanescu
== ConnectorDirect ==
75 39 Luci Stanescu
76 44 Luci Stanescu
This class is implemented in the {{{msrplib.connect}}} module and is used for outbound MSRP connections without a relay.
77 39 Luci Stanescu
78 49 Adrian Georgescu
==== methods ====
79 39 Luci Stanescu
80 39 Luci Stanescu
 '''!__init!__'''(''self'', '''loger'''={{{None}}})::
81 44 Luci Stanescu
 Constructs a new ConnectorDirect.
82 39 Luci Stanescu
 [[BR]]''logger'':[[BR]]
83 39 Luci Stanescu
 The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
84 39 Luci Stanescu
85 39 Luci Stanescu
 '''prepare'''(''self'', '''local_uri'''={{{None}}})::
86 39 Luci Stanescu
 This method returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute.
87 39 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
88 39 Luci Stanescu
 This attribute will be used to construct the local path, but other than that it is not used anywhere else in case of the ConnectorDirect. If not provided, one
89 39 Luci Stanescu
 will be automatically generated
90 1 Adrian Georgescu
 
91 1 Adrian Georgescu
 '''complete'''(''self'', '''full_remote_path''')::
92 39 Luci Stanescu
 This method establishes the connection and binds it (sends an empty chunk to verify each other's From-Path and To-Path). It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks.
93 1 Adrian Georgescu
 [[BR]]''full_remote_path'':[[BR]]
94 39 Luci Stanescu
 A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party.
95 1 Adrian Georgescu
96 39 Luci Stanescu
 '''cleanup'''(''self'')::
97 39 Luci Stanescu
 This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason.
98 1 Adrian Georgescu
99 48 Luci Stanescu
== ConnectorRelay ==
100 1 Adrian Georgescu
101 44 Luci Stanescu
This class is implemented in the {{{msrplib.connect}}} module and is used for outbound MSRP connections using a relay.
102 1 Adrian Georgescu
103 49 Adrian Georgescu
==== methods ====
104 39 Luci Stanescu
105 39 Luci Stanescu
 '''!__init!__'''(''self'', '''relay''', '''loger'''={{{None}}})::
106 39 Luci Stanescu
 Constructs a new ConnectorRelay.
107 39 Luci Stanescu
 [[BR]]''relay'':[[BR]]
108 39 Luci Stanescu
 An instance of {{{MSRPRelaySettings}}} which identifies the relay which is to be used.
109 39 Luci Stanescu
 [[BR]]''logger'':[[BR]]
110 39 Luci Stanescu
 The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
111 39 Luci Stanescu
112 39 Luci Stanescu
 '''prepare'''(''self'', '''local_uri'''={{{None}}})::
113 39 Luci Stanescu
 This method returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute.
114 39 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
115 1 Adrian Georgescu
 This attribute will be used to construct the local path, but other than that it is not used anywhere else in case of the ConnectorRelay. If not provided, one
116 39 Luci Stanescu
 will be automatically generated
117 39 Luci Stanescu
 
118 1 Adrian Georgescu
 '''complete'''(''self'', '''full_remote_path''')::
119 39 Luci Stanescu
 This method establishes the connection to the relay and binds it (sends an empty chunk to verify each other's From-Path and To-Path). It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks.
120 39 Luci Stanescu
 [[BR]]''full_remote_path'':[[BR]]
121 39 Luci Stanescu
 A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party.
122 39 Luci Stanescu
123 1 Adrian Georgescu
 '''cleanup'''(''self'')::
124 39 Luci Stanescu
 This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason.
125 1 Adrian Georgescu
126 48 Luci Stanescu
== AcceptorDirect ==
127 1 Adrian Georgescu
128 44 Luci Stanescu
This class is implemented in the {{{msrplib.connect}}} module and is used for inbound MSRP connections without using a relay.
129 1 Adrian Georgescu
130 49 Adrian Georgescu
==== methods ====
131 39 Luci Stanescu
132 39 Luci Stanescu
 '''!__init!__'''(''self'', '''loger'''={{{None}}})::
133 39 Luci Stanescu
  Constructs a new AcceptorDirect.
134 39 Luci Stanescu
 [[BR]]''logger'':[[BR]]
135 39 Luci Stanescu
 The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
136 39 Luci Stanescu
137 39 Luci Stanescu
 '''prepare'''(''self'', '''local_uri'''={{{None}}})::
138 1 Adrian Georgescu
 This method starts listening on a socket identified by the parameters in the {{{local_uri}}} argument. It returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute.
139 39 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
140 39 Luci Stanescu
 This attribute will be used to construct the local path and to listen for incomming connections. If not provided, one
141 52 Luci Stanescu
 will be automatically generated. Note that the object may be changed in place: for example, if the port specified is 0,
142 52 Luci Stanescu
 a random one will be selected and the object will be updated accordingly.
143 39 Luci Stanescu
 
144 39 Luci Stanescu
 '''complete'''(''self'', '''full_remote_path''')::
145 39 Luci Stanescu
 This method waits for an incoming connection and a chunk sent by the other party. It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks.
146 39 Luci Stanescu
 [[BR]]''full_remote_path'':[[BR]]
147 39 Luci Stanescu
 A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. This is checked agains the From-Path header in the binding chunk.
148 39 Luci Stanescu
149 39 Luci Stanescu
 '''cleanup'''(''self'')::
150 39 Luci Stanescu
 This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason.
151 39 Luci Stanescu
152 48 Luci Stanescu
== AcceptorRelay ==
153 39 Luci Stanescu
154 44 Luci Stanescu
This class is implemented in the {{{msrplib.connect}}} module and is used for inbound MSRP connections using a relay.
155 39 Luci Stanescu
156 49 Adrian Georgescu
==== methods ====
157 39 Luci Stanescu
158 39 Luci Stanescu
 '''!__init!__'''(''self'', '''relay''', '''loger'''={{{None}}})::
159 39 Luci Stanescu
 Constructs a new AcceptorRelay.
160 39 Luci Stanescu
 [[BR]]''relay'':[[BR]]
161 39 Luci Stanescu
 An instance of {{{MSRPRelaySettings}}} which identifies the relay which is to be used.
162 39 Luci Stanescu
 [[BR]]''logger'':[[BR]]
163 1 Adrian Georgescu
 The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
164 39 Luci Stanescu
165 39 Luci Stanescu
 '''prepare'''(''self'', '''local_uri'''={{{None}}})::
166 1 Adrian Georgescu
 This method connects to the relay specified in {{{__init__}}}. It returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute.
167 39 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
168 39 Luci Stanescu
 This attribute will be used to construct the local path. If not provided, one will be automatically generated
169 39 Luci Stanescu
 
170 39 Luci Stanescu
 '''complete'''(''self'', '''full_remote_path''')::
171 39 Luci Stanescu
 This method waits for an incoming chunk sent by the other party. It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks.
172 39 Luci Stanescu
 [[BR]]''full_remote_path'':[[BR]]
173 39 Luci Stanescu
 A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. This is checked agains the From-Path header in the binding chunk.
174 39 Luci Stanescu
175 39 Luci Stanescu
 '''cleanup'''(''self'')::
176 39 Luci Stanescu
 This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason.
177 39 Luci Stanescu
178 53 Luci Stanescu
== Headers ==
179 53 Luci Stanescu
180 53 Luci Stanescu
The MSRP headers are represented using objects from the {{{msrplib.protocol module}}}. All MSRP header object provide three properties:
181 53 Luci Stanescu
 ''name'':[[BR]]
182 53 Luci Stanescu
 The name of the header, as it appears in MSRP chunks.
183 53 Luci Stanescu
 [[BR]]''encode'':[[BR]]
184 53 Luci Stanescu
 The MSRP encoded header value, as it appears in MSRP chunks.
185 53 Luci Stanescu
 [[BR]]''decode'':[[BR]]
186 53 Luci Stanescu
 The high-level object representing the header value.
187 53 Luci Stanescu
188 53 Luci Stanescu
All headers can be constructed by passing either the encoded or decoded objects to {{{__init__}}}. The following headers are provided:
189 53 Luci Stanescu
190 53 Luci Stanescu
=== ToPathHeader ===
191 53 Luci Stanescu
192 53 Luci Stanescu
The name of the header is {{{'To-Path'}}} and the decoded value is a deque of {{{URI}}} objects.
193 53 Luci Stanescu
194 53 Luci Stanescu
=== FromPathHeader ===
195 53 Luci Stanescu
196 53 Luci Stanescu
The name of the header is {{{'From-Path'}}} and the decoded value is a deque of {{{URI}}} objects.
197 53 Luci Stanescu
198 53 Luci Stanescu
=== MessageIDHeader ===
199 53 Luci Stanescu
200 53 Luci Stanescu
The name of the header is {{{'Message-ID'}}} and the decoded value is the string containing the message ID.
201 53 Luci Stanescu
202 53 Luci Stanescu
=== SuccessReportHeader ===
203 53 Luci Stanescu
204 53 Luci Stanescu
The name of the header is {{{'Success-Report'}}} and the decoded value is one of {{{'yes'}}} or {{{'no'}}}.
205 53 Luci Stanescu
206 53 Luci Stanescu
=== FailureReportHeader ===
207 53 Luci Stanescu
208 53 Luci Stanescu
The name of the header is {{{'Failure-Report'}}} and the decoded value is one of {{{'yes'}}}, {{{'partial'}}} or {{{'no'}}}.
209 53 Luci Stanescu
210 53 Luci Stanescu
=== ByteRangeHeader ===
211 53 Luci Stanescu
212 53 Luci Stanescu
The name of the header is {{{'Byte-Range'}}} and the decoded value is a 3-tuple containing the start, end and length values.
213 53 Luci Stanescu
214 53 Luci Stanescu
==== attributes ====
215 53 Luci Stanescu
216 53 Luci Stanescu
 '''fro'''::
217 53 Luci Stanescu
  The start value of the header: the index within the whole message payload where a chunk's payload starts.
218 53 Luci Stanescu
 '''end'''::
219 53 Luci Stanescu
  The end value of the header: the index within the whole message payload where a chunk's payload ends. Note that this index is inclusive.
220 53 Luci Stanescu
 '''length'''::
221 53 Luci Stanescu
  The total size of the message payload.
222 53 Luci Stanescu
223 53 Luci Stanescu
=== StatusHeader ===
224 53 Luci Stanescu
225 53 Luci Stanescu
The name of the header is {{{'Status'}}} and the decoded value is a 2-tuple containing the status code and comment.
226 53 Luci Stanescu
227 53 Luci Stanescu
==== attributes ====
228 53 Luci Stanescu
229 53 Luci Stanescu
 '''code'''::
230 53 Luci Stanescu
  The code component of the header.
231 53 Luci Stanescu
 '''comment'''::
232 53 Luci Stanescu
  The comment component of the header.
233 53 Luci Stanescu
234 53 Luci Stanescu
=== ExpiresHeader ===
235 53 Luci Stanescu
236 53 Luci Stanescu
The name of the header is {{{'Expires'}}} and the decoded value is an integer.
237 53 Luci Stanescu
238 53 Luci Stanescu
=== MinExpiresHeader ===
239 53 Luci Stanescu
240 53 Luci Stanescu
The name of the header is {{{'Min-Expires'}}} and the decoded value is an integer.
241 53 Luci Stanescu
242 53 Luci Stanescu
=== MaxExpiresHeader ===
243 53 Luci Stanescu
244 53 Luci Stanescu
The name of the header is {{{'Max-Expires'}}} and the decoded value is an integer.
245 53 Luci Stanescu
246 53 Luci Stanescu
=== UsePathHeader ===
247 53 Luci Stanescu
248 53 Luci Stanescu
The name of the header is {{{'Use-Path'}}} and the decoded value is a deque of {{{URI}}} objects.
249 53 Luci Stanescu
250 53 Luci Stanescu
=== WWWAuthenticateHeader ===
251 53 Luci Stanescu
252 53 Luci Stanescu
The name of the header is {{{'WWW-Authenticate'}}} and the decoded value is a dictionary of the parameters within the header.
253 53 Luci Stanescu
254 53 Luci Stanescu
=== AuthorizationHeader ===
255 53 Luci Stanescu
256 53 Luci Stanescu
The name of the header is {{{'Authorization'}}} and the decoded value is a dictionary of the parameters within the header.
257 53 Luci Stanescu
258 53 Luci Stanescu
=== AuthenticationInfoHeader ===
259 53 Luci Stanescu
260 53 Luci Stanescu
The name of the header is {{{'Authentication-Info'}}} and the decoded value is a dictionary of the parameters within the header.
261 53 Luci Stanescu
262 53 Luci Stanescu
=== ContentTypeHeader ===
263 53 Luci Stanescu
264 53 Luci Stanescu
The name of the header is {{{'Content-Type'}}} and the decoded value is the string representing the MIME type.
265 53 Luci Stanescu
266 53 Luci Stanescu
=== ContentIDHeader ===
267 53 Luci Stanescu
268 53 Luci Stanescu
The name of the header is {{{'Content-ID'}}} and the decoded value is the string with the value of the header.
269 53 Luci Stanescu
270 53 Luci Stanescu
=== ContentDescriptionHeader ===
271 53 Luci Stanescu
272 53 Luci Stanescu
The name of the header is {{{'Content-Description'}}} and the decoded value is the string with the value of the header.
273 53 Luci Stanescu
274 53 Luci Stanescu
=== ContentDispositionHeader ===
275 53 Luci Stanescu
276 53 Luci Stanescu
The name of the header is {{{'Content-Disposition'}}} and the decoded value is a list with two elements: the disposition and a dict with the parameters.
277 53 Luci Stanescu
278 51 Luci Stanescu
279 14 Oliver Bril
== MSRPTransport ==
280 1 Adrian Georgescu
281 1 Adrian Georgescu
This class is implemented in the {{{msrplib.transport}}} module and provies low level access to the MSRP connection. This class should not be constructed directly, but rather its intances should be obtained by using the various connector/acceptor classes documented above.
282 1 Adrian Georgescu
283 1 Adrian Georgescu
==== methods ====
284 1 Adrian Georgescu
285 1 Adrian Georgescu
 '''make_chunk'''(''self'', '''transaction_id'''={{{None}}}, '''method'''={{{'SEND'}}}, '''code'''={{{None}}}, '''comment'''={{{None}}}, '''data'''={{{''}}}, '''contflag'''={{{None}}}, '''start'''={{{1}}}, '''end'''={{{None}}}, '''length'''={{{None}}}, '''message_id'''={{{None}}})::
286 1 Adrian Georgescu
 Creates a new chunk ({{{protocol.MSRPData}}} instance), which is either an MSRP request or a response. Proper {{{From-Path}}}, {{{To-Path}}}, {{{Byte-Range}}} and {{{Message-ID}}} headers are added based on MSRPTransport's state and the parameters provided. Use ''data'' for payload, and ''start''/''end''/''length'' to generate the {{{Byte-Range}}} header.
287 1 Adrian Georgescu
 [[BR]]''transaction_id'':[[BR]]
288 1 Adrian Georgescu
 The transaction id which will be put in the chunk. If it is not provided, one will be randomly generated.
289 1 Adrian Georgescu
 [[BR]]''method'':[[BR]]
290 1 Adrian Georgescu
 The method of the new MSRP request, or {{{None}}} if a response is required.
291 1 Adrian Georgescu
 [[BR]]''code'':[[BR]]
292 1 Adrian Georgescu
 The code of the new MSRP response, or {{{None}}} if a request is required.
293 1 Adrian Georgescu
 [[BR]]''code'':[[BR]]
294 1 Adrian Georgescu
 The comment of the new MSRP response, or {{{None}}} if a request is required or a comment on the response is not.
295 1 Adrian Georgescu
 [[BR]]''data'':[[BR]]
296 1 Adrian Georgescu
 The payload of the new chunk, or an empty string if no payload is required.
297 1 Adrian Georgescu
 [[BR]]''contflag'':[[BR]]
298 1 Adrian Georgescu
 MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}} for a full message, unless a partial {{{SEND}}} chunk required, in which case it should be set to {{{'+'}}}. If {{{None}}} is provided, either {{{'$'}}} or {{{'+'}}} will be used depending on whether this chunk seems to carry the last part of the message data.
299 1 Adrian Georgescu
 [[BR]]''start'':[[BR]]
300 1 Adrian Georgescu
 The first byte's index within the whole message payload this chunk will carry as its own payload.
301 1 Adrian Georgescu
 [[BR]]''end'':[[BR]]
302 1 Adrian Georgescu
 The last byte's index within the whole message payload this chunk will carry as its own payload. Note that this is an inclusive index. If this is not provided, it's computed based on the number of bytes in data and {{{start}}}.
303 1 Adrian Georgescu
 [[BR]]''length'':[[BR]]
304 1 Adrian Georgescu
 The total number of bytes of the whole message payload. If this is not provided, it is computed as if this chunk carries that last part of the message payload.
305 1 Adrian Georgescu
 [[BR]]''message_id'':[[BR]]
306 1 Adrian Georgescu
 The ID of the message this chunk is part of. If it is not provided, one will be randomly generated.
307 1 Adrian Georgescu
308 1 Adrian Georgescu
 '''write_chunk'''(''self'', '''chunk''', '''wait'''={{{True}}})::
309 1 Adrian Georgescu
 Writes the chunk provided to the underlying socket.
310 1 Adrian Georgescu
 [[BR]]''chunk'':[[BR]]
311 1 Adrian Georgescu
 The chunk which is to be written, an instance of {{{MSRPData}}}.
312 1 Adrian Georgescu
 [[BR]]''wait'':[[BR]]
313 1 Adrian Georgescu
 If {{{True}}}, waits for the operation to complete.
314 1 Adrian Georgescu
315 1 Adrian Georgescu
 '''write_response'''(''self'', '''chunk''', '''code''', '''comment''', '''wait'''={{{True}}}):
316 1 Adrian Georgescu
 Creates a response which is suitable as a reply to the specified chunk and writes it to the underlying socket.
317 1 Adrian Georgescu
 [[BR]]''chunk'':[[BR]]
318 1 Adrian Georgescu
 The chunk for which to create a response.
319 1 Adrian Georgescu
 [[BR]]''code'':[[BR]]
320 1 Adrian Georgescu
 The status code of the response which is to be created.
321 1 Adrian Georgescu
 [[BR]]''comment'':[[BR]]
322 1 Adrian Georgescu
 The comment of the response which is to be created.
323 1 Adrian Georgescu
 [[BR]]''wait'':[[BR]]
324 1 Adrian Georgescu
 If {{{True}}}, waits for the operation to complete.
325 1 Adrian Georgescu
326 1 Adrian Georgescu
 '''read_chunk'''(''self'', '''size'''={{{None}}})::
327 1 Adrian Georgescu
 Waits for a new chunk and returns it.
328 1 Adrian Georgescu
 If there was an error, closes the connection and raises {{{ChunkParseError}}}.
329 1 Adrian Georgescu
330 1 Adrian Georgescu
 In case of unintelligible input, loses the connection and returns {{{None}}}.
331 1 Adrian Georgescu
 When the connection is closed, raises the reason of the closure (e.g. {{{ConnectionDone}}}).
332 1 Adrian Georgescu
333 1 Adrian Georgescu
 If the data already read exceeds ''size'', stops reading the data and returns
334 1 Adrian Georgescu
 a "virtual" chunk, i.e. the one that does not actually correspond the the real
335 1 Adrian Georgescu
 MSRP chunk. Such chunks have Byte-Range header changed to match the number of
336 1 Adrian Georgescu
 bytes read and continuation that is {{{'+'}}}; they also possess {{{segment}}} attribute,
337 1 Adrian Georgescu
 an integer, starting with 1 and increasing with every new segment of the chunk.
338 1 Adrian Georgescu
339 1 Adrian Georgescu
 Note, that ''size'' only hints when to interrupt the segment but does not affect
340 1 Adrian Georgescu
 how the data is read from socket. You may have segments bigger than ''size'' and it's
341 1 Adrian Georgescu
 legal to set ''size'' to zero (which would mean return a chunk as long as you get
342 1 Adrian Georgescu
 some data, regardless how small).
343 1 Adrian Georgescu
 
344 1 Adrian Georgescu
 [[BR]]''size'':[[BR]]
345 1 Adrian Georgescu
 The hint towards how much to read from the socket. If the data already read is larger, then all the data will be returned, even if it exceeds {{{size}}} bytes.
346 1 Adrian Georgescu
347 1 Adrian Georgescu
 '''check_incoming_SEND_chunk'''(''self'', '''chunk''')::
348 1 Adrian Georgescu
 Checks the 'To-Path' and 'From-Path' of the incoming SEND chunk.
349 1 Adrian Georgescu
 Returns None is the paths are valid for this connection.
350 1 Adrian Georgescu
 If an error is detected an MSRPError is created and returned.
351 58 Adrian Georgescu
352 58 Adrian Georgescu
== MSRPData ==
353 58 Adrian Georgescu
354 58 Adrian Georgescu
This class is implemented in the {{{msrplib.protocol}}} module and represents an MSRP chunk, either a request or a response.
355 58 Adrian Georgescu
356 58 Adrian Georgescu
==== attributes ====
357 58 Adrian Georgescu
358 58 Adrian Georgescu
 The following attributes are read-only.
359 58 Adrian Georgescu
360 58 Adrian Georgescu
 '''content_type'''::
361 58 Adrian Georgescu
  The MIME type of the payload carried by this chunk, which is stored in the Content-Type header.
362 58 Adrian Georgescu
363 58 Adrian Georgescu
 '''message_id'''::
364 58 Adrian Georgescu
  The ID of the message this chunk is part of, which is stored in the Message-ID header.
365 58 Adrian Georgescu
366 58 Adrian Georgescu
 '''byte_range'''::
367 58 Adrian Georgescu
  A 3-tuple containing the start, end and length values (in this order) from the Byte-Range header.
368 58 Adrian Georgescu
369 58 Adrian Georgescu
 '''status'''::
370 58 Adrian Georgescu
  The value of the Status header.
371 58 Adrian Georgescu
372 58 Adrian Georgescu
 '''failure_report'''::
373 58 Adrian Georgescu
  The value of the Failure-Report header, whether it exists or it is implied; one of {{{'yes'}}}, {{{'no'}}}, {{{'partial'}}}.
374 58 Adrian Georgescu
375 58 Adrian Georgescu
 '''success_report'''::
376 58 Adrian Georgescu
  The value of the Success-Report header, whether it exists or it is implied; one of {{{'yes'}}} or {{{'no'}}}.
377 58 Adrian Georgescu
378 58 Adrian Georgescu
 '''size'''::
379 58 Adrian Georgescu
  The size of the payload of this chunk, in bytes.
380 58 Adrian Georgescu
381 58 Adrian Georgescu
==== methods ====
382 58 Adrian Georgescu
383 58 Adrian Georgescu
 '''!__init!__'''(''self'', '''transaction_id''', '''method'''={{{None}}}, '''code'''={{{None}}}, '''comment'''={{{None}}}, '''headers'''={{{None}}}, '''data'''={{{''}}}, '''contflag'''={{{'$'}}})::
384 58 Adrian Georgescu
  Initializes a new MSRPData instance. All the arguments are also available as attributes.
385 58 Adrian Georgescu
  [[BR]]''transaction_id'':[[BR]]
386 58 Adrian Georgescu
  The transaction identified of this chunk.
387 58 Adrian Georgescu
  [[BR]]''method'':[[BR]]
388 58 Adrian Georgescu
  The method of this chunk if it a request and {{{None}}} if it is a response.
389 58 Adrian Georgescu
  [[BR]]''code'':[[BR]]
390 58 Adrian Georgescu
  The status code of this chunk if it is a response and {{{None}}} if it is a request.
391 58 Adrian Georgescu
  [[BR]]''comment'':[[BR]]
392 58 Adrian Georgescu
  The comment of this chunk if it is a response and {{{None}}} if it is a request.
393 58 Adrian Georgescu
  [[BR]]''headers'':[[BR]]
394 58 Adrian Georgescu
  A dict containing the headers which are to be added to this chunk, or {{{None}}} if no headers are to be added.
395 58 Adrian Georgescu
  [[BR]]''data'':[[BR]]
396 58 Adrian Georgescu
  The payload of this chunk, or an empty string if no payload is to be added.
397 58 Adrian Georgescu
  [[BR]]''contflag'':[[BR]]
398 58 Adrian Georgescu
  The MSRP continuation flag of this chunk, one of {{{'$'}}}, {{{'#'}}} or {{{'+'}}}.
399 58 Adrian Georgescu
400 58 Adrian Georgescu
 '''copy'''(''self'')::
401 58 Adrian Georgescu
  Returns a new MSRPData instance with exactly the same attributes as this object.
402 58 Adrian Georgescu
403 58 Adrian Georgescu
 '''add_header'''(''self'', '''header''')::
404 58 Adrian Georgescu
  Add a MSRP header to this chunk.
405 58 Adrian Georgescu
  [[BR]]''header'':[[BR]]
406 58 Adrian Georgescu
  The header object which is to be added to this chunk.
407 58 Adrian Georgescu
408 58 Adrian Georgescu
 '''verify_headers'''(''self'')::
409 58 Adrian Georgescu
  Verifies that the chunk contains a To-Path and a From-Path header and that all the headers are valid.
410 58 Adrian Georgescu
411 58 Adrian Georgescu
 '''encode_start'''(''self'')::
412 58 Adrian Georgescu
  Returns a string containing the MSRP header of this chunk.
413 58 Adrian Georgescu
414 58 Adrian Georgescu
 '''encode_end'''(''self'', '''continuation''')::
415 58 Adrian Georgescu
  Returns a string containing the MSRP end line of this chunk: 7 commas followed by the transaction identifier and the continuation flag specified.
416 58 Adrian Georgescu
  [[BR]]''continuation'':[[BR]]
417 58 Adrian Georgescu
  The continuation flag which is to be used in the end line.
418 58 Adrian Georgescu
419 58 Adrian Georgescu
 '''encode'''(''self''):
420 58 Adrian Georgescu
  Returns a string containing the whole of this MSRP chunk.
421 58 Adrian Georgescu
422 1 Adrian Georgescu
423 51 Luci Stanescu
== OutgoingFile ==
424 51 Luci Stanescu
425 51 Luci Stanescu
This class is implemented in the {{{msrplib.session}}} module and represents a file which is to be sent via MSRP.
426 51 Luci Stanescu
427 51 Luci Stanescu
==== attributes ====
428 51 Luci Stanescu
429 51 Luci Stanescu
 '''headers'''::
430 51 Luci Stanescu
  A dict which maps header names to header objects. These headers will be sent in the MSRP message used to send the file.
431 51 Luci Stanescu
432 51 Luci Stanescu
==== methods ====
433 51 Luci Stanescu
434 51 Luci Stanescu
 '''!__init!__'''(''self'', '''fileobj''', '''size''', '''content_type'''={{{None}}}, '''position'''={{{0}}}, '''message_id'''={{{None}}})::
435 51 Luci Stanescu
  Initializes a new OutgoingFile using the specified file object. All arguments are available as attributes, except for {{{content_type}}} which will be part of the {{{headers}}} attribute.
436 51 Luci Stanescu
  [[BR]]''fileobj'':[[BR]]
437 51 Luci Stanescu
  A file-like object which will be used for reading the data to be sent.
438 51 Luci Stanescu
  [[BR]]''size'':[[BR]]
439 51 Luci Stanescu
  The size of the whole file.
440 51 Luci Stanescu
  [[BR]]''content_type'':[[BR]]
441 51 Luci Stanescu
  The MIME type associated with the file's data. If provided, it will be added as a Content-Type header.
442 51 Luci Stanescu
  [[BR]]''position'':[[BR]]
443 51 Luci Stanescu
  The position within the file from which data will be sent. The file object must already be seeked to this position.
444 51 Luci Stanescu
  [[BR]]''message_id'':[[BR]]
445 51 Luci Stanescu
  The message ID which will be used for sending this file.
446 51 Luci Stanescu
447 1 Adrian Georgescu
== MSRPSession ==
448 1 Adrian Georgescu
449 1 Adrian Georgescu
This class is implemented in the {{{msrplib.session}}} module and provides a high level API for MSRP sessions.
450 1 Adrian Georgescu
451 1 Adrian Georgescu
==== methods ====
452 1 Adrian Georgescu
453 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''msrptransport''', '''accept_types'''={{{['*']}}}, '''on_incoming_cb'''={{{None}}})::
454 51 Luci Stanescu
 Initializes MSRPSession instance over the specified transport. The incoming chunks are reported through the ''on_incoming_cb'' callback.
455 51 Luci Stanescu
 [[BR]]''msrptransport'':[[BR]]
456 51 Luci Stanescu
 An instance of {{{MSRPTransport}}} over which this session will operate.
457 51 Luci Stanescu
 [[BR]]''accept_types'':[[BR]]
458 51 Luci Stanescu
 A list of MIME types which are acceptable over this session. If data is received with a Content-Type header which doesn't match this list, a negative response is sent back and the application does not get the received data. The special strings {{{'*'}}} and {{{'<type>/*'}}} can be used to match multiple MIME types.
459 51 Luci Stanescu
 [[BR]]''on_incoming_cb'':[[BR]]
460 51 Luci Stanescu
 A function which receives two arguments, both optional with default values of {{{None}}}: ''chunk'' and ''error''. This will be called when a new chunk is received.
461 1 Adrian Georgescu
462 1 Adrian Georgescu
 '''send_chunk'''(''self'', '''chunk''', '''response_cb'''={{{None}}})::
463 51 Luci Stanescu
 Sends the specified chunk and reports the result via the ''response_cb'' callback.
464 1 Adrian Georgescu
465 1 Adrian Georgescu
 When ''response_cb'' argument is present, it will be used to report
466 1 Adrian Georgescu
 the transaction response to the caller. When a response is received or generated
467 1 Adrian Georgescu
 locally, ''response_cb'' is called with one argument. The function must do something
468 38 Adrian Georgescu
 quickly and must not block, because otherwise it would block the reader greenlet.
469 39 Luci Stanescu
470 1 Adrian Georgescu
 If no response was received after {{{RESPONSE_TIMEOUT}}} seconds,
471 1 Adrian Georgescu
 * 408 response is generated if Failure-Report was {{{'yes'}}} or absent
472 1 Adrian Georgescu
 * 200 response is generated if Failure-Report was {{{'partial'}}} or {{{'no'}}}
473 1 Adrian Georgescu
474 1 Adrian Georgescu
 Note that it's rather wasteful to provide ''response_cb'' argument other than {{{None}}}
475 1 Adrian Georgescu
 for chunks with Failure-Report='no' since it will always fire 30 seconds later
476 1 Adrian Georgescu
 with 200 result (unless the other party is broken and ignores Failure-Report header)
477 1 Adrian Georgescu
478 51 Luci Stanescu
 If sending is not possible, {{{MSRPSessionError}}} is raised.
479 1 Adrian Georgescu
480 51 Luci Stanescu
 [[BR]]''chunk'':[[BR]]
481 51 Luci Stanescu
 The chunk which is to be sent. It must be an instance of {{{MSRPData}}} which represents a request.
482 51 Luci Stanescu
 [[BR]]''response_cb'':[[BR]]
483 51 Luci Stanescu
 A function receiving a single argument which will be the response received for the sent chunk.
484 51 Luci Stanescu
485 1 Adrian Georgescu
 '''deliver_chunk'''(''self'', '''chunk''', '''event'''={{{None}}})::
486 51 Luci Stanescu
 Sends the specified chunk and waits for the transaction response (if Failure-Report header is not {{{'no'}}}).
487 51 Luci Stanescu
 Returns the transaction response if it's a success or raise {{{MSRPTransactionError}}} if it's not.
488 1 Adrian Georgescu
489 1 Adrian Georgescu
 If chunk's Failure-Report is {{{'no'}}}, returns {{{None}}} immediately.
490 1 Adrian Georgescu
491 51 Luci Stanescu
 [[BR]]''chunk'':[[BR]]
492 51 Luci Stanescu
 The chunk which is to be sent. It must be an intance of {{{MSRPData}}} which represents a request.
493 51 Luci Stanescu
 [[BR]]''event'':[[BR]]
494 51 Luci Stanescu
 The {{{eventlet.coros.event}}} object which will be used to wait for a response. It's send method will be called when a response is received. If it is not provided, one will be constructed automatically and used.
495 51 Luci Stanescu
 
496 51 Luci Stanescu
 '''send_file'''(''self'', '''outgoing_file''')::
497 51 Luci Stanescu
 Adds the specified file to the queue of files to be sent. The method returns immediately.
498 51 Luci Stanescu
 [[BR]]''outgoing_file'':[[BR]]
499 51 Luci Stanescu
 An instance of {{{OutgoingFile}}} which represents the file to be sent.
500 51 Luci Stanescu
501 44 Luci Stanescu
 '''shutdown'''(''self'', '''sync'''={{{True}}})::
502 1 Adrian Georgescu
 Sends the messages already in queue then closes the connection.
503 44 Luci Stanescu
504 44 Luci Stanescu
== MSRPServer ==
505 44 Luci Stanescu
506 1 Adrian Georgescu
This class is implemented in the {{{msrplib.connect}}} module.
507 44 Luci Stanescu
    
508 39 Luci Stanescu
MSRPServer solves the problem with AcceptorDirect: concurrent using of 2
509 39 Luci Stanescu
or more AcceptorDirect instances on the same non-zero port is not possible.
510 49 Adrian Georgescu
If you initialize() those instances, one after another, one will listen on
511 1 Adrian Georgescu
the socket and another will get BindError.
512 1 Adrian Georgescu
513 1 Adrian Georgescu
MSRPServer avoids the problem by sharing the listening socket between multiple connections.
514 39 Luci Stanescu
It has a slightly different interface from AcceptorDirect, so it cannot be considered a drop-in
515 46 Luci Stanescu
replacement.
516 46 Luci Stanescu
517 1 Adrian Georgescu
It manages the listening sockets and binds incoming requests.
518 1 Adrian Georgescu
519 1 Adrian Georgescu
==== methods ====
520 1 Adrian Georgescu
521 1 Adrian Georgescu
 '''!__init!__'''(''self'', '''logger''')::
522 51 Luci Stanescu
 Constructs a new MSRPServer which will be using the specifed logger for its connections.
523 51 Luci Stanescu
 [[BR]]''logger'':[[BR]]
524 51 Luci Stanescu
 The default logger which will be used for this object's MSRP connections. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
525 1 Adrian Georgescu
526 1 Adrian Georgescu
 '''prepare'''(''self'', ''local_uri''={{{None}}}, ''logger''={{{None}}})::
527 1 Adrian Georgescu
 Starts a listening port specified by ''local_uri'' if there isn't one on that port/interface already.
528 1 Adrian Georgescu
 Adds ''local_uri'' to the list of expected URIs, so that incoming connections featuring this URI won't be rejected.
529 51 Luci Stanescu
 If ''logger'' is provided, it uses it for this connection instead of the one specified in {{{__init___}}}.
530 51 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
531 51 Luci Stanescu
 The URI which will be added to the list of expected URIs. Connections from this URI will be accepted.
532 51 Luci Stanescu
 [[BR]]''logger'':[[BR]]
533 51 Luci Stanescu
 The logger which will be used for connections from the specified URI. See the [wiki:SipMSRPApi#Logging Logging] section for more information.
534 15 Oliver Bril
535 1 Adrian Georgescu
 '''complete'''(''self'', ''full_remote_path'')::
536 51 Luci Stanescu
 Waits until one of the incoming connections binds using the provided ''full_remote_path''.
537 51 Luci Stanescu
 Returns the connected and bound {{{MSRPTransport}}} instance.
538 51 Luci Stanescu
 If no such binding was made within {{{MSRPBindSessionTimeout.seconds}}}, {{{MSRPBindSessionTimeout}}} is raised.
539 51 Luci Stanescu
 [[BR]]''full_remote_path'':[[BR]]
540 51 Luci Stanescu
 A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party.
541 38 Adrian Georgescu
542 38 Adrian Georgescu
 '''cleanup'''(''self'', ''local_uri'')::
543 46 Luci Stanescu
 Removes ''local_uri'' from the list of expected URIs.
544 51 Luci Stanescu
 [[BR]]''local_uri'':[[BR]]
545 51 Luci Stanescu
 The URI which is to be removed from the list of expected URIs.
546 49 Adrian Georgescu
547 46 Luci Stanescu
== Logging ==
548 46 Luci Stanescu
549 46 Luci Stanescu
Logging is done throughout the library using objects defined by the application, called loggers. If logging is not desired, the {{{application.python.Null}}} object of {{{python-application}}} can be used. These loggers must define the following methods:
550 46 Luci Stanescu
551 46 Luci Stanescu
==== methods ====
552 46 Luci Stanescu
553 46 Luci Stanescu
 '''received_new_chunk'''('''data''', '''transport''', '''chunk''')::
554 46 Luci Stanescu
  This method is called when the start of a new chunk is received.
555 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
556 46 Luci Stanescu
  The data which came along with the start of the chunk.
557 46 Luci Stanescu
  [[BR]]''transport'':[[BR]]
558 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was received.
559 46 Luci Stanescu
  [[BR]]''chunk'':[[BR]]
560 46 Luci Stanescu
  The actual chunk object.
561 46 Luci Stanescu
562 46 Luci Stanescu
 '''received_chunk_data'''('''data''', '''transport''', '''transaction_id''')::
563 46 Luci Stanescu
  This method is called when data is received as part of a chunk previously announced via '''received_new_chunk'''.
564 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
565 46 Luci Stanescu
  The data received as part of the chunk.
566 47 Luci Stanescu
  [[BR]]''transport'':[[BR]]
567 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was received.
568 46 Luci Stanescu
  [[BR]]''transaction_id'':[[BR]]
569 46 Luci Stanescu
  The transaction ID which identifies the chunk for which data was received.
570 46 Luci Stanescu
571 46 Luci Stanescu
 '''received_chunk_end'''('''data''', '''transport''', '''transaction_id''')::
572 46 Luci Stanescu
  This method is called when the last data of a chunk is received. The chunk was previously announced via '''received_new_chunk'''.
573 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
574 46 Luci Stanescu
  The last data received as part of the chunk.
575 46 Luci Stanescu
  [[BR]]''transport'':[[BR]]
576 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was received.
577 46 Luci Stanescu
  [[BR]]''transaction_id'':[[BR]]
578 46 Luci Stanescu
  The transaction ID which identifies the chunk which was ended.
579 46 Luci Stanescu
580 46 Luci Stanescu
 '''sent_new_chunk'''('''data''', '''transport''', '''chunk''')::
581 46 Luci Stanescu
  This method is called when the start of a new chunk is sent.
582 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
583 46 Luci Stanescu
  The data which was sent along with the start of the chunk.
584 46 Luci Stanescu
  [[BR]]''transport'':[[BR]]
585 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was sent.
586 46 Luci Stanescu
  [[BR]]''chunk'':[[BR]]
587 46 Luci Stanescu
  The actual chunk object.
588 46 Luci Stanescu
589 46 Luci Stanescu
 '''sent_chunk_data'''('''data''', '''transport''', '''transaction_id''')::
590 46 Luci Stanescu
  This method is called when data is sent as part of a chunk previously announced via '''sent_new_chunk'''.
591 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
592 46 Luci Stanescu
  The data sent as part of the chunk.
593 47 Luci Stanescu
  [[BR]]''transport'':[[BR]]
594 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was sent.
595 46 Luci Stanescu
  [[BR]]''transaction_id'':[[BR]]
596 46 Luci Stanescu
  The transaction ID which identifies the chunk for which data was sent.
597 46 Luci Stanescu
598 46 Luci Stanescu
 '''sent_chunk_end'''('''data''', '''transport''', '''transaction_id''')::
599 46 Luci Stanescu
  This method is called when the last data of a chunk is sent. The chunk was previously announced via '''sent_new_chunk'''.
600 46 Luci Stanescu
  [[BR]]''data'':[[BR]]
601 46 Luci Stanescu
  The last data sent as part of the chunk.
602 46 Luci Stanescu
  [[BR]]''transport'':[[BR]]
603 46 Luci Stanescu
  The {{{MSRPTransport}}} instance on which the chunk was sent.
604 46 Luci Stanescu
  [[BR]]''transaction_id'':[[BR]]
605 46 Luci Stanescu
  The transaction ID which identifies the chunk which was ended.
606 46 Luci Stanescu
607 46 Luci Stanescu
 '''debug'''('''message''')::
608 46 Luci Stanescu
  This method is called when a debug level message is sent by the library.
609 46 Luci Stanescu
610 46 Luci Stanescu
 '''info'''('''message''')::
611 46 Luci Stanescu
  This method is called when a info level message is sent by the library.
612 46 Luci Stanescu
613 46 Luci Stanescu
 '''warn'''('''message''')::
614 46 Luci Stanescu
  This method is called when a warning level message is sent by the library.
615 46 Luci Stanescu
616 38 Adrian Georgescu
 '''error'''('''message''')::
617 39 Luci Stanescu
  This method is called when a error level message is sent by the library.
618 38 Adrian Georgescu
619 38 Adrian Georgescu
 '''fatal'''('''message''')::
620 1 Adrian Georgescu
  This method is called when a fatal level message is sent by the library.
621 1 Adrian Georgescu
622 52 Luci Stanescu
== Examples ==
623 1 Adrian Georgescu
624 52 Luci Stanescu
=== Creating an outbound connection ===
625 1 Adrian Georgescu
626 52 Luci Stanescu
When creating an outbound connection, a relay is not usually used because NAT traversal is not a problem for the endpoing creating the connection. If one is nevertheless desired, a {{{ConnectorRelay}}} can be used instead:
627 1 Adrian Georgescu
628 52 Luci Stanescu
{{{
629 52 Luci Stanescu
from msrplib.connect import ConnectorDirect
630 52 Luci Stanescu
from msrplib.session import MSRPSession
631 1 Adrian Georgescu
632 52 Luci Stanescu
connector = ConnectorDirect()
633 52 Luci Stanescu
full_local_path = connector.prepare()
634 52 Luci Stanescu
try:
635 52 Luci Stanescu
    # put full_local_path in SDP 'a:path' attribute of offer
636 52 Luci Stanescu
    # get full_remote_path from remote's 'a:path: attribute of reply
637 52 Luci Stanescu
    msrp_transport = connector.complete(full_remote_path)
638 52 Luci Stanescu
except:
639 52 Luci Stanescu
    connector.cleanup()
640 52 Luci Stanescu
    raise
641 1 Adrian Georgescu
642 52 Luci Stanescu
def handle_incoming(chunk=None, error=None):
643 52 Luci Stanescu
    if error is not None:
644 52 Luci Stanescu
       print 'Error: %s' % error
645 52 Luci Stanescu
       session.shutdown()
646 52 Luci Stanescu
    elif chunk is not None:
647 52 Luci Stanescu
       print 'Got data: %s' % chunk.data
648 1 Adrian Georgescu
649 52 Luci Stanescu
session = MSRPSession(msrp_transport, on_incoming_cb=handle_incoming)
650 52 Luci Stanescu
session.send_chunk(msrp_transport.make_chunk(data='Hello world!'))
651 52 Luci Stanescu
}}}
652 38 Adrian Georgescu
653 52 Luci Stanescu
=== Waiting for an inbound connection ===
654 52 Luci Stanescu
655 52 Luci Stanescu
When creating an inbound connection, a relay must be used for NAT traversal. However, if one is not desired, an {{{AceptorDirect}}} can be used instead:
656 52 Luci Stanescu
657 38 Adrian Georgescu
{{{
658 52 Luci Stanescu
from msrplib.connect import AcceptorRelay, MSRPRelaySettings
659 52 Luci Stanescu
from msrplib.session import MSRPSession
660 52 Luci Stanescu
661 52 Luci Stanescu
relay = MSRPRelaySettings(domain='example.org', username='user', password='pass')
662 52 Luci Stanescu
connector = AcceptorRelay(relay)
663 1 Adrian Georgescu
full_local_path = connector.prepare()
664 1 Adrian Georgescu
try:
665 52 Luci Stanescu
    # get full_remote_path from remote's 'a:path: attribute of offer
666 52 Luci Stanescu
    # put full_local_path in SDP 'a:path' attribute of reply
667 52 Luci Stanescu
    msrp_transport = connector.complete(full_remote_path)
668 52 Luci Stanescu
except:
669 1 Adrian Georgescu
    connector.cleanup()
670 52 Luci Stanescu
    raise
671 1 Adrian Georgescu
672 52 Luci Stanescu
def handle_incoming(chunk=None, error=None):
673 52 Luci Stanescu
    if error is not None:
674 52 Luci Stanescu
       print 'Error: %s' % error
675 52 Luci Stanescu
       session.shutdown()
676 52 Luci Stanescu
    elif chunk is not None:
677 52 Luci Stanescu
       print 'Got data: %s' % chunk.data
678 1 Adrian Georgescu
679 52 Luci Stanescu
session = MSRPSession(msrp_transport, on_incoming_cb=handle_incoming)
680 52 Luci Stanescu
session.send_chunk(msrp_transport.make_chunk(data='Hello world!'))
681 52 Luci Stanescu
}}}