SipConfigurationAPI

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