Project

General

Profile

SipConfigurationAPI » History » Version 1

Adrian Georgescu, 04/13/2009 10:47 AM

1 1 Adrian Georgescu
= Configuration API =
2
3
[[TOC(WikiStart, Sip*, depth=2)]]
4
5
The configuration API is used by the [wiki:SipMiddlewareApi middleware] to store its settings. By managing the settings of the middleware through this configuration API one can create different applications that behave consistently and inherit the same settings. For example a command line client or a GUI program can read and write their settings through this API. 
6
7
The settings can be managed by API calls or by using the provided [wiki:sip_settings] command line tool. The configuration API has appropriate defaults so that the middleware can function with a minimum amount of settings. To use the middleware one must define at a minium only one SIP account:
8
9
{{{
10
sip_settings --account add user@domain password
11
}}}
12
13
== Settings index ==
14
15
These are the current settings, kept in the modules '''sipsimple.configuration.settings''' and '''sipsimple.account'''. The main classes used to access the settings are Account, BonjourAccount and SIPSimpleSettings. All settings can be accessed as simple attributes. The types of attributes is described for each setting below. When setting the value of an attribute, if it's not of the required type, it will be given to the specified type as the only argument. The modified settings are not saved to the persistent storage until the '''save''' method is called on the main object. Once this is done, a CFGSettingsObjectDidChange notification is sent, the data of which is explained in [wiki:SipSettingsAPI#SettingsObjectNotifications SettingsObject Notifications].
16
17
Only a nillable setting can be assigned the value {{{None}}}, even if the type of the setting would otherwise accept {{{None}}} as an argument. The settings as described below are ''not'' nillable, unless specified explicitely. To reset the value of a setting, the special object {{{sipsimple.configuration.DefaultValue}}} can be assigned to it. If a default value is not explicitely specified below, it defaults to {{{None}}}. Note that a nillable setting cannot have the default value of {{{None}}}.
18
19
{{{
20
21
                     +-- default_account (automatically set; see AccountManager.default_account)
22
                     |-- user_agent (default = sipsimple)
23
                     |-- local_ip (default = auto)
24
                     |-- data_directory (default = ~/.sipclient)
25
                     |                       +-- local_udp_port (default = 0, auto allocated)
26
                     |-- sip ----------------|-- local_tcp_port (default = 0, auto allocated)
27
                     |                       |-- local_tls_port (default = 0, auto allocated)
28
                     |                       +-- transports (default = tls,tcp,udp)
29
                     |
30
                     |                       +-- port_range (default = 8000 8100)
31
                     |-- rtp ----------------|
32
                     |                       +
33
SIPSimpleSettings ---|
34
                     |                       +-- local_port (default = 0, auto allocated)
35
                     |-- msrp ---------------|-- transport (default = tls)
36
                     |                       +
37
                     |
38
                     |                       +-- message_received_sound (default = None)
39
                     |-- chat ---------------|-- message_sent_sound (default = None)
40
                     |                       |-- history_directory (default = ~/.sipclient/history)
41
                     |                       |-- accept_types (default = 'message/cpim','text/*')
42
                     |                       +-- accept_wrapped_types (default = ('*',))
43
                     |
44
                     |                       +-- ca_list_file (default = ~/.sipclient/tls/ca.crt)
45
                     |-- tls ----------------|-- certificate_file (default = None)
46
                     |                       |-- private_key_file (default = None)
47
                     |                       |-- protocol (default = TLSv1)
48
                     |                       |-- verify_server (default = true)
49
                     |                       +-- timeout (default = 1000)
50
                     |
51
                     |                       +-- trace_pjsip (default = false)
52
                     |-- logging ------------|-- trace_sip (default = false)
53
                     |                       |-- trace_xcap (default = false)
54
                     |                       |-- trace_msrp (default = false)
55
                     |                       |-- pjsip_level (default = 5)
56
                     |                       +-- directory (default = ~/.sipclient/log)
57
                     |
58
                     |                       +-- directory (default = ~/.sipclient/file_transfers)
59
                     |-- file_transfer ------|-- file_received_sound (default = None)
60
                     |                       +-- file_sent_sound (default = None)
61
                     |
62
                     |                       +-- color_depth (default = 8)
63
                     |-- desktop_sharing ----|-- resolution (default = 1024x768)
64
                     |                       |-- client_command (default = None)
65
                     |                       |-- server_command (default = None)
66
                     |                       +
67
                     |
68
                     |                       +-- input_device (default = auto)
69
                     |-- audio --------------|-- output_device (default = auto)
70
                     |                       |-- sample_rate (default = 32)
71
                     |                       |-- echo_delay (default = 200)
72
                     |                       |-- recordings_directory (default = ~/.sipclient/history)
73
                     |                       |-- silent (default = False)
74
                     |                       +-- playback_dtmf (default = True)
75
                     |
76
                     |                       +-- inbound (default = None)
77
                     |-- ringtone -----------|-- outbound (default = None)
78
                     |                       +
79
                     +
80
81
82
          +-- id (mandatory)
83
          |-- password (mandatory)
84
          |-- enabled (default = true)
85
          |-- display_name (default = None)
86
          |-- outbound_proxy (default = auto)
87
          |-- stun_servers (default = auto)
88
          |-- xcap_root (default = None)
89
          |                         +-- relay (default = auto)
90
          |-- msrp -----------------|-- use_relay_for_inbound (default = true)
91
          |                         +-- use_relay_for_outbound (default = false)
92
          |
93
          |                         +-- enabled (default=true)
94
          |-- message_summary ------|-- subscribe_interval (default = 600)
95
          |                         +-- voicemail_uri (default = None)
96
          |
97
          |                         +-- enabled (default = true)
98
          |-- dialog_event ---------|-- publish_interval (default = 600)
99
          |                         +-- subscribe_interval (default = 600)
100
          |
101
          |                         +-- enabled (default = true)
102
          |-- enum -----------------|-- country_code (default = None)
103
          |                         +-- tld_list (default = (e164.arpa,))
104
          |
105
          |                         +-- enabled (default = false)
106
          |-- ice ------------------|-- use_stun (default = true)
107
          |                         +
108
          |
109
          |                         +-- enabled (default = true)
110
          |-- registration ---------|-- interval (default = 600)
111
Account --|                         +-- use_stun (default = false)
112
          |
113
          |                         +-- enabled (default = true)
114
          |                         |-- subscribe_interval (default = 600)
115
          |-- presence -------------|-- publish_interval (default = 600)
116
          |                         |-- subscribe_rls_services (default = true)
117
          |                         +-- subscribe_xcap_diff (default = true)
118
          |
119
          |                         +-- codec_list (default = speex,g722,g711,ilbc,gsm)
120
          |-- audio ----------------|-- srtp_encryption (default = true)
121
          |                         +-- use_srtp_without_tls (default = false)
122
          |                         
123
          |                         +-- inbound (default = None)
124
          |-- ringtone -------------|
125
          |                         +
126
          +
127
128
129
                 +-- enabled (default = true)
130
                 |-- display_name (default = None)
131
                 |-- transports (default = tls,tcp,udp)
132
                 |                         +-- codec_list (default = speex,g722,g711,ilbc,gsm)
133
                 |-- audio ----------------|-- srtp_encryption (default = true)
134
BonjourAccount --|                         +-- use_srtp_without_tls (default = false)
135
                 |
136
                 |                         +-- inbound (default = None)
137
                 |-- ringtone -------------|
138
                 |                         +
139
                 +
140
141
}}}
142
143
=== SIPSimpleSettings ===
144
145
The {{{sipsimple.configuration.settings.SIPSimpleSettings}}} class is a singleton can be instantiated and used anywhere after the [wiki:SipSettingsAPI#ConfigurationManager ConfigurationManager] has been started. 
146
147
The Settings on it are explained below:
148
149
 '''SIPSimpleSettings.default_account''' (type={{{str}}}, default={{{'bonjour@local'}}}, nillable={{{True}}})::
150
  A string, which contains the id of the default Account. This setting is managed by the AccountManager and should not be changed manually. See [wiki:SipMiddlewareApi#AccountManager AccountManager] for more information.
151
152
 '''SIPSimpleSettings.user_agent''' (type={{{str}}}, default={{{'sipsimple VERSION'}}})::
153
  This setting will be used to set the value of the User-Agent header in outgoing SIP requests and of the Server header in all SIP responses.
154
155
 '''SIPSimpleSettings.local_ip''' (type={{{LocalIPAddress}}}, default={{{LocalIPAddress.DefaultHostIP}}})::
156
  The value of this setting is a complex type; the real used IP address can be accessed on the {{{value}}} attribute, which will always be a string:
157
  {{{
158
  SIPSimpleSettings().local_ip.value
159
  }}}
160
  If it is set to the special value LocalIPAddress.DefaultHostIP, then the IP address that would be used by the operating system to send packets over the default route will be used. Otherwise, it can be set to a string that must represent a local IP address on which the program can bind.
161
162
 '''SIPSimpleSettings.data_directory''' (type={{{AbsolutePath}}}, default={{{'~/.sipclient}}})::
163
  This is the directory, which will be used by default for storing the SIP SIMPLE data. The relative paths are calculated on runtime based on this setting, which means that if this setting is changed, all relative paths will point inside the new directory. It is a string, which must be an absolute path.
164
165
 '''SIPSimpleSettings.sip.local_udp_port''' (type={{{Port}}}, default={{{0}}})::
166
  This is the port on which the Engine will bind and for for sending and receiving UDP packets. It is an integer in the range 0-65535. If it is set to 0, it will be allocated automatically.
167
168
 '''SIPSimpleSettings.sip.local_tcp_port''' (type={{{Port}}}, default={{{0}}})::
169
  This is the port on which the Engine will listen for TCP connections. It is an integer in the range 0-65535. If it is set to 0, it will be allocated automatically.
170
171
 '''SIPSimpleSettings.sip.local_tls_port''' (type={{{Port}}}, default={{{0}}})::
172
  This is the port on which the Engine will listen for TLS connections. It is an integer in the range 0-65535. If it is set to 0, it will be allocated automatically.
173
174
 '''SIPSimpleSettings.sip.transports''' (type={{{Transports}}}, default={{{('tls', 'tcp', 'udp')}}})::
175
  This setting's value is a tuple, which can only contain the strings 'tls', 'tcp' and 'udp'. It has a double purpose:
176
   * Only the transports specified here are used to SIP requests associated with normal accounts.
177
   * The order of the transports specified in this tuple represent the preferred order in which transports should be used. This applies to all SIP requests.
178
179
 '''SIPSimpleSettings.rtp.port_range''' (type={{{PortRange}}}, default={{{PortRange(50000, 50400)}}})::
180
  This setting controls the port range from which ports used by RTP transport will be assigned. The values of the ports need to be in the range 1-65535; the start port must not be larger than the end port.
181
182
 '''SIPSimpleSettings.msrp.transport''' (type={{{MSRPTransport}}}, default={{{'tls'}}})::
183
  MSRP can use either TLS or TCP and this setting controls which one should be used.
184
185
 '''SIPSimpleSettings.msrp.local_port''' (type={{{Port}}}, default={{{0}}})::
186
  This setting specifies the TCP port on which MSRP will listen for connections.
187
188
 '''SIPSimpleSettings.chat.message_received_sound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
