Project

General

Profile

SipConfigurationAPI » History » Version 15

Adrian Georgescu, 08/21/2009 05:32 PM

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 2 Adrian Georgescu
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:SipConfigurationAPI#SettingsObjectNotifications SettingsObject Notifications].
16 1 Adrian Georgescu
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 11 Adrian Georgescu
== SIP Simple ==
20 5 Adrian Georgescu
21 1 Adrian Georgescu
{{{
22 7 Adrian Georgescu
             +-- default_account = user@example.com
23 15 Adrian Georgescu
SIP SIMPLE --|-- resources_directory = None
24 7 Adrian Georgescu
             |-- user_agent = sipsimple-0.9.0
25
             |-- user_data_directory = ~/.sipclient
26 4 Adrian Georgescu
             |-- audio
27
             |-- chat
28
             |-- desktop_sharing
29
             |-- file_transfer
30
             |-- logging
31
             |-- msrp
32
             |-- rtp
33
             |-- sip
34
             |-- sounds
35
             +-- tls
36 1 Adrian Georgescu
37 4 Adrian Georgescu
        +-- alert_device = Built-in Output
38
audio --|-- directory = history
39
        |-- input_device = Built-in Microphone
40
        |-- output_device = Built-in Output
41
        |-- sample_rate = 32000
42
        |-- silent = False
43
        +-- tail_length = 200
44 1 Adrian Georgescu
45 4 Adrian Georgescu
       +-- accept_types = ('message/cpim', 'text/*')
46
chat --|-- accept_wrapped_types = ('*',)
47
       +-- directory = history
48 1 Adrian Georgescu
49 4 Adrian Georgescu
                  +-- client_command = None
50
desktop_sharing --|-- color_depth = 8
51
                  |-- resolution = 1024x768
52
                  +-- server_command = None
53 1 Adrian Georgescu
54 4 Adrian Georgescu
                +-- directory = file_transfers
55
file_transfer --|
56
                +
57 1 Adrian Georgescu
58 4 Adrian Georgescu
          +-- directory = logs
59
logging --|-- pjsip_level = 5
60
          |-- trace_msrp = False
61
          |-- trace_notifications = True
62
          |-- trace_pjsip = True
63
          |-- trace_sip = True
64
          +-- trace_xcap = False
65 1 Adrian Georgescu
66 4 Adrian Georgescu
       +-- local_port = 0
67
msrp --|-- transport = tls
68
       +
69
70
      +-- audio_codecs = ('speex', 'G722', 'PCMU', 'PCMA', 'iLBC', 'GSM')
71
rtp --|-- local_ip = auto
72
      |-- port_range = PortRange(start=50000, end=50400)
73 1 Adrian Georgescu
      +-- timeout = 30
74 4 Adrian Georgescu
75 15 Adrian Georgescu
      +-- local_ip = auto
76 4 Adrian Georgescu
      +-- local_tcp_port = 0
77
sip --|-- local_tls_port = 0
78
      |-- local_udp_port = 0
79 1 Adrian Georgescu
      +-- transports = ('tls', 'tcp', 'udp')
80
81 5 Adrian Georgescu
         +-- audio_inbound = ring_inbound.wav,91
82
sounds --|-- audio_outbound = ring_outbound.wav,95
83
         |-- file_received = file_received.wav,34
84
         |-- file_sent = file_received.wav,39
85
         |-- message_received = file_received.wav,37
86
         +-- message_sent = file_received.wav,40
87 4 Adrian Georgescu
88
      +-- ca_list = None
89
tls --|-- certificate = None
90
      |-- private_key = None
91
      |-- protocol = TLSv1
92
      |-- timeout = 1000
93 1 Adrian Georgescu
      +-- verify_server = False
94
95 4 Adrian Georgescu
}}}
96 1 Adrian Georgescu
97
The {{{sipsimple.configuration.settings.SIPSimpleSettings}}} class is a singleton can be instantiated and used anywhere after the [wiki:SipConfigurationAPI#ConfigurationManager ConfigurationManager] has been started. 
98
99 5 Adrian Georgescu
The settings are explained below:
100 1 Adrian Georgescu
101
 '''SIPSimpleSettings.default_account''' (type={{{str}}}, default={{{'bonjour@local'}}}, nillable={{{True}}})::
102 2 Adrian Georgescu
  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.
103 1 Adrian Georgescu
104
 '''SIPSimpleSettings.user_agent''' (type={{{str}}}, default={{{'sipsimple VERSION'}}})::
105
  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.
106
107
 '''SIPSimpleSettings.data_directory''' (type={{{AbsolutePath}}}, default={{{'~/.sipclient}}})::
108
  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.
109
110 6 Adrian Georgescu
=== Audio ===
111 5 Adrian Georgescu
112
 '''SIPSimpleSettings.audio.input_device''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
113
  The name of the audio device, which will be used for input (recording). If it is set to {{{None}}}, one will be selected automatically.
114
115
 '''SIPSimpleSettings.audio.output_device''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
116
  The name of the audio device, which will be used for output (playback). If it is set to {{{None}}}, one will be selected automatically.
117
118
 '''SIPSimpleSettings.audio.tail_length''' (type={{{NonNegativeInteger}}}, default={{{200}}})::
119
  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.
120
121
 '''SIPSimpleSettings.audio.directory''' (type={{{DataPath}}}, default={{{DataPath('history')}}})::
122
  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:
123
  {{{
124
  SIPSimpleSettings().audio.directory.value
125 1 Adrian Georgescu
  }}}
126
127
 '''SIPSimpleSettings.audio.sample_rate''' (type={{{SampleRate}}}, default={{{32}}})::
128
  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.
129
 
130
 '''SIPSimpleSettings.audio.silent''' (type={{{bool}}}, default={{{False}}})::
131
  If this setting is set to True, no audio notifications will be played.
132 5 Adrian Georgescu
133
=== SIP ===
134 15 Adrian Georgescu
135
 '''SIPSimpleSettings.sip.local_ip''' (type={{{LocalIPAddress}}}, default={{{LocalIPAddress.DefaultHostIP}}})::
136
  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:
137
  {{{
138
  SIPSimpleSettings().sip.local_ip.value
139
  }}}
140
  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.
141 5 Adrian Georgescu
142 1 Adrian Georgescu
 '''SIPSimpleSettings.sip.local_udp_port''' (type={{{Port}}}, default={{{0}}})::
143
  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.
144
145
 '''SIPSimpleSettings.sip.local_tcp_port''' (type={{{Port}}}, default={{{0}}})::
146
  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.
147
148
 '''SIPSimpleSettings.sip.local_tls_port''' (type={{{Port}}}, default={{{0}}})::
149
  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.
150
151
 '''SIPSimpleSettings.sip.transports''' (type={{{Transports}}}, default={{{('tls', 'tcp', 'udp')}}})::
152
  This setting's value is a tuple, which can only contain the strings 'tls', 'tcp' and 'udp'. It has a double purpose:
153
   * Only the transports specified here are used to SIP requests associated with normal accounts.
154
   * 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.
155
156 4 Adrian Georgescu
=== RTP ===
157
158 1 Adrian Georgescu
 '''SIPSimpleSettings.rtp.port_range''' (type={{{PortRange}}}, default={{{PortRange(50000, 50400)}}})::
159
  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.
160
161 4 Adrian Georgescu
 '''SIPSimpleSettings.rtp.audio_codecs''' (type={{{AudioCodecs}}}, default={{{('speex', 'G722', 'PCMU', 'PCMA', 'iLBC', 'GSM')}}})::
162
  This setting is used to specify the preferred audio codecs, which should be used for audio calls. 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. This setting can be overridden per account.
163
164
=== MSRP ===
165
166 1 Adrian Georgescu
 '''SIPSimpleSettings.msrp.transport''' (type={{{MSRPTransport}}}, default={{{'tls'}}})::
167
  MSRP can use either TLS or TCP and this setting controls which one should be used.
168
169
 '''SIPSimpleSettings.msrp.local_port''' (type={{{Port}}}, default={{{0}}})::
170
  This setting specifies the TCP port on which MSRP will listen for connections.
171
172 4 Adrian Georgescu
=== Chat ===
173 1 Adrian Georgescu
174 4 Adrian Georgescu
 '''SIPSimpleSettings.chat.directory''' (type={{{DataPath}}}, default={{{DataPath('history')}}})::
175 1 Adrian Georgescu
  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:
176
  {{{
177 4 Adrian Georgescu
  SIPSimpleSettings().chat.directory.value
178 1 Adrian Georgescu
  }}}
179
180
 '''SIPSimpleSettings.chat.accept_types''' (type={{{ContentTypeList}}}, default={{{('message/cpim', 'test/*')}}})::
181
  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.
182
183
 '''SIPSimpleSettings.chat.accept_wrapped_types''' (type={{{ContentTypeList}}}, default={{{('*',)}}})::
184
  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.
185 4 Adrian Georgescu
186
=== TLS ===
187
188 1 Adrian Georgescu
 '''SIPSimpleSettings.tls.ca_list''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
189
  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:
190 4 Adrian Georgescu
  {{{
191 1 Adrian Georgescu
  SIPSimpleSettings().tls.ca_list.value
192
  }}}
193 4 Adrian Georgescu
194 1 Adrian Georgescu
 '''SIPSimpleSettings.tls.certificate''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
195
  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:
196 4 Adrian Georgescu
  {{{
197 1 Adrian Georgescu
  SIPSimpleSettings().tls.certificate.value
198
  }}}
199 4 Adrian Georgescu
200 1 Adrian Georgescu
 '''SIPSimpleSettings.tls.private_key''' (type={{{DataPath}}}, default={{{None}}}, nillable={{{True}}})::
201
  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:
202 4 Adrian Georgescu
  {{{
203 1 Adrian Georgescu
  SIPSimpleSettings().tls.private_key.value
204
  }}}
205
206
 '''SIPSimpleSettings.tls.protocol''' (type={{{TLSProtocol}}}, default={{{'TLSv1'}}})::
207 4 Adrian Georgescu
  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'}}}.
208
209 1 Adrian Georgescu
 '''SIPSimpleSettings.tls.verify_protocol''' (type={{{bool}}}, default={{{False}}})::
210
  If this setting is set to {{{True}}}, the middleware will verify the server's certificate when connecting via TLS.
211
212
 '''SIPSimpleSettings.tls.timeout''' (type={{{NonNegativeInteger}}}, default={{{1000}}})::
213
  This is the timeout for negotiating TLS connections, in milliseconds. It must be an non-negative integer.
214
215 5 Adrian Georgescu
=== Logs ===
216 1 Adrian Georgescu
217
 '''SIPSimpleSettings.logging.directory''' (type={{{DataPath}}}, default={{{DataPath('logs')}}})::
218 4 Adrian Georgescu
  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:
219 1 Adrian Georgescu
  {{{
220
  SIPSimpleSettings().logging.directory.value
221
  }}}
222
223
 '''SIPSimpleSettings.logging.trace_sip''' (type={{{bool}}}, default={{{False}}})::
224
  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}}}.
225
226
 '''SIPSimpleSettings.logging.trace_pjsip''' (type={{{bool}}}, default={{{False}}})::
227
  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}}}.
