SipConfigurationAPI

Version 24 (Adrian Georgescu, 02/28/2010 12:55 pm)

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