189
  This setting is a string representing an absolute path to a wav file, which is played when a message is received in a chat session. If it is set to {{{None}}}, no sound is played.
190
191
 '''SIPSimpleSettings.chat.message_sent_sound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
192
  This setting is a string representing an absolute path to a wav file, which is played when a message is sent in a chat session. If it is set to {{{None}}}, no sound is played.
193
194
 '''SIPSimpleSettings.chat.history_directory''' (type={{{DataPath}}}, default={{{DataPath('history')}}})::
195
  The history directory is where chat conversations are saved. If it is set to a relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In this directory, a subdirectory per account with the id of the account as the name will be created. In order to access the full path to the history directory, the value attribute on the setting can be used:
196
  {{{
197
  SIPSimpleSettings().chat.history_directory.value
198
  }}}
199
200
 '''SIPSimpleSettings.chat.accept_types''' (type={{{ContentTypeList}}}, default={{{('message/cpim', 'test/*')}}})::
201
  This setting controls which content types are accepted when negotiating an MSRP chat session. It is a tuple of strings and each string must be a valid content type in the form {{{TYPE/SUBTYPE}}}; {{{SUBTYPE}}} can be {{{*}}}; the special value {{{*}}} can also be used to represent any type.
202
203
 '''SIPSimpleSettings.chat.accept_wrapped_types''' (type={{{ContentTypeList}}}, default={{{('*',)}}})::
204
  This setting controls which the content types are accepted inside message/cpim messages. It is a tuple of strings and each string must be a valid content type in the form {{{TYPE/SUBTYPE}}}; {{{SUBTYPE}}} can be {{{*}}}; the special value {{{*}}} can also be used to represent any type.
205
206
 '''SIPSimpleSettings.tls.ca_list_file''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