228
229
 '''SIPSimpleSettings.logging.trace_msrp''' (type={{{bool}}}, default={{{False}}})::
230
  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}}}.
231
232
 '''SIPSimpleSettings.logging.trace_xcap''' (type={{{bool}}}, default={{{False}}})::
233
  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}}}.
234
235
 '''SIPSimpleSettings.logging.pjsip_level''' (type={{{NonNegativeInteger}}}, default={{{5}}})::
236
  This setting controls the amount of log messages generated by the PJSIP core. It must be set to a non-negative integer.
237 4 Adrian Georgescu
238
=== Desktop sharing ===
239 1 Adrian Georgescu
240
 '''SIPSimpleSettings.desktop_sharing.color_depth''' (type={{{ImageDepth}}}, default={{{8}}})::
241
  The number of bits used to represent colored pixels when using desktop sharing. It must be one of {{{8}}}, {{{16}}} or {{{32}}}.
242
243
 '''SIPSimpleSettings.desktop_sharing.resolution''' (type={{{Resolution}}}, default={{{Resolution(width=1024, height=768)}}})::
244
  The resolution used for desktop sharing.
245 4 Adrian Georgescu
246
 '''SIPSimpleSettings.desktop_sharing.client_command''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
247 1 Adrian Georgescu
  The path to the VNC viewer program, which will be used with desktop sharing.
248 4 Adrian Georgescu
249 1 Adrian Georgescu
 '''SIPSimpleSettings.desktop_sharing.server_command''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
