41cc6c5c493a81f54ad2763ef45b72fc8df05fa9
[asterisk/asterisk.git] / apps / confbridge / conf_config_parser.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2011, Digium, Inc.
5  *
6  * David Vossel <dvossel@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief ConfBridge config parser
22  *
23  * \author David Vossel <dvossel@digium.com>
24  */
25
26 /*** MODULEINFO
27         <support_level>core</support_level>
28  ***/
29
30 #include "asterisk.h"
31
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include "asterisk/logger.h"
34 #include "asterisk/config.h"
35 #include "asterisk/config_options.h"
36 #include "include/confbridge.h"
37 #include "asterisk/astobj2.h"
38 #include "asterisk/cli.h"
39 #include "asterisk/bridge_features.h"
40 #include "asterisk/stringfields.h"
41 #include "asterisk/pbx.h"
42
43
44 /*** DOCUMENTATION
45         <configInfo name="app_confbridge" language="en_US">
46                 <synopsis>Conference Bridge Application</synopsis>
47                 <configFile name="confbridge.conf">
48                         <configObject name="global">
49                                 <synopsis>Unused, but reserved.</synopsis>
50                         </configObject>
51                         <configObject name="user_profile">
52                                 <synopsis>A named profile to apply to specific callers.</synopsis>
53                                 <description><para>Callers in a ConfBridge have a profile associated with them
54                                 that determine their options. A configuration section is determined to be a
55                                 user_profile when the <literal>type</literal> parameter has a value
56                                 of <literal>user</literal>.
57                                 </para></description>
58                                 <configOption name="type">
59                                         <synopsis>Define this configuration category as a user profile.</synopsis>
60                                         <description><para>The type parameter determines how a context in the
61                                         configuration file is interpreted.</para>
62                                         <enumlist>
63                                                 <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
64                                                 <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
65                                                 <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
66                                         </enumlist>
67                                         </description>
68                                 </configOption>
69                                 <configOption name="admin">
70                                         <synopsis>Sets if the user is an admin or not</synopsis>
71                                 </configOption>
72                                 <configOption name="marked">
73                                         <synopsis>Sets if this is a marked user or not</synopsis>
74                                 </configOption>
75                                 <configOption name="startmuted">
76                                         <synopsis>Sets if all users should start out muted</synopsis>
77                                 </configOption>
78                                 <configOption name="music_on_hold_when_empty">
79                                         <synopsis>Play MOH when user is alone or waiting on a marked user</synopsis>
80                                 </configOption>
81                                 <configOption name="quiet">
82                                         <synopsis>Silence enter/leave prompts and user intros for this user</synopsis>
83                                 </configOption>
84                                 <configOption name="announce_user_count">
85                                         <synopsis>Sets if the number of users should be announced to the user</synopsis>
86                                 </configOption>
87                                 <configOption name="announce_user_count_all">
88                                         <synopsis>Announce user count to all the other users when this user joins</synopsis>
89                                         <description><para>Sets if the number of users should be announced to all the other users
90                                         in the conference when this user joins. This option can be either set to 'yes' or
91                                         a number. When set to a number, the announcement will only occur once the user
92                                         count is above the specified number.
93                                         </para></description>
94                                 </configOption>
95                                 <configOption name="announce_only_user">
96                                         <synopsis>Announce to a user when they join an empty conference</synopsis>
97                                 </configOption>
98                                 <configOption name="wait_marked">
99                                         <synopsis>Sets if the user must wait for a marked user to enter before joining a conference</synopsis>
100                                 </configOption>
101                                 <configOption name="end_marked">
102                                         <synopsis>Kick the user from the conference when the last marked user leaves</synopsis>
103                                 </configOption>
104                                 <configOption name="talk_detection_events">
105                                         <synopsis>Set whether or not notifications of when a user begins and ends talking should be sent out as events over AMI</synopsis>
106                                 </configOption>
107                                 <configOption name="dtmf_passthrough">
108                                         <synopsis>Sets whether or not DTMF should pass through the conference</synopsis>
109                                 </configOption>
110                                 <configOption name="announce_join_leave">
111                                         <synopsis>Prompt user for their name when joining a conference and play it to the conference when they enter</synopsis>
112                                 </configOption>
113                                 <configOption name="announce_join_leave_review">
114                                         <synopsis>Prompt user for their name when joining a conference and play it to the conference when they enter.
115                                         The user will be asked to review the recording of their name before entering the conference.</synopsis>
116                                 </configOption>
117                                 <configOption name="pin">
118                                         <synopsis>Sets a PIN the user must enter before joining the conference</synopsis>
119                                 </configOption>
120                                 <configOption name="music_on_hold_class">
121                                         <synopsis>The MOH class to use for this user</synopsis>
122                                 </configOption>
123                                 <configOption name="announcement">
124                                         <synopsis>Sound file to play to the user when they join a conference</synopsis>
125                                 </configOption>
126                                 <configOption name="denoise">
127                                         <synopsis>Apply a denoise filter to the audio before mixing</synopsis>
128                                         <description><para>Sets whether or not a denoise filter should be applied
129                                         to the audio before mixing or not.  Off by default. Requires
130                                         <literal>codec_speex</literal> to be built and installed.  Do not confuse this option
131                                         with <replaceable>drop_silence</replaceable>.  Denoise is useful if there is a lot of background
132                                         noise for a user as it attempts to remove the noise while preserving
133                                         the speech.  This option does NOT remove silence from being mixed into
134                                         the conference and does come at the cost of a slight performance hit.
135                                         </para></description>
136                                 </configOption>
137                                 <configOption name="dsp_drop_silence">
138                                         <synopsis>Drop what Asterisk detects as silence from audio sent to the bridge</synopsis>
139                                         <description><para>
140                                         This option drops what Asterisk detects as silence from
141                                         entering into the bridge.  Enabling this option will drastically
142                                         improve performance and help remove the buildup of background
143                                         noise from the conference. Highly recommended for large conferences
144                                         due to its performance enhancements.
145                                         </para></description>
146                                 </configOption>
147                                 <configOption name="dsp_silence_threshold">
148                                         <synopsis>The number of milliseconds of detected silence necessary to trigger silence detection</synopsis>
149                                         <description><para>
150                                         The time in milliseconds of sound falling within the what
151                                         the dsp has established as baseline silence before a user
152                                         is considered be silent.  This value affects several
153                                         operations and should not be changed unless the impact
154                                         on call quality is fully understood.</para>
155                                         <para>What this value affects internally:</para>
156                                         <para>
157                                                 1. When talk detection AMI events are enabled, this value
158                                                 determines when the user has stopped talking after a
159                                                 period of talking.  If this value is set too low
160                                                 AMI events indicating the user has stopped talking
161                                                 may get falsely sent out when the user briefly pauses
162                                                 during mid sentence.
163                                         </para>
164                                         <para>
165                                                 2. The <replaceable>drop_silence</replaceable> option depends on this value to
166                                                 determine when the user's audio should begin to be
167                                                 dropped from the conference bridge after the user
168                                                 stops talking.  If this value is set too low the user's
169                                                 audio stream may sound choppy to the other participants.
170                                                 This is caused by the user transitioning constantly from
171                                                 silence to talking during mid sentence.
172                                         </para>
173                                         <para>
174                                                 The best way to approach this option is to set it slightly above
175                                                 the maximum amount of ms of silence a user may generate during
176                                                 natural speech.
177                                         </para>
178                                         <para>By default this value is 2500ms. Valid values are 1 through 2^31.</para>
179                                         </description>
180                                 </configOption>
181                                 <configOption name="dsp_talking_threshold">
182                                         <synopsis>The number of milliseconds of detected non-silence necessary to triger talk detection</synopsis>
183                                         <description><para>
184                                                 The time in milliseconds of sound above what the dsp has
185                                                 established as base line silence for a user before a user
186                                                 is considered to be talking.  This value affects several
187                                                 operations and should not be changed unless the impact on
188                                                 call quality is fully understood.</para>
189                                                 <para>
190                                                 What this value affects internally:
191                                                 </para>
192                                                 <para>
193                                                 1. Audio is only mixed out of a user's incoming audio stream
194                                                 if talking is detected.  If this value is set too
195                                                 loose the user will hear themselves briefly each
196                                                 time they begin talking until the dsp has time to
197                                                 establish that they are in fact talking.
198                                                 </para>
199                                                 <para>
200                                                 2. When talk detection AMI events are enabled, this value
201                                                 determines when talking has begun which results in
202                                                 an AMI event to fire.  If this value is set too tight
203                                                 AMI events may be falsely triggered by variants in
204                                                 room noise.
205                                                 </para>
206                                                 <para>
207                                                 3. The <replaceable>drop_silence</replaceable> option depends on this value to determine
208                                                 when the user's audio should be mixed into the bridge
209                                                 after periods of silence.  If this value is too loose
210                                                 the beginning of a user's speech will get cut off as they
211                                                 transition from silence to talking.
212                                                 </para>
213                                                 <para>By default this value is 160 ms. Valid values are 1 through 2^31</para>
214                                         </description>
215                                 </configOption>
216                                 <configOption name="jitterbuffer">
217                                         <synopsis>Place a jitter buffer on the user's audio stream before audio mixing is performed</synopsis>
218                                         <description><para>
219                                                 Enabling this option places a jitterbuffer on the user's audio stream
220                                                 before audio mixing is performed.  This is highly recommended but will
221                                                 add a slight delay to the audio.  This option is using the <literal>JITTERBUFFER</literal>
222                                                 dialplan function's default adaptive jitterbuffer.  For a more fine tuned
223                                                 jitterbuffer, disable this option and use the <literal>JITTERBUFFER</literal> dialplan function
224                                                 on the user before entering the ConfBridge application.
225                                         </para></description>
226                                 </configOption>
227                                 <configOption name="template">
228                                         <synopsis>When using the CONFBRIDGE dialplan function, use a user profile as a template for creating a new temporary profile</synopsis>
229                                 </configOption>
230                         </configObject>
231                         <configObject name="bridge_profile">
232                                 <synopsis>A named profile to apply to specific bridges.</synopsis>
233                                 <description><para>ConfBridge bridges have a profile associated with them
234                                 that determine their options. A configuration section is determined to be a
235                                 <literal>bridge_profile</literal> when the <literal>type</literal> parameter has a value
236                                 of <literal>bridge</literal>.
237                                 </para></description>
238                                 <configOption name="type">
239                                         <synopsis>Define this configuration category as a bridge profile</synopsis>
240                                         <description><para>The type parameter determines how a context in the
241                                         configuration file is interpreted.</para>
242                                         <enumlist>
243                                                 <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
244                                                 <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
245                                                 <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
246                                         </enumlist>
247                                         </description>
248                                 </configOption>
249                                 <configOption name="jitterbuffer">
250                                         <synopsis>Place a jitter buffer on the conference's audio stream</synopsis>
251                                 </configOption>
252                                 <configOption name="internal_sample_rate">
253                                         <synopsis>Set the internal native sample rate for mixing the conference</synopsis>
254                                         <description><para>
255                                                 Sets the internal native sample rate the
256                                                 conference is mixed at.  This is set to automatically
257                                                 adjust the sample rate to the best quality by default.
258                                                 Other values can be anything from 8000-192000.  If a
259                                                 sample rate is set that Asterisk does not support, the
260                                                 closest sample rate Asterisk does support to the one requested
261                                                 will be used.
262                                         </para></description>
263                                 </configOption>
264                                 <configOption name="language" default="en">
265                                         <synopsis>The language used for announcements to the conference.</synopsis>
266                                         <description><para>
267                                                 By default, announcements to a conference use English.  Which means
268                                                 the prompts played to all users within the conference will be
269                                                 English.  By changing the language of a bridge, this will change
270                                                 the language of the prompts played to all users.
271                                         </para></description>
272                                 </configOption>
273                                 <configOption name="mixing_interval">
274                                         <synopsis>Sets the internal mixing interval in milliseconds for the bridge</synopsis>
275                                         <description><para>
276                                                 Sets the internal mixing interval in milliseconds for the bridge.  This
277                                                 number reflects how tight or loose the mixing will be for the conference.
278                                                 In order to improve performance a larger mixing interval such as 40ms may
279                                                 be chosen.  Using a larger mixing interval comes at the cost of introducing
280                                                 larger amounts of delay into the bridge.  Valid values here are 10, 20, 40,
281                                                 or 80.
282                                         </para></description>
283                                 </configOption>
284                                 <configOption name="record_conference">
285                                         <synopsis>Record the conference starting with the first active user's entrance and ending with the last active user's exit</synopsis>
286                                         <description><para>
287                                                 Records the conference call starting when the first user
288                                                 enters the room, and ending when the last user exits the room.
289                                                 The default recorded filename is
290                                                 <filename>'confbridge-${name of conference bridge}-${start time}.wav'</filename>
291                                                 and the default format is 8khz slinear.  This file will be
292                                                 located in the configured monitoring directory in <filename>asterisk.conf</filename>.
293                                         </para></description>
294                                 </configOption>
295                                 <configOption name="record_file" default="confbridge-${name of conference bridge}-${start time}.wav">
296                                         <synopsis>The filename of the conference recording</synopsis>
297                                         <description><para>
298                                                 When <replaceable>record_conference</replaceable> is set to yes, the specific name of the
299                                                 record file can be set using this option.  Note that since multiple
300                                                 conferences may use the same bridge profile, this may cause issues
301                                                 depending on the configuration.  It is recommended to only use this
302                                                 option dynamically with the <literal>CONFBRIDGE()</literal> dialplan function. This
303                                                 allows the record name to be specified and a unique name to be chosen.
304                                                 By default, the record_file is stored in Asterisk's spool/monitor directory
305                                                 with a unique filename starting with the 'confbridge' prefix.
306                                         </para></description>
307                                 </configOption>
308                                 <configOption name="record_file_append" default="yes">
309                                         <synopsis>Append to record file when starting/stopping on same conference recording</synopsis>
310                                         <description><para>
311                                                 When <replaceable>record_file_append</replaceable> is set to yes, stopping and starting recording on a
312                                                 conference adds the new portion to end of current record_file. When this is
313                                                 set to no, a new <replaceable>record_file</replaceable> is generated every time you start then stop recording
314                                                 on a conference.
315                                         </para></description>
316                                 </configOption>
317                                 <configOption name="record_file_timestamp" default="yes">
318                                         <synopsis>Append the start time to the record_file name so that it is unique.</synopsis>
319                                         <description><para>
320                                                 When <replaceable>record_file_timestamp</replaceable> is set to yes, the start time is appended to
321                                                 <replaceable>record_file</replaceable> so that the filename is unique. This allows you to specify
322                                                 a <replaceable>record_file</replaceable> but not overwrite existing recordings.
323                                         </para></description>
324                                 </configOption>
325                                 <configOption name="record_options" default="">
326                                         <synopsis>Pass additional options to MixMonitor when recording</synopsis>
327                                         <description><para>
328                                                 Pass additional options to MixMonitor when <replaceable>record_conference</replaceable> is set to yes.
329                                                 See <literal>MixMonitor</literal> for available options.
330                                         </para></description>
331                                 </configOption>
332                                 <configOption name="record_command" default="">
333                                         <synopsis>Execute a command after recording ends</synopsis>
334                                         <description><para>
335                                                 Executes the specified command when recording ends. Any strings matching <literal>^{X}</literal> will be
336                                                 unescaped to <variable>X</variable>. All variables will be evaluated at the time ConfBridge is called.
337                                         </para></description>
338                                 </configOption>
339                                 <configOption name="video_mode">
340                                         <synopsis>Sets how confbridge handles video distribution to the conference participants</synopsis>
341                                         <description><para>
342                                                 Sets how confbridge handles video distribution to the conference participants.
343                                                 Note that participants wanting to view and be the source of a video feed
344                                                 <emphasis>MUST</emphasis> be sharing the same video codec.  Also, using video in conjunction with
345                                                 with the jitterbuffer currently results in the audio being slightly out of sync
346                                                 with the video.  This is a result of the jitterbuffer only working on the audio
347                                                 stream.  It is recommended to disable the jitterbuffer when video is used.</para>
348                                                 <enumlist>
349                                                         <enum name="none">
350                                                                 <para>No video sources are set by default in the conference. It is still
351                                                                 possible for a user to be set as a video source via AMI or DTMF action
352                                                                 at any time.</para>
353                                                         </enum>
354                                                         <enum name="follow_talker">
355                                                                 <para>The video feed will follow whoever is talking and providing video.</para>
356                                                         </enum>
357                                                         <enum name="last_marked">
358                                                                 <para>The last marked user to join the conference with video capabilities
359                                                                 will be the single source of video distributed to all participants.
360                                                                 If multiple marked users are capable of video, the last one to join
361                                                                 is always the source, when that user leaves it goes to the one who
362                                                                 joined before them.</para>
363                                                         </enum>
364                                                         <enum name="first_marked">
365                                                                 <para>The first marked user to join the conference with video capabilities
366                                                                 is the single source of video distribution among all participants. If
367                                                                 that user leaves, the marked user to join after them becomes the source.</para>
368                                                         </enum>
369                                                 </enumlist>
370                                         </description>
371                                 </configOption>
372                                 <configOption name="max_members">
373                                         <synopsis>Limit the maximum number of participants for a single conference</synopsis>
374                                         <description><para>
375                                                 This option limits the number of participants for a single
376                                                 conference to a specific number.  By default conferences
377                                                 have no participant limit. After the limit is reached, the
378                                                 conference will be locked until someone leaves.  Note however
379                                                 that an Admin user will always be alowed to join the conference
380                                                 regardless if this limit is reached or not.
381                                         </para></description>
382                                 </configOption>
383                                 <configOption name="^sound_">
384                                         <synopsis>Override the various conference bridge sound files</synopsis>
385                                         <description><para>
386                                                 All sounds in the conference are customizable using the bridge profile options below.
387                                                 Simply state the option followed by the filename or full path of the filename after
388                                                 the option.  Example: <literal>sound_had_joined=conf-hasjoin</literal>  This will play the <literal>conf-hasjoin</literal>
389                                                 sound file found in the sounds directory when announcing someone's name is joining the
390                                                 conference.</para>
391                                                 <enumlist>
392                                                         <enum name="sound_join"><para>The sound played to everyone when someone enters the conference.</para></enum>
393                                                         <enum name="sound_leave"><para>The sound played to everyone when someone leaves the conference.</para></enum>
394                                                         <enum name="sound_has_joined"><para>The sound played before announcing someone's name has
395                                                                                 joined the conference. This is used for user intros.
396                                                                                 Example <literal>"_____ has joined the conference"</literal></para></enum>
397                                                         <enum name="sound_has_left"><para>The sound played when announcing someone's name has
398                                                                                 left the conference. This is used for user intros.
399                                                                                 Example <literal>"_____ has left the conference"</literal></para></enum>
400                                                         <enum name="sound_kicked"><para>The sound played to a user who has been kicked from the conference.</para></enum>
401                                                         <enum name="sound_muted"><para>The sound played when the mute option it toggled on.</para></enum>
402                                                         <enum name="sound_unmuted"><para>The sound played when the mute option it toggled off.</para></enum>
403                                                         <enum name="sound_only_person"><para>The sound played when the user is the only person in the conference.</para></enum>
404                                                         <enum name="sound_only_one"><para>The sound played to a user when there is only one other
405                                                                                 person is in the conference.</para></enum>
406                                                         <enum name="sound_there_are"><para>The sound played when announcing how many users there
407                                                                                 are in a conference.</para></enum>
408                                                         <enum name="sound_other_in_party"><para>This file is used in conjunction with <literal>sound_there_are</literal>
409                                                                                 when announcing how many users there are in the conference.
410                                                                                 The sounds are stringed together like this.
411                                                                                 <literal>"sound_there_are" ${number of participants} "sound_other_in_party"</literal></para></enum>
412                                                         <enum name="sound_place_into_conference"><para>The sound played when someone is placed into the conference
413                                                                                 after waiting for a marked user.</para></enum>
414                                                         <enum name="sound_wait_for_leader"><para>The sound played when a user is placed into a conference that
415                                                                                 can not start until a marked user enters.</para></enum>
416                                                         <enum name="sound_leader_has_left"><para>The sound played when the last marked user leaves the conference.</para></enum>
417                                                         <enum name="sound_get_pin"><para>The sound played when prompting for a conference pin number.</para></enum>
418                                                         <enum name="sound_invalid_pin"><para>The sound played when an invalid pin is entered too many times.</para></enum>
419                                                         <enum name="sound_locked"><para>The sound played to a user trying to join a locked conference.</para></enum>
420                                                         <enum name="sound_locked_now"><para>The sound played to an admin after toggling the conference to locked mode.</para></enum>
421                                                         <enum name="sound_unlocked_now"><para>The sound played to an admin after toggling the conference to unlocked mode.</para></enum>
422                                                         <enum name="sound_error_menu"><para>The sound played when an invalid menu option is entered.</para></enum>
423                                                 </enumlist>
424                                         </description>
425                                 </configOption>
426                                 <configOption name="template">
427                                         <synopsis>When using the CONFBRIDGE dialplan function, use a bridge profile as a template for creating a new temporary profile</synopsis>
428                                 </configOption>
429                         </configObject>
430                         <configObject name="menu">
431                                 <synopsis>A conference user menu</synopsis>
432                                 <description>
433                                         <para>Conference users, as defined by a <replaceable>conf_user</replaceable>,
434                                         can have a DTMF menu assigned to their profile when they enter the
435                                         <literal>ConfBridge</literal> application.</para>
436                                 </description>
437                                 <configOption name="type">
438                                         <synopsis>Define this configuration category as a menu</synopsis>
439                                         <description><para>The type parameter determines how a context in the
440                                         configuration file is interpreted.</para>
441                                         <enumlist>
442                                                 <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
443                                                 <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
444                                                 <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
445                                         </enumlist>
446                                         </description>
447                                 </configOption>
448                                 <configOption name="template">
449                                         <synopsis>When using the CONFBRIDGE dialplan function, use a menu profile as a template for creating a new temporary profile</synopsis>
450                                 </configOption>
451                                 <configOption name="^[0-9A-D*#]+$">
452                                         <synopsis>DTMF sequences to assign various confbridge actions to</synopsis>
453                                         <description>
454                                         <para>The ConfBridge application also has the ability to apply custom DTMF menus to
455                                         each channel using the application.  Like the User and Bridge profiles a menu
456                                         is passed in to ConfBridge as an argument in the dialplan.</para>
457                                         <para>Below is a list of menu actions that can be assigned to a DTMF sequence.</para>
458                                         <note><para>
459                                                 To have the first DTMF digit in a sequence be the '#' character, you need to
460                                                 escape it.  If it is not escaped then normal config file processing will
461                                                 think it is a directive like #include.  For example: The mute setting is
462                                                 toggled when <literal>#1</literal> is pressed.</para>
463                                                 <para><literal>\#1=toggle_mute</literal></para>
464                                         </note>
465                                         <note><para>
466                                         A single DTMF sequence can have multiple actions associated with it. This is
467                                         accomplished by stringing the actions together and using a <literal>,</literal> as the
468                                         delimiter.  Example:  Both listening and talking volume is reset when <literal>5</literal> is
469                                         pressed.  <literal>5=reset_talking_volume, reset_listening_volume</literal></para></note>
470                                         <enumlist>
471                                                 <enum name="playback(filename&amp;filename2&amp;...)"><para>
472                                                         <literal>playback</literal> will play back an audio file to a channel
473                                                         and then immediately return to the conference.
474                                                         This file can not be interupted by DTMF.
475                                                         Multiple files can be chained together using the
476                                                         <literal>&amp;</literal> character.</para></enum>
477                                                 <enum name="playback_and_continue(filename&amp;filename2&amp;...)"><para>
478                                                         <literal>playback_and_continue</literal> will
479                                                         play back a prompt while continuing to
480                                                         collect the dtmf sequence.  This is useful
481                                                         when using a menu prompt that describes all
482                                                         the menu options.  Note however that any DTMF
483                                                         during this action will terminate the prompts
484                                                         playback.  Prompt files can be chained together
485                                                         using the <literal>&amp;</literal> character as a delimiter.</para></enum>
486                                                 <enum name="toggle_mute"><para>
487                                                         Toggle turning on and off mute.  Mute will make the user silent
488                                                         to everyone else, but the user will still be able to listen in.
489                                                         </para></enum>
490                                                 <enum name="no_op"><para>
491                                                         This action does nothing (No Operation). Its only real purpose exists for
492                                                         being able to reserve a sequence in the config as a menu exit sequence.</para></enum>
493                                                 <enum name="decrease_listening_volume"><para>
494                                                         Decreases the channel's listening volume.</para></enum>
495                                                 <enum name="increase_listening_volume"><para>
496                                                         Increases the channel's listening volume.</para></enum>
497                                                 <enum name="reset_listening_volume"><para>
498                                                         Reset channel's listening volume to default level.</para></enum>
499                                                 <enum name="decrease_talking_volume"><para>
500                                                         Decreases the channel's talking volume.</para></enum>
501                                                 <enum name="increase_talking_volume"><para>
502                                                         Increases the channel's talking volume.</para></enum>
503                                                 <enum name="reset_talking_volume"><para>
504                                                         Reset channel's talking volume to default level.</para></enum>
505                                                 <enum name="dialplan_exec(context,exten,priority)"><para>
506                                                         The <literal>dialplan_exec</literal> action allows a user
507                                                         to escape from the conference and execute
508                                                         commands in the dialplan.  Once the dialplan
509                                                         exits the user will be put back into the
510                                                         conference.  The possibilities are endless!</para></enum>
511                                                 <enum name="leave_conference"><para>
512                                                         This action allows a user to exit the conference and continue
513                                                         execution in the dialplan.</para></enum>
514                                                 <enum name="admin_kick_last"><para>
515                                                         This action allows an Admin to kick the last participant from the
516                                                         conference. This action will only work for admins which allows
517                                                         a single menu to be used for both users and admins.</para></enum>
518                                                 <enum name="admin_toggle_conference_lock"><para>
519                                                         This action allows an Admin to toggle locking and
520                                                         unlocking the conference.  Non admins can not use
521                                                         this action even if it is in their menu.</para></enum>
522                                                 <enum name="set_as_single_video_src"><para>
523                                                         This action allows any user to set themselves as the
524                                                         single video source distributed to all participants.
525                                                         This will make the video feed stick to them regardless
526                                                         of what the <literal>video_mode</literal> is set to.</para></enum>
527                                                 <enum name="release_as_single_video_src"><para>
528                                                         This action allows a user to release themselves as
529                                                         the video source.  If <literal>video_mode</literal> is not set to <literal>none</literal>
530                                                         this action will result in the conference returning to
531                                                         whatever video mode the bridge profile is using.</para>
532                                                         <para>Note that this action will have no effect if the user
533                                                         is not currently the video source.  Also, the user is
534                                                         not guaranteed by using this action that they will not
535                                                         become the video source again.  The bridge will return
536                                                         to whatever operation the <literal>video_mode</literal> option is set to
537                                                         upon release of the video src.</para></enum>
538                                                 <enum name="admin_toggle_mute_participants"><para>
539                                                         This action allows an administrator to toggle the mute
540                                                         state for all non-admins within a conference.  All
541                                                         admin users are unaffected by this option.  Note that all
542                                                         users, regardless of their admin status, are notified
543                                                         that the conference is muted.</para></enum>
544                                                 <enum name="participant_count"><para>
545                                                         This action plays back the number of participants currently
546                                                         in a conference</para></enum>
547                                                 </enumlist>
548                                         </description>
549                                 </configOption>
550                         </configObject>
551                 </configFile>
552         </configInfo>
553 ***/
554
555 struct confbridge_cfg {
556         struct ao2_container *bridge_profiles;
557         struct ao2_container *user_profiles;
558         struct ao2_container *menus;
559 };
560
561 static int verify_default_profiles(void);
562 static void *bridge_profile_alloc(const char *category);
563 static void *bridge_profile_find(struct ao2_container *container, const char *category);
564 static struct bridge_profile_sounds *bridge_profile_sounds_alloc(void);
565
566 static void bridge_profile_destructor(void *obj)
567 {
568         struct bridge_profile *b_profile = obj;
569         ao2_cleanup(b_profile->sounds);
570 }
571
572 static void *bridge_profile_alloc(const char *category)
573 {
574         struct bridge_profile *b_profile;
575
576         if (!(b_profile = ao2_alloc(sizeof(*b_profile), bridge_profile_destructor))) {
577                 return NULL;
578         }
579
580         if (!(b_profile->sounds = bridge_profile_sounds_alloc())) {
581                 ao2_ref(b_profile, -1);
582                 return NULL;
583         }
584
585         ast_copy_string(b_profile->name, category, sizeof(b_profile->name));
586
587         return b_profile;
588 }
589
590 static void *bridge_profile_find(struct ao2_container *container, const char *category)
591 {
592         return ao2_find(container, category, OBJ_KEY);
593 }
594
595 static struct aco_type bridge_type = {
596         .type = ACO_ITEM,
597         .name = "bridge_profile",
598         .category_match = ACO_BLACKLIST,
599         .category = "^general$",
600         .matchfield = "type",
601         .matchvalue = "bridge",
602         .item_alloc = bridge_profile_alloc,
603         .item_find = bridge_profile_find,
604         .item_offset = offsetof(struct confbridge_cfg, bridge_profiles),
605 };
606
607 static void *user_profile_alloc(const char *category);
608 static void *user_profile_find(struct ao2_container *container, const char *category);
609 static void user_profile_destructor(void *obj)
610 {
611         return;
612 }
613
614 static void *user_profile_alloc(const char *category)
615 {
616         struct user_profile *u_profile;
617
618         if (!(u_profile = ao2_alloc(sizeof(*u_profile), user_profile_destructor))) {
619                 return NULL;
620         }
621
622         ast_copy_string(u_profile->name, category, sizeof(u_profile->name));
623
624         return u_profile;
625 }
626
627 static void *user_profile_find(struct ao2_container *container, const char *category)
628 {
629         return ao2_find(container, category, OBJ_KEY);
630 }
631
632 static struct aco_type user_type = {
633         .type = ACO_ITEM,
634         .name  = "user_profile",
635         .category_match = ACO_BLACKLIST,
636         .category = "^general$",
637         .matchfield = "type",
638         .matchvalue = "user",
639         .item_alloc = user_profile_alloc,
640         .item_find = user_profile_find,
641         .item_offset = offsetof(struct confbridge_cfg, user_profiles),
642 };
643
644 static void *menu_alloc(const char *category);
645 static void *menu_find(struct ao2_container *container, const char *category);
646 static void menu_destructor(void *obj);
647
648 static void *menu_alloc(const char *category)
649 {
650         struct conf_menu *menu;
651         if (!(menu = ao2_alloc(sizeof(*menu), menu_destructor))) {
652                 return NULL;
653         }
654         ast_copy_string(menu->name, category, sizeof(menu->name));
655         return menu;
656 }
657
658 static void *menu_find(struct ao2_container *container, const char *category)
659 {
660         return ao2_find(container, category, OBJ_KEY);
661 }
662
663 static struct aco_type menu_type = {
664         .type = ACO_ITEM,
665         .name = "menu",
666         .category_match = ACO_BLACKLIST,
667         .category = "^general$",
668         .matchfield = "type",
669         .matchvalue = "menu",
670         .item_alloc = menu_alloc,
671         .item_find = menu_find,
672         .item_offset = offsetof(struct confbridge_cfg, menus),
673 };
674
675 /* Used to pass to aco_option_register */
676 static struct aco_type *bridge_types[] = ACO_TYPES(&bridge_type);
677 static struct aco_type *menu_types[] = ACO_TYPES(&menu_type);
678 static struct aco_type *user_types[] = ACO_TYPES(&user_type);
679
680 /* The general category is reserved, but unused */
681 static struct aco_type general_type = {
682         .type = ACO_GLOBAL,
683         .name = "global",
684         .category_match = ACO_WHITELIST,
685         .category = "^general$",
686 };
687
688 static struct aco_file confbridge_conf = {
689         .filename = "confbridge.conf",
690         .types = ACO_TYPES(&bridge_type, &user_type, &menu_type, &general_type),
691 };
692
693 static AO2_GLOBAL_OBJ_STATIC(cfg_handle);
694
695 static void *confbridge_cfg_alloc(void);
696
697 CONFIG_INFO_STANDARD(cfg_info, cfg_handle, confbridge_cfg_alloc,
698         .files = ACO_FILES(&confbridge_conf),
699         .pre_apply_config = verify_default_profiles,
700 );
701
702 /*! bridge profile container functions */
703 static int bridge_cmp_cb(void *obj, void *arg, int flags)
704 {
705         const struct bridge_profile *left = obj;
706         const struct bridge_profile *right = arg;
707         const char *right_name = arg;
708         int cmp;
709
710         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
711         default:
712         case OBJ_POINTER:
713                 right_name = right->name;
714                 /* Fall through */
715         case OBJ_KEY:
716                 cmp = strcasecmp(left->name, right_name);
717                 break;
718         case OBJ_PARTIAL_KEY:
719                 cmp = strncasecmp(left->name, right_name, strlen(right_name));
720                 break;
721         }
722         return cmp ? 0 : CMP_MATCH;
723 }
724
725 static int bridge_hash_cb(const void *obj, const int flags)
726 {
727         const struct bridge_profile *b_profile = obj;
728         const char *name = obj;
729         int hash;
730
731         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
732         default:
733         case OBJ_POINTER:
734                 name = b_profile->name;
735                 /* Fall through */
736         case OBJ_KEY:
737                 hash = ast_str_case_hash(name);
738                 break;
739         case OBJ_PARTIAL_KEY:
740                 /* Should never happen in hash callback. */
741                 ast_assert(0);
742                 hash = 0;
743                 break;
744         }
745         return hash;
746 }
747
748 /*! menu container functions */
749 static int menu_cmp_cb(void *obj, void *arg, int flags)
750 {
751         const struct conf_menu *left = obj;
752         const struct conf_menu *right = arg;
753         const char *right_name = arg;
754         int cmp;
755
756         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
757         default:
758         case OBJ_POINTER:
759                 right_name = right->name;
760                 /* Fall through */
761         case OBJ_KEY:
762                 cmp = strcasecmp(left->name, right_name);
763                 break;
764         case OBJ_PARTIAL_KEY:
765                 cmp = strncasecmp(left->name, right_name, strlen(right_name));
766                 break;
767         }
768         return cmp ? 0 : CMP_MATCH;
769 }
770
771 static int menu_hash_cb(const void *obj, const int flags)
772 {
773         const struct conf_menu *menu = obj;
774         const char *name = obj;
775         int hash;
776
777         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
778         default:
779         case OBJ_POINTER:
780                 name = menu->name;
781                 /* Fall through */
782         case OBJ_KEY:
783                 hash = ast_str_case_hash(name);
784                 break;
785         case OBJ_PARTIAL_KEY:
786                 /* Should never happen in hash callback. */
787                 ast_assert(0);
788                 hash = 0;
789                 break;
790         }
791         return hash;
792 }
793
794 static void menu_destructor(void *obj)
795 {
796         struct conf_menu *menu = obj;
797         struct conf_menu_entry *entry = NULL;
798
799         while ((entry = AST_LIST_REMOVE_HEAD(&menu->entries, entry))) {
800                 conf_menu_entry_destroy(entry);
801                 ast_free(entry);
802         }
803 }
804
805 /*! User profile container functions */
806 static int user_cmp_cb(void *obj, void *arg, int flags)
807 {
808         const struct user_profile *left = obj;
809         const struct user_profile *right = arg;
810         const char *right_name = arg;
811         int cmp;
812
813         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
814         default:
815         case OBJ_POINTER:
816                 right_name = right->name;
817                 /* Fall through */
818         case OBJ_KEY:
819                 cmp = strcasecmp(left->name, right_name);
820                 break;
821         case OBJ_PARTIAL_KEY:
822                 cmp = strncasecmp(left->name, right_name, strlen(right_name));
823                 break;
824         }
825         return cmp ? 0 : CMP_MATCH;
826 }
827
828 static int user_hash_cb(const void *obj, const int flags)
829 {
830         const struct user_profile *u_profile = obj;
831         const char *name = obj;
832         int hash;
833
834         switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
835         default:
836         case OBJ_POINTER:
837                 name = u_profile->name;
838                 /* Fall through */
839         case OBJ_KEY:
840                 hash = ast_str_case_hash(name);
841                 break;
842         case OBJ_PARTIAL_KEY:
843                 /* Should never happen in hash callback. */
844                 ast_assert(0);
845                 hash = 0;
846                 break;
847         }
848         return hash;
849 }
850
851 /*! Bridge Profile Sounds functions */
852 static void bridge_profile_sounds_destroy_cb(void *obj)
853 {
854         struct bridge_profile_sounds *sounds = obj;
855         ast_string_field_free_memory(sounds);
856 }
857
858 static struct bridge_profile_sounds *bridge_profile_sounds_alloc(void)
859 {
860         struct bridge_profile_sounds *sounds = ao2_alloc(sizeof(*sounds), bridge_profile_sounds_destroy_cb);
861
862         if (!sounds) {
863                 return NULL;
864         }
865         if (ast_string_field_init(sounds, 512)) {
866                 ao2_ref(sounds, -1);
867                 return NULL;
868         }
869
870         return sounds;
871 }
872
873 static int set_sound(const char *sound_name, const char *sound_file, struct bridge_profile *b_profile)
874 {
875         struct bridge_profile_sounds *sounds = b_profile->sounds;
876         if (ast_strlen_zero(sound_file)) {
877                 return -1;
878         }
879
880         if (!strcasecmp(sound_name, "sound_only_person")) {
881                 ast_string_field_set(sounds, onlyperson, sound_file);
882         } else if (!strcasecmp(sound_name, "sound_only_one")) {
883                 ast_string_field_set(sounds, onlyone, sound_file);
884         } else if (!strcasecmp(sound_name, "sound_has_joined")) {
885                 ast_string_field_set(sounds, hasjoin, sound_file);
886         } else if (!strcasecmp(sound_name, "sound_has_left")) {
887                 ast_string_field_set(sounds, hasleft, sound_file);
888         } else if (!strcasecmp(sound_name, "sound_kicked")) {
889                 ast_string_field_set(sounds, kicked, sound_file);
890         } else if (!strcasecmp(sound_name, "sound_muted")) {
891                 ast_string_field_set(sounds, muted, sound_file);
892         } else if (!strcasecmp(sound_name, "sound_unmuted")) {
893                 ast_string_field_set(sounds, unmuted, sound_file);
894         } else if (!strcasecmp(sound_name, "sound_there_are")) {
895                 ast_string_field_set(sounds, thereare, sound_file);
896         } else if (!strcasecmp(sound_name, "sound_other_in_party")) {
897                 ast_string_field_set(sounds, otherinparty, sound_file);
898         } else if (!strcasecmp(sound_name, "sound_place_into_conference")) {
899                 static int deprecation_warning = 1;
900                 if (deprecation_warning) {
901                         ast_log(LOG_WARNING, "sound_place_into_conference is deprecated"
902                                 " and unused. Use sound_begin for similar functionality.");
903                         deprecation_warning = 0;
904                 }
905                 ast_string_field_set(sounds, placeintoconf, sound_file);
906         } else if (!strcasecmp(sound_name, "sound_wait_for_leader")) {
907                 ast_string_field_set(sounds, waitforleader, sound_file);
908         } else if (!strcasecmp(sound_name, "sound_leader_has_left")) {
909                 ast_string_field_set(sounds, leaderhasleft, sound_file);
910         } else if (!strcasecmp(sound_name, "sound_get_pin")) {
911                 ast_string_field_set(sounds, getpin, sound_file);
912         } else if (!strcasecmp(sound_name, "sound_invalid_pin")) {
913                 ast_string_field_set(sounds, invalidpin, sound_file);
914         } else if (!strcasecmp(sound_name, "sound_locked")) {
915                 ast_string_field_set(sounds, locked, sound_file);
916         } else if (!strcasecmp(sound_name, "sound_unlocked_now")) {
917                 ast_string_field_set(sounds, unlockednow, sound_file);
918         } else if (!strcasecmp(sound_name, "sound_locked_now")) {
919                 ast_string_field_set(sounds, lockednow, sound_file);
920         } else if (!strcasecmp(sound_name, "sound_error_menu")) {
921                 ast_string_field_set(sounds, errormenu, sound_file);
922         } else if (!strcasecmp(sound_name, "sound_join")) {
923                 ast_string_field_set(sounds, join, sound_file);
924         } else if (!strcasecmp(sound_name, "sound_leave")) {
925                 ast_string_field_set(sounds, leave, sound_file);
926         } else if (!strcasecmp(sound_name, "sound_participants_muted")) {
927                 ast_string_field_set(sounds, participantsmuted, sound_file);
928         } else if (!strcasecmp(sound_name, "sound_participants_unmuted")) {
929                 ast_string_field_set(sounds, participantsunmuted, sound_file);
930         } else if (!strcasecmp(sound_name, "sound_begin")) {
931                 ast_string_field_set(sounds, begin, sound_file);
932         } else {
933                 return -1;
934         }
935
936         return 0;
937 }
938
939 /*! CONFBRIDGE dialplan function functions and channel datastore. */
940 struct func_confbridge_data {
941         struct bridge_profile b_profile;
942         struct user_profile u_profile;
943         struct conf_menu *menu;
944         unsigned int b_usable:1; /*!< Tells if bridge profile is usable or not */
945         unsigned int u_usable:1; /*!< Tells if user profile is usable or not */
946         unsigned int m_usable:1; /*!< Tells if menu profile is usable or not */
947 };
948
949 static void func_confbridge_data_destructor(struct func_confbridge_data *b_data)
950 {
951         conf_bridge_profile_destroy(&b_data->b_profile);
952         ao2_cleanup(b_data->menu);
953         ast_free(b_data);
954 }
955
956 static void func_confbridge_destroy_cb(void *data)
957 {
958         struct func_confbridge_data *b_data = data;
959         func_confbridge_data_destructor(b_data);
960 };
961
962 static const struct ast_datastore_info confbridge_datastore = {
963         .type = "confbridge",
964         .destroy = func_confbridge_destroy_cb
965 };
966 int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)
967 {
968         struct ast_datastore *datastore;
969         struct func_confbridge_data *b_data;
970         char *parse;
971         struct ast_variable tmpvar = { 0, };
972         AST_DECLARE_APP_ARGS(args,
973                 AST_APP_ARG(type);
974                 AST_APP_ARG(option);
975         );
976
977         if (!chan) {
978                 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
979                 return -1;
980         }
981
982         /* parse all the required arguments and make sure they exist. */
983         if (ast_strlen_zero(data)) {
984                 return -1;
985         }
986         parse = ast_strdupa(data);
987         AST_STANDARD_APP_ARGS(args, parse);
988         if (ast_strlen_zero(args.type) || ast_strlen_zero(args.option)) {
989                 return -1;
990         }
991
992         ast_channel_lock(chan);
993         datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
994         if (!datastore) {
995                 datastore = ast_datastore_alloc(&confbridge_datastore, NULL);
996                 if (!datastore) {
997                         ast_channel_unlock(chan);
998                         return 0;
999                 }
1000                 b_data = ast_calloc(1, sizeof(*b_data));
1001                 if (!b_data) {
1002                         ast_channel_unlock(chan);
1003                         ast_datastore_free(datastore);
1004                         return 0;
1005                 }
1006                 datastore->data = b_data;
1007                 b_data->b_profile.sounds = bridge_profile_sounds_alloc();
1008                 if (!b_data->b_profile.sounds) {
1009                         ast_channel_unlock(chan);
1010                         ast_datastore_free(datastore);
1011                         return 0;
1012                 }
1013                 if (!(b_data->menu = menu_alloc("dialplan"))) {
1014                         ast_channel_unlock(chan);
1015                         ast_datastore_free(datastore);
1016                         return 0;
1017                 }
1018                 ast_channel_datastore_add(chan, datastore);
1019         } else {
1020                 b_data = datastore->data;
1021         }
1022         ast_channel_unlock(chan);
1023
1024         /* SET(CONFBRIDGE(type,option)=value) */
1025         if (!value) {
1026                 value = "";
1027         }
1028         tmpvar.name = args.option;
1029         tmpvar.value = value;
1030         tmpvar.file = "CONFBRIDGE";
1031         if (!strcasecmp(args.type, "bridge")) {
1032                 if (!strcasecmp(args.option, "clear")) {
1033                         b_data->b_usable = 0;
1034                         conf_bridge_profile_destroy(&b_data->b_profile);
1035                         memset(&b_data->b_profile, 0, sizeof(b_data->b_profile)) ;
1036                         if (!(b_data->b_profile.sounds = bridge_profile_sounds_alloc())) {
1037                                 /* If this reallocation fails, the datastore has become unusable and must be destroyed. */
1038                                 ast_channel_lock(chan);
1039                                 ast_channel_datastore_remove(chan, datastore);
1040                                 ast_channel_unlock(chan);
1041                                 ast_datastore_free(datastore);
1042                         }
1043                         return 0;
1044                 } else if (!aco_process_var(&bridge_type, "dialplan", &tmpvar, &b_data->b_profile)) {
1045                         b_data->b_usable = 1;
1046                         return 0;
1047                 }
1048         } else if (!strcasecmp(args.type, "user")) {
1049                 if (!strcasecmp(args.option, "clear")) {
1050                         b_data->u_usable = 0;
1051                         user_profile_destructor(&b_data->u_profile);
1052                         memset(&b_data->u_profile, 0, sizeof(b_data->u_profile));
1053                         return 0;
1054                 } else if (!aco_process_var(&user_type, "dialplan", &tmpvar, &b_data->u_profile)) {
1055                         b_data->u_usable = 1;
1056                         return 0;
1057                 }
1058         } else if (!strcasecmp(args.type, "menu")) {
1059                 if (!strcasecmp(args.option, "clear")) {
1060                         b_data->m_usable = 0;
1061                         ao2_cleanup(b_data->menu);
1062                         if (!(b_data->menu = menu_alloc("dialplan"))) {
1063                                 /* If this reallocation fails, the datastore has become unusable and must be destroyed */
1064                                 ast_channel_lock(chan);
1065                                 ast_channel_datastore_remove(chan, datastore);
1066                                 ast_channel_unlock(chan);
1067                                 ast_datastore_free(datastore);
1068                         }
1069                         return 0;
1070                 } else if (!aco_process_var(&menu_type, "dialplan", &tmpvar, b_data->menu)) {
1071                         b_data->m_usable = 1;
1072                         return 0;
1073                 }
1074         }
1075
1076         ast_log(LOG_WARNING, "%s(%s,%s) cannot be set to '%s'. Invalid type, option, or value.\n",
1077                 cmd, args.type, args.option, value);
1078         return -1;
1079 }
1080
1081 static int add_action_to_menu_entry(struct conf_menu_entry *menu_entry, enum conf_menu_action_id id, char *databuf)
1082 {
1083         struct conf_menu_action *menu_action = ast_calloc(1, sizeof(*menu_action));
1084
1085         if (!menu_action) {
1086                 return -1;
1087         }
1088         menu_action->id = id;
1089
1090         switch (id) {
1091         case MENU_ACTION_NOOP:
1092         case MENU_ACTION_TOGGLE_MUTE:
1093         case MENU_ACTION_INCREASE_LISTENING:
1094         case MENU_ACTION_DECREASE_LISTENING:
1095         case MENU_ACTION_INCREASE_TALKING:
1096         case MENU_ACTION_DECREASE_TALKING:
1097         case MENU_ACTION_RESET_LISTENING:
1098         case MENU_ACTION_RESET_TALKING:
1099         case MENU_ACTION_ADMIN_TOGGLE_LOCK:
1100         case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
1101         case MENU_ACTION_PARTICIPANT_COUNT:
1102         case MENU_ACTION_ADMIN_KICK_LAST:
1103         case MENU_ACTION_LEAVE:
1104         case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
1105         case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
1106                 break;
1107         case MENU_ACTION_PLAYBACK:
1108         case MENU_ACTION_PLAYBACK_AND_CONTINUE:
1109                 if (!(ast_strlen_zero(databuf))) {
1110                         ast_copy_string(menu_action->data.playback_file, databuf, sizeof(menu_action->data.playback_file));
1111                 } else {
1112                         ast_free(menu_action);
1113                         return -1;
1114                 }
1115                 break;
1116         case MENU_ACTION_DIALPLAN_EXEC:
1117                 if (!(ast_strlen_zero(databuf))) {
1118                         AST_DECLARE_APP_ARGS(args,
1119                                 AST_APP_ARG(context);
1120                                 AST_APP_ARG(exten);
1121                                 AST_APP_ARG(priority);
1122                         );
1123                         AST_STANDARD_APP_ARGS(args, databuf);
1124                         if (!ast_strlen_zero(args.context)) {
1125                                 ast_copy_string(menu_action->data.dialplan_args.context,
1126                                         args.context,
1127                                         sizeof(menu_action->data.dialplan_args.context));
1128                         }
1129                         if (!ast_strlen_zero(args.exten)) {
1130                                 ast_copy_string(menu_action->data.dialplan_args.exten,
1131                                         args.exten,
1132                                         sizeof(menu_action->data.dialplan_args.exten));
1133                         }
1134                         menu_action->data.dialplan_args.priority = 1; /* 1 by default */
1135                         if (!ast_strlen_zero(args.priority) &&
1136                                 (sscanf(args.priority, "%30d", &menu_action->data.dialplan_args.priority) != 1)) {
1137                                 /* invalid priority */
1138                                 ast_free(menu_action);
1139                                 return -1;
1140                         }
1141                 } else {
1142                         ast_free(menu_action);
1143                         return -1;
1144                 }
1145         };
1146
1147         AST_LIST_INSERT_TAIL(&menu_entry->actions, menu_action, action);
1148
1149         return 0;
1150 }
1151
1152 static int add_menu_entry(struct conf_menu *menu, const char *dtmf, const char *action_names)
1153 {
1154         struct conf_menu_entry *menu_entry = NULL, *cur = NULL;
1155         int res = 0;
1156         char *tmp_action_names = ast_strdupa(action_names);
1157         char *action = NULL;
1158         char *action_args;
1159         char *tmp;
1160         char buf[PATH_MAX];
1161         char *delimiter = ",";
1162
1163         if (!(menu_entry = ast_calloc(1, sizeof(*menu_entry)))) {
1164                 return -1;
1165         }
1166
1167         for (;;) {
1168                 char *comma;
1169                 char *startbrace;
1170                 char *endbrace;
1171                 unsigned int action_len;
1172
1173                 if (ast_strlen_zero(tmp_action_names)) {
1174                         break;
1175                 }
1176                 startbrace = strchr(tmp_action_names, '(');
1177                 endbrace = strchr(tmp_action_names, ')');
1178                 comma = strchr(tmp_action_names, ',');
1179
1180                 /* If the next action has brackets with comma delimited arguments in it,
1181                  * make the delimeter ')' instead of a comma to preserve the argments */
1182                 if (startbrace && endbrace && comma && (comma > startbrace && comma < endbrace)) {
1183                         delimiter = ")";
1184                 } else {
1185                         delimiter = ",";
1186                 }
1187
1188                 if (!(action = strsep(&tmp_action_names, delimiter))) {
1189                         break;
1190                 }
1191
1192                 action = ast_strip(action);
1193                 if (ast_strlen_zero(action)) {
1194                         continue;
1195                 }
1196
1197                 action_len = strlen(action);
1198                 ast_copy_string(menu_entry->dtmf, dtmf, sizeof(menu_entry->dtmf));
1199                 if (!strcasecmp(action, "toggle_mute")) {
1200                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_TOGGLE_MUTE, NULL);
1201                 } else if (!strcasecmp(action, "no_op")) {
1202                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_NOOP, NULL);
1203                 } else if (!strcasecmp(action, "increase_listening_volume")) {
1204                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_INCREASE_LISTENING, NULL);
1205                 } else if (!strcasecmp(action, "decrease_listening_volume")) {
1206                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DECREASE_LISTENING, NULL);
1207                 } else if (!strcasecmp(action, "increase_talking_volume")) {
1208                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_INCREASE_TALKING, NULL);
1209                 } else if (!strcasecmp(action, "reset_listening_volume")) {
1210                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RESET_LISTENING, NULL);
1211                 } else if (!strcasecmp(action, "reset_talking_volume")) {
1212                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RESET_TALKING, NULL);
1213                 } else if (!strcasecmp(action, "decrease_talking_volume")) {
1214                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DECREASE_TALKING, NULL);
1215                 } else if (!strcasecmp(action, "admin_toggle_conference_lock")) {
1216                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_TOGGLE_LOCK, NULL);
1217                 } else if (!strcasecmp(action, "admin_toggle_mute_participants")) {
1218                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS, NULL);
1219                 } else if (!strcasecmp(action, "participant_count")) {
1220                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PARTICIPANT_COUNT, NULL);
1221                 } else if (!strcasecmp(action, "admin_kick_last")) {
1222                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_KICK_LAST, NULL);
1223                 } else if (!strcasecmp(action, "leave_conference")) {
1224                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_LEAVE, NULL);
1225                 } else if (!strcasecmp(action, "set_as_single_video_src")) {
1226                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_SET_SINGLE_VIDEO_SRC, NULL);
1227                 } else if (!strcasecmp(action, "release_as_single_video_src")) {
1228                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC, NULL);
1229                 } else if (!strncasecmp(action, "dialplan_exec(", 14)) {
1230                         ast_copy_string(buf, action, sizeof(buf));
1231                         action_args = buf;
1232                         if ((action_args = strchr(action, '('))) {
1233                                 action_args++;
1234                         }
1235                         /* it is possible that this argument may or may not
1236                          * have a closing brace at this point, it all depends on if
1237                          * comma delimited arguments were provided */
1238                         if ((tmp = strchr(action, ')'))) {
1239                                 *tmp = '\0';
1240                         }
1241                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DIALPLAN_EXEC, action_args);
1242                 } else if (action_len >= 21 && !strncasecmp(action, "playback_and_continue(", 22)) {
1243                         ast_copy_string(buf, action, sizeof(buf));
1244                         action_args = buf;
1245                         if ((action_args = strchr(action, '(')) && (tmp = strrchr(action_args, ')'))) {
1246                                 *tmp = '\0';
1247                                 action_args++;
1248                         }
1249                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PLAYBACK_AND_CONTINUE, action_args);
1250                 } else if (action_len >= 8 && !strncasecmp(action, "playback(", 9)) {
1251                         ast_copy_string(buf, action, sizeof(buf));
1252                         action_args = buf;
1253                         if ((action_args = strchr(action, '(')) && (tmp = strrchr(action_args, ')'))) {
1254                                 *tmp = '\0';
1255                                 action_args++;
1256                         }
1257                         res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PLAYBACK, action_args);
1258                 }
1259         }
1260
1261         /* if adding any of the actions failed, bail */
1262         if (res) {
1263                 struct conf_menu_action *menu_action;
1264                 while ((menu_action = AST_LIST_REMOVE_HEAD(&menu_entry->actions, action))) {
1265                         ast_free(menu_action);
1266                 }
1267                 ast_free(menu_entry);
1268                 return -1;
1269         }
1270
1271         /* remove any list entry with an identical DTMF sequence for overrides */
1272         AST_LIST_TRAVERSE_SAFE_BEGIN(&menu->entries, cur, entry) {
1273                 if (!strcasecmp(cur->dtmf, menu_entry->dtmf)) {
1274                         AST_LIST_REMOVE_CURRENT(entry);
1275                         ast_free(cur);
1276                         break;
1277                 }
1278         }
1279         AST_LIST_TRAVERSE_SAFE_END;
1280
1281         AST_LIST_INSERT_TAIL(&menu->entries, menu_entry, entry);
1282
1283         return 0;
1284 }
1285
1286 static char *complete_user_profile_name(const char *line, const char *word, int pos, int state)
1287 {
1288         int which = 0;
1289         char *res = NULL;
1290         int wordlen = strlen(word);
1291         struct ao2_iterator i;
1292         struct user_profile *u_profile = NULL;
1293         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
1294
1295         if (!cfg) {
1296                 return NULL;
1297         }
1298
1299         i = ao2_iterator_init(cfg->user_profiles, 0);
1300         while ((u_profile = ao2_iterator_next(&i))) {
1301                 if (!strncasecmp(u_profile->name, word, wordlen) && ++which > state) {
1302                         res = ast_strdup(u_profile->name);
1303                         ao2_ref(u_profile, -1);
1304                         break;
1305                 }
1306                 ao2_ref(u_profile, -1);
1307         }
1308         ao2_iterator_destroy(&i);
1309
1310         return res;
1311 }
1312
1313 static char *handle_cli_confbridge_show_user_profiles(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1314 {
1315         struct ao2_iterator it;
1316         struct user_profile *u_profile;
1317         RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
1318
1319         switch (cmd) {
1320         case CLI_INIT:
1321                 e->command = "confbridge show profile users";
1322                 e->usage =
1323                         "Usage confbridge show profile users\n";
1324                 return NULL;
1325         case CLI_GENERATE:
1326                 return NULL;
1327         }
1328
1329         if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
1330                 return NULL;
1331         }
1332
1333         ast_cli(a->fd,"--------- User Profiles -----------\n");
1334         ao2_lock(cfg->user_profiles);
1335         it = ao2_iterator_init(cfg->user_profiles, 0);
1336         while ((u_profile = ao2_iterator_next(&it))) {
1337                 ast_cli(a->fd,"%s\n", u_profile->name);
1338                 ao2_ref(u_profile, -1);
1339         }
1340         ao2_iterator_destroy(&it);
1341         ao2_unlock(cfg->user_profiles);
1342
1343         return CLI_SUCCESS;
1344 }
1345 static char *handle_cli_confbridge_show_user_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1346 {
1347         struct user_profile u_profile;
1348
1349         switch (cmd) {
1350         case CLI_INIT:
1351                 e->command = "confbridge show profile user";
1352                 e->usage =
1353                         "Usage confbridge show profile user [<profile name>]\n";
1354                 return NULL;
1355         case CLI_GENERATE:
1356                 if (a->pos == 4) {
1357                         return complete_user_profile_name(a->line, a->word, a->pos, a->n);
1358                 }
1359                 return NULL;
1360         }
1361
1362         if (a->argc != 5) {
1363                 return CLI_SHOWUSAGE;
1364         }
1365
1366         if (!(conf_find_user_profile(NULL, a->argv[4], &u_profile))) {
1367                 ast_cli(a->fd, "No conference user profile named '%s' found!\n", a->argv[4]);
1368                 return CLI_SUCCESS;
1369         }
1370
1371         ast_cli(a->fd,"--------------------------------------------\n");
1372         ast_cli(a->fd,"Name:                    %s\n",
1373                 u_profile.name);
1374         ast_cli(a->fd,"Admin:                   %s\n",
1375                 u_profile.flags & USER_OPT_ADMIN ?
1376                 "true" : "false");
1377         ast_cli(a->fd,"Marked User:             %s\n",
1378                 u_profile.flags & USER_OPT_MARKEDUSER ?
1379                 "true" : "false");
1380         ast_cli(a->fd,"Start Muted:             %s\n",
1381                 u_profile.flags & USER_OPT_STARTMUTED?
1382                 "true" : "false");
1383         ast_cli(a->fd,"MOH When Empty:          %s\n",
1384                 u_profile.flags & USER_OPT_MUSICONHOLD ?
1385                 "enabled" : "disabled");
1386         ast_cli(a->fd,"MOH Class:               %s\n",
1387                 ast_strlen_zero(u_profile.moh_class) ?
1388                 "default" : u_profile.moh_class);
1389         ast_cli(a->fd,"Announcement:            %s\n",
1390                 u_profile.announcement);
1391         ast_cli(a->fd,"Quiet:                   %s\n",
1392                 u_profile.flags & USER_OPT_QUIET ?
1393                 "enabled" : "disabled");
1394         ast_cli(a->fd,"Wait Marked:             %s\n",
1395                 u_profile.flags & USER_OPT_WAITMARKED ?
1396                 "enabled" : "disabled");
1397         ast_cli(a->fd,"END Marked:              %s\n",
1398                 u_profile.flags & USER_OPT_ENDMARKED ?
1399                 "enabled" : "disabled");
1400         ast_cli(a->fd,"Drop_silence:            %s\n",
1401                 u_profile.flags & USER_OPT_DROP_SILENCE ?
1402                 "enabled" : "disabled");
1403         ast_cli(a->fd,"Silence Threshold:       %ums\n",
1404                 u_profile.silence_threshold);
1405         ast_cli(a->fd,"Talking Threshold:       %ums\n",
1406                 u_profile.talking_threshold);
1407         ast_cli(a->fd,"Denoise:                 %s\n",
1408                 u_profile.flags & USER_OPT_DENOISE ?
1409                 "enabled" : "disabled");
1410         ast_cli(a->fd,"Jitterbuffer:            %s\n",
1411                 u_profile.flags & USER_OPT_JITTERBUFFER ?
1412                 "enabled" : "disabled");
1413         ast_cli(a->fd,"Talk Detect Events:      %s\n",
1414                 u_profile.flags & USER_OPT_TALKER_DETECT ?
1415                 "enabled" : "disabled");
1416         ast_cli(a->fd,"DTMF Pass Through:       %s\n",
1417                 u_profile.flags & USER_OPT_DTMF_PASS ?
1418                 "enabled" : "disabled");
1419         ast_cli(a->fd,"PIN:                     %s\n",
1420                 ast_strlen_zero(u_profile.pin) ?
1421                 "None" : u_profile.pin);
1422         ast_cli(a->fd,"Announce User Count:     %s\n",
1423                 u_profile.flags & USER_OPT_ANNOUNCEUSERCOUNT ?
1424                 "enabled" : "disabled");
1425         ast_cli(a->fd,"Announce join/leave:     %s\n",
1426                 u_profile.flags & (USER_OPT_ANNOUNCE_JOIN_LEAVE | USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW) ?
1427                 u_profile.flags & USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW ?
1428                 "enabled (with review)" : "enabled" : "disabled");
1429         ast_cli(a->fd,"Announce User Count all: %s\n",
1430                 u_profile.flags & USER_OPT_ANNOUNCEUSERCOUNTALL ?
1431                 "enabled" : "disabled");
1432                 ast_cli(a->fd,"\n");
1433
1434         return CLI_SUCCESS;
1435 }
1436
1437 static char *complete_bridge_profile_name(const char *line, const char *word, int pos, int state)
1438 {
1439         int which = 0;
1440         char *res = NULL;
1441         int wordlen = strlen(word);
1442         struct ao2_iterator i;
1443         struct bridge_profile *b_profile = NULL;
1444         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
1445
1446         if (!cfg) {
1447                 return NULL;
1448         }
1449
1450         i = ao2_iterator_init(cfg->bridge_profiles, 0);
1451         while ((b_profile = ao2_iterator_next(&i))) {
1452                 if (!strncasecmp(b_profile->name, word, wordlen) && ++which > state) {
1453                         res = ast_strdup(b_profile->name);
1454                         ao2_ref(b_profile, -1);
1455                         break;
1456                 }
1457                 ao2_ref(b_profile, -1);
1458         }
1459         ao2_iterator_destroy(&i);
1460
1461         return res;
1462 }
1463
1464 static char *handle_cli_confbridge_show_bridge_profiles(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1465 {
1466         struct ao2_iterator it;
1467         struct bridge_profile *b_profile;
1468         RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
1469
1470         switch (cmd) {
1471         case CLI_INIT:
1472                 e->command = "confbridge show profile bridges";
1473                 e->usage =
1474                         "Usage confbridge show profile bridges\n";
1475                 return NULL;
1476         case CLI_GENERATE:
1477                 return NULL;
1478         }
1479
1480         if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
1481                 return NULL;
1482         }
1483
1484         ast_cli(a->fd,"--------- Bridge Profiles -----------\n");
1485         ao2_lock(cfg->bridge_profiles);
1486         it = ao2_iterator_init(cfg->bridge_profiles, 0);
1487         while ((b_profile = ao2_iterator_next(&it))) {
1488                 ast_cli(a->fd,"%s\n", b_profile->name);
1489                 ao2_ref(b_profile, -1);
1490         }
1491         ao2_iterator_destroy(&it);
1492         ao2_unlock(cfg->bridge_profiles);
1493
1494         return CLI_SUCCESS;
1495 }
1496
1497 static char *handle_cli_confbridge_show_bridge_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1498 {
1499         struct bridge_profile b_profile;
1500         char tmp[64];
1501
1502         switch (cmd) {
1503         case CLI_INIT:
1504                 e->command = "confbridge show profile bridge";
1505                 e->usage =
1506                         "Usage confbridge show profile bridge <profile name>\n";
1507                 return NULL;
1508         case CLI_GENERATE:
1509                 if (a->pos == 4) {
1510                         return complete_bridge_profile_name(a->line, a->word, a->pos, a->n);
1511                 }
1512                 return NULL;
1513         }
1514
1515         if (a->argc != 5) {
1516                 return CLI_SHOWUSAGE;
1517         }
1518
1519         if (!(conf_find_bridge_profile(NULL, a->argv[4], &b_profile))) {
1520                 ast_cli(a->fd, "No conference bridge profile named '%s' found!\n", a->argv[4]);
1521                 return CLI_SUCCESS;
1522         }
1523
1524         ast_cli(a->fd,"--------------------------------------------\n");
1525         ast_cli(a->fd,"Name:                 %s\n", b_profile.name);
1526         ast_cli(a->fd,"Language:             %s\n", b_profile.language);
1527
1528         if (b_profile.internal_sample_rate) {
1529                 snprintf(tmp, sizeof(tmp), "%u", b_profile.internal_sample_rate);
1530         } else {
1531                 ast_copy_string(tmp, "auto", sizeof(tmp));
1532         }
1533         ast_cli(a->fd,"Internal Sample Rate: %s\n", tmp);
1534
1535         if (b_profile.mix_interval) {
1536                 ast_cli(a->fd,"Mixing Interval:      %u\n", b_profile.mix_interval);
1537         } else {
1538                 ast_cli(a->fd,"Mixing Interval:      Default 20ms\n");
1539         }
1540
1541         ast_cli(a->fd,"Record Conference:    %s\n",
1542                 b_profile.flags & BRIDGE_OPT_RECORD_CONFERENCE ?
1543                 "yes" : "no");
1544
1545         ast_cli(a->fd,"Record File Append:    %s\n",
1546                 b_profile.flags & BRIDGE_OPT_RECORD_FILE_APPEND ?
1547                 "yes" : "no");
1548
1549         ast_cli(a->fd,"Record File Timestamp: %s\n",
1550                 b_profile.flags & BRIDGE_OPT_RECORD_FILE_TIMESTAMP ?
1551                 "yes" : "no");
1552
1553         ast_cli(a->fd,"Record File:          %s\n",
1554                 ast_strlen_zero(b_profile.rec_file) ? "Auto Generated" :
1555                 b_profile.rec_file);
1556
1557         ast_cli(a->fd,"Record Options:       %s\n",
1558                 b_profile.rec_options);
1559
1560         ast_cli(a->fd,"Record Command:       %s\n",
1561                 b_profile.rec_command);
1562
1563         if (b_profile.max_members) {
1564                 ast_cli(a->fd,"Max Members:          %u\n", b_profile.max_members);
1565         } else {
1566                 ast_cli(a->fd,"Max Members:          No Limit\n");
1567         }
1568
1569         switch (b_profile.flags
1570                 & (BRIDGE_OPT_VIDEO_SRC_LAST_MARKED | BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
1571                         | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
1572         case BRIDGE_OPT_VIDEO_SRC_LAST_MARKED:
1573                 ast_cli(a->fd, "Video Mode:           last_marked\n");
1574                 break;
1575         case BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED:
1576                 ast_cli(a->fd, "Video Mode:           first_marked\n");
1577                 break;
1578         case BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER:
1579                 ast_cli(a->fd, "Video Mode:           follow_talker\n");
1580                 break;
1581         case 0:
1582                 ast_cli(a->fd, "Video Mode:           no video\n");
1583                 break;
1584         default:
1585                 /* Opps.  We have more than one video mode flag set. */
1586                 ast_assert(0);
1587                 break;
1588         }
1589
1590         ast_cli(a->fd,"sound_only_person:    %s\n", conf_get_sound(CONF_SOUND_ONLY_PERSON, b_profile.sounds));
1591         ast_cli(a->fd,"sound_only_one:       %s\n", conf_get_sound(CONF_SOUND_ONLY_ONE, b_profile.sounds));
1592         ast_cli(a->fd,"sound_has_joined:     %s\n", conf_get_sound(CONF_SOUND_HAS_JOINED, b_profile.sounds));
1593         ast_cli(a->fd,"sound_has_left:       %s\n", conf_get_sound(CONF_SOUND_HAS_LEFT, b_profile.sounds));
1594         ast_cli(a->fd,"sound_kicked:         %s\n", conf_get_sound(CONF_SOUND_KICKED, b_profile.sounds));
1595         ast_cli(a->fd,"sound_muted:          %s\n", conf_get_sound(CONF_SOUND_MUTED, b_profile.sounds));
1596         ast_cli(a->fd,"sound_unmuted:        %s\n", conf_get_sound(CONF_SOUND_UNMUTED, b_profile.sounds));
1597         ast_cli(a->fd,"sound_there_are:      %s\n", conf_get_sound(CONF_SOUND_THERE_ARE, b_profile.sounds));
1598         ast_cli(a->fd,"sound_other_in_party: %s\n", conf_get_sound(CONF_SOUND_OTHER_IN_PARTY, b_profile.sounds));
1599         ast_cli(a->fd,"sound_place_into_conference: %s\n", conf_get_sound(CONF_SOUND_PLACE_IN_CONF, b_profile.sounds));
1600         ast_cli(a->fd,"sound_wait_for_leader:       %s\n", conf_get_sound(CONF_SOUND_WAIT_FOR_LEADER, b_profile.sounds));
1601         ast_cli(a->fd,"sound_leader_has_left:       %s\n", conf_get_sound(CONF_SOUND_LEADER_HAS_LEFT, b_profile.sounds));
1602         ast_cli(a->fd,"sound_get_pin:        %s\n", conf_get_sound(CONF_SOUND_GET_PIN, b_profile.sounds));
1603         ast_cli(a->fd,"sound_invalid_pin:    %s\n", conf_get_sound(CONF_SOUND_INVALID_PIN, b_profile.sounds));
1604         ast_cli(a->fd,"sound_locked:         %s\n", conf_get_sound(CONF_SOUND_LOCKED, b_profile.sounds));
1605         ast_cli(a->fd,"sound_unlocked_now:   %s\n", conf_get_sound(CONF_SOUND_UNLOCKED_NOW, b_profile.sounds));
1606         ast_cli(a->fd,"sound_lockednow:      %s\n", conf_get_sound(CONF_SOUND_LOCKED_NOW, b_profile.sounds));
1607         ast_cli(a->fd,"sound_error_menu:     %s\n", conf_get_sound(CONF_SOUND_ERROR_MENU, b_profile.sounds));
1608         ast_cli(a->fd,"sound_join:           %s\n", conf_get_sound(CONF_SOUND_JOIN, b_profile.sounds));
1609         ast_cli(a->fd,"sound_leave:          %s\n", conf_get_sound(CONF_SOUND_LEAVE, b_profile.sounds));
1610         ast_cli(a->fd,"sound_participants_muted:     %s\n", conf_get_sound(CONF_SOUND_PARTICIPANTS_MUTED, b_profile.sounds));
1611         ast_cli(a->fd,"sound_participants_unmuted:     %s\n", conf_get_sound(CONF_SOUND_PARTICIPANTS_UNMUTED, b_profile.sounds));
1612         ast_cli(a->fd,"sound_begin:          %s\n", conf_get_sound(CONF_SOUND_BEGIN, b_profile.sounds));
1613         ast_cli(a->fd,"\n");
1614
1615         conf_bridge_profile_destroy(&b_profile);
1616         return CLI_SUCCESS;
1617 }
1618
1619 static char *complete_menu_name(const char *line, const char *word, int pos, int state)
1620 {
1621         int which = 0;
1622         char *res = NULL;
1623         int wordlen = strlen(word);
1624         struct ao2_iterator i;
1625         struct conf_menu *menu = NULL;
1626         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
1627
1628         if (!cfg) {
1629                 return NULL;
1630         }
1631
1632         i = ao2_iterator_init(cfg->menus, 0);
1633         while ((menu = ao2_iterator_next(&i))) {
1634                 if (!strncasecmp(menu->name, word, wordlen) && ++which > state) {
1635                         res = ast_strdup(menu->name);
1636                         ao2_ref(menu, -1);
1637                         break;
1638                 }
1639                 ao2_ref(menu, -1);
1640         }
1641         ao2_iterator_destroy(&i);
1642
1643         return res;
1644 }
1645
1646 static char *handle_cli_confbridge_show_menus(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1647 {
1648         struct ao2_iterator it;
1649         struct conf_menu *menu;
1650         RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
1651
1652         switch (cmd) {
1653         case CLI_INIT:
1654                 e->command = "confbridge show menus";
1655                 e->usage =
1656                         "Usage confbridge show profile menus\n";
1657                 return NULL;
1658         case CLI_GENERATE:
1659                 return NULL;
1660         }
1661
1662         if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
1663                 return NULL;
1664         }
1665
1666         ast_cli(a->fd,"--------- Menus -----------\n");
1667         ao2_lock(cfg->menus);
1668         it = ao2_iterator_init(cfg->menus, 0);
1669         while ((menu = ao2_iterator_next(&it))) {
1670                 ast_cli(a->fd,"%s\n", menu->name);
1671                 ao2_ref(menu, -1);
1672         }
1673         ao2_iterator_destroy(&it);
1674         ao2_unlock(cfg->menus);
1675
1676         return CLI_SUCCESS;
1677 }
1678
1679 static char *handle_cli_confbridge_show_menu(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1680 {
1681         RAII_VAR(struct conf_menu *, menu, NULL, ao2_cleanup);
1682         RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
1683         struct conf_menu_entry *menu_entry = NULL;
1684         struct conf_menu_action *menu_action = NULL;
1685
1686         switch (cmd) {
1687         case CLI_INIT:
1688                 e->command = "confbridge show menu";
1689                 e->usage =
1690                         "Usage confbridge show menu [<menu name>]\n";
1691                 return NULL;
1692         case CLI_GENERATE:
1693                 if (a->pos == 3) {
1694                         return complete_menu_name(a->line, a->word, a->pos, a->n);
1695                 }
1696                 return NULL;
1697         }
1698
1699         if (a->argc != 4) {
1700                 return CLI_SHOWUSAGE;
1701         }
1702
1703         if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
1704                 return NULL;
1705         }
1706
1707         if (!(menu = menu_find(cfg->menus, a->argv[3]))) {
1708                 ast_cli(a->fd, "No conference menu named '%s' found!\n", a->argv[3]);
1709                 return CLI_SUCCESS;
1710         }
1711         ao2_lock(menu);
1712
1713         ast_cli(a->fd,"Name: %s\n", menu->name);
1714         AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
1715                 int action_num = 0;
1716                 ast_cli(a->fd, "%s=", menu_entry->dtmf);
1717                 AST_LIST_TRAVERSE(&menu_entry->actions, menu_action, action) {
1718                         if (action_num) {
1719                                 ast_cli(a->fd, ", ");
1720                         }
1721                         switch (menu_action->id) {
1722                         case MENU_ACTION_TOGGLE_MUTE:
1723                                 ast_cli(a->fd, "toggle_mute");
1724                                 break;
1725                         case MENU_ACTION_NOOP:
1726                                 ast_cli(a->fd, "no_op");
1727                                 break;
1728                         case MENU_ACTION_INCREASE_LISTENING:
1729                                 ast_cli(a->fd, "increase_listening_volume");
1730                                 break;
1731                         case MENU_ACTION_DECREASE_LISTENING:
1732                                 ast_cli(a->fd, "decrease_listening_volume");
1733                                 break;
1734                         case MENU_ACTION_RESET_LISTENING:
1735                                 ast_cli(a->fd, "reset_listening_volume");
1736                                 break;
1737                         case MENU_ACTION_RESET_TALKING:
1738                                 ast_cli(a->fd, "reset_talking_volume");
1739                                 break;
1740                         case MENU_ACTION_INCREASE_TALKING:
1741                                 ast_cli(a->fd, "increase_talking_volume");
1742                                 break;
1743                         case MENU_ACTION_DECREASE_TALKING:
1744                                 ast_cli(a->fd, "decrease_talking_volume");
1745                                 break;
1746                         case MENU_ACTION_PLAYBACK:
1747                                 ast_cli(a->fd, "playback(%s)", menu_action->data.playback_file);
1748                                 break;
1749                         case MENU_ACTION_PLAYBACK_AND_CONTINUE:
1750                                 ast_cli(a->fd, "playback_and_continue(%s)", menu_action->data.playback_file);
1751                                 break;
1752                         case MENU_ACTION_DIALPLAN_EXEC:
1753                                 ast_cli(a->fd, "dialplan_exec(%s,%s,%d)",
1754                                         menu_action->data.dialplan_args.context,
1755                                         menu_action->data.dialplan_args.exten,
1756                                         menu_action->data.dialplan_args.priority);
1757                                 break;
1758                         case MENU_ACTION_ADMIN_TOGGLE_LOCK:
1759                                 ast_cli(a->fd, "admin_toggle_conference_lock");
1760                                 break;
1761                         case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
1762                                 ast_cli(a->fd, "admin_toggle_mute_participants");
1763                                 break;
1764                         case MENU_ACTION_PARTICIPANT_COUNT:
1765                                 ast_cli(a->fd, "participant_count");
1766                                 break;
1767                         case MENU_ACTION_ADMIN_KICK_LAST:
1768                                 ast_cli(a->fd, "admin_kick_last");
1769                                 break;
1770                         case MENU_ACTION_LEAVE:
1771                                 ast_cli(a->fd, "leave_conference");
1772                                 break;
1773                         case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
1774                                 ast_cli(a->fd, "set_as_single_video_src");
1775                                 break;
1776                         case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
1777                                 ast_cli(a->fd, "release_as_single_video_src");
1778                                 break;
1779                         }
1780                         action_num++;
1781                 }
1782                 ast_cli(a->fd,"\n");
1783         }
1784
1785
1786         ao2_unlock(menu);
1787         return CLI_SUCCESS;
1788 }
1789
1790 static struct ast_cli_entry cli_confbridge_parser[] = {
1791         AST_CLI_DEFINE(handle_cli_confbridge_show_user_profile, "Show a conference user profile."),
1792         AST_CLI_DEFINE(handle_cli_confbridge_show_bridge_profile, "Show a conference bridge profile."),
1793         AST_CLI_DEFINE(handle_cli_confbridge_show_menu, "Show a conference menu"),
1794         AST_CLI_DEFINE(handle_cli_confbridge_show_user_profiles, "Show a list of conference user profiles."),
1795         AST_CLI_DEFINE(handle_cli_confbridge_show_bridge_profiles, "Show a list of conference bridge profiles."),
1796         AST_CLI_DEFINE(handle_cli_confbridge_show_menus, "Show a list of conference menus"),
1797
1798 };
1799
1800 static void confbridge_cfg_destructor(void *obj)
1801 {
1802         struct confbridge_cfg *cfg = obj;
1803         ao2_cleanup(cfg->user_profiles);
1804         ao2_cleanup(cfg->bridge_profiles);
1805         ao2_cleanup(cfg->menus);
1806 }
1807
1808 void *confbridge_cfg_alloc(void)
1809 {
1810         struct confbridge_cfg *cfg;
1811
1812         if (!(cfg = ao2_alloc(sizeof(*cfg), confbridge_cfg_destructor))) {
1813                 return NULL;
1814         }
1815
1816         if (!(cfg->user_profiles = ao2_container_alloc(283, user_hash_cb, user_cmp_cb))) {
1817                 goto error;
1818         }
1819
1820         if (!(cfg->bridge_profiles = ao2_container_alloc(283, bridge_hash_cb, bridge_cmp_cb))) {
1821                 goto error;
1822         }
1823
1824         if (!(cfg->menus = ao2_container_alloc(283, menu_hash_cb, menu_cmp_cb))) {
1825                 goto error;
1826         }
1827
1828         return cfg;
1829 error:
1830         ao2_ref(cfg, -1);
1831         return NULL;
1832 }
1833
1834 static int announce_user_count_all_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1835 {
1836         struct user_profile *u_profile = obj;
1837
1838         if (strcasecmp(var->name, "announce_user_count_all")) {
1839                 return -1;
1840         }
1841         if (ast_true(var->value)) {
1842                 u_profile->flags = u_profile->flags | USER_OPT_ANNOUNCEUSERCOUNTALL;
1843         } else if (ast_false(var->value)) {
1844                 u_profile->flags = u_profile->flags & ~USER_OPT_ANNOUNCEUSERCOUNTALL;
1845         } else if (sscanf(var->value, "%30u", &u_profile->announce_user_count_all_after) == 1) {
1846                 u_profile->flags = u_profile->flags | USER_OPT_ANNOUNCEUSERCOUNTALL;
1847         } else {
1848                 return -1;
1849         }
1850         return 0;
1851 }
1852
1853 static int mix_interval_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1854 {
1855         struct bridge_profile *b_profile = obj;
1856
1857         if (strcasecmp(var->name, "mixing_interval")) {
1858                 return -1;
1859         }
1860         if (sscanf(var->value, "%30u", &b_profile->mix_interval) != 1) {
1861                 return -1;
1862         }
1863         switch (b_profile->mix_interval) {
1864         case 10:
1865         case 20:
1866         case 40:
1867         case 80:
1868                 return 0;
1869         default:
1870                 return -1;
1871         }
1872 }
1873
1874 static int video_mode_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1875 {
1876         struct bridge_profile *b_profile = obj;
1877
1878         if (strcasecmp(var->name, "video_mode")) {
1879                 return -1;
1880         }
1881         if (!strcasecmp(var->value, "first_marked")) {
1882                 ast_set_flags_to(b_profile,
1883                         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
1884                                 | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
1885                                 | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
1886                         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED);
1887         } else if (!strcasecmp(var->value, "last_marked")) {
1888                 ast_set_flags_to(b_profile,
1889                         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
1890                                 | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
1891                                 | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
1892                         BRIDGE_OPT_VIDEO_SRC_LAST_MARKED);
1893         } else if (!strcasecmp(var->value, "follow_talker")) {
1894                 ast_set_flags_to(b_profile,
1895                         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
1896                                 | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
1897                                 | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
1898                         BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
1899         } else if (!strcasecmp(var->value, "none")) {
1900                 ast_clear_flag(b_profile,
1901                         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
1902                                 | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
1903                                 | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
1904         } else {
1905                 return -1;
1906         }
1907         return 0;
1908 }
1909
1910 static int user_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1911 {
1912         struct user_profile *u_profile = obj;
1913
1914         return conf_find_user_profile(NULL, var->value, u_profile) ? 0 : -1;
1915 }
1916
1917 static int bridge_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1918 {
1919         struct bridge_profile *b_profile = obj;
1920         struct bridge_profile_sounds *sounds = bridge_profile_sounds_alloc();
1921         struct bridge_profile_sounds *oldsounds = b_profile->sounds;
1922
1923         if (!sounds) {
1924                 return -1;
1925         }
1926         if (!(conf_find_bridge_profile(NULL, var->value, b_profile))) {
1927                 ao2_ref(sounds, -1);
1928                 return -1;
1929         }
1930         /* Using a bridge profile as a template is a little complicated due to the sounds. Since the sounds
1931          * structure of a dynamic profile will need to be altered, a completely new sounds structure must be
1932          * created instead of simply holding a reference to the one built by the config file. */
1933         ast_string_field_set(sounds, onlyperson, b_profile->sounds->onlyperson);
1934         ast_string_field_set(sounds, onlyone, b_profile->sounds->onlyone);
1935         ast_string_field_set(sounds, hasjoin, b_profile->sounds->hasjoin);
1936         ast_string_field_set(sounds, hasleft, b_profile->sounds->hasleft);
1937         ast_string_field_set(sounds, kicked, b_profile->sounds->kicked);
1938         ast_string_field_set(sounds, muted, b_profile->sounds->muted);
1939         ast_string_field_set(sounds, unmuted, b_profile->sounds->unmuted);
1940         ast_string_field_set(sounds, thereare, b_profile->sounds->thereare);
1941         ast_string_field_set(sounds, otherinparty, b_profile->sounds->otherinparty);
1942         ast_string_field_set(sounds, placeintoconf, b_profile->sounds->placeintoconf);
1943         ast_string_field_set(sounds, waitforleader, b_profile->sounds->waitforleader);
1944         ast_string_field_set(sounds, leaderhasleft, b_profile->sounds->leaderhasleft);
1945         ast_string_field_set(sounds, getpin, b_profile->sounds->getpin);
1946         ast_string_field_set(sounds, invalidpin, b_profile->sounds->invalidpin);
1947         ast_string_field_set(sounds, locked, b_profile->sounds->locked);
1948         ast_string_field_set(sounds, unlockednow, b_profile->sounds->unlockednow);
1949         ast_string_field_set(sounds, lockednow, b_profile->sounds->lockednow);
1950         ast_string_field_set(sounds, errormenu, b_profile->sounds->errormenu);
1951         ast_string_field_set(sounds, join, b_profile->sounds->join);
1952         ast_string_field_set(sounds, leave, b_profile->sounds->leave);
1953         ast_string_field_set(sounds, participantsmuted, b_profile->sounds->participantsmuted);
1954         ast_string_field_set(sounds, participantsunmuted, b_profile->sounds->participantsunmuted);
1955         ast_string_field_set(sounds, begin, b_profile->sounds->begin);
1956
1957         ao2_ref(b_profile->sounds, -1); /* sounds struct copied over to it from the template by reference only. */
1958         ao2_ref(oldsounds, -1);    /* original sounds struct we don't need anymore */
1959         b_profile->sounds = sounds;     /* the new sounds struct that is a deep copy of the one from the template. */
1960
1961         return 0;
1962 }
1963
1964 static int copy_menu_entry(struct conf_menu_entry *dst, struct conf_menu_entry *src)
1965 {
1966         struct conf_menu_action *menu_action;
1967         struct conf_menu_action *new_menu_action;
1968
1969         ast_copy_string(dst->dtmf, src->dtmf, sizeof(dst->dtmf));
1970         AST_LIST_HEAD_INIT_NOLOCK(&dst->actions);
1971
1972         AST_LIST_TRAVERSE(&src->actions, menu_action, action) {
1973                 if (!(new_menu_action = ast_calloc(1, sizeof(*new_menu_action)))) {
1974                         return -1;
1975                 }
1976                 memcpy(new_menu_action, menu_action, sizeof(*new_menu_action));
1977                 AST_LIST_NEXT(new_menu_action, action) = NULL;
1978                 AST_LIST_INSERT_TAIL(&dst->actions, new_menu_action, action);
1979         }
1980
1981         return 0;
1982 }
1983
1984 static int conf_menu_profile_copy(struct conf_menu *dst, struct conf_menu *src)
1985 {
1986         /* Copy each menu item to the dst struct */
1987         struct conf_menu_entry *cur;
1988
1989         AST_LIST_TRAVERSE(&src->entries, cur, entry) {
1990                 struct conf_menu_entry *cpy;
1991
1992                 if (!(cpy = ast_calloc(1, sizeof(*cpy)))) {
1993                         return -1;
1994                 }
1995
1996                 if (copy_menu_entry(cpy, cur)) {
1997                         conf_menu_entry_destroy(cpy);
1998                         ast_free(cpy);
1999                         return -1;
2000                 }
2001                 AST_LIST_INSERT_TAIL(&dst->entries, cpy, entry);
2002         }
2003
2004         return 0;
2005 }
2006
2007 static int menu_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2008 {
2009         struct conf_menu *dst_menu = obj;
2010         struct confbridge_cfg *cfg = aco_pending_config(&cfg_info);
2011         RAII_VAR(struct conf_menu *, src_menu, NULL, ao2_cleanup);
2012
2013         if (!cfg) {
2014                 return 0;
2015         }
2016
2017         if (!(src_menu = ao2_find(cfg->menus, var->value, OBJ_KEY))) {
2018                 return -1;
2019         }
2020
2021         if (conf_menu_profile_copy(dst_menu, src_menu)) {
2022                 return -1;
2023         }
2024
2025         return 0;
2026 }
2027
2028 static int sound_option_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2029 {
2030         set_sound(var->name, var->value, obj);
2031         return 0;
2032 }
2033
2034 static int menu_option_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2035 {
2036         add_menu_entry(obj, var->name, var->value);
2037         return 0;
2038 }
2039
2040 static int verify_default_profiles(void)
2041 {
2042         RAII_VAR(struct user_profile *, user_profile, NULL, ao2_cleanup);
2043         RAII_VAR(struct bridge_profile *, bridge_profile, NULL, ao2_cleanup);
2044         RAII_VAR(struct conf_menu *, menu_profile, NULL, ao2_cleanup);
2045         struct confbridge_cfg *cfg = aco_pending_config(&cfg_info);
2046
2047         if (!cfg) {
2048                 return 0;
2049         }
2050
2051         bridge_profile = ao2_find(cfg->bridge_profiles, DEFAULT_BRIDGE_PROFILE, OBJ_KEY);
2052         if (!bridge_profile) {
2053                 bridge_profile = bridge_profile_alloc(DEFAULT_BRIDGE_PROFILE);
2054                 if (!bridge_profile) {
2055                         return -1;
2056                 }
2057                 ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_BRIDGE_PROFILE);
2058                 aco_set_defaults(&bridge_type, DEFAULT_BRIDGE_PROFILE, bridge_profile);
2059                 ao2_link(cfg->bridge_profiles, bridge_profile);
2060         }
2061
2062         user_profile = ao2_find(cfg->user_profiles, DEFAULT_USER_PROFILE, OBJ_KEY);
2063         if (!user_profile) {
2064                 user_profile = user_profile_alloc(DEFAULT_USER_PROFILE);
2065                 if (!user_profile) {
2066                         return -1;
2067                 }
2068                 ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_USER_PROFILE);
2069                 aco_set_defaults(&user_type, DEFAULT_USER_PROFILE, user_profile);
2070                 ao2_link(cfg->user_profiles, user_profile);
2071         }
2072
2073         menu_profile = ao2_find(cfg->menus, DEFAULT_MENU_PROFILE, OBJ_KEY);
2074         if (!menu_profile) {
2075                 menu_profile = menu_alloc(DEFAULT_MENU_PROFILE);
2076                 if (!menu_profile) {
2077                         return -1;
2078                 }
2079                 ast_log(AST_LOG_NOTICE, "Adding %s menu to app_confbridge\n", DEFAULT_MENU_PROFILE);
2080                 aco_set_defaults(&menu_type, DEFAULT_MENU_PROFILE, menu_profile);
2081                 ao2_link(cfg->menus, menu_profile);
2082         }
2083
2084         return 0;
2085 }
2086
2087 int conf_load_config(void)
2088 {
2089         if (aco_info_init(&cfg_info)) {
2090                 return -1;
2091         }
2092
2093         /* User options */
2094         aco_option_register(&cfg_info, "type", ACO_EXACT, user_types, NULL, OPT_NOOP_T, 0, 0);
2095         aco_option_register(&cfg_info, "admin", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ADMIN);
2096         aco_option_register(&cfg_info, "marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MARKEDUSER);
2097         aco_option_register(&cfg_info, "startmuted", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_STARTMUTED);
2098         aco_option_register(&cfg_info, "music_on_hold_when_empty", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MUSICONHOLD);
2099         aco_option_register(&cfg_info, "quiet", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_QUIET);
2100         aco_option_register_custom(&cfg_info, "announce_user_count_all", ACO_EXACT, user_types, "no", announce_user_count_all_handler, 0);
2101         aco_option_register(&cfg_info, "announce_user_count", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCEUSERCOUNT);
2102         /* Negative logic. Defaults to "yes" and evaluates with ast_false(). If !ast_false(), USER_OPT_NOONLYPERSON is cleared */
2103         aco_option_register(&cfg_info, "announce_only_user", ACO_EXACT, user_types, "yes", OPT_BOOLFLAG_T, 0, FLDSET(struct user_profile, flags), USER_OPT_NOONLYPERSON);
2104         aco_option_register(&cfg_info, "wait_marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_WAITMARKED);
2105         aco_option_register(&cfg_info, "end_marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ENDMARKED);
2106         aco_option_register(&cfg_info, "talk_detection_events", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_TALKER_DETECT);
2107         aco_option_register(&cfg_info, "dtmf_passthrough", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DTMF_PASS);
2108         aco_option_register(&cfg_info, "announce_join_leave", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCE_JOIN_LEAVE);
2109         aco_option_register(&cfg_info, "announce_join_leave_review", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW);
2110         aco_option_register(&cfg_info, "pin", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, pin));
2111         aco_option_register(&cfg_info, "music_on_hold_class", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, moh_class));
2112         aco_option_register(&cfg_info, "announcement", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, announcement));
2113         aco_option_register(&cfg_info, "denoise", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DENOISE);
2114         aco_option_register(&cfg_info, "dsp_drop_silence", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DROP_SILENCE);
2115         aco_option_register(&cfg_info, "dsp_silence_threshold", ACO_EXACT, user_types, __stringify(DEFAULT_SILENCE_THRESHOLD), OPT_UINT_T, 0, FLDSET(struct user_profile, silence_threshold));
2116         aco_option_register(&cfg_info, "dsp_talking_threshold", ACO_EXACT, user_types, __stringify(DEFAULT_TALKING_THRESHOLD), OPT_UINT_T, 0, FLDSET(struct user_profile, talking_threshold));
2117         aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_JITTERBUFFER);
2118         /* This option should only be used with the CONFBRIDGE dialplan function */
2119         aco_option_register_custom(&cfg_info, "template", ACO_EXACT, user_types, NULL, user_template_handler, 0);
2120
2121 /* XXX ASTERISK-21271 need a user supplied bridge merge_priority to merge ConfBridges (default = 1, range 1-INT_MAX) */
2122         /* Bridge options */
2123         aco_option_register(&cfg_info, "type", ACO_EXACT, bridge_types, NULL, OPT_NOOP_T, 0, 0);
2124         aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), USER_OPT_JITTERBUFFER);
2125         /* "auto" will fail to parse as a uint, but we use PARSE_DEFAULT to set the value to 0 in that case, which is the value that auto resolves to */
2126         aco_option_register(&cfg_info, "internal_sample_rate", ACO_EXACT, bridge_types, "0", OPT_UINT_T, PARSE_DEFAULT, FLDSET(struct bridge_profile, internal_sample_rate), 0);
2127         aco_option_register_custom(&cfg_info, "mixing_interval", ACO_EXACT, bridge_types, "20", mix_interval_handler, 0);
2128         aco_option_register(&cfg_info, "record_conference", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_CONFERENCE);
2129         aco_option_register_custom(&cfg_info, "video_mode", ACO_EXACT, bridge_types, NULL, video_mode_handler, 0);
2130         aco_option_register(&cfg_info, "record_file_append", ACO_EXACT, bridge_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_FILE_APPEND);
2131         aco_option_register(&cfg_info, "record_file_timestamp", ACO_EXACT, bridge_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_FILE_TIMESTAMP);
2132         aco_option_register(&cfg_info, "max_members", ACO_EXACT, bridge_types, "0", OPT_UINT_T, 0, FLDSET(struct bridge_profile, max_members));
2133         aco_option_register(&cfg_info, "record_file", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_file));
2134         aco_option_register(&cfg_info, "record_options", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_options));
2135         aco_option_register(&cfg_info, "record_command", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_command));
2136         aco_option_register(&cfg_info, "language", ACO_EXACT, bridge_types, "en", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, language));
2137         aco_option_register_custom(&cfg_info, "^sound_", ACO_REGEX, bridge_types, NULL, sound_option_handler, 0);
2138         /* This option should only be used with the CONFBRIDGE dialplan function */
2139         aco_option_register_custom(&cfg_info, "template", ACO_EXACT, bridge_types, NULL, bridge_template_handler, 0);
2140
2141         /* Menu options */
2142         aco_option_register(&cfg_info, "type", ACO_EXACT, menu_types, NULL, OPT_NOOP_T, 0, 0);
2143         aco_option_register_custom(&cfg_info, "template", ACO_EXACT, menu_types, NULL, menu_template_handler, 0);
2144         aco_option_register_custom(&cfg_info, "^[0-9A-D*#]+$", ACO_REGEX, menu_types, NULL, menu_option_handler, 0);
2145
2146         if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
2147                 goto error;
2148         }
2149
2150         if (ast_cli_register_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser))) {
2151                 goto error;
2152         }
2153
2154         return 0;
2155 error:
2156         conf_destroy_config();
2157         return -1;
2158 }
2159
2160 int conf_reload_config(void)
2161 {
2162         if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
2163                 /* On a reload, just keep the config we already have in place. */
2164                 return -1;
2165         }
2166         return 0;
2167 }
2168
2169 static void conf_user_profile_copy(struct user_profile *dst, struct user_profile *src)
2170 {
2171         *dst = *src;
2172 }
2173
2174 const struct user_profile *conf_find_user_profile(struct ast_channel *chan, const char *user_profile_name, struct user_profile *result)
2175 {
2176         struct user_profile *tmp2;
2177         struct ast_datastore *datastore = NULL;
2178         struct func_confbridge_data *b_data = NULL;
2179         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2180
2181         if (chan && ast_strlen_zero(user_profile_name)) {
2182                 ast_channel_lock(chan);
2183                 datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2184                 ast_channel_unlock(chan);
2185                 if (datastore) {
2186                         b_data = datastore->data;
2187                         if (b_data->u_usable) {
2188                                 conf_user_profile_copy(result, &b_data->u_profile);
2189                                 return result;
2190                         }
2191                 }
2192         }
2193
2194         if (!cfg) {
2195                 return NULL;
2196         }
2197         if (ast_strlen_zero(user_profile_name)) {
2198                 user_profile_name = DEFAULT_USER_PROFILE;
2199         }
2200         if (!(tmp2 = ao2_find(cfg->user_profiles, user_profile_name, OBJ_KEY))) {
2201                 return NULL;
2202         }
2203         ao2_lock(tmp2);
2204         conf_user_profile_copy(result, tmp2);
2205         ao2_unlock(tmp2);
2206         ao2_ref(tmp2, -1);
2207
2208         return result;
2209 }
2210
2211 void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src)
2212 {
2213         *dst = *src;
2214         if (src->sounds) {
2215                 ao2_ref(src->sounds, +1);
2216         }
2217 }
2218
2219 void conf_bridge_profile_destroy(struct bridge_profile *b_profile)
2220 {
2221         if (b_profile->sounds) {
2222                 ao2_ref(b_profile->sounds, -1);
2223                 b_profile->sounds = NULL;
2224         }
2225 }
2226
2227 const struct bridge_profile *conf_find_bridge_profile(struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result)
2228 {
2229         struct bridge_profile *tmp2;
2230         struct ast_datastore *datastore = NULL;
2231         struct func_confbridge_data *b_data = NULL;
2232         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2233
2234         if (chan && ast_strlen_zero(bridge_profile_name)) {
2235                 ast_channel_lock(chan);
2236                 datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2237                 ast_channel_unlock(chan);
2238                 if (datastore) {
2239                         b_data = datastore->data;
2240                         if (b_data->b_usable) {
2241                                 conf_bridge_profile_copy(result, &b_data->b_profile);
2242                                 return result;
2243                         }
2244                 }
2245         }
2246
2247         if (!cfg) {
2248                 return NULL;
2249         }
2250         if (ast_strlen_zero(bridge_profile_name)) {
2251                 bridge_profile_name = DEFAULT_BRIDGE_PROFILE;
2252         }
2253         if (!(tmp2 = ao2_find(cfg->bridge_profiles, bridge_profile_name, OBJ_KEY))) {
2254                 return NULL;
2255         }
2256         ao2_lock(tmp2);
2257         conf_bridge_profile_copy(result, tmp2);
2258         ao2_unlock(tmp2);
2259         ao2_ref(tmp2, -1);
2260
2261         return result;
2262 }
2263
2264 struct dtmf_menu_hook_pvt {
2265         struct confbridge_user *user;
2266         struct conf_menu_entry menu_entry;
2267         struct conf_menu *menu;
2268 };
2269
2270 static void menu_hook_destroy(void *hook_pvt)
2271 {
2272         struct dtmf_menu_hook_pvt *pvt = hook_pvt;
2273         struct conf_menu_action *action = NULL;
2274
2275         ao2_cleanup(pvt->menu);
2276
2277         while ((action = AST_LIST_REMOVE_HEAD(&pvt->menu_entry.actions, action))) {
2278                 ast_free(action);
2279         }
2280         ast_free(pvt);
2281 }
2282
2283 static int menu_hook_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
2284 {
2285         struct dtmf_menu_hook_pvt *pvt = hook_pvt;
2286
2287         return conf_handle_dtmf(bridge_channel, pvt->user, &pvt->menu_entry, pvt->menu);
2288 }
2289
2290 void conf_menu_entry_destroy(struct conf_menu_entry *menu_entry)
2291 {
2292         struct conf_menu_action *menu_action = NULL;
2293         while ((menu_action = AST_LIST_REMOVE_HEAD(&menu_entry->actions, action))) {
2294                 ast_free(menu_action);
2295         }
2296 }
2297
2298 int conf_find_menu_entry_by_sequence(const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result)
2299 {
2300         struct conf_menu_entry *menu_entry = NULL;
2301
2302         ao2_lock(menu);
2303         AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
2304                 if (!strcasecmp(menu_entry->dtmf, dtmf_sequence)) {
2305                         copy_menu_entry(result, menu_entry);
2306                         ao2_unlock(menu);
2307                         return 1;
2308                 }
2309         }
2310         ao2_unlock(menu);
2311
2312         return 0;
2313 }
2314
2315 static int apply_menu_to_user(struct confbridge_user *user, struct conf_menu *menu)
2316 {
2317         struct conf_menu_entry *menu_entry;
2318
2319         SCOPED_AO2LOCK(menu_lock, menu);
2320         AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
2321                 struct dtmf_menu_hook_pvt *pvt;
2322
2323                 if (!(pvt = ast_calloc(1, sizeof(*pvt)))) {
2324                         return -1;
2325                 }
2326                 pvt->user = user;
2327                 pvt->menu = ao2_bump(menu);
2328
2329                 if (copy_menu_entry(&pvt->menu_entry, menu_entry)) {
2330                         menu_hook_destroy(pvt);
2331                         return -1;
2332                 }
2333
2334                 if (ast_bridge_dtmf_hook(&user->features, pvt->menu_entry.dtmf,
2335                         menu_hook_callback, pvt, menu_hook_destroy, 0)) {
2336                         menu_hook_destroy(pvt);
2337                 }
2338         }
2339         strcpy(user->menu_name, menu->name); /* Safe */
2340
2341         return 0;
2342 }
2343
2344 int conf_set_menu_to_user(struct ast_channel *chan, struct confbridge_user *user, const char *menu_profile_name)
2345 {
2346         RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2347         RAII_VAR(struct conf_menu *, menu, NULL, ao2_cleanup);
2348
2349         if (chan && ast_strlen_zero(menu_profile_name)) {
2350                 struct ast_datastore *datastore;
2351                 struct func_confbridge_data *b_data;
2352
2353                 ast_channel_lock(chan);
2354                 datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2355                 ast_channel_unlock(chan);
2356                 if (datastore) {
2357                         /* If a menu exists in the CONFBRIDGE function datastore, use it. */
2358                         b_data = datastore->data;
2359                         if (b_data->m_usable) {
2360                                 menu = ao2_bump(b_data->menu);
2361                                 return apply_menu_to_user(user, menu);
2362                         }
2363                 }
2364         }
2365
2366         /* Otherwise, we need to get whatever menu profile is specified to use (or default). */
2367         if (!cfg) {
2368                 return -1;
2369         }
2370
2371         if (ast_strlen_zero(menu_profile_name)) {
2372                 menu_profile_name = DEFAULT_MENU_PROFILE;
2373         }
2374
2375         if (!(menu = ao2_find(cfg->menus, menu_profile_name, OBJ_KEY))) {
2376                 return -1;
2377         }
2378
2379         return apply_menu_to_user(user, menu);
2380 }
2381
2382 void conf_destroy_config(void)
2383 {
2384         ast_cli_unregister_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser));
2385         aco_info_destroy(&cfg_info);
2386         ao2_global_obj_release(cfg_handle);
2387 }