207
  The settings points to a file which contains the CA certificates. In can be {{{None}}}, in which case no CAs are available. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
208
  {{{
209
  SIPSimpleSettings().tls.ca_list_file.value
210
  }}}
211
212
 '''SIPSimpleSettings.tls.certificate_file''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
213
  The path to the certificate file used to authenticate on TLS connections. If it is set, the {{{SIPSimpleSettings.tls.private_key_file}}} must also be set. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
214
  {{{
215
  SIPSimpleSettings().tls.certificate_file.value
216
  }}}
217
218
 '''SIPSimpleSettings.tls.private_key_file''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
219
  The path to the private key file used for TLS connections. The key file must be un-encrypted. If it is set, the {{{SIPSimpleSettings.tls.certificate_file}}} must also be set. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
220
  {{{
221
  SIPSimpleSettings().tls.private_key_file.value
222
  }}}
223
224
 '''SIPSimpleSettings.tls.protocol''' (type={{{TLSProtocol}}}, default={{{'TLSv1'}}})::
225
  This setting sets the version of the TLS protocol which will be used. It is a string and must be one of {{{'TLSv1'}}}, {{{'SSLv2'}}}, {{{'SSL3'}}}, {{{'SSL23'}}}.
226
227
 '''SIPSimpleSettings.tls.verify_protocol''' (type={{{bool}}}, default={{{False}}})::
228
  If this setting is set to {{{True}}}, the middleware will verify the server's certificate when connecting via TLS.
229
230
 '''SIPSimpleSettings.tls.timeout''' (type={{{NonNegativeInteger}}}, default={{{1000}}})::
231
  This is the timeout for negotiating TLS connections, in milliseconds. It must be an non-negative integer.
232
233
 '''SIPSimpleSettings.logging.directory''' (type={{{DataPath}}}, default={{{DataPath('logs')}}})::
234
  This is the directory where the logs create by the SIP SIMPLE middleware will be stored. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
235
  {{{
236
  SIPSimpleSettings().logging.directory.value
237
  }}}
238
239
 '''SIPSimpleSettings.logging.trace_sip''' (type={{{bool}}}, default={{{False}}})::
240
  If this setting is set to True, the SIP packets will be written to a log file named 'sip_trace.txt', inside the directory pointed by {{{SIPSimpleSettings.logging.directory}}}.
241
242
 '''SIPSimpleSettings.logging.trace_pjsip''' (type={{{bool}}}, default={{{False}}})::
243
  If this setting is set to True, the PJSIP log messages will be written to a log file named 'pjsip_trace.txt', inside the directory pointed by {{{SIPSimpleSettings.logging.directory}}}.
244
245
 '''SIPSimpleSettings.logging.trace_msrp''' (type={{{bool}}}, default={{{False}}})::
246
  If this setting is set to True, the MSRP packets will be written to a log file named 'msrp_trace.txt', inside the directory pointed by {{{SIPSimpleSettings.logging.directory}}}.