250
  The path to the VNC server program, which will be used with desktop sharing.
251 4 Adrian Georgescu
252 5 Adrian Georgescu
=== File transfer ===
253 1 Adrian Georgescu
254 5 Adrian Georgescu
 '''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 1 Adrian Georgescu
  {{{
257 5 Adrian Georgescu
  SIPSimpleSettings().file_transfer.directory.value
258 1 Adrian Georgescu
  }}}
259
260 6 Adrian Georgescu
=== Sounds ===
261 1 Adrian Georgescu
262 4 Adrian Georgescu
 '''SIPSimpleSettings.sound.message_received''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
263
  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.
264 1 Adrian Georgescu
265 4 Adrian Georgescu
 '''SIPSimpleSettings.sound.message_sent''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
266
  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.
267
268
 '''SIPSimpleSettings.sounds.audio_inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
269 1 Adrian Georgescu
  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.
270
271 4 Adrian Georgescu
 '''SIPSimpleSettings.sounds.audio_outbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
272 1 Adrian Georgescu
  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.
273
274 4 Adrian Georgescu
 '''SIPSimpleSettings.sounds.file_received''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
275
  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.
276 1 Adrian Georgescu
277 4 Adrian Georgescu
 '''SIPSimpleSettings.sounds.file_sent''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
278
  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.
279
280
== Account ==
281 1 Adrian Georgescu
282 8 Adrian Georgescu
{{{
283
Account user@example.com:
284
          +-- display_name = Bob G.
285
account --|-- enabled = True
286
          |-- password = 1234
287
          |-- chat
288
          |-- dialog_event
289
          |-- message_summary
290
          |-- msrp
291
          |-- nat_traversal
292
          |-- presence
293
          |-- registration
294
          |-- rtp
295
          |-- sip
296
          +-- sounds
297
298
       +-- server = None
299
chat --|
300
       +
301
302
               +-- enabled = True
303
dialog_event --|
304
               +
305
306
                  +-- enabled = True
307
message_summary --|-- voicemail_uri = None
308
                  +
309
310
       +-- use_relay_for_inbound = True
311
msrp --|-- use_relay_for_outbound = False
312
       +
313
314
                +-- enable_ice = True
315
nat_traversal --|-- msrp_relay = None
316
                +-- stun_servers = None
317
318
           +-- enabled = True
319
presence --|-- subscribe_rls_services = True
320
           |-- subscribe_xcap_diff = True
321
           +-- xcap_root = https://xcap.sipthor.net/xcap-root/
322
323
               +-- enabled = True
324
registration --|
325
               +
326
327
      +-- audio_codecs = None
328
rtp --|-- srtp_encryption = optional
329
      +-- use_srtp_without_tls = True
330
331
      +-- outbound_proxy = None
332
sip --|-- publish_interval = 600
333
      |-- register_interval = 600
334
      +-- subscribe_interval = 600
335
336
         +-- audio_inbound = None
337
sounds --|
338
         +
339
340
}}}
341
342 1 Adrian Georgescu
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]. 
343
344
The settings that can be accessed on an Account are described below:
345
346
 '''Account.id''' (type={{{SIPAddress}}})::
347
  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.
348
349
 '''Account.enabled''' (type={{{bool}}}, default={{{False}}})::
350
  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].
351
352
 '''Account.password''' (type={{{str}}}, default={{{''}}})::
353
  The password, which will be used with this account for authentication.
354
355
 '''Account.display_name''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
