SipConfigurationAPI

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