247
248
 '''SIPSimpleSettings.logging.trace_xcap''' (type={{{bool}}}, default={{{False}}})::
249
  If this setting is set to True, the XCAP packets will be written to a log file named 'xcap_trace.txt', inside the directory pointed by {{{SIPSimpleSettings.logging.directory}}}.
250
251
 '''SIPSimpleSettings.logging.pjsip_level''' (type={{{NonNegativeInteger}}}, default={{{5}}})::
252
  This setting controls the amount of log messages generated by the PJSIP core. It must be set to a non-negative integer.
253
254
 '''SIPSimpleSettings.file_transfer.directory''' (type={{{DataPath}}}, default={{{DataPath('file_transfers')}}})::
255
  This directory is used to store the files obtained via MSRP file transfer. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
256
  {{{
257
  SIPSimpleSettings().file_transfer.directory.value
258
  }}}
259
260
 '''SIPSimpleSettings.file_transfer.file_received_sound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
261
  This setting should point to a wav file, which will be played when an incoming file transfer is finished. If it is set to {{{None}}}, no sound will be played.
262
263
 '''SIPSimpleSettings.file_transfer.file_sent_sound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
264
  This setting should point to a wav file, which will be played when an outgoing file transfer is finished. If it is set to {{{None}}}, no sound will be played.
265
266
 '''SIPSimpleSettings.desktop_sharing.color_depth''' (type={{{ImageDepth}}}, default={{{8}}})::
267
  The number of bits used to represent colored pixels when using desktop sharing. It must be one of {{{8}}}, {{{16}}} or {{{32}}}.
268
269
 '''SIPSimpleSettings.desktop_sharing.resolution''' (type={{{Resolution}}}, default={{{Resolution(width=1024, height=768)}}})::
270
  The resolution used for desktop sharing.
271
272
 '''SIPSimpleSettings.desktop_sharing.client_command''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
273
  The path to the VNC viewer program, which will be used with desktop sharing.
274
275
 '''SIPSimpleSettings.desktop_sharing.server_command''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
276
  The path to the VNC server program, which will be used with desktop sharing.
277
278
 '''SIPSimpleSettings.audio.input_device''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
279
  The name of the audio device, which will be used for input (recording). If it is set to {{{None}}}, one will be selected automatically.
280
281
 '''SIPSimpleSettings.audio.output_device''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
282
  The name of the audio device, which will be used for output (playback). If it is set to {{{None}}}, one will be selected automatically.
283
284
 '''SIPSimpleSettings.audio.echo_delay''' (type={{{NonNegativeInteger}}}, default={{{200}}})::
285
  This setting is used as a parameter for the audio echo cancellation algorithm. It's value is a non-negative integer which represents milliseconds. It specifies the length of the echo cancellation filter. The recommended value is the third of the room reverberation time.
286
287
 '''SIPSimpleSettings.audio.recordings_directory''' (type={{{DataPath}}}, default={{{DataPath('history')}}})::
288
  This directory will be used to store recorded audio conversations. Under this directory, a subdirectory per account with the id of the account as the name will be created. If it is set to relative path, it is taken relative to {{{SIPSimpleSettings.data_directory}}}; otherwise it is interpreted as an absolute path. In order to access the full path to the history directory, the value attribute on the setting can be used:
289
  {{{
290
  SIPSimpleSettings().audio.recordings_directory.value
291
  }}}
292
293
 '''SIPSimpleSettings.audio.sample_rate''' (type={{{SampleRate}}}, default={{{32}}})::
294
  This is the sample rate at which the audio system runs. All playback and recording will be done at this rate. If an audio codec has a smaller or larger sample rate, it will be resampled to this value. The possible values are 8, 16 and 32, and represent kHz.
295
 
296
 '''SIPSimpleSettings.audio.silent''' (type={{{bool}}}, default={{{False}}})::
297
  If this setting is set to True, no audio notifications will be played.
298
299
 '''SIPSimpleSettings.audio.playback_dtmf''' (type={{{bool}}}, default={{{True}}})::
300
  If this setting is set to {{{True}}}, whenever a DTMF is sent or received it will be played on the audio system. This does not control the DTMF related notifications.
301
302
 '''SIPSimpleSettings.ringtone.inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
303
  This setting should point to a wav file, which will be played when a SIP session request is received. If it is set to {{{None}}}, no sound will be played.
304
305
 '''SIPSimpleSettings.ringtone.outbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
306
  This setting should point to a wav file, which will be used as ringtone during an outgoing SIP session request as a response to a 180 Ringing. If it is set to {{{None}}}, no sound will be played.
307
308
309
=== Account ===
310
311
The Account object is used to represent a normal SIP account registered at a SIP provider. It is uniquely identifiable by it's SIP ID, in the form ''user@domain''. There is exactly one instance of Account per ID, which means that an Account can be accessed by instantianting it anywhere. However, this is not the recommended way of accessing accounts, since it can lead to creating new accounts. The recommended way is by using the [wiki:SipMiddlewareApi#AccountManager AccountManager]. Information about the roles of Account, apart from being a collection of settings, is explained in the [wiki:SipMiddlewareApi#Account Middleware API]. 
312
313
The settings that can be accessed on an Account are described below:
314
315
 '''Account.id''' (type={{{SIPAddress}}})::