356
  The contents of this setting will be sent as part of the ''From'' header when sending SIP requests.
357
358 8 Adrian Georgescu
=== SIP ===
359
360 14 Adrian Georgescu
 '''Account.sip.enable_register''' (type={{{bool}}}, default={{{True}}})::
361
  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].
362
363 8 Adrian Georgescu
 '''Account.sip.outbound_proxy''' (type={{{SIPProxy}}}, default={{{None}}}, nillable={{{True}}})::
364 1 Adrian Georgescu
  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.
365
366 8 Adrian Georgescu
 '''Account.sip.publish_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
367
  This setting controls the number of seconds used for the ''Expire'' header when publishing events. It must be a non-negative integer.
368 1 Adrian Georgescu
369 8 Adrian Georgescu
 '''Account.sip.subscribe_interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
370
  This setting controls the number of seconds used for the ''Expire'' header when subscribing to events. It must be a non-negative integer.
371 1 Adrian Georgescu
372 8 Adrian Georgescu
 '''Account.registration.interval''' (type={{{NonNegativeInteger}}}, default={{{600}}})::
373
  This setting controls the number of seconds used for the ''Expire'' header when registering. It must be a non-negative integer.
374 1 Adrian Georgescu
375 8 Adrian Georgescu
=== Presence  ===
376 1 Adrian Georgescu
377 8 Adrian Georgescu
 '''Account.presence.enabled''' (type={{{bool}}}, default={{{True}}})::
378
  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].
379 1 Adrian Georgescu
380 8 Adrian Georgescu
 '''Account.presence.xcap_root''' (type={{{XCAPRoot}}}, default={{{None}}}, nillable={{{True}}})::
381
  The XCAP root is required for accessing documents via the XCAP protocol. It must be a URL with either the ''http'' or ''https'' schemes.
382 1 Adrian Georgescu
383 8 Adrian Georgescu
 '''Account.presence.subscribe_rls_services''' (type={{{bool}}}, default={{{True}}})::
384
  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.
385 1 Adrian Georgescu
386 8 Adrian Georgescu
 '''Account.presence.subscribe_xcap_diff''' (type={{{bool}}}, default={{{True}}})::
387
  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.
388 1 Adrian Georgescu
389 8 Adrian Georgescu
=== NAT traversal ===
390 1 Adrian Georgescu
391
 '''Account.ice.enabled''' (type={{{bool}}}, default={{{False}}})::
392
  If this setting is set to {{{True}}}, ICE will be used for finding candidates for communication over NATed networks.
393
394 8 Adrian Georgescu
 '''Account.nat_traversal.stun_servers''' (type={{{StunServerAddresses}}}, default={{{None}}}, nillable={{{True}}})::
395 1 Adrian Georgescu
  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}}}.
396 8 Adrian Georgescu
397
 '''Account.nat_traversal.msrp_relay''' (type={{{MSRPRelayAddress}}}, default={{{None}}}, nillable={{{True}}})::
398 1 Adrian Georgescu
  This setting can be used to specify a MSRP relay for use in MSRP connections. If it is set to {{{None}}}, TODO.
399 9 Adrian Georgescu
400 14 Adrian Georgescu
 '''Account.nat_traversal.use_msrp_relay_for_inbound''' (type={{{bool}}}, default={{{True}}})::
401 8 Adrian Georgescu
  If this setting is set to {{{True}}}, the MSRP relay will be used for all incoming MSRP connections.
402 1 Adrian Georgescu
403 14 Adrian Georgescu
 '''Account.nat_traversal.use_msrp_relay_for_outbound''' (type={{{bool}}}, default={{{False}}})::
404 8 Adrian Georgescu
  If this setting is set to {{{True}}}, the MSRP relay will be used for all outgoing MSRP connections.
405 1 Adrian Georgescu
406 8 Adrian Georgescu
=== Message summary ===
407 1 Adrian Georgescu
408 8 Adrian Georgescu
 '''Account.message_summary.enabled''' (type={{{bool}}}, default={{{False}}})::
409
  If this setting is set to {{{True}}}, the Account will subscribe to the ''message-summary'' event, as specified by RFC3842.
410 1 Adrian Georgescu
411 8 Adrian Georgescu
 '''Account.message_summary.voicemail_uri''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
412
  This is the SIP URI which can be called to listen to the voicemail messages.
413 1 Adrian Georgescu
414 8 Adrian Georgescu
=== Dialog  event ===
415 1 Adrian Georgescu
416 8 Adrian Georgescu
 '''Account.dialog_event.enabled''' (type={{{bool}}}, default={{{True}}})::
417
  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.
418 1 Adrian Georgescu
419 8 Adrian Georgescu
=== RTP ===
420 1 Adrian Georgescu
421 8 Adrian Georgescu
 '''Account.rtp.audio_codecs''' (type={{{AudioCodecs}}}, default={{{None}}}, nillable={{{True}}})::
422
  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, or {{{None}}} if the codec_list from the general rtp settings is to be used.
423
424 1 Adrian Georgescu
 '''Account.audio.srtp_encryption''' (type={{{SRTPEncryption}}}, default={{{'optional'}}})::
425
  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'}}}.
426
427
 '''Account.audio.use_srtp_without_tls''' (type={{{bool}}}, default={{{False}}})::
428
  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.
429
430 8 Adrian Georgescu
=== Audio ===
431 1 Adrian Georgescu
432 8 Adrian Georgescu
 '''Account.sounds.audio_inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