316
  This is not a setting, as it cannot be modified. It's type is a subclass of {{{str}}}, so it can be used as a normal string, however it also has two attributes {{{username}}} and {{{domain}}} which point to the specific parts of the SIP address.
317
318
 '''Account.enabled''' (type={{{bool}}}, default={{{False}}})::
319
  If this setting is set to {{{True}}}, the Account will automatically activate and can be used in other parts of the middleware. More about this is described in [wiki:SipMiddlewareApi#Account Account].
320
321
 '''Account.password''' (type={{{str}}}, default={{{''}}})::
322
  The password, which will be used with this account for authentication.
323
324
 '''Account.display_name''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
325
  The contents of this setting will be sent as part of the ''From'' header when sending SIP requests.
326
327
 '''Account.outbound_proxy''' (type={{{SIPProxy}}}, default={{{None}}}, nillable={{{True}}})::
328
  This setting specifies whether to send all SIP requests when creating a new SIP dialog to a specific proxy. If this setting is set to {{{None}}}, then an RFC3263 lookup will be done based on the domain part of the SIP request URI.
329
330
 '''Account.stun_servers''' (type={{{StunServerAddresses}}}, default={{{None}}}, nillable={{{True}}})::
331
  This setting used for NAT traversal can be used to specify the addresses of the STUN servers used for detecting server reflexive candidates in the context of ICE. The value of the setting is a tuple of objects of type {{{StunServerAddress}}}.
332
333
 '''Account.xcap_root''' (type={{{XCAPRoot}}}, default={{{None}}}, nillable={{{True}}})::
334
  The XCAP root is required for accessing documents via the XCAP protocol. It must be a URL with either the ''http'' or ''https'' schemes.
335
336
 '''Account.msrp.relay''' (type={{{MSRPRelayAddress}}}, default={{{None}}}, nillable={{{True}}})::
337
  This setting can be used to specify a MSRP relay for use in MSRP connections. If it is set to {{{None}}}, TODO.
338
339
 '''Account.msrp.use_relay_for_inbound''' (type={{{bool}}}, default={{{True}}})::
340
  If this setting is set to {{{True}}}, the MSRP relay will be used for all incoming MSRP connections.
341
342
 '''Account.msrp.use_relay_for_outbound''' (type={{{bool}}}, default={{{False}}})::
343
  If this setting is set to {{{True}}}, the MSRP relay will be used for all outgoing MSRP connections.
344
345
 '''Account.message_summary.enabled''' (type={{{bool}}}, default={{{False}}})::
346
  If this setting is set to {{{True}}}, the Account will subscribe to the ''message-summary'' event, as specified by RFC3842.
347
348
 '''Account.message_summary.subscribe_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
349
  This setting controls the number of seconds used for the ''Expire'' header when subscribing to the ''message-summary'' event. It must be a non-negative integer.
350
351
 '''Account.message_summary.voicemail_uri''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
352
  This is the SIP URI which can be called to listen to the voicemail messages.
353
354
 '''Account.dialog_event.enabled''' (type={{{bool}}}, default={{{True}}})::
355
  If this setting is set to {{{True}}}, the Account will subscribe to the ''dialog'' event, and publish information for this event, as specified by RFC4235.
356
357
 '''Account.dialog_event.publish_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
358
  This setting controls the number of seconds used for the ''Expire'' header when publishing for the ''dialog'' event. It must be a non-negative integer.
359
360
 '''Account.dialog_event.subscribe_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
361
  This setting controls the number of seconds used for the ''Expire'' header when subscribing to the ''dialog'' event. It must be a non-negative integer.
362
 
363
 '''Account.enum.country_code''' (type={{{CountryCode}}}, default={{{None}}}, nillable={{{True}}})::
364
  This setting controls the country number prefix which will be used for ENUM lookups. It is string which consists only of digits and must start with a non-zero digit.
365
366
 '''Account.enum.tld_list''' (type={{{DomainList}}}, default={{{('e164.arpa',)}}})::
367
  The value of this setting is a tuple of domains, which are used for doing ENUM lookups.
368
369
 '''Account.ice.enabled''' (type={{{bool}}}, default={{{False}}})::
370
  If this setting is set to {{{True}}}, ICE will be used for finding candidates for communication over NATed networks.
371
372
 '''Account.ice.use_stun''' (type={{{bool}}}, default={{{True}}})::
373
  If this setting is set to {{{True}}} and ICE is enabled, STUN servers will be contacted in order to generate candidates for ICE.
374
375
 '''Account.registration.enabled''' (type={{{bool}}}, default={{{True}}})::
376
  If this setting is set to {{{True}}}, the Account will automatically register when it is active. More about this is described in [wiki:SipMiddlewareApi#Account Account].
377
378
 '''Account.registration.interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
379
  This setting controls the number of seconds used for the ''Expire'' header when registering. It must be a non-negative integer.
380
381
 '''Account.registration.use_stun''' (type={{{bool}}}, default={{{False}}})::
382
  If this setting is set to {{{True}}}, STUN servers will be contacted for use in setting the contact URI for registrations.
383
384
 '''Account.presence.enabled''' (type={{{bool}}}, default={{{True}}})::
385
  If this setting is set to {{{True}}}, the presence related features of the Account will be activated. More about this is described in [wiki:SipMiddlewareApi#Account Account].
386
387
 '''Account.presence.subscribe_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
388
  This setting controls the number of seconds used for the ''Expire'' header when subscribing to the ''presence'' event. It must be a non-negative integer.
389
390
 '''Account.presence.publish_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
391
  This setting controls the number of seconds used for the ''Expire'' header when publishing for the ''presence'' event. It must be a non-negative integer.
392
393
 '''Account.presence.subscribe_rls_services''' (type={{{bool}}}, default={{{True}}})::
394
  If this setting is set to {{{True}}}, the Account will use RLS services to subscribe to the ''presence'' event in order to obtain the presence information for its buddies. If it is set to {{{False}}}, it will subscribe to each buddy individually.
395
396
 '''Account.presence.subscribe_xcap_diff''' (type={{{bool}}}, default={{{True}}})::
397
  If this setting is set to {{{True}}}, the Account will subscribe to the ''xcap-diff'' event in order to find out if the XCAP documents handled by the Account are modified by another entity.
398
399
 '''Account.audio.codec_list''' (type={{{AudioCodecs}}}, default={{{('speex', 'g722', 'g711', 'ilbc', 'gsm')}}})::
400
  This setting is used to specify the preferred audio codecs, which should be used for audio calls of this account. It must be a tuple containing only strings, which represent the supported codecs (speex, g722, g711, ilbc and gsm), in the order in which they are preferred.
401
402
 '''Account.audio.srtp_encryption''' (type={{{SRTPEncryption}}}, default={{{'optional'}}})::
403
  The value of this setting specifies how the account requires the calls to be encrypted using SRTP. It can be one of the values {{{'disabled'}}}, {{{'optional'}}} or {{{'mandatory'}}}.
404
405
 '''Account.audio.use_srtp_without_tls''' (type={{{bool}}}, default={{{False}}})::
406
  If this setting is set to {{{True}}}, SRTP could be used even if the SIP signaling used to control the call is not over TLS.
407
408
 '''Account.ringtone.inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
409
  This setting should point to a wav file, which will be used to play the incoming ringtone. If it is set to {{{None}}}, the wav file set in {{{SIPSimpleSettings.ringtone.inbound}}} will be used instead.
410
411
412
=== BonjourAccount ===
413
414
The BonjourAccount is a singleton object as there can only be one bonjour account on a system. A bonjour account is used in P2P mode and does not interact with any server. Similar to the Account, it is used both as a complex object, which contains the required behavior for bonjour, as well as a container for the settings which apply to it. 
415
416
The settings of the BonjourAccount are described below:
417
 
418
 '''BonjourAccount.id''' (type={{{SIPAddress}}})::
419
  This is not a setting, as it is the static string 'bonjour@local' which represents the id of the BonjourAccount.
420
421
 '''BonjourAccount.enabled''' (type={{{bool}}}, default={{{True}}})::
422
  If this setting is set to {{{True}}}, the account will be used. More information about this is in [wiki:SipMiddlewareApi#BonjourAccount BonjourAccount].
423
424
 '''BonjourAccount.display_name''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
425
  The contents of this setting will be sent as part of the ''From'' header when sending SIP requests.
426
427
 '''BonjourAccount.transports''' (type={{{Transports}}}, default={{{('tls', 'tcp', 'udp')}}})::
428
  This setting's value is a tuple which can only contain the strings 'tls', 'tcp' and 'udp'. It has a double purpose:
429
   * Only the transports specified here are used to SIP requests associated with the BonjourAccount.
430
   * The order of the transports specified in this tuple represent the preferred order in which transports should be used. This applies to all SIP requests used.
431
432
 '''BonjourAccount.audio.codec_list''' (type={{{AudioCodecs}}}, default={{{('speex', 'g722', 'g711', 'ilbc', 'gsm')}}})::
433
  This setting is used to specify the preferred audio codecs, which should be used for audio calls of this account. It must be a tuple containing only strings, which represent the supported codecs (speex, g722, g711, ilbc and gsm), in the order in which they are preferred.
434
435
 '''BonjourAccount.audio.srtp_encryption''' (type={{{SRTPEncryption}}}, default={{{'optional'}}})::
436
  The value of this setting specifies how the account requires the calls to be encrypted using SRTP. It can be one of the values {{{'disabled'}}}, {{{'optional'}}} or {{{'mandatory'}}}.
437
438
 '''BonjourAccount.audio.use_srtp_without_tls''' (type={{{bool}}}, default={{{False}}})::
439
  If this setting is set to {{{True}}}, SRTP could be used even if the SIP signaling used to control the call is not over TLS.
440
441
 '''BonjourAccount.ringtone.inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
442
  This setting should point to a wav file which will be used as the incoming ringtone. If it is set to {{{None}}}, the wav file set in {{{SIPSimpleSettings.ringtone.inbound}}} will be used instead.
443
444
445
== Architecture ==
446
447
Configuration API consists of the low-level classes that can be used for storing and retrieving configuration objects. Moreover, it allows the creation of a higher level API for accessing configuration items. The SIP SIMPLE settings are defined using this API, however application-specific settings can also make use of it in order to define a consistent view of all the settings.
448
449
The module '''sipsimple.configuration''' contains the main classes of the configuration API. These are:
450
451
 * ConfigurationManager
452
 * SettingsObject
453
 * SettingsGroup
454
 * Setting
455
456
In addition, the exceptions which make up this package are:
457
458
 * ConfigurationError (base class for all other configuration errors)
459
 * DuplicateSectionError
460
 * UnknownSectionError
461
 * UnknownNameError
462
463
The package '''sipsimple.configuration.backend''' contains the abstract interface for configuration backends, as well as concrete implementations of backends. This package is explained in more detail in [wiki:SipSettingsAPI#ConfigurationBackendAPI Configuration Backend API].
464
465
=== Configuration Manager ===
466
467
The central entity is the ConfigurationManager, which is used for storing and retrieving configuration objects. Each stored configuration object has an associated name and a section, which allows similar objects or objects of the same type to be grouped together under the same section. Note that the names of the objects need to be unique inside a section. A pluggable backend system explained in [wiki:SipSettingsAPI#ConfigurationBackendAPI Configuration Backend API] allows the configuration to be stored using any format, which can store (name, value) string pairs in sections.
468
469
The ConfigurationManager class is a singleton to allow any part of the code to access it without the need to pass references. However, its '''start''' method needs to be called before it can be used. Once this is done, objects can be added, retrieved or deleted from the underlying storage. The methods of ConfigurationManager are:
470
471
 '''!__init!__'''(''self'')::
472
 References to the ConfigurationManager instance can be obtained anytime without passing any arguments. However, it needs the manager needs to be started in order to be used, otherwise all methods will raise a RuntimeError.
473
 '''start'''(''self'', '''backend'''={{{None}}})::
474
 The start method allows the ConfigurationManager instance to use the specified backend for accessing the underlying storage. If a backend is not provided, then a {{{sipsimple.configuration.backend.configfile.ConfigFileBackend}}} instance will be created, without passing any arguments to the constructor. See [wiki:SipSettingsAPI#ConfigFileBackend ConfigFileBackend] for information on how this object stores the data.
475
 '''set'''(''self'', '''section''', '''name''', '''object''')::
476
 The {{{object}}} will be sent to the configuration backend for storing, under {{{section}}}, with the specified {{{name}}}. If there already was an object with that name, it will be overwritten. If the section did not exist, then it will be created first. Note that changes are not guaranteed to have been written to the underlying storage until the '''save''' method is called.
477
 '''delete'''(''self'', '''section''', '''name''')::
478
 If an object stored as {{{name}}} exists in {{{section}}}, then it will be deleted. If the section was never created, then an {{{UnknownSectionError}}} will be raised.
479
 '''get'''(''self'', '''section''', '''name''')::
480
 Retrieves the object stored with {{{name}}} in {{{section}}}, if it exists. Otherwise, the method will raise an {{{UnknownSectionError}}} or an {{{UnknownNameError}}} if the section or name do not exist.
481
 '''get_names'''(''self'', '''section''')::
482
 Returns a list with all the names of the objects in {{{section}}}. Will raise {{{UnknownSectionError}}} if the section does not exist.
483
 '''save'''(''self'')::
484
 Flushes the changes made to the configuration to disk. This method must be called to ensure that all changes have been written.
485
486
The notifications of the ConfigurationManager are:
487
 '''CFGManagerSaveFailed'''::
488
 This notification is sent when a SettingsObject needs to be stored to the persisent storage, but the process fails. The attributes of it are:
489
 [[BR]]''exception'':[[BR]]
490
 The exception which was raised when the storing failed.
491
 [[BR]]''modified'':[[BR]]
492
 This attribute is only set if the storage process was started as a result of calling the save method on the SettingsObject. It's contents is the same as for the {{{CFGSettingsObjectDidChange}}} notification.
493
494
495
=== SettingsObject ===
496
497
A SettingsObject is used to represent a hierarchy of settings, which are managed via the ConfigurationManager. There are two types of SettingsObject:
498
 * pure Singleton SettingsObjects, i.e. there is only one instance of this SettingsObject in an application. This also means that the object cannot be deleted. An example of such a SettingsObject is SIPSimpleSettings. These SettingsObjects are useful to represent global settings.
499
 * SettingsObject with an associated id. These are Singleton as well, but there is more than one instance: one per id. The instances are not necessarily persistent. New ones can be created and existing ones can be deleted. An example of such a SettingsObject is the Account. These SettingsObjects are useful to represent settings which apply to entities identifiable by a string id.
500
501
All SettingsObjects belong to a specific section, specified using the {{{__section__}}} attribute.
502
503
When a SettingsObject is instantiated its contained settings are loaded from the configuration storage. If it is the first time a SettingsObject is created, the default values for the settings will apply. The SettingsObject will only be copied to storage when its '''save''' method is called.
504
505
==== Defining a global SettingsObject ====
506
507
In order to define a global SettingsObject, the {{{__section__}}} and {{{__id__}}} attributes must be defined on the class. The {{{__id__}}} must not be used in any other SettingsObject which is stored in the same section. An example of defining a global SettingsObject:
508
{{{
509
from sipsimple.configuration import SettingsObject
510
511
class SIPSimpleSettings(SettingsObject):
512
    __section__ = 'Global'
513
    __id__ = 'SIPSimple'
514
}}}
515
516
The {{{__init__}}} method must not accept any other argument except ''self''. It will be called each time the settings are loaded from the storage, not only the first time the object is created.
517
518
519
==== Defining a per-id SettingsObject ====
520
521
In order to define a per-id SettingsObject, the {{{__section__}}} attribute must be defined on the class, while the {{{__id__}}} attribute must be left to None. When instantiating the resulting class, exactly one argument must be given, which represents the string id. Each class defined as a per-id SettingsObject must be allocated a different section from all the other SettingsObjects (including global ones), otherwise the keys under which the SettingsObjects are stored could overlap. An example of defining a per-id SettingsObject:
522
{{{
523
from sipsimple.configuration import SettingsObject
524
525
class Account(SettingsObject):
526
    __section__ = 'Accounts'
527
    def __init__(self, id):
528
        """Do something each time the Account is loaded"""
529
}}}
530
531
The {{{__init__}}} method must accept exactly one argument except ''self''. It will be called each time the object is loaded from the storage, in addition to the first time the object is created. This allows the SettingsObject to be more than a simple collection of settings.
532
533
==== Instance methods of SettingsObjects ====
534
535
 '''save'''(''self'')::
536
 If the contained Settings of this SettingsObject have changed, the object will be saved to the persistent storage. A CFGSettingsObjectDidChange notification will be issued which contains the modified settings. If the save fails, a CFGManagerSaveFailed notification is issued in addition.
537
 '''delete'''(''self'')::
538
 This method can only be called on per-id SettingsObjects. It will delete the object from the persistent storage. All references to this SettingsObject must be removed.
539
540
==== Notifications ====#SettingsObjectNotifications
541
542
 '''CFGSettingsObjectDidChange'''::
543
 This notification is sent when the save method of a SettingsObject is called. Attributes:
544
 [[BR]]''modified'':[[BR]]
545
 A dict instance which maps settings keys in their fully qualified form (attribute names seperated by '.', relative to the SettingsObject) to a ModifiedValue instance; the ModifiedValue instance contains two attributes: ''old'' and ''new'' which are set to the old and the new Setting's value respectively.
546
547
548
=== Setting ===
549
550
The Setting descriptor is used to describe a setting in SettingsObjects. The following methods are part of the public API of it:
551
 '''!__init!__'''(''self'', '''type''', '''default'''={{{None}}}, '''nillable'''={{{False}}})::
552
 Create a new Setting descriptor which represents a setting in all instances of a SettingsObject. The default value must be specified if the setting is not nillable. The type will be applied to the values which are set to this descriptor if the value is not already an instance of the type.
553
554
An example of using a setting:
555
{{{
556
from sipsimple.configuration import Setting, SettingsObject
557
558
class SIPSimpleSettings(SettingsObject):
559
    __section__ = 'Global'
560
    __id__ = 'SIPSimple'
561
562
    user_agent = Setting(type=str, default='sipsimple %s' % __version__)
563
}}}
564
565
566
=== SettingsGroup ===
567
568
A SettingsGroup allows settings to be structured hierarchically. Subclasses of SettingsGroup are containers for Settings and other SettingsGroups just as SettingsObjects are. In addition, the subclasses of SettingsGroup are descriptors and can be used as such to assign a SettingsGroup as a child of another SettingsGroup or a SettingsObject. An example usage containing Setting, SettingsGroup and SettingsObject:
569
{{{
570
from sipsimple.configuration import Setting, SettingsGroup, SettingsObject
571
572
class TLSSettings(SettingsGroup):
573
    verify_server = Setting(type=bool, default=False)
574
575
class SIPSimpleSettings(SettingsObject):
576
    __section__ = 'Global'
577
    __id__ = 'SIPSimple'
578
579
    user_agent = Setting(type=str, default='sipsimple %s' % __version__)
580
581
    tls = TLSSettings
582
}}}
583
584
=== Backend API ===
585
586
The backend API provides a way to use the configuration framework consistently, while using any system for storing the data persistently. The ConfigurationManager makes use of a backend whenever it needs to write/read something to the persistent storage. The backend only needs to know how to handle (key, value) string pairs in sections. In order to use a specific backend, it is given to the ConfigurationManager in its start method.
587
588
The interface '''sipsimple.configuration.backend.IBackend''' describes the backend:
589
 '''add_section'''('''section''')::
590
 Add a section with a specified name or raise DuplicateSectionError if the section already exists.
591
 '''delete_section'''('''section''')::
592
 Delete a section identified by a name or raise UnknownSectionError if the section does not exist.
593
 '''set'''('''section''', '''name''', '''value''')::
594
 Set a name, value pair inside a section. Will overwrite the previous pair, if it exists; otherwise raise UnknownSectionError if the section does not exist.
595
 '''delete'''('''section''', '''name''')::
596
 Delete a name, value pair from a section or raise UnknownSectionError if the section does not exist.
597
 '''get'''('''section''', '''name''')::
598
 Get the value associated to the name, in the specified section or raise UnknownNameError if such a name, value pair does not exist and UnknownSectionError if the section does not exist.
599
 '''get_names'''('''section''')::
600
 Get all the names from  the specified section or raise UnknownSectionError if the section does not exist.
601
 '''save'''()::
602
 Flush the modified name, value pairs.
603
604
605
==== ConfigFileBackend ====
606
607
A concrete implementation of the '''IBackend''' interface resides in '''sipsimple.configuration.backend.configfile.ConfigFileBackend'''. The methods different from the ones in '''IBackend''' are:
608
609
 '''!__init!__'''(''self'', '''filename'''={{{None}}})::
610
 Create a new ConfigFileBackend which uses the specified filename for loading and storing the data to. If it is not given, it defaults to {{{~/.sipclient/config}}}.