433
  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.sounds.audio_inbound}}} will be used instead.
434 1 Adrian Georgescu
435 10 Adrian Georgescu
== BonjourAccount ==
436 9 Adrian Georgescu
437
{{{
438
Account bonjour@local:
439
          +-- display_name = Bob @ Local
440
account --|-- enabled = True
441
          |-- rtp
442
          +-- sounds
443
444
      +-- audio_codecs = None
445
rtp --|-- srtp_encryption = optional
446
      +-- use_srtp_without_tls = True
447
448
         +-- audio_inbound = None
449
sounds --|
450
         +
451
}}}
452
453 1 Adrian Georgescu
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. 
454
455
The settings of the BonjourAccount are described below:
456
 
457
 '''BonjourAccount.id''' (type={{{SIPAddress}}})::
458
  This is not a setting, as it is the static string 'bonjour@local' which represents the id of the BonjourAccount.
459
460
 '''BonjourAccount.enabled''' (type={{{bool}}}, default={{{True}}})::
461
  If this setting is set to {{{True}}}, the account will be used. More information about this is in [wiki:SipMiddlewareApi#BonjourAccount BonjourAccount].
462
463
 '''BonjourAccount.display_name''' (type={{{str}}}, default={{{None}}}, nillable={{{True}}})::
464
  The contents of this setting will be sent as part of the ''From'' header when sending SIP requests.
465
466 9 Adrian Georgescu
=== RTP ===
467
468
 '''BonjourAccount.rtp.audio.codecs''' (type={{{AudioCodecs}}}, default={{{('speex', 'g722', 'g711', 'ilbc', 'gsm')}}})::
469 1 Adrian Georgescu
  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.
470
471 9 Adrian Georgescu
 '''BonjourAccount.rtp.srtp_encryption''' (type={{{SRTPEncryption}}}, default={{{'optional'}}})::
472 1 Adrian Georgescu
  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'}}}.
473
474 9 Adrian Georgescu
 '''BonjourAccount.rtp.use_srtp_without_tls''' (type={{{bool}}}, default={{{False}}})::
475 1 Adrian Georgescu
  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.
476
477 9 Adrian Georgescu
=== Sounds ===
478
479
 '''BonjourAccount.sounds.audio_inbound''' (type={{{AbsolutePath}}}, default={{{None}}}, nillable={{{True}}})::
480
  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.sounds.audio_inbound}}} will be used instead.
481 1 Adrian Georgescu
482
483
== Architecture ==
484 2 Adrian Georgescu
485 1 Adrian Georgescu
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.
486
487
The module '''sipsimple.configuration''' contains the main classes of the configuration API. These are:
488
489
 * ConfigurationManager
490
 * SettingsObject
491
 * SettingsGroup
492
 * Setting
493
494
In addition, the exceptions which make up this package are:
495
496
 * ConfigurationError (base class for all other configuration errors)
497
 * DuplicateSectionError
498
 * UnknownSectionError
499
 * UnknownNameError
500
501
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:SipConfigurationAPI#ConfigurationBackendAPI Configuration Backend API].
502
503
=== Configuration Manager ===
504
505
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:SipConfigurationAPI#ConfigurationBackendAPI Configuration Backend API] allows the configuration to be stored using any format, which can store (name, value) string pairs in sections.
506
507
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:
508
509
 '''!__init!__'''(''self'')::
510
 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.
511
 '''start'''(''self'', '''backend'''={{{None}}})::
512
 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:SipConfigurationAPI#ConfigFileBackend ConfigFileBackend] for information on how this object stores the data.
513
 '''set'''(''self'', '''section''', '''name''', '''object''')::
514
 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.
515
 '''delete'''(''self'', '''section''', '''name''')::
516
 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.
517
 '''get'''(''self'', '''section''', '''name''')::
518
 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.
519
 '''get_names'''(''self'', '''section''')::
520
 Returns a list with all the names of the objects in {{{section}}}. Will raise {{{UnknownSectionError}}} if the section does not exist.
521
 '''save'''(''self'')::
522
 Flushes the changes made to the configuration to disk. This method must be called to ensure that all changes have been written.
523
524
The notifications of the ConfigurationManager are:
525
 '''CFGManagerSaveFailed'''::
526
 This notification is sent when a SettingsObject needs to be stored to the persisent storage, but the process fails. The attributes of it are:
527
 [[BR]]''exception'':[[BR]]
528
 The exception which was raised when the storing failed.
529
 [[BR]]''modified'':[[BR]]
530
 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.
531
532
533
=== SettingsObject ===
534
535
A SettingsObject is used to represent a hierarchy of settings, which are managed via the ConfigurationManager. There are two types of SettingsObject:
536
 * 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.
537
 * 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.
538
539
All SettingsObjects belong to a specific section, specified using the {{{__section__}}} attribute.
540
541
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.
542
543
==== Defining a global SettingsObject ====
544
545
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:
546
{{{
547
from sipsimple.configuration import SettingsObject
548
549
class SIPSimpleSettings(SettingsObject):
550
    __section__ = 'Global'
551
    __id__ = 'SIPSimple'
552
}}}
553
554
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.
555
556
557
==== Defining a per-id SettingsObject ====
558
559
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:
560
{{{
561
from sipsimple.configuration import SettingsObject
562
563
class Account(SettingsObject):
564
    __section__ = 'Accounts'
565
    def __init__(self, id):
566
        """Do something each time the Account is loaded"""
567
}}}
568
569
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.
570
571
==== Instance methods of SettingsObjects ====
572
573
 '''save'''(''self'')::
574
 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.
575
 '''delete'''(''self'')::
576
 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.
577
578
==== Notifications ====#SettingsObjectNotifications
579
580
 '''CFGSettingsObjectDidChange'''::
581
 This notification is sent when the save method of a SettingsObject is called. Attributes:
582
 [[BR]]''modified'':[[BR]]
583
 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.
584
585
586
=== Setting ===
587
588
The Setting descriptor is used to describe a setting in SettingsObjects. The following methods are part of the public API of it:
589
 '''!__init!__'''(''self'', '''type''', '''default'''={{{None}}}, '''nillable'''={{{False}}})::
590
 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.
591
592
An example of using a setting:
593
{{{
594
from sipsimple.configuration import Setting, SettingsObject
595
596
class SIPSimpleSettings(SettingsObject):
597
    __section__ = 'Global'
598
    __id__ = 'SIPSimple'
599
600
    user_agent = Setting(type=str, default='sipsimple %s' % __version__)
601
}}}
602
603
604
=== SettingsGroup ===
605
606
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:
607
{{{
608
from sipsimple.configuration import Setting, SettingsGroup, SettingsObject
609
610
class TLSSettings(SettingsGroup):
611
    verify_server = Setting(type=bool, default=False)
612
613
class SIPSimpleSettings(SettingsObject):
614
    __section__ = 'Global'
615
    __id__ = 'SIPSimple'
616
617
    user_agent = Setting(type=str, default='sipsimple %s' % __version__)
618
619
    tls = TLSSettings
620
}}}
621
622
=== Backend API ===
623
624
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.
625
626
The interface '''sipsimple.configuration.backend.IBackend''' describes the backend:
627
 '''add_section'''('''section''')::
628
 Add a section with a specified name or raise DuplicateSectionError if the section already exists.
629
 '''delete_section'''('''section''')::
630
 Delete a section identified by a name or raise UnknownSectionError if the section does not exist.
631
 '''set'''('''section''', '''name''', '''value''')::
632
 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.
633
 '''delete'''('''section''', '''name''')::
634
 Delete a name, value pair from a section or raise UnknownSectionError if the section does not exist.
635
 '''get'''('''section''', '''name''')::
636
 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.
637
 '''get_names'''('''section''')::
638
 Get all the names from  the specified section or raise UnknownSectionError if the section does not exist.
639
 '''save'''()::
640
 Flush the modified name, value pairs.
641
642
643
==== ConfigFileBackend ====
644
645
A concrete implementation of the '''IBackend''' interface resides in '''sipsimple.configuration.backend.configfile.ConfigFileBackend'''. The methods different from the ones in '''IBackend''' are:
646
647
 '''!__init!__'''(''self'', '''filename'''={{{None}}})::
648
 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}}}.