Debian Codegraph @

apps/app_confbridge.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2007-2008, Digium, Inc.
5 *
6 * Joshua Colp <[email protected]>
7 * David Vossel <[email protected]>
8 *
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
14 *
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
18 */
19
20 /*! \file
21 *
22 * \brief Conference Bridge application
23 *
24 * \author\verbatim Joshua Colp <[email protected]> \endverbatim
25 * \author\verbatim David Vossel <[email protected]> \endverbatim
26 *
27 * This is a conference bridge application utilizing the bridging core.
28 * \ingroup applications
29 */
30
31 /*! \li \ref app_confbridge.c uses the configuration file \ref confbridge.conf
32 * \addtogroup configuration_file Configuration Files
33 */
34
35 /*!
36 * \page confbridge.conf confbridge.conf
37 * \verbinclude confbridge.conf.sample
38 */
39
40 /*** MODULEINFO
41 <support_level>core</support_level>
42 ***/
43
44 #include "asterisk.h"
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <unistd.h>
49 #include <string.h>
50 #include <signal.h>
51
52 #include "asterisk/cli.h"
53 #include "asterisk/file.h"
54 #include "asterisk/channel.h"
55 #include "asterisk/pbx.h"
56 #include "asterisk/pbx.h"
57 #include "asterisk/module.h"
58 #include "asterisk/lock.h"
59 #include "asterisk/bridge.h"
60 #include "asterisk/musiconhold.h"
61 #include "asterisk/say.h"
62 #include "asterisk/audiohook.h"
63 #include "asterisk/astobj2.h"
64 #include "confbridge/include/confbridge.h"
65 #include "asterisk/paths.h"
66 #include "asterisk/manager.h"
67 #include "asterisk/test.h"
68 #include "asterisk/stasis.h"
69 #include "asterisk/stasis_bridges.h"
70 #include "asterisk/stasis_channels.h"
71 #include "asterisk/json.h"
72 #include "asterisk/format_cache.h"
73 #include "asterisk/taskprocessor.h"
74 #include "asterisk/stream.h"
75 #include "asterisk/message.h"
76
77 /*** DOCUMENTATION
78 <application name="ConfBridge" language="en_US">
79 <since>
80 <version>12.0.0</version>
81 </since>
82 <synopsis>
83 Conference bridge application.
84 </synopsis>
85 <syntax>
86 <parameter name="conference" required="true">
87 <para>Name of the conference bridge. You are not limited to just
88 numbers.</para>
89 </parameter>
90 <parameter name="bridge_profile">
91 <para>The bridge profile name from confbridge.conf. When left blank,
92 a dynamically built bridge profile created by the CONFBRIDGE dialplan
93 function is searched for on the channel and used. If no dynamic
94 profile is present, the 'default_bridge' profile found in
95 confbridge.conf is used. </para>
96 <para>It is important to note that while user profiles may be unique
97 for each participant, mixing bridge profiles on a single conference
98 is _NOT_ recommended and will produce undefined results.</para>
99 </parameter>
100 <parameter name="user_profile">
101 <para>The user profile name from confbridge.conf. When left blank,
102 a dynamically built user profile created by the CONFBRIDGE dialplan
103 function is searched for on the channel and used. If no dynamic
104 profile is present, the 'default_user' profile found in
105 confbridge.conf is used.</para>
106 </parameter>
107 <parameter name="menu">
108 <para>The name of the DTMF menu in confbridge.conf to be applied to
109 this channel. When left blank, a dynamically built menu profile
110 created by the CONFBRIDGE dialplan function is searched for on
111 the channel and used. If no dynamic profile is present, the
112 'default_menu' profile found in confbridge.conf is used.</para>
113 </parameter>
114 </syntax>
115 <description>
116 <para>Enters the user into a specified conference bridge. The user can
117 exit the conference by hangup or DTMF menu option.</para>
118 <para>This application sets the following channel variable upon completion:</para>
119 <variablelist>
120 <variable name="CONFBRIDGE_RESULT">
121 <value name="FAILED">The channel encountered an error and could not enter the conference.</value>
122 <value name="HANGUP">The channel exited the conference by hanging up.</value>
123 <value name="KICKED">The channel was kicked from the conference.</value>
124 <value name="ENDMARKED">The channel left the conference as a result of the last marked user leaving.</value>
125 <value name="DTMF">The channel pressed a DTMF sequence to exit the conference.</value>
126 <value name="TIMEOUT">The channel reached its configured timeout.</value>
127 </variable>
128 </variablelist>
129 </description>
130 <see-also>
131 <ref type="application">ConfKick</ref>
132 <ref type="function">CONFBRIDGE</ref>
133 <ref type="function">CONFBRIDGE_INFO</ref>
134 <ref type="function">CONFBRIDGE_CHANNELS</ref>
135 </see-also>
136 </application>
137 <application name="ConfKick" language="en_US">
138 <since>
139 <version>16.19.0</version>
140 <version>18.5.0</version>
141 </since>
142 <synopsis>
143 Kicks channel(s) from the requested ConfBridge.
144 </synopsis>
145 <syntax>
146 <parameter name="conference" required="true" />
147 <parameter name="channel">
148 <para>The channel to kick, <literal>all</literal>
149 to kick all users, or <literal>participants</literal>
150 to kick all non-admin participants. Default is all.</para>
151 </parameter>
152 </syntax>
153 <description>
154 <para>Kicks the requested channel(s) from a conference bridge.</para>
155 <variablelist>
156 <variable name="CONFKICKSTATUS">
157 <value name="FAILURE">
158 Could not kick any users with the provided arguments.
159 </value>
160 <value name="SUCCESS">
161 Successfully kicked users from specified conference bridge.
162 </value>
163 </variable>
164 </variablelist>
165 </description>
166 <see-also>
167 <ref type="application">ConfBridge</ref>
168 <ref type="function">CONFBRIDGE</ref>
169 <ref type="function">CONFBRIDGE_INFO</ref>
170 <ref type="function">CONFBRIDGE_CHANNELS</ref>
171 </see-also>
172 </application>
173 <function name="CONFBRIDGE" language="en_US">
174 <since>
175 <version>10.0.0</version>
176 </since>
177 <synopsis>
178 Set a custom dynamic bridge, user, or menu profile on a channel for the
179 ConfBridge application using the same options available in confbridge.conf.
180 </synopsis>
181 <syntax>
182 <parameter name="type" required="true">
183 <para>To what type of conference profile the option applies.</para>
184 <enumlist>
185 <enum name="bridge"></enum>
186 <enum name="menu"></enum>
187 <enum name="user"></enum>
188 </enumlist>
189 </parameter>
190 <parameter name="option" required="true">
191 <para>Option refers to a <filename>confbridge.conf</filename> option
192 that is being set dynamically on this channel, or <literal>clear</literal>
193 to remove already applied profile options from the channel.</para>
194 </parameter>
195 </syntax>
196 <description>
197 <para>A custom profile uses the default profile type settings defined in
198 <filename>confbridge.conf</filename> as defaults if the profile template
199 is not explicitly specified first.</para>
200 <para>For <literal>bridge</literal> profiles the default template is <literal>default_bridge</literal>.</para>
201 <para>For <literal>menu</literal> profiles the default template is <literal>default_menu</literal>.</para>
202 <para>For <literal>user</literal> profiles the default template is <literal>default_user</literal>.</para>
203 <para>---- Example 1 ----</para>
204 <para>In this example the custom user profile set on the channel will
205 automatically be used by the ConfBridge application.</para>
206 <example title="Example 1">
207 exten => 1,1,Answer()
208 </example>
209 <para>; In this example the effect of the following line is</para>
210 <para>; implied:</para>
211 <example title="Example 1b">
212 same => n,Set(CONFBRIDGE(user,template)=default_user)
213 same => n,Set(CONFBRIDGE(user,announce_join_leave)=yes)
214 same => n,Set(CONFBRIDGE(user,startmuted)=yes)
215 same => n,ConfBridge(1)
216 </example>
217 <para>---- Example 2 ----</para>
218 <para>This example shows how to use a predefined user profile in
219 <filename>confbridge.conf</filename> as a template for a dynamic profile.
220 Here we make an admin/marked user out of the <literal>my_user</literal>
221 profile that you define in <filename>confbridge.conf</filename>.</para>
222 <example title="Example 2">
223 exten => 1,1,Answer()
224 same => n,Set(CONFBRIDGE(user,template)=my_user)
225 same => n,Set(CONFBRIDGE(user,admin)=yes)
226 same => n,Set(CONFBRIDGE(user,marked)=yes)
227 same => n,ConfBridge(1)
228 </example>
229 </description>
230 </function>
231 <function name="CONFBRIDGE_INFO" language="en_US">
232 <since>
233 <version>10.0.0</version>
234 </since>
235 <synopsis>
236 Get information about a ConfBridge conference.
237 </synopsis>
238 <syntax>
239 <parameter name="type" required="true">
240 <para>What conference information is requested.</para>
241 <enumlist>
242 <enum name="admins">
243 <para>Get the number of admin users in the conference.</para>
244 </enum>
245 <enum name="locked">
246 <para>Determine if the conference is locked. (0 or 1)</para>
247 </enum>
248 <enum name="marked">
249 <para>Get the number of marked users in the conference.</para>
250 </enum>
251 <enum name="muted">
252 <para>Determine if the conference is muted. (0 or 1)</para>
253 </enum>
254 <enum name="parties">
255 <para>Get the number of users in the conference.</para>
256 </enum>
257 </enumlist>
258 </parameter>
259 <parameter name="conf" required="true">
260 <para>The name of the conference being referenced.</para>
261 </parameter>
262 </syntax>
263 <description>
264 <para>This function returns a non-negative integer for valid conference
265 names and an empty string for invalid conference names.</para>
266 </description>
267 <see-also>
268 <ref type="function">CONFBRIDGE_CHANNELS</ref>
269 </see-also>
270 </function>
271 <function name="CONFBRIDGE_CHANNELS" language="en_US">
272 <since>
273 <version>16.27.0</version>
274 <version>18.13.0</version>
275 <version>19.5.0</version>
276 </since>
277 <synopsis>
278 Get a list of channels in a ConfBridge conference.
279 </synopsis>
280 <syntax>
281 <parameter name="type" required="true">
282 <para>What conference information is requested.</para>
283 <enumlist>
284 <enum name="admins">
285 <para>Get the number of admin users in the conference.</para>
286 </enum>
287 <enum name="marked">
288 <para>Get the number of marked users in the conference.</para>
289 </enum>
290 <enum name="parties">
291 <para>Get the number of total users in the conference.</para>
292 </enum>
293 <enum name="active">
294 <para>Get the number of active users in the conference.</para>
295 </enum>
296 <enum name="waiting">
297 <para>Get the number of waiting users in the conference.</para>
298 </enum>
299 </enumlist>
300 </parameter>
301 <parameter name="conf" required="true">
302 <para>The name of the conference being referenced.</para>
303 </parameter>
304 </syntax>
305 <description>
306 <para>This function returns a comma-separated list of channels in a ConfBridge conference, optionally filtered by a type of participant.</para>
307 </description>
308 <see-also>
309 <ref type="function">CONFBRIDGE_INFO</ref>
310 </see-also>
311 </function>
312 <manager name="ConfbridgeList" language="en_US">
313 <since>
314 <version>10.0.0</version>
315 </since>
316 <synopsis>
317 List participants in a conference.
318 </synopsis>
319 <syntax>
320 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
321 <parameter name="Conference" required="true">
322 <para>Conference number.</para>
323 </parameter>
324 </syntax>
325 <description>
326 <para>Lists all users in a particular ConfBridge conference.
327 ConfbridgeList will follow as separate events, followed by a final event called
328 ConfbridgeListComplete.</para>
329 </description>
330 </manager>
331 <managerEvent language="en_US" name="ConfbridgeList">
332 <managerEventInstance class="EVENT_FLAG_REPORTING">
333 <since>
334 <version>13.20.0</version>
335 <version>15.3.0</version>
336 </since>
337 <synopsis>Raised as part of the ConfbridgeList action response list.</synopsis>
338 <syntax>
339 <parameter name="Conference">
340 <para>The name of the Confbridge conference.</para>
341 </parameter>
342 <parameter name="Admin">
343 <para>Identifies this user as an admin user.</para>
344 <enumlist>
345 <enum name="Yes"/>
346 <enum name="No"/>
347 </enumlist>
348 </parameter>
349 <parameter name="MarkedUser">
350 <para>Identifies this user as a marked user.</para>
351 <enumlist>
352 <enum name="Yes"/>
353 <enum name="No"/>
354 </enumlist>
355 </parameter>
356 <parameter name="WaitMarked">
357 <para>Must this user wait for a marked user to join?</para>
358 <enumlist>
359 <enum name="Yes"/>
360 <enum name="No"/>
361 </enumlist>
362 </parameter>
363 <parameter name="EndMarked">
364 <para>Does this user get kicked after the last marked user leaves?</para>
365 <enumlist>
366 <enum name="Yes"/>
367 <enum name="No"/>
368 </enumlist>
369 </parameter>
370 <parameter name="Waiting">
371 <para>Is this user waiting for a marked user to join?</para>
372 <enumlist>
373 <enum name="Yes"/>
374 <enum name="No"/>
375 </enumlist>
376 </parameter>
377 <parameter name="Muted">
378 <para>The current mute status.</para>
379 <enumlist>
380 <enum name="Yes"/>
381 <enum name="No"/>
382 </enumlist>
383 </parameter>
384 <parameter name="Talking">
385 <para>Is this user talking?</para>
386 <enumlist>
387 <enum name="Yes"/>
388 <enum name="No"/>
389 </enumlist>
390 </parameter>
391 <parameter name="AnsweredTime">
392 <para>The number of seconds the channel has been up.</para>
393 </parameter>
394 <channel_snapshot/>
395 </syntax>
396 </managerEventInstance>
397 </managerEvent>
398 <manager name="ConfbridgeListRooms" language="en_US">
399 <since>
400 <version>10.0.0</version>
401 </since>
402 <synopsis>
403 List active conferences.
404 </synopsis>
405 <syntax>
406 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
407 </syntax>
408 <description>
409 <para>Lists data about all active conferences.
410 ConfbridgeListRooms will follow as separate events, followed by a final event called
411 ConfbridgeListRoomsComplete.</para>
412 </description>
413 </manager>
414 <managerEvent language="en_US" name="ConfbridgeListRooms">
415 <managerEventInstance class="EVENT_FLAG_REPORTING">
416 <since>
417 <version>16.29.0</version>
418 <version>18.15.0</version>
419 <version>19.7.0</version>
420 </since>
421 <synopsis>Raised as part of the ConfbridgeListRooms action response list.</synopsis>
422 <syntax>
423 <parameter name="Conference">
424 <para>The name of the Confbridge conference.</para>
425 </parameter>
426 <parameter name="Parties">
427 <para>Number of users in the conference.</para>
428 <para>This includes both active and waiting users.</para>
429 </parameter>
430 <parameter name="Marked">
431 <para>Number of marked users in the conference.</para>
432 </parameter>
433 <parameter name="Locked">
434 <para>Is the conference locked?</para>
435 <enumlist>
436 <enum name="Yes"/>
437 <enum name="No"/>
438 </enumlist>
439 </parameter>
440 <parameter name="Muted">
441 <para>Is the conference muted?</para>
442 <enumlist>
443 <enum name="Yes"/>
444 <enum name="No"/>
445 </enumlist>
446 </parameter>
447 </syntax>
448 </managerEventInstance>
449 </managerEvent>
450 <manager name="ConfbridgeMute" language="en_US">
451 <since>
452 <version>10.0.0</version>
453 </since>
454 <synopsis>
455 Mute a Confbridge user.
456 </synopsis>
457 <syntax>
458 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
459 <parameter name="Conference" required="true" />
460 <parameter name="Channel" required="true">
461 <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
462 <para>If this parameter is "all", all channels will be muted.</para>
463 <para>If this parameter is "participants", all non-admin channels will be muted.</para>
464 </parameter>
465 </syntax>
466 <description>
467 </description>
468 </manager>
469 <manager name="ConfbridgeUnmute" language="en_US">
470 <since>
471 <version>10.0.0</version>
472 </since>
473 <synopsis>
474 Unmute a Confbridge user.
475 </synopsis>
476 <syntax>
477 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
478 <parameter name="Conference" required="true" />
479 <parameter name="Channel" required="true">
480 <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
481 <para>If this parameter is "all", all channels will be unmuted.</para>
482 <para>If this parameter is "participants", all non-admin channels will be unmuted.</para>
483 </parameter>
484 </syntax>
485 <description>
486 </description>
487 </manager>
488 <manager name="ConfbridgeKick" language="en_US">
489 <since>
490 <version>10.0.0</version>
491 </since>
492 <synopsis>
493 Kick a Confbridge user.
494 </synopsis>
495 <syntax>
496 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
497 <parameter name="Conference" required="true" />
498 <parameter name="Channel" required="true" >
499 <para>If this parameter is "all", all channels will be kicked from the conference.</para>
500 <para>If this parameter is "participants", all non-admin channels will be kicked from the conference.</para>
501 </parameter>
502 </syntax>
503 <description>
504 </description>
505 </manager>
506 <manager name="ConfbridgeLock" language="en_US">
507 <since>
508 <version>10.0.0</version>
509 </since>
510 <synopsis>
511 Lock a Confbridge conference.
512 </synopsis>
513 <syntax>
514 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
515 <parameter name="Conference" required="true" />
516 </syntax>
517 <description>
518 </description>
519 </manager>
520 <manager name="ConfbridgeUnlock" language="en_US">
521 <since>
522 <version>10.0.0</version>
523 </since>
524 <synopsis>
525 Unlock a Confbridge conference.
526 </synopsis>
527 <syntax>
528 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
529 <parameter name="Conference" required="true" />
530 </syntax>
531 <description>
532 </description>
533 </manager>
534 <manager name="ConfbridgeStartRecord" language="en_US">
535 <since>
536 <version>10.0.0</version>
537 </since>
538 <synopsis>
539 Start recording a Confbridge conference.
540 </synopsis>
541 <syntax>
542 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
543 <parameter name="Conference" required="true" />
544 <parameter name="RecordFile" required="false" />
545 </syntax>
546 <description>
547 <para>Start recording a conference. If recording is already present an error will be returned. If RecordFile is not provided, the default record file specified in the conference's bridge profile will be used, if that is not present either a file will automatically be generated in the monitor directory.</para>
548 </description>
549 </manager>
550 <manager name="ConfbridgeStopRecord" language="en_US">
551 <since>
552 <version>10.0.0</version>
553 </since>
554 <synopsis>
555 Stop recording a Confbridge conference.
556 </synopsis>
557 <syntax>
558 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
559 <parameter name="Conference" required="true" />
560 </syntax>
561 <description>
562 </description>
563 </manager>
564 <manager name="ConfbridgeSetSingleVideoSrc" language="en_US">
565 <since>
566 <version>10.0.0</version>
567 </since>
568 <synopsis>
569 Set a conference user as the single video source distributed to all other participants.
570 </synopsis>
571 <syntax>
572 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
573 <parameter name="Conference" required="true" />
574 <parameter name="Channel" required="true">
575 <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
576 </parameter>
577 </syntax>
578 <description>
579 </description>
580 </manager>
581
582 ***/
583
584 /*!
585 * \par Playing back a file to a channel in a conference
586 * You might notice in this application that while playing a sound file
587 * to a channel the actual conference bridge lock is not held. This is done so
588 * that other channels are not blocked from interacting with the conference bridge.
589 * Unfortunately because of this it is possible for things to change after the sound file
590 * is done being played. Data must therefore be checked after reacquiring the conference
591 * bridge lock if it is important.
592 */
593
594 static const char app[] = "ConfBridge";
595 static const char app2[] = "ConfKick";
596
597 /*! Number of buckets our conference bridges container can have */
598 #define CONFERENCE_BRIDGE_BUCKETS 53
599
600 /*! Initial recording filename space. */
601 #define RECORD_FILENAME_INITIAL_SPACE 128
602
603 /*! \brief Container to hold all conference bridges in progress */
604 struct ao2_container *conference_bridges;
605
606 static void leave_conference(struct confbridge_user *user);
607 static int play_sound_number(struct confbridge_conference *conference, int say_number);
608 static int execute_menu_entry(struct confbridge_conference *conference,
609 struct confbridge_user *user,
610 struct ast_bridge_channel *bridge_channel,
611 struct conf_menu_entry *menu_entry,
612 struct conf_menu *menu);
613
614 /*! \brief Hashing function used for conference bridges container */
615 static int conference_bridge_hash_cb(const void *obj, const int flags)
616 {
617 const struct confbridge_conference *conference = obj;
618 const char *name = obj;
619 int hash;
620
621 switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
622 default:
623 case OBJ_POINTER:
624 name = conference->name;
625 /* Fall through */
626 case OBJ_KEY:
627 hash = ast_str_case_hash(name);
628 break;
629 case OBJ_PARTIAL_KEY:
630 /* Should never happen in hash callback. */
631 ast_assert(0);
632 hash = 0;
633 break;
634 }
635 return hash;
636 }
637
638 /*! \brief Comparison function used for conference bridges container */
639 static int conference_bridge_cmp_cb(void *obj, void *arg, int flags)
640 {
641 const struct confbridge_conference *left = obj;
642 const struct confbridge_conference *right = arg;
643 const char *right_name = arg;
644 int cmp;
645
646 switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
647 default:
648 case OBJ_POINTER:
649 right_name = right->name;
650 /* Fall through */
651 case OBJ_KEY:
652 cmp = strcasecmp(left->name, right_name);
653 break;
654 case OBJ_PARTIAL_KEY:
655 cmp = strncasecmp(left->name, right_name, strlen(right_name));
656 break;
657 }
658 return cmp ? 0 : CMP_MATCH;
659 }
660
661 const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds)
662 {
663 switch (sound) {
664 case CONF_SOUND_HAS_JOINED:
665 return S_OR(custom_sounds->hasjoin, "conf-hasjoin");
666 case CONF_SOUND_HAS_LEFT:
667 return S_OR(custom_sounds->hasleft, "conf-hasleft");
668 case CONF_SOUND_KICKED:
669 return S_OR(custom_sounds->kicked, "conf-kicked");
670 case CONF_SOUND_MUTED:
671 return S_OR(custom_sounds->muted, "conf-muted");
672 case CONF_SOUND_UNMUTED:
673 return S_OR(custom_sounds->unmuted, "conf-unmuted");
674 case CONF_SOUND_BINAURAL_ON:
675 return S_OR(custom_sounds->binauralon, "confbridge-binaural-on");
676 case CONF_SOUND_BINAURAL_OFF:
677 return S_OR(custom_sounds->binauraloff, "confbridge-binaural-off");
678 case CONF_SOUND_ONLY_ONE:
679 return S_OR(custom_sounds->onlyone, "conf-onlyone");
680 case CONF_SOUND_THERE_ARE:
681 return S_OR(custom_sounds->thereare, "conf-thereare");
682 case CONF_SOUND_OTHER_IN_PARTY:
683 return S_OR(custom_sounds->otherinparty, "conf-otherinparty");
684 case CONF_SOUND_PLACE_IN_CONF:
685 return S_OR(custom_sounds->placeintoconf, "conf-placeintoconf");
686 case CONF_SOUND_WAIT_FOR_LEADER:
687 return S_OR(custom_sounds->waitforleader, "conf-waitforleader");
688 case CONF_SOUND_LEADER_HAS_LEFT:
689 return S_OR(custom_sounds->leaderhasleft, "conf-leaderhasleft");
690 case CONF_SOUND_GET_PIN:
691 return S_OR(custom_sounds->getpin, "conf-getpin");
692 case CONF_SOUND_INVALID_PIN:
693 return S_OR(custom_sounds->invalidpin, "conf-invalidpin");
694 case CONF_SOUND_ONLY_PERSON:
695 return S_OR(custom_sounds->onlyperson, "conf-onlyperson");
696 case CONF_SOUND_LOCKED:
697 return S_OR(custom_sounds->locked, "conf-locked");
698 case CONF_SOUND_LOCKED_NOW:
699 return S_OR(custom_sounds->lockednow, "conf-lockednow");
700 case CONF_SOUND_UNLOCKED_NOW:
701 return S_OR(custom_sounds->unlockednow, "conf-unlockednow");
702 case CONF_SOUND_ERROR_MENU:
703 return S_OR(custom_sounds->errormenu, "conf-errormenu");
704 case CONF_SOUND_JOIN:
705 return S_OR(custom_sounds->join, "confbridge-join");
706 case CONF_SOUND_LEAVE:
707 return S_OR(custom_sounds->leave, "confbridge-leave");
708 case CONF_SOUND_PARTICIPANTS_MUTED:
709 return S_OR(custom_sounds->participantsmuted, "conf-now-muted");
710 case CONF_SOUND_PARTICIPANTS_UNMUTED:
711 return S_OR(custom_sounds->participantsunmuted, "conf-now-unmuted");
712 case CONF_SOUND_BEGIN:
713 return S_OR(custom_sounds->begin, "confbridge-conf-begin");
714 }
715
716 return "";
717 }
718
719
720 static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan,
721 struct stasis_message_type *type, struct ast_json *extras, int channel_topic)
722 {
723 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
724 RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
725
726 json_object = ast_json_pack("{s: s}",
727 "conference", conference->name);
728 if (!json_object) {
729 return;
730 }
731
732 if (extras) {
733 ast_json_object_update(json_object, extras);
734 }
735
736 ast_bridge_lock(conference->bridge);
737 msg = ast_bridge_blob_create(type,
738 conference->bridge,
739 chan,
740 json_object);
741 ast_bridge_unlock(conference->bridge);
742 if (!msg) {
743 return;
744 }
745
746 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_ENABLE_EVENTS)) {
747 conf_send_event_to_participants(conference, chan, msg);
748 }
749
750 if (channel_topic) {
751 stasis_publish(ast_channel_topic(chan), msg);
752 } else {
753 stasis_publish(ast_bridge_topic(conference->bridge), msg);
754 }
755 }
756
757 static void send_conf_stasis_snapshots(struct confbridge_conference *conference,
758 struct ast_channel_snapshot *chan_snapshot, struct stasis_message_type *type,
759 struct ast_json *extras)
760 {
761 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
762 RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
763 RAII_VAR(struct ast_bridge_snapshot *, bridge_snapshot, NULL, ao2_cleanup);
764
765 json_object = ast_json_pack("{s: s}",
766 "conference", conference->name);
767 if (!json_object) {
768 return;
769 }
770
771 if (extras) {
772 ast_json_object_update(json_object, extras);
773 }
774
775 ast_bridge_lock(conference->bridge);
776 bridge_snapshot = ast_bridge_snapshot_create(conference->bridge);
777 ast_bridge_unlock(conference->bridge);
778 if (!bridge_snapshot) {
779 return;
780 }
781
782 msg = ast_bridge_blob_create_from_snapshots(type,
783 bridge_snapshot,
784 chan_snapshot,
785 json_object);
786 if (!msg) {
787 return;
788 }
789
790 stasis_publish(ast_bridge_topic(conference->bridge), msg);
791 }
792
793
794 static void send_conf_start_event(struct confbridge_conference *conference)
795 {
796 send_conf_stasis(conference, NULL, confbridge_start_type(), NULL, 0);
797 }
798
799 static void send_conf_end_event(struct confbridge_conference *conference)
800 {
801 send_conf_stasis(conference, NULL, confbridge_end_type(), NULL, 0);
802 }
803
804 static void send_join_event(struct confbridge_user *user, struct confbridge_conference *conference)
805 {
806 struct ast_json *json_object;
807
808 json_object = ast_json_pack("{s: b, s: b}",
809 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN),
810 "muted", user->muted);
811 if (!json_object) {
812 return;
813 }
814 send_conf_stasis(conference, user->chan, confbridge_join_type(), json_object, 0);
815 ast_json_unref(json_object);
816 }
817
818 static void send_leave_event(struct confbridge_user *user, struct confbridge_conference *conference)
819 {
820 struct ast_json *json_object;
821
822 json_object = ast_json_pack("{s: b}",
823 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
824 );
825 if (!json_object) {
826 return;
827 }
828 send_conf_stasis(conference, user->chan, confbridge_leave_type(), json_object, 0);
829 ast_json_unref(json_object);
830 }
831
832 static void send_start_record_event(struct confbridge_conference *conference)
833 {
834 send_conf_stasis(conference, NULL, confbridge_start_record_type(), NULL, 0);
835 }
836
837 static void send_stop_record_event(struct confbridge_conference *conference)
838 {
839 send_conf_stasis(conference, NULL, confbridge_stop_record_type(), NULL, 0);
840 }
841
842 static void send_mute_event(struct confbridge_user *user, struct confbridge_conference *conference)
843 {
844 struct ast_json *json_object;
845
846 json_object = ast_json_pack("{s: b}",
847 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
848 );
849 if (!json_object) {
850 return;
851 }
852 send_conf_stasis(conference, user->chan, confbridge_mute_type(), json_object, 1);
853 ast_json_unref(json_object);
854 }
855
856 static void send_unmute_event(struct confbridge_user *user, struct confbridge_conference *conference)
857 {
858 struct ast_json *json_object;
859
860 json_object = ast_json_pack("{s: b}",
861 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
862 );
863 if (!json_object) {
864 return;
865 }
866 send_conf_stasis(conference, user->chan, confbridge_unmute_type(), json_object, 1);
867 ast_json_unref(json_object);
868 }
869
870 static void set_rec_filename(struct confbridge_conference *conference, struct ast_str **filename, int is_new)
871 {
872 char *rec_file = conference->b_profile.rec_file;
873 char *ext;
874 time_t now;
875
876 if (ast_str_strlen(*filename)
877 && ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND)
878 && !is_new) {
879 return;
880 }
881
882 time(&now);
883
884 ast_str_reset(*filename);
885 if (ast_strlen_zero(rec_file)) {
886 ast_str_set(filename, 0, "confbridge-%s-%u.wav", conference->name,
887 (unsigned int) now);
888 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_TIMESTAMP)) {
889 /* insert time before file extension */
890 ext = strrchr(rec_file, '.');
891 if (ext) {
892 ast_str_set_substr(filename, 0, rec_file, ext - rec_file);
893 ast_str_append(filename, 0, "-%u%s", (unsigned int) now, ext);
894 } else {
895 ast_str_set(filename, 0, "%s-%u", rec_file, (unsigned int) now);
896 }
897 } else {
898 ast_str_set(filename, 0, "%s", rec_file);
899 }
900 ast_str_append(filename, 0, ",%s%s,%s",
901 ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND) ? "a" : "",
902 conference->b_profile.rec_options,
903 conference->b_profile.rec_command);
904 }
905
906 static int is_new_rec_file(const char *rec_file, struct ast_str **orig_rec_file)
907 {
908 if (!ast_strlen_zero(rec_file)) {
909 if (!*orig_rec_file) {
910 *orig_rec_file = ast_str_create(RECORD_FILENAME_INITIAL_SPACE);
911 }
912
913 if (*orig_rec_file
914 && strcmp(ast_str_buffer(*orig_rec_file), rec_file)) {
915 ast_str_set(orig_rec_file, 0, "%s", rec_file);
916 return 1;
917 }
918 }
919 return 0;
920 }
921
922 struct confbridge_conference *conf_find_bridge(const char *conference_name)
923 {
924 return ao2_find(conference_bridges, conference_name, OBJ_KEY);
925 }
926
927 /*!
928 * \internal
929 * \brief Returns whether or not conference is being recorded.
930 *
931 * \param conference The bridge to check for recording
932 *
933 * \note Must be called with the conference locked
934 *
935 * \retval 1 conference is recording.
936 * \retval 0 conference is NOT recording.
937 */
938 static int conf_is_recording(struct confbridge_conference *conference)
939 {
940 return conference->record_chan != NULL;
941 }
942
943 /*!
944 * \internal
945 * \brief Stop recording a conference bridge
946 *
947 * \param conference The conference bridge on which to stop the recording
948 *
949 * \note Must be called with the conference locked
950 *
951 * \retval -1 Failure
952 * \retval 0 Success
953 */
954 static int conf_stop_record(struct confbridge_conference *conference)
955 {
956 struct ast_channel *chan;
957 struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
958
959 if (!conf_is_recording(conference)) {
960 return -1;
961 }
962
963 /* Remove the recording channel from the conference bridge. */
964 chan = conference->record_chan;
965 conference->record_chan = NULL;
966 ast_queue_frame(chan, &f);
967 ast_channel_unref(chan);
968
969 ast_test_suite_event_notify("CONF_STOP_RECORD", "Message: stopped conference recording channel\r\nConference: %s", conference->b_profile.name);
970 send_stop_record_event(conference);
971
972 return 0;
973 }
974
975 /*!
976 * \internal
977 * \brief Start recording the conference
978 *
979 * \param conference The conference bridge to start recording
980 *
981 * \note Must be called with the conference locked
982 *
983 * \retval 0 success
984 * \retval non-zero failure
985 */
986 static int conf_start_record(struct confbridge_conference *conference)
987 {
988 struct ast_app *mixmonapp;
989 struct ast_channel *chan;
990 struct ast_format_cap *cap;
991 struct ast_bridge_features *features;
992
993 if (conf_is_recording(conference)) {
994 return -1;
995 }
996
997 mixmonapp = pbx_findapp("MixMonitor");
998 if (!mixmonapp) {
999 ast_log(LOG_WARNING, "Cannot record ConfBridge, MixMonitor app is not installed\n");
1000 return -1;
1001 }
1002
1003 features = ast_bridge_features_new();
1004 if (!features) {
1005 return -1;
1006 }
1007 ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE);
1008
1009 cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
1010 if (!cap) {
1011 ast_bridge_features_destroy(features);
1012 return -1;
1013 }
1014 ast_format_cap_append(cap, ast_format_slin, 0);
1015
1016 /* Create the recording channel. */
1017 chan = ast_request("CBRec", cap, NULL, NULL, conference->name, NULL);
1018 ao2_ref(cap, -1);
1019 if (!chan) {
1020 ast_bridge_features_destroy(features);
1021 return -1;
1022 }
1023
1024 /* Start recording. */
1025 set_rec_filename(conference, &conference->record_filename,
1026 is_new_rec_file(conference->b_profile.rec_file, &conference->orig_rec_file));
1027 ast_answer(chan);
1028 pbx_exec(chan, mixmonapp, ast_str_buffer(conference->record_filename));
1029
1030 /* Put the channel into the conference bridge. */
1031 ast_channel_ref(chan);
1032 conference->record_chan = chan;
1033 if (ast_bridge_impart(conference->bridge, chan, NULL, features,
1034 AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
1035 ast_hangup(chan);
1036 ast_channel_unref(chan);
1037 conference->record_chan = NULL;
1038 return -1;
1039 }
1040
1041 ast_test_suite_event_notify("CONF_START_RECORD", "Message: started conference recording channel\r\nConference: %s", conference->b_profile.name);
1042 send_start_record_event(conference);
1043
1044 return 0;
1045 }
1046
1047 /*! \brief Playback the given filename and monitor for any dtmf interrupts.
1048 *
1049 * This function is used to playback sound files on a given channel and optionally
1050 * allow dtmf interrupts to occur.
1051 *
1052 * If the optional bridge_channel parameter is given then sound file playback
1053 * is played on that channel and dtmf interruptions are allowed. However, if
1054 * bridge_channel is not set then the channel parameter is expected to be set
1055 * instead and non interruptible playback is played on that channel.
1056 *
1057 * \param bridge_channel Bridge channel to play file on
1058 * \param channel Optional channel to play file on if bridge_channel not given
1059 * \param filename The file name to playback
1060 *
1061 * \retval -1 failure during playback.
1062 * \retval 0 on file was fully played.
1063 * \retval 1 on dtmf interrupt.
1064 */
1065 static int play_file(struct ast_bridge_channel *bridge_channel, struct ast_channel *channel,
1066 const char *filename)
1067 {
1068 struct ast_channel *chan;
1069 const char *stop_digits;
1070 int digit;
1071
1072 if (bridge_channel) {
1073 chan = bridge_channel->chan;
1074 stop_digits = AST_DIGIT_ANY;
1075 } else {
1076 chan = channel;
1077 stop_digits = AST_DIGIT_NONE;
1078 }
1079
1080 digit = ast_stream_and_wait(chan, filename, stop_digits);
1081 if (digit < 0) {
1082 ast_log(LOG_WARNING, "Failed to playback file '%s' to channel\n", filename);
1083 return -1;
1084 }
1085
1086 if (digit > 0) {
1087 ast_stopstream(bridge_channel->chan);
1088 ast_bridge_channel_feature_digit_add(bridge_channel, digit);
1089 return 1;
1090 }
1091
1092 return 0;
1093 }
1094
1095 /*!
1096 * \internal
1097 * \brief Complain if the given sound file does not exist.
1098 *
1099 * \param filename Sound file to check if exists.
1100 *
1101 * \retval non-zero if the file exists.
1102 */
1103 static int sound_file_exists(const char *filename)
1104 {
1105 if (ast_fileexists(filename, NULL, NULL)) {
1106 return -1;
1107 }
1108 ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename);
1109 return 0;
1110 }
1111
1112 /*!
1113 * \brief Announce number of users in the conference bridge to the caller
1114 *
1115 * \param conference Conference bridge to peek at
1116 * \param user Optional Caller
1117 * \param bridge_channel The bridged channel involved
1118 *
1119 * \note if caller is NULL, the announcement will be sent to all participants in the conference.
1120 * \retval 0 on success.
1121 * \retval -1 if the user hung up.
1122 */
1123 static int announce_user_count(struct confbridge_conference *conference, struct confbridge_user *user,
1124 struct ast_bridge_channel *bridge_channel)
1125 {
1126 const char *other_in_party = conf_get_sound(CONF_SOUND_OTHER_IN_PARTY, conference->b_profile.sounds);
1127 const char *only_one = conf_get_sound(CONF_SOUND_ONLY_ONE, conference->b_profile.sounds);
1128 const char *there_are = conf_get_sound(CONF_SOUND_THERE_ARE, conference->b_profile.sounds);
1129
1130 if (conference->activeusers <= 1) {
1131 /* Awww we are the only person in the conference bridge OR we only have waitmarked users */
1132 return 0;
1133 } else if (conference->activeusers == 2) {
1134 if (user) {
1135 /* Eep, there is one other person */
1136 if (play_file(bridge_channel, user->chan, only_one) < 0) {
1137 return -1;
1138 }
1139 } else {
1140 play_sound_file(conference, only_one);
1141 }
1142 } else {
1143 /* Alas multiple others in here */
1144 if (user) {
1145 if (ast_stream_and_wait(user->chan,
1146 there_are,
1147 "")) {
1148 return -1;
1149 }
1150 if (ast_say_number(user->chan, conference->activeusers - 1, "", ast_channel_language(user->chan), NULL)) {
1151 return -1;
1152 }
1153 if (play_file(bridge_channel, user->chan, other_in_party) < 0) {
1154 return -1;
1155 }
1156 } else if (sound_file_exists(there_are) && sound_file_exists(other_in_party)) {
1157 play_sound_file(conference, there_are);
1158 play_sound_number(conference, conference->activeusers - 1);
1159 play_sound_file(conference, other_in_party);
1160 }
1161 }
1162 return 0;
1163 }
1164
1165 /*!
1166 * \brief Play back an audio file to a channel
1167 *
1168 * \param user User to play audio prompt to
1169 * \param filename Prompt to play
1170 *
1171 * \retval 0 on success.
1172 * \retval -1 if the user hung up.
1173 *
1174 * \note Generally this should be called when the conference is unlocked to avoid blocking
1175 * the entire conference while the sound is played. But don't unlock the conference bridge
1176 * in the middle of a state transition.
1177 */
1178 static int play_prompt_to_user(struct confbridge_user *user, const char *filename)
1179 {
1180 return ast_stream_and_wait(user->chan, filename, "");
1181 }
1182
1183 static void handle_video_on_join(struct confbridge_conference *conference, struct ast_channel *chan, int marked)
1184 {
1185 /* Right now, only marked users are automatically set as the single src of video.*/
1186 if (!marked) {
1187 return;
1188 }
1189
1190 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED)) {
1191 int set = 1;
1192 struct confbridge_user *user = NULL;
1193
1194 ao2_lock(conference);
1195 /* see if anyone is already the video src */
1196 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
1197 if (user->chan == chan) {
1198 continue;
1199 }
1200 if (ast_bridge_is_video_src(conference->bridge, user->chan)) {
1201 set = 0;
1202 break;
1203 }
1204 }
1205 ao2_unlock(conference);
1206 if (set) {
1207 ast_bridge_set_single_src_video_mode(conference->bridge, chan);
1208 }
1209 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
1210 /* we joined and are video capable, we override anyone else that may have already been the video feed */
1211 ast_bridge_set_single_src_video_mode(conference->bridge, chan);
1212 }
1213 }
1214
1215 static void handle_video_on_exit(struct confbridge_conference *conference, struct ast_channel *chan)
1216 {
1217 struct confbridge_user *user = NULL;
1218
1219 /* if this isn't a video source, nothing to update */
1220 if (!ast_bridge_is_video_src(conference->bridge, chan)) {
1221 return;
1222 }
1223
1224 ast_bridge_remove_video_src(conference->bridge, chan);
1225
1226 /* If in follow talker mode, make sure to restore this mode on the
1227 * bridge when a source is removed. It is possible this channel was
1228 * only set temporarily as a video source by an AMI or DTMF action. */
1229 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
1230 ast_bridge_set_talker_src_video_mode(conference->bridge);
1231 }
1232
1233 /* if the video_mode isn't set to automatically pick the video source, do nothing on exit. */
1234 if (!ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED) &&
1235 !ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
1236 return;
1237 }
1238
1239 /* Make the next available marked user the video src. */
1240 ao2_lock(conference);
1241 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
1242 if (user->chan == chan) {
1243 continue;
1244 }
1245 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
1246 ast_bridge_set_single_src_video_mode(conference->bridge, user->chan);
1247 break;
1248 }
1249 }
1250 ao2_unlock(conference);
1251 }
1252
1253 struct hangup_data
1254 {
1255 struct confbridge_conference *conference;
1256 ast_mutex_t lock;
1257 ast_cond_t cond;
1258 int hungup;
1259 };
1260
1261 /*!
1262 * \brief Hang up the announcer channel
1263 *
1264 * This hangs up the announcer channel in the conference. This
1265 * runs in the playback queue taskprocessor since we do not want
1266 * to hang up the channel while it's trying to play an announcement.
1267 *
1268 * This task is performed synchronously, so there is no need to
1269 * perform any cleanup on the passed-in data.
1270 *
1271 * \param data A hangup_data structure
1272 * \return 0
1273 */
1274 static int hangup_playback(void *data)
1275 {
1276 struct hangup_data *hangup = data;
1277
1278 ast_autoservice_stop(hangup->conference->playback_chan);
1279
1280 ast_hangup(hangup->conference->playback_chan);
1281 hangup->conference->playback_chan = NULL;
1282
1283 ast_mutex_lock(&hangup->lock);
1284 hangup->hungup = 1;
1285 ast_cond_signal(&hangup->cond);
1286 ast_mutex_unlock(&hangup->lock);
1287
1288 return 0;
1289 }
1290
1291 static void hangup_data_init(struct hangup_data *hangup, struct confbridge_conference *conference)
1292 {
1293 ast_mutex_init(&hangup->lock);
1294 ast_cond_init(&hangup->cond, NULL);
1295
1296 hangup->conference = conference;
1297 hangup->hungup = 0;
1298 }
1299
1300 static void hangup_data_destroy(struct hangup_data *hangup)
1301 {
1302 ast_mutex_destroy(&hangup->lock);
1303 ast_cond_destroy(&hangup->cond);
1304 }
1305
1306 /*!
1307 * \brief Destroy a conference bridge
1308 *
1309 * \param obj The conference bridge object
1310 */
1311 static void destroy_conference_bridge(void *obj)
1312 {
1313 struct confbridge_conference *conference = obj;
1314
1315 ast_debug(1, "Destroying conference bridge '%s'\n", conference->name);
1316
1317 if (conference->playback_chan) {
1318 if (conference->playback_queue) {
1319 struct hangup_data hangup;
1320 hangup_data_init(&hangup, conference);
1321
1322 if (!ast_taskprocessor_push(conference->playback_queue, hangup_playback, &hangup)) {
1323 ast_mutex_lock(&hangup.lock);
1324 while (!hangup.hungup) {
1325 ast_cond_wait(&hangup.cond, &hangup.lock);
1326 }
1327 ast_mutex_unlock(&hangup.lock);
1328 }
1329
1330 hangup_data_destroy(&hangup);
1331 } else {
1332 /* Playback queue is not yet allocated. Just hang up the channel straight */
1333 ast_hangup(conference->playback_chan);
1334 conference->playback_chan = NULL;
1335 }
1336 }
1337
1338 /* Destroying a conference bridge is simple, all we have to do is destroy the bridging object */
1339 if (conference->bridge) {
1340 ast_bridge_destroy(conference->bridge, 0);
1341 conference->bridge = NULL;
1342 }
1343
1344 ast_channel_cleanup(conference->record_chan);
1345 ast_free(conference->orig_rec_file);
1346 ast_free(conference->record_filename);
1347
1348 conf_bridge_profile_destroy(&conference->b_profile);
1349 ast_taskprocessor_unreference(conference->playback_queue);
1350 }
1351
1352 /*! \brief Call the proper join event handler for the user for the conference bridge's current state
1353 * \internal
1354 * \param user The conference bridge user that is joining
1355 * \retval 0 success
1356 * \retval -1 failure
1357 */
1358 static int handle_conf_user_join(struct confbridge_user *user)
1359 {
1360 conference_event_fn handler;
1361 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
1362 handler = user->conference->state->join_marked;
1363 } else if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
1364 handler = user->conference->state->join_waitmarked;
1365 } else {
1366 handler = user->conference->state->join_unmarked;
1367 }
1368
1369 ast_assert(handler != NULL);
1370
1371 if (!handler) {
1372 conf_invalid_event_fn(user);
1373 return -1;
1374 }
1375
1376 handler(user);
1377
1378 return 0;
1379 }
1380
1381 /*! \brief Call the proper leave event handler for the user for the conference bridge's current state
1382 * \internal
1383 * \param user The conference bridge user that is leaving
1384 * \retval 0 success
1385 * \retval -1 failure
1386 */
1387 static int handle_conf_user_leave(struct confbridge_user *user)
1388 {
1389 conference_event_fn handler;
1390 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
1391 handler = user->conference->state->leave_marked;
1392 } else if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
1393 handler = user->conference->state->leave_waitmarked;
1394 } else {
1395 handler = user->conference->state->leave_unmarked;
1396 }
1397
1398 ast_assert(handler != NULL);
1399
1400 if (!handler) {
1401 /* This should never happen. If it does, though, it is bad. The user will not have been removed
1402 * from the appropriate list, so counts will be off and stuff. The conference won't be torn down, etc.
1403 * Shouldn't happen, though. */
1404 conf_invalid_event_fn(user);
1405 return -1;
1406 }
1407
1408 handler(user);
1409
1410 return 0;
1411 }
1412
1413 void conf_update_user_mute(struct confbridge_user *user)
1414 {
1415 int mute_user;
1416 int mute_system;
1417 int mute_effective;
1418
1419 /* User level mute request. */
1420 mute_user = user->muted;
1421
1422 /* System level mute request. */
1423 mute_system = user->playing_moh
1424 /*
1425 * Do not allow waitmarked users to talk to anyone unless there
1426 * is a marked user present.
1427 */
1428 || (!user->conference->markedusers
1429 && ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED));
1430
1431 mute_effective = mute_user || mute_system;
1432
1433 ast_debug(1, "User %s is %s: user:%d system:%d.\n",
1434 ast_channel_name(user->chan), mute_effective ? "muted" : "unmuted",
1435 mute_user, mute_system);
1436 user->features.mute = mute_effective;
1437 ast_test_suite_event_notify("CONF_MUTE_UPDATE",
1438 "Mode: %s\r\n"
1439 "Conference: %s\r\n"
1440 "Channel: %s",
1441 mute_effective ? "muted" : "unmuted",
1442 user->conference->b_profile.name,
1443 ast_channel_name(user->chan));
1444 }
1445
1446 /*!
1447 * \internal
1448 * \brief Mute/unmute a single user.
1449 */
1450 static void generic_mute_unmute_user(struct confbridge_conference *conference, struct confbridge_user *user, int mute)
1451 {
1452 /* Set user level mute request. */
1453 user->muted = mute ? 1 : 0;
1454
1455 conf_update_user_mute(user);
1456 ast_test_suite_event_notify("CONF_MUTE",
1457 "Message: participant %s %s\r\n"
1458 "Conference: %s\r\n"
1459 "Channel: %s",
1460 ast_channel_name(user->chan),
1461 mute ? "muted" : "unmuted",
1462 conference->b_profile.name,
1463 ast_channel_name(user->chan));
1464 if (mute) {
1465 send_mute_event(user, conference);
1466 } else {
1467 send_unmute_event(user, conference);
1468 }
1469 }
1470
1471 void conf_moh_stop(struct confbridge_user *user)
1472 {
1473 user->playing_moh = 0;
1474 if (!user->suspended_moh) {
1475 int in_bridge;
1476
1477 /*
1478 * Locking the ast_bridge here is the only way to hold off the
1479 * call to ast_bridge_join() in confbridge_exec() from
1480 * interfering with the bridge and MOH operations here.
1481 */
1482 ast_bridge_lock(user->conference->bridge);
1483
1484 /*
1485 * Temporarily suspend the user from the bridge so we have
1486 * control to stop MOH if needed.
1487 */
1488 in_bridge = !ast_bridge_suspend(user->conference->bridge, user->chan);
1489 ast_moh_stop(user->chan);
1490 if (in_bridge) {
1491 ast_bridge_unsuspend(user->conference->bridge, user->chan);
1492 }
1493
1494 ast_bridge_unlock(user->conference->bridge);
1495 }
1496 }
1497
1498 void conf_moh_start(struct confbridge_user *user)
1499 {
1500 user->playing_moh = 1;
1501 if (!user->suspended_moh) {
1502 int in_bridge;
1503
1504 /*
1505 * Locking the ast_bridge here is the only way to hold off the
1506 * call to ast_bridge_join() in confbridge_exec() from
1507 * interfering with the bridge and MOH operations here.
1508 */
1509 ast_bridge_lock(user->conference->bridge);
1510
1511 /*
1512 * Temporarily suspend the user from the bridge so we have
1513 * control to start MOH if needed.
1514 */
1515 in_bridge = !ast_bridge_suspend(user->conference->bridge, user->chan);
1516 ast_moh_start(user->chan, user->u_profile.moh_class, NULL);
1517 if (in_bridge) {
1518 ast_bridge_unsuspend(user->conference->bridge, user->chan);
1519 }
1520
1521 ast_bridge_unlock(user->conference->bridge);
1522 }
1523 }
1524
1525 /*!
1526 * \internal
1527 * \brief Unsuspend MOH for the conference user.
1528 *
1529 * \param user Conference user to unsuspend MOH on.
1530 */
1531 static void conf_moh_unsuspend(struct confbridge_user *user)
1532 {
1533 ao2_lock(user->conference);
1534 if (--user->suspended_moh == 0 && user->playing_moh) {
1535 ast_moh_start(user->chan, user->u_profile.moh_class, NULL);
1536 }
1537 ao2_unlock(user->conference);
1538 }
1539
1540 /*!
1541 * \internal
1542 * \brief Suspend MOH for the conference user.
1543 *
1544 * \param user Conference user to suspend MOH on.
1545 */
1546 static void conf_moh_suspend(struct confbridge_user *user)
1547 {
1548 ao2_lock(user->conference);
1549 if (user->suspended_moh++ == 0 && user->playing_moh) {
1550 ast_moh_stop(user->chan);
1551 }
1552 ao2_unlock(user->conference);
1553 }
1554
1555 int conf_handle_inactive_waitmarked(struct confbridge_user *user)
1556 {
1557 /* If we have not been quieted play back that they are waiting for the leader */
1558 if (!ast_test_flag(&user->u_profile, USER_OPT_QUIET) && play_prompt_to_user(user,
1559 conf_get_sound(CONF_SOUND_WAIT_FOR_LEADER, user->conference->b_profile.sounds))) {
1560 /* user hungup while the sound was playing */
1561 return -1;
1562 }
1563 return 0;
1564 }
1565
1566 int conf_handle_only_person(struct confbridge_user *user)
1567 {
1568 /* If audio prompts have not been quieted or this prompt quieted play it on out */
1569 if (!ast_test_flag(&user->u_profile, USER_OPT_QUIET | USER_OPT_NOONLYPERSON)) {
1570 if (play_prompt_to_user(user,
1571 conf_get_sound(CONF_SOUND_ONLY_PERSON, user->conference->b_profile.sounds))) {
1572 /* user hungup while the sound was playing */
1573 return -1;
1574 }
1575 }
1576 return 0;
1577 }
1578
1579 int conf_add_post_join_action(struct confbridge_user *user, int (*func)(struct confbridge_user *user))
1580 {
1581 struct post_join_action *action;
1582 if (!(action = ast_calloc(1, sizeof(*action)))) {
1583 return -1;
1584 }
1585 action->func = func;
1586 AST_LIST_INSERT_TAIL(&user->post_join_list, action, list);
1587 return 0;
1588 }
1589
1590
1591 void conf_handle_first_join(struct confbridge_conference *conference)
1592 {
1593 ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE, "confbridge:%s", conference->name);
1594 }
1595
1596 void conf_handle_second_active(struct confbridge_conference *conference)
1597 {
1598 /* If we are the second participant we may need to stop music on hold on the first */
1599 struct confbridge_user *first_user = AST_LIST_FIRST(&conference->active_list);
1600
1601 if (ast_test_flag(&first_user->u_profile, USER_OPT_MUSICONHOLD)) {
1602 conf_moh_stop(first_user);
1603 }
1604 conf_update_user_mute(first_user);
1605 }
1606
1607 void conf_ended(struct confbridge_conference *conference)
1608 {
1609 struct pbx_find_info q = { .stacklen = 0 };
1610
1611 /* Called with a reference to conference */
1612 ao2_unlink(conference_bridges, conference);
1613 send_conf_end_event(conference);
1614 if (!ast_strlen_zero(conference->b_profile.regcontext) &&
1615 pbx_find_extension(NULL, NULL, &q, conference->b_profile.regcontext,
1616 conference->name, 1, NULL, "", E_MATCH)) {
1617 ast_context_remove_extension(conference->b_profile.regcontext,
1618 conference->name, 1, NULL);
1619 }
1620 ao2_lock(conference);
1621 conf_stop_record(conference);
1622 ao2_unlock(conference);
1623 }
1624
1625 /*!
1626 * \internal
1627 * \brief Allocate playback channel for a conference.
1628 * \pre expects conference to be locked before calling this function
1629 */
1630 static int alloc_playback_chan(struct confbridge_conference *conference)
1631 {
1632 struct ast_format_cap *cap;
1633 char taskprocessor_name[AST_TASKPROCESSOR_MAX_NAME + 1];
1634
1635 cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
1636 if (!cap) {
1637 return -1;
1638 }
1639 ast_format_cap_append(cap, ast_format_slin, 0);
1640 conference->playback_chan = ast_request("CBAnn", cap, NULL, NULL,
1641 conference->name, NULL);
1642 ao2_ref(cap, -1);
1643 if (!conference->playback_chan) {
1644 return -1;
1645 }
1646
1647 /* To make sure playback_chan has the same language as the bridge */
1648 ast_channel_lock(conference->playback_chan);
1649 ast_channel_language_set(conference->playback_chan, conference->b_profile.language);
1650 ast_channel_unlock(conference->playback_chan);
1651
1652 ast_debug(1, "Created announcer channel '%s' to conference bridge '%s'\n",
1653 ast_channel_name(conference->playback_chan), conference->name);
1654
1655 ast_taskprocessor_build_name(taskprocessor_name, sizeof(taskprocessor_name),
1656 "Confbridge/%s", conference->name);
1657 conference->playback_queue = ast_taskprocessor_get(taskprocessor_name, TPS_REF_DEFAULT);
1658 if (!conference->playback_queue) {
1659 ast_hangup(conference->playback_chan);
1660 conference->playback_chan = NULL;
1661 return -1;
1662 }
1663 return 0;
1664 }
1665
1666 /*!
1667 * \brief Push the announcer channel into the bridge
1668 *
1669 * \param conference Conference bridge to push the announcer to
1670 * \retval 0 Success
1671 * \retval -1 Failed to push the channel to the bridge
1672 */
1673 static int push_announcer(struct confbridge_conference *conference)
1674 {
1675 if (conf_announce_channel_push(conference->playback_chan)) {
1676 ast_hangup(conference->playback_chan);
1677 conference->playback_chan = NULL;
1678 return -1;
1679 }
1680
1681 ast_autoservice_start(conference->playback_chan);
1682 return 0;
1683 }
1684
1685 static void confbridge_unlock_and_unref(void *obj)
1686 {
1687 struct confbridge_conference *conference = obj;
1688
1689 if (!obj) {
1690 return;
1691 }
1692 ao2_unlock(conference);
1693 ao2_ref(conference, -1);
1694 }
1695
1696 void confbridge_handle_atxfer(struct ast_attended_transfer_message *msg)
1697 {
1698 struct ast_channel_snapshot *old_snapshot;
1699 struct ast_channel_snapshot *new_snapshot;
1700 char *confbr_name = NULL;
1701 char *comma;
1702 RAII_VAR(struct confbridge_conference *, conference, NULL, confbridge_unlock_and_unref);
1703 struct confbridge_user *user = NULL;
1704 int found_user = 0;
1705 struct ast_json *json_object;
1706
1707 if (msg->to_transferee.channel_snapshot
1708 && strcmp(msg->to_transferee.channel_snapshot->dialplan->appl, "ConfBridge") == 0
1709 && msg->target) {
1710 /* We're transferring a bridge to an extension */
1711 old_snapshot = msg->to_transferee.channel_snapshot;
1712 new_snapshot = msg->target;
1713 } else if (msg->to_transfer_target.channel_snapshot
1714 && strcmp(msg->to_transfer_target.channel_snapshot->dialplan->appl, "ConfBridge") == 0
1715 && msg->transferee) {
1716 /* We're transferring a call to a bridge */
1717 old_snapshot = msg->to_transfer_target.channel_snapshot;
1718 new_snapshot = msg->transferee;
1719 } else {
1720 ast_log(LOG_ERROR, "Could not determine proper channels\n");
1721 return;
1722 }
1723
1724 /*
1725 * old_snapshot->data should have the original parameters passed to
1726 * the ConfBridge app:
1727 * conference[,bridge_profile[,user_profile[,menu]]]
1728 * We'll use "conference" to look up the bridge.
1729 *
1730 * We _could_ use old_snapshot->bridgeid to get the bridge but
1731 * that would involve locking the conference_bridges container
1732 * and iterating over it looking for a matching bridge.
1733 */
1734 if (ast_strlen_zero(old_snapshot->dialplan->data)) {
1735 ast_log(LOG_ERROR, "Channel '%s' didn't have app data set\n", old_snapshot->base->name);
1736 return;
1737 }
1738 confbr_name = ast_strdupa(old_snapshot->dialplan->data);
1739 comma = strchr(confbr_name, ',');
1740 if (comma) {
1741 *comma = '\0';
1742 }
1743
1744 ast_debug(1, "Confbr: %s Leaving: %s Joining: %s\n", confbr_name, old_snapshot->base->name, new_snapshot->base->name);
1745
1746 conference = ao2_find(conference_bridges, confbr_name, OBJ_SEARCH_KEY);
1747 if (!conference) {
1748 ast_log(LOG_ERROR, "Conference bridge '%s' not found\n", confbr_name);
1749 return;
1750 }
1751 ao2_lock(conference);
1752
1753 /*
1754 * We need to grab the user profile for the departing user in order to
1755 * properly format the join/leave messages.
1756 */
1757 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
1758 if (strcasecmp(ast_channel_name(user->chan), old_snapshot->base->name) == 0) {
1759 found_user = 1;
1760 break;
1761 }
1762 }
1763
1764 /*
1765 * If we didn't find the user in the active list, try the waiting list.
1766 */
1767 if (!found_user && conference->waitingusers) {
1768 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
1769 if (strcasecmp(ast_channel_name(user->chan), old_snapshot->base->name) == 0) {
1770 found_user = 1;
1771 break;
1772 }
1773 }
1774 }
1775
1776 if (!found_user) {
1777 ast_log(LOG_ERROR, "Unable to find user profile for channel '%s' in bridge '%s'\n",
1778 old_snapshot->base->name, confbr_name);
1779 return;
1780 }
1781
1782 /*
1783 * We're going to use the existing user profile to create the messages.
1784 */
1785 json_object = ast_json_pack("{s: b}",
1786 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
1787 );
1788 if (!json_object) {
1789 return;
1790 }
1791
1792 send_conf_stasis_snapshots(conference, old_snapshot, confbridge_leave_type(), json_object);
1793 ast_json_unref(json_object);
1794
1795 json_object = ast_json_pack("{s: b, s: b}",
1796 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN),
1797 "muted", user->muted);
1798 if (!json_object) {
1799 return;
1800 }
1801 send_conf_stasis_snapshots(conference, new_snapshot, confbridge_join_type(), json_object);
1802 ast_json_unref(json_object);
1803 }
1804
1805 /*!
1806 * \brief Join a conference bridge
1807 *
1808 * \param conference_name The conference name
1809 * \param user Conference bridge user structure
1810 *
1811 * \return A pointer to the conference bridge struct, or NULL if the conference room wasn't found.
1812 */
1813 static struct confbridge_conference *join_conference_bridge(const char *conference_name, struct confbridge_user *user)
1814 {
1815 struct confbridge_conference *conference;
1816 struct post_join_action *action;
1817 int max_members_reached = 0;
1818
1819 /* We explicitly lock the conference bridges container ourselves so that other callers can not create duplicate conferences at the same time */
1820 ao2_lock(conference_bridges);
1821
1822 ast_debug(1, "Trying to find conference bridge '%s'\n", conference_name);
1823
1824 /* Attempt to find an existing conference bridge */
1825 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
1826 if (conference && conference->b_profile.max_members) {
1827 max_members_reached = conference->b_profile.max_members > conference->activeusers ? 0 : 1;
1828 }
1829
1830 /* When finding a conference bridge that already exists make sure that it is not locked, and if so that we are not an admin */
1831 if (conference && (max_members_reached || conference->locked) && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
1832 ao2_unlock(conference_bridges);
1833 ast_debug(1, "Conference '%s' is locked and caller is not an admin\n", conference_name);
1834 ast_stream_and_wait(user->chan,
1835 conf_get_sound(CONF_SOUND_LOCKED, conference->b_profile.sounds),
1836 "");
1837 ao2_ref(conference, -1);
1838 return NULL;
1839 }
1840
1841 /* If no conference bridge was found see if we can create one */
1842 if (!conference) {
1843 /* Try to allocate memory for a new conference bridge, if we fail... this won't end well. */
1844 if (!(conference = ao2_alloc(sizeof(*conference), destroy_conference_bridge))) {
1845 ao2_unlock(conference_bridges);
1846 ast_log(LOG_ERROR, "Conference '%s' could not be created.\n", conference_name);
1847 return NULL;
1848 }
1849
1850 /* Setup for the record channel */
1851 conference->record_filename = ast_str_create(RECORD_FILENAME_INITIAL_SPACE);
1852 if (!conference->record_filename) {
1853 ao2_ref(conference, -1);
1854 ao2_unlock(conference_bridges);
1855 return NULL;
1856 }
1857
1858 /* Setup conference bridge parameters */
1859 ast_copy_string(conference->name, conference_name, sizeof(conference->name));
1860 conf_bridge_profile_copy(&conference->b_profile, &user->b_profile);
1861
1862 /* Create an actual bridge that will do the audio mixing */
1863 conference->bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_MULTIMIX,
1864 AST_BRIDGE_FLAG_MASQUERADE_ONLY | AST_BRIDGE_FLAG_TRANSFER_BRIDGE_ONLY,
1865 app, conference_name, NULL);
1866 if (!conference->bridge) {
1867 ao2_ref(conference, -1);
1868 ao2_unlock(conference_bridges);
1869 ast_log(LOG_ERROR, "Conference '%s' mixing bridge could not be created.\n", conference_name);
1870 return NULL;
1871 }
1872
1873 /* Set the internal sample rate on the bridge from the bridge profile */
1874 ast_bridge_set_internal_sample_rate(conference->bridge, conference->b_profile.internal_sample_rate);
1875 /* Set the maximum sample rate on the bridge from the bridge profile */
1876 ast_bridge_set_maximum_sample_rate(conference->bridge, conference->b_profile.maximum_sample_rate);
1877 /* Set the internal mixing interval on the bridge from the bridge profile */
1878 ast_bridge_set_mixing_interval(conference->bridge, conference->b_profile.mix_interval);
1879 ast_bridge_set_binaural_active(conference->bridge, ast_test_flag(&conference->b_profile, BRIDGE_OPT_BINAURAL_ACTIVE));
1880
1881 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
1882 ast_bridge_set_talker_src_video_mode(conference->bridge);
1883 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_SFU)) {
1884 ast_bridge_set_sfu_video_mode(conference->bridge);
1885 ast_bridge_set_remb_send_interval(conference->bridge, conference->b_profile.remb_send_interval);
1886 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE)) {
1887 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_AVERAGE);
1888 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_LOWEST)) {
1889 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_LOWEST);
1890 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST)) {
1891 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_HIGHEST);
1892 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE_ALL)) {
1893 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_AVERAGE_ALL);
1894 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_LOWEST_ALL)) {
1895 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_LOWEST_ALL);
1896 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST_ALL)) {
1897 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_HIGHEST_ALL);
1898 } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_FORCE)) {
1899 ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_FORCE);
1900 ast_bridge_set_remb_estimated_bitrate(conference->bridge, conference->b_profile.remb_estimated_bitrate);
1901 }
1902 }
1903
1904 /* Always set the minimum interval between video updates, to avoid infinite video updates. */
1905 ast_bridge_set_video_update_discard(conference->bridge, conference->b_profile.video_update_discard);
1906
1907 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_ENABLE_EVENTS)) {
1908 ast_bridge_set_send_sdp_label(conference->bridge, 1);
1909 }
1910
1911 /* Link it into the conference bridges container */
1912 if (!ao2_link(conference_bridges, conference)) {
1913 ao2_ref(conference, -1);
1914 ao2_unlock(conference_bridges);
1915 ast_log(LOG_ERROR,
1916 "Conference '%s' could not be added to the conferences list.\n", conference_name);
1917 return NULL;
1918 }
1919
1920 /* Set the initial state to EMPTY */
1921 conference->state = CONF_STATE_EMPTY;
1922
1923 if (alloc_playback_chan(conference)) {
1924 ao2_unlink(conference_bridges, conference);
1925 ao2_ref(conference, -1);
1926 ao2_unlock(conference_bridges);
1927 ast_log(LOG_ERROR, "Could not allocate announcer channel for conference '%s'\n", conference_name);
1928 return NULL;
1929 }
1930
1931 if (push_announcer(conference)) {
1932 ao2_unlink(conference_bridges, conference);
1933 ao2_ref(conference, -1);
1934 ao2_unlock(conference_bridges);
1935 ast_log(LOG_ERROR, "Could not add announcer channel for conference '%s' bridge\n", conference_name);
1936 return NULL;
1937 }
1938
1939 if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_CONFERENCE)) {
1940 ao2_lock(conference);
1941 conf_start_record(conference);
1942 ao2_unlock(conference);
1943 }
1944
1945 send_conf_start_event(conference);
1946
1947 if (!ast_strlen_zero(conference->b_profile.regcontext)) {
1948 if (!ast_exists_extension(NULL, conference->b_profile.regcontext, conference->name, 1, NULL)) {
1949 ast_add_extension(conference->b_profile.regcontext, 1, conference->name, 1, NULL, NULL, "Noop", NULL, NULL, "ConfBridge");
1950 }
1951 }
1952
1953 ast_debug(1, "Created conference '%s' and linked to container.\n", conference_name);
1954 }
1955
1956 ao2_unlock(conference_bridges);
1957
1958 /* Setup conference bridge user parameters */
1959 user->conference = conference;
1960
1961 ao2_lock(conference);
1962
1963 /* Determine if the new user should join the conference muted. */
1964 if (ast_test_flag(&user->u_profile, USER_OPT_STARTMUTED)
1965 || (!ast_test_flag(&user->u_profile, USER_OPT_ADMIN) && conference->muted)) {
1966 /* Set user level mute request. */
1967 user->muted = 1;
1968 }
1969
1970 /*
1971 * Suspend any MOH until the user actually joins the bridge of
1972 * the conference. This way any pre-join file playback does not
1973 * need to worry about MOH.
1974 */
1975 user->suspended_moh = 1;
1976
1977 if (handle_conf_user_join(user)) {
1978 /* Invalid event, nothing was done, so we don't want to process a leave. */
1979 ao2_unlock(conference);
1980 ao2_ref(conference, -1);
1981 user->conference = NULL;
1982 return NULL;
1983 }
1984
1985 if (ast_check_hangup(user->chan)) {
1986 ao2_unlock(conference);
1987 leave_conference(user);
1988 return NULL;
1989 }
1990
1991 ao2_unlock(conference);
1992
1993 /* If an announcement is to be played play it */
1994 if (!ast_strlen_zero(user->u_profile.announcement)) {
1995 if (play_prompt_to_user(user,
1996 user->u_profile.announcement)) {
1997 leave_conference(user);
1998 return NULL;
1999 }
2000 }
2001
2002 /* Announce number of users if need be */
2003 if (ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCEUSERCOUNT)) {
2004 if (announce_user_count(conference, user, NULL)) {
2005 leave_conference(user);
2006 return NULL;
2007 }
2008 }
2009
2010 if (ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCEUSERCOUNTALL) &&
2011 (conference->activeusers > user->u_profile.announce_user_count_all_after)) {
2012 int user_count_res;
2013
2014 /*
2015 * We have to autoservice the new user because he has not quite
2016 * joined the conference yet.
2017 */
2018 ast_autoservice_start(user->chan);
2019 user_count_res = announce_user_count(conference, NULL, NULL);
2020 ast_autoservice_stop(user->chan);
2021 if (user_count_res) {
2022 leave_conference(user);
2023 return NULL;
2024 }
2025 }
2026
2027 /* Handle post-join actions */
2028 while ((action = AST_LIST_REMOVE_HEAD(&user->post_join_list, list))) {
2029 action->func(user);
2030 ast_free(action);
2031 }
2032
2033 return conference;
2034 }
2035
2036 /*!
2037 * \brief Leave a conference
2038 *
2039 * \param user The conference user
2040 */
2041 static void leave_conference(struct confbridge_user *user)
2042 {
2043 struct post_join_action *action;
2044
2045 ao2_lock(user->conference);
2046 handle_conf_user_leave(user);
2047 ao2_unlock(user->conference);
2048
2049 /* Discard any post-join actions */
2050 while ((action = AST_LIST_REMOVE_HEAD(&user->post_join_list, list))) {
2051 ast_free(action);
2052 }
2053
2054 /* Done mucking with the conference, huzzah */
2055 ao2_ref(user->conference, -1);
2056 user->conference = NULL;
2057 }
2058
2059 static void playback_common(struct confbridge_conference *conference, const char *filename, int say_number)
2060 {
2061 /* Don't try to play if the playback channel has been hung up */
2062 if (!conference->playback_chan) {
2063 return;
2064 }
2065
2066 ast_autoservice_stop(conference->playback_chan);
2067
2068 /* The channel is all under our control, in goes the prompt */
2069 if (!ast_strlen_zero(filename)) {
2070 ast_stream_and_wait(conference->playback_chan, filename, "");
2071 } else if (say_number >= 0) {
2072 ast_say_number(conference->playback_chan, say_number, "",
2073 ast_channel_language(conference->playback_chan), NULL);
2074 }
2075
2076 ast_autoservice_start(conference->playback_chan);
2077 }
2078
2079 struct playback_task_data {
2080 struct confbridge_conference *conference;
2081 const char *filename;
2082 int say_number;
2083 int playback_finished;
2084 ast_mutex_t lock;
2085 ast_cond_t cond;
2086 };
2087
2088 /*!
2089 * \brief Play an announcement into a confbridge
2090 *
2091 * This runs in the playback queue taskprocessor. This ensures that
2092 * all playbacks are handled in sequence and do not play over top one
2093 * another.
2094 *
2095 * This task runs synchronously so there is no need for performing any
2096 * sort of cleanup on the input parameter.
2097 *
2098 * \param data A playback_task_data
2099 * \return 0
2100 */
2101 static int playback_task(void *data)
2102 {
2103 struct playback_task_data *ptd = data;
2104
2105 playback_common(ptd->conference, ptd->filename, ptd->say_number);
2106
2107 ast_mutex_lock(&ptd->lock);
2108 ptd->playback_finished = 1;
2109 ast_cond_signal(&ptd->cond);
2110 ast_mutex_unlock(&ptd->lock);
2111
2112 return 0;
2113 }
2114
2115 static void playback_task_data_init(struct playback_task_data *ptd, struct confbridge_conference *conference,
2116 const char *filename, int say_number)
2117 {
2118 ast_mutex_init(&ptd->lock);
2119 ast_cond_init(&ptd->cond, NULL);
2120
2121 ptd->filename = filename;
2122 ptd->say_number = say_number;
2123 ptd->conference = conference;
2124 ptd->playback_finished = 0;
2125 }
2126
2127 static void playback_task_data_destroy(struct playback_task_data *ptd)
2128 {
2129 ast_mutex_destroy(&ptd->lock);
2130 ast_cond_destroy(&ptd->cond);
2131 }
2132
2133 static int play_sound_helper(struct confbridge_conference *conference, const char *filename, int say_number)
2134 {
2135 struct playback_task_data ptd;
2136
2137 /* Do not waste resources trying to play files that do not exist */
2138 if (ast_strlen_zero(filename)) {
2139 if (say_number < 0) {
2140 return 0;
2141 }
2142 } else if (!sound_file_exists(filename)) {
2143 return 0;
2144 }
2145
2146 playback_task_data_init(&ptd, conference, filename, say_number);
2147 if (ast_taskprocessor_push(conference->playback_queue, playback_task, &ptd)) {
2148 if (!ast_strlen_zero(filename)) {
2149 ast_log(LOG_WARNING, "Unable to play file '%s' to conference %s\n",
2150 filename, conference->name);
2151 } else {
2152 ast_log(LOG_WARNING, "Unable to say number '%d' to conference %s\n",
2153 say_number, conference->name);
2154 }
2155 playback_task_data_destroy(&ptd);
2156 return -1;
2157 }
2158
2159 /* Wait for the playback to complete */
2160 ast_mutex_lock(&ptd.lock);
2161 while (!ptd.playback_finished) {
2162 ast_cond_wait(&ptd.cond, &ptd.lock);
2163 }
2164 ast_mutex_unlock(&ptd.lock);
2165
2166 playback_task_data_destroy(&ptd);
2167
2168 return 0;
2169 }
2170
2171 int play_sound_file(struct confbridge_conference *conference, const char *filename)
2172 {
2173 return play_sound_helper(conference, filename, -1);
2174 }
2175
2176 struct async_playback_task_data {
2177 struct confbridge_conference *conference;
2178 int say_number;
2179 struct ast_channel *initiator;
2180 char filename[0];
2181 };
2182
2183 struct async_datastore_data {
2184 ast_mutex_t lock;
2185 ast_cond_t cond;
2186 int wait;
2187 };
2188
2189 static void async_datastore_data_destroy(void *data)
2190 {
2191 struct async_datastore_data *add = data;
2192
2193 ast_mutex_destroy(&add->lock);
2194 ast_cond_destroy(&add->cond);
2195
2196 ast_free(add);
2197 }
2198
2199 /*!
2200 * \brief Datastore used for timing of async announcement playback
2201 *
2202 * Announcements that are played to the entire conference can be played
2203 * asynchronously (i.e. The channel that queues the playback does not wait
2204 * for the playback to complete before continuing)
2205 *
2206 * The thing about async announcements is that the channel that queues the
2207 * announcement is either not in the bridge or is in some other way "occupied"
2208 * at the time the announcement is queued. Because of that, the initiator of
2209 * the announcement may enter after the announcement has already started,
2210 * resulting in the sound being "clipped".
2211 *
2212 * This datastore makes it so that the channel that queues the async announcement
2213 * can say "I'm ready now". This way the announcement does not start until the
2214 * initiator of the announcement is ready to hear the sound.
2215 */
2216 static struct ast_datastore_info async_datastore_info = {
2217 .type = "Confbridge async playback",
2218 .destroy = async_datastore_data_destroy,
2219 };
2220
2221 static struct async_datastore_data *async_datastore_data_alloc(void)
2222 {
2223 struct async_datastore_data *add;
2224
2225 add = ast_malloc(sizeof(*add));
2226 if (!add) {
2227 return NULL;
2228 }
2229
2230 ast_mutex_init(&add->lock);
2231 ast_cond_init(&add->cond, NULL);
2232 add->wait = 1;
2233
2234 return add;
2235 }
2236
2237 /*!
2238 * \brief Prepare the async playback datastore
2239 *
2240 * This is done prior to queuing an async announcement. If the
2241 * datastore has not yet been created, it is allocated and initialized.
2242 * If it already exists, we set it to be in "waiting" mode.
2243 *
2244 * \param initiator The channel that is queuing the async playback
2245 * \retval 0 Success
2246 * \retval -1 Failure :(
2247 */
2248 static int setup_async_playback_datastore(struct ast_channel *initiator)
2249 {
2250 struct ast_datastore *async_datastore;
2251
2252 async_datastore = ast_channel_datastore_find(initiator, &async_datastore_info, NULL);
2253 if (async_datastore) {
2254 struct async_datastore_data *add;
2255
2256 add = async_datastore->data;
2257 add->wait = 1;
2258
2259 return 0;
2260 }
2261
2262 async_datastore = ast_datastore_alloc(&async_datastore_info, NULL);
2263 if (!async_datastore) {
2264 return -1;
2265 }
2266
2267 async_datastore->data = async_datastore_data_alloc();
2268 if (!async_datastore->data) {
2269 ast_datastore_free(async_datastore);
2270 return -1;
2271 }
2272
2273 ast_channel_datastore_add(initiator, async_datastore);
2274 return 0;
2275 }
2276
2277 static struct async_playback_task_data *async_playback_task_data_alloc(
2278 struct confbridge_conference *conference, const char *filename, int say_number,
2279 struct ast_channel *initiator)
2280 {
2281 struct async_playback_task_data *aptd;
2282
2283 aptd = ast_malloc(sizeof(*aptd) + strlen(filename) + 1);
2284 if (!aptd) {
2285 return NULL;
2286 }
2287
2288 /* Safe */
2289 strcpy(aptd->filename, filename);
2290 aptd->say_number = say_number;
2291
2292 /* You may think that we need to bump the conference refcount since we are pushing
2293 * this task to the taskprocessor.
2294 *
2295 * In this case, that actually causes a problem. The destructor for the conference
2296 * pushes a hangup task into the taskprocessor and waits for it to complete before
2297 * continuing. If the destructor gets called from a taskprocessor task, we're
2298 * deadlocked.
2299 *
2300 * So is there a risk of the conference being freed out from under us? No. Since
2301 * the destructor pushes a task into the taskprocessor and waits for it to complete,
2302 * the destructor cannot free the conference out from under us. No further tasks
2303 * can be queued onto the taskprocessor after the hangup since no channels are referencing
2304 * the conference at that point any more.
2305 */
2306 aptd->conference = conference;
2307
2308 aptd->initiator = initiator;
2309 if (initiator) {
2310 ast_channel_ref(initiator);
2311 ast_channel_lock(aptd->initiator);
2312 /* We don't really care if this fails. If the datastore fails to get set up
2313 * we'll still play the announcement. It's possible that the sound will be
2314 * clipped for the initiator, but that's not the end of the world.
2315 */
2316 setup_async_playback_datastore(aptd->initiator);
2317 ast_channel_unlock(aptd->initiator);
2318 }
2319
2320 return aptd;
2321 }
2322
2323 static void async_playback_task_data_destroy(struct async_playback_task_data *aptd)
2324 {
2325 ast_channel_cleanup(aptd->initiator);
2326 ast_free(aptd);
2327 }
2328
2329 /*!
2330 * \brief Wait for the initiator of an async playback to be ready
2331 *
2332 * See the description on the async_datastore_info structure for more
2333 * information about what this is about.
2334 *
2335 * \param initiator The channel that queued the async announcement
2336 */
2337 static void wait_for_initiator(struct ast_channel *initiator)
2338 {
2339 struct ast_datastore *async_datastore;
2340 struct async_datastore_data *add;
2341
2342 ast_channel_lock(initiator);
2343 async_datastore = ast_channel_datastore_find(initiator, &async_datastore_info, NULL);
2344 ast_channel_unlock(initiator);
2345
2346 if (!async_datastore) {
2347 return;
2348 }
2349
2350 add = async_datastore->data;
2351
2352 ast_mutex_lock(&add->lock);
2353 while (add->wait) {
2354 ast_cond_wait(&add->cond, &add->lock);
2355 }
2356 ast_mutex_unlock(&add->lock);
2357 }
2358
2359 /*!
2360 * \brief Play an announcement into a confbridge asynchronously
2361 *
2362 * This runs in the playback queue taskprocessor. This ensures that
2363 * all playbacks are handled in sequence and do not play over top one
2364 * another.
2365 *
2366 * \param data An async_playback_task_data
2367 * \return 0
2368 */
2369 static int async_playback_task(void *data)
2370 {
2371 struct async_playback_task_data *aptd = data;
2372
2373 /* Wait for the initiator to get back in the bridge or be hung up */
2374 if (aptd->initiator) {
2375 wait_for_initiator(aptd->initiator);
2376 }
2377
2378 playback_common(aptd->conference, aptd->filename, aptd->say_number);
2379
2380 async_playback_task_data_destroy(aptd);
2381 return 0;
2382 }
2383
2384 static int async_play_sound_helper(struct confbridge_conference *conference,
2385 const char *filename, int say_number, struct ast_channel *initiator)
2386 {
2387 struct async_playback_task_data *aptd;
2388
2389 /* Do not waste resources trying to play files that do not exist */
2390 if (ast_strlen_zero(filename)) {
2391 if (say_number < 0) {
2392 return 0;
2393 }
2394 } else if (!sound_file_exists(filename)) {
2395 return 0;
2396 }
2397
2398 aptd = async_playback_task_data_alloc(conference, filename, say_number, initiator);
2399 if (!aptd) {
2400 return -1;
2401 }
2402
2403 if (ast_taskprocessor_push(conference->playback_queue, async_playback_task, aptd)) {
2404 if (!ast_strlen_zero(filename)) {
2405 ast_log(LOG_WARNING, "Unable to play file '%s' to conference '%s'\n",
2406 filename, conference->name);
2407 } else {
2408 ast_log(LOG_WARNING, "Unable to say number '%d' to conference '%s'\n",
2409 say_number, conference->name);
2410 }
2411 async_playback_task_data_destroy(aptd);
2412 return -1;
2413 }
2414
2415 return 0;
2416 }
2417
2418 int async_play_sound_file(struct confbridge_conference *conference,
2419 const char *filename, struct ast_channel *initiator)
2420 {
2421 return async_play_sound_helper(conference, filename, -1, initiator);
2422 }
2423
2424 void async_play_sound_ready(struct ast_channel *chan)
2425 {
2426 struct ast_datastore *async_datastore;
2427 struct async_datastore_data *add;
2428
2429 ast_channel_lock(chan);
2430 async_datastore = ast_channel_datastore_find(chan, &async_datastore_info, NULL);
2431 ast_channel_unlock(chan);
2432 if (!async_datastore) {
2433 return;
2434 }
2435
2436 add = async_datastore->data;
2437
2438 ast_mutex_lock(&add->lock);
2439 add->wait = 0;
2440 ast_cond_signal(&add->cond);
2441 ast_mutex_unlock(&add->lock);
2442 }
2443
2444 /*!
2445 * \brief Play number into the conference bridge
2446 *
2447 * \param conference The conference bridge to say the number into
2448 * \param say_number number to say
2449 *
2450 * \retval 0 success
2451 * \retval -1 failure
2452 */
2453 static int play_sound_number(struct confbridge_conference *conference, int say_number)
2454 {
2455 return play_sound_helper(conference, NULL, say_number);
2456 }
2457
2458 static int conf_handle_talker_cb(struct ast_bridge_channel *bridge_channel, void *hook_pvt, int talking)
2459 {
2460 struct confbridge_user *user = hook_pvt;
2461 RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
2462 struct ast_json *talking_extras;
2463
2464 conference = ao2_find(conference_bridges, user->conference->name, OBJ_KEY);
2465 if (!conference) {
2466 /* Remove the hook since the conference does not exist. */
2467 return -1;
2468 }
2469
2470 ao2_lock(conference);
2471 user->talking = talking;
2472 ao2_unlock(conference);
2473
2474 talking_extras = ast_json_pack("{s: s, s: b}",
2475 "talking_status", talking ? "on" : "off",
2476 "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN));
2477 if (!talking_extras) {
2478 return 0;
2479 }
2480
2481 send_conf_stasis(conference, bridge_channel->chan, confbridge_talking_type(), talking_extras, 0);
2482 ast_json_unref(talking_extras);
2483 return 0;
2484 }
2485
2486 static int conf_get_pin(struct ast_channel *chan, struct confbridge_user *user)
2487 {
2488 char pin_guess[MAX_PIN+1] = { 0, };
2489 const char *pin = user->u_profile.pin;
2490 char *tmp = pin_guess;
2491 int i, res;
2492 unsigned int len = MAX_PIN;
2493
2494 /*
2495 * NOTE: We have not joined a conference yet so we have to use
2496 * the bridge profile requested by the user.
2497 */
2498
2499 /* give them three tries to get the pin right */
2500 for (i = 0; i < 3; i++) {
2501 if (ast_app_getdata(chan,
2502 conf_get_sound(CONF_SOUND_GET_PIN, user->b_profile.sounds),
2503 tmp, len, 0) >= 0) {
2504 if (!strcasecmp(pin, pin_guess)) {
2505 return 0;
2506 }
2507 }
2508 ast_streamfile(chan,
2509 conf_get_sound(CONF_SOUND_INVALID_PIN, user->b_profile.sounds),
2510 ast_channel_language(chan));
2511 res = ast_waitstream(chan, AST_DIGIT_ANY);
2512 if (res > 0) {
2513 /* Account for digit already read during ivalid pin playback
2514 * resetting pin buf. */
2515 pin_guess[0] = res;
2516 pin_guess[1] = '\0';
2517 tmp = pin_guess + 1;
2518 len = MAX_PIN - 1;
2519 } else {
2520 /* reset pin buf as empty buffer. */
2521 tmp = pin_guess;
2522 len = MAX_PIN;
2523 }
2524 }
2525 return -1;
2526 }
2527
2528 static int user_timeout(struct ast_bridge_channel *bridge_channel, void *ignore)
2529 {
2530 ast_bridge_channel_leave_bridge(bridge_channel, BRIDGE_CHANNEL_STATE_END, 0);
2531 pbx_builtin_setvar_helper(bridge_channel->chan, "CONFBRIDGE_RESULT", "TIMEOUT");
2532 return -1;
2533 }
2534
2535 static int conf_rec_name(struct confbridge_user *user, const char *conf_name)
2536 {
2537 char destdir[PATH_MAX];
2538 int res;
2539 int duration = 20;
2540
2541 snprintf(destdir, sizeof(destdir), "%s/confbridge", ast_config_AST_SPOOL_DIR);
2542
2543 if (ast_mkdir(destdir, 0777) != 0) {
2544 ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", destdir, strerror(errno));
2545 return -1;
2546 }
2547 snprintf(user->name_rec_location, sizeof(user->name_rec_location),
2548 "%s/confbridge-name-%s-%s", destdir,
2549 conf_name, ast_channel_uniqueid(user->chan));
2550
2551 if (!(ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW))) {
2552 res = ast_play_and_record(user->chan,
2553 "vm-rec-name",
2554 user->name_rec_location,
2555 10,
2556 "sln",
2557 &duration,
2558 NULL,
2559 ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE),
2560 0,
2561 NULL);
2562 } else {
2563 res = ast_record_review(user->chan,
2564 "vm-rec-name",
2565 user->name_rec_location,
2566 10,
2567 "sln",
2568 &duration,
2569 NULL);
2570 }
2571
2572 if (res == -1) {
2573 ast_filedelete(user->name_rec_location, NULL);
2574 user->name_rec_location[0] = '\0';
2575 return -1;
2576 }
2577 return 0;
2578 }
2579
2580 struct async_delete_name_rec_task_data {
2581 struct confbridge_conference *conference;
2582 char filename[0];
2583 };
2584
2585 static struct async_delete_name_rec_task_data *async_delete_name_rec_task_data_alloc(
2586 struct confbridge_conference *conference, const char *filename)
2587 {
2588 struct async_delete_name_rec_task_data *atd;
2589
2590 atd = ast_malloc(sizeof(*atd) + strlen(filename) + 1);
2591 if (!atd) {
2592 return NULL;
2593 }
2594
2595 /* Safe */
2596 strcpy(atd->filename, filename);
2597 atd->conference = conference;
2598
2599 return atd;
2600 }
2601
2602 static void async_delete_name_rec_task_data_destroy(struct async_delete_name_rec_task_data *atd)
2603 {
2604 ast_free(atd);
2605 }
2606
2607 /*!
2608 * \brief Delete user's name file asynchronously
2609 *
2610 * This runs in the playback queue taskprocessor. This ensures that
2611 * sound file is removed after playback is finished and not before.
2612 *
2613 * \param data An async_delete_name_rec_task_data
2614 * \return 0
2615 */
2616 static int async_delete_name_rec_task(void *data)
2617 {
2618 struct async_delete_name_rec_task_data *atd = data;
2619
2620 ast_filedelete(atd->filename, NULL);
2621 ast_log(LOG_DEBUG, "Conference '%s' removed user name file '%s'\n",
2622 atd->conference->name, atd->filename);
2623
2624 async_delete_name_rec_task_data_destroy(atd);
2625 return 0;
2626 }
2627
2628 static int async_delete_name_rec(struct confbridge_conference *conference,
2629 const char *filename)
2630 {
2631 struct async_delete_name_rec_task_data *atd;
2632
2633 if (ast_strlen_zero(filename)) {
2634 return 0;
2635 } else if (!sound_file_exists(filename)) {
2636 return 0;
2637 }
2638
2639 atd = async_delete_name_rec_task_data_alloc(conference, filename);
2640 if (!atd) {
2641 return -1;
2642 }
2643
2644 if (ast_taskprocessor_push(conference->playback_queue, async_delete_name_rec_task, atd)) {
2645 ast_log(LOG_WARNING, "Conference '%s' was unable to remove user name file '%s'\n",
2646 conference->name, filename);
2647 async_delete_name_rec_task_data_destroy(atd);
2648 return -1;
2649 }
2650
2651 return 0;
2652 }
2653
2654 static int join_callback(struct ast_bridge_channel *bridge_channel, void *ignore)
2655 {
2656 async_play_sound_ready(bridge_channel->chan);
2657 return 0;
2658 }
2659
2660 struct confbridge_hook_data {
2661 struct confbridge_conference *conference;
2662 struct confbridge_user *user;
2663 enum ast_bridge_hook_type hook_type;
2664 };
2665
2666 static int send_event_hook_callback(struct ast_bridge_channel *bridge_channel, void *data)
2667 {
2668 struct confbridge_hook_data *hook_data = data;
2669
2670 if (hook_data->hook_type == AST_BRIDGE_HOOK_TYPE_JOIN) {
2671 send_join_event(hook_data->user, hook_data->conference);
2672 } else {
2673 send_leave_event(hook_data->user, hook_data->conference);
2674 }
2675
2676 return 0;
2677 }
2678
2679 /*! \brief The ConfBridge application */
2680 static int confbridge_exec(struct ast_channel *chan, const char *data)
2681 {
2682 int res = 0, volume_adjustments[2];
2683 int quiet = 0;
2684 int async_delete_task_pushed = 0;
2685 char *parse;
2686 const char *b_profile_name = NULL;
2687 const char *u_profile_name = NULL;
2688 const char *menu_profile_name = NULL;
2689 struct confbridge_conference *conference = NULL;
2690 struct confbridge_user user = {
2691 .chan = chan,
2692 .tech_args.talking_threshold = DEFAULT_TALKING_THRESHOLD,
2693 .tech_args.silence_threshold = DEFAULT_SILENCE_THRESHOLD,
2694 .tech_args.drop_silence = 0,
2695 };
2696 struct confbridge_hook_data *join_hook_data;
2697 struct confbridge_hook_data *leave_hook_data;
2698
2699 AST_DECLARE_APP_ARGS(args,
2700 AST_APP_ARG(conf_name);
2701 AST_APP_ARG(b_profile_name);
2702 AST_APP_ARG(u_profile_name);
2703 AST_APP_ARG(menu_profile_name);
2704 );
2705
2706 if (ast_bridge_features_init(&user.features)) {
2707 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2708 res = -1;
2709 goto confbridge_cleanup;
2710 }
2711
2712 /* We need to make a copy of the input string if we are going to modify it! */
2713 parse = ast_strdupa(data);
2714
2715 AST_STANDARD_APP_ARGS(args, parse);
2716
2717 if (ast_strlen_zero(args.conf_name)) {
2718 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2719 ast_log(LOG_WARNING, "%s requires an argument (conference name[,options])\n", app);
2720 res = -1;
2721 goto confbridge_cleanup;
2722 }
2723
2724 if (strlen(args.conf_name) >= MAX_CONF_NAME) {
2725 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2726 ast_log(LOG_WARNING, "%s does not accept conference names longer than %d\n", app, MAX_CONF_NAME - 1);
2727 res = -1;
2728 goto confbridge_cleanup;
2729 }
2730
2731 /* bridge profile name */
2732 if (args.argc > 1 && !ast_strlen_zero(args.b_profile_name)) {
2733 b_profile_name = args.b_profile_name;
2734 }
2735 if (!conf_find_bridge_profile(chan, b_profile_name, &user.b_profile)) {
2736 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2737 ast_log(LOG_WARNING, "Conference bridge profile %s does not exist\n", b_profile_name ?
2738 b_profile_name : DEFAULT_BRIDGE_PROFILE);
2739 res = -1;
2740 goto confbridge_cleanup;
2741 }
2742
2743 /* user profile name */
2744 if (args.argc > 2 && !ast_strlen_zero(args.u_profile_name)) {
2745 u_profile_name = args.u_profile_name;
2746 }
2747 if (!conf_find_user_profile(chan, u_profile_name, &user.u_profile)) {
2748 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2749 ast_log(LOG_WARNING, "Conference user profile %s does not exist\n", u_profile_name ?
2750 u_profile_name : DEFAULT_USER_PROFILE);
2751 res = -1;
2752 goto confbridge_cleanup;
2753 }
2754
2755 /* If channel hasn't been answered already, answer it, unless we're explicitly not supposed to */
2756 if ((ast_channel_state(chan) != AST_STATE_UP) && (ast_test_flag(&user.u_profile, USER_OPT_ANSWER_CHANNEL))) {
2757 ast_answer(chan);
2758 }
2759
2760 quiet = ast_test_flag(&user.u_profile, USER_OPT_QUIET);
2761
2762 /* ask for a PIN immediately after finding user profile. This has to be
2763 * prompted for requardless of quiet setting. */
2764 if (!ast_strlen_zero(user.u_profile.pin)) {
2765 if (conf_get_pin(chan, &user)) {
2766 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2767 res = -1; /* invalid PIN */
2768 goto confbridge_cleanup;
2769 }
2770 }
2771
2772 /* See if we need them to record a intro name */
2773 if (!quiet &&
2774 (ast_test_flag(&user.u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE) ||
2775 (ast_test_flag(&user.u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW)))) {
2776 if (conf_rec_name(&user, args.conf_name)) {
2777 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2778 res = -1; /* Hangup during name recording */
2779 goto confbridge_cleanup;
2780 }
2781 }
2782
2783 /* menu name */
2784 if (args.argc > 3 && !ast_strlen_zero(args.menu_profile_name)) {
2785 menu_profile_name = args.menu_profile_name;
2786 }
2787
2788 if (conf_set_menu_to_user(chan, &user, menu_profile_name)) {
2789 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2790 ast_log(LOG_WARNING, "Conference menu profile %s does not exist\n", menu_profile_name ?
2791 menu_profile_name : DEFAULT_MENU_PROFILE);
2792 res = -1;
2793 goto confbridge_cleanup;
2794 }
2795
2796 /* Set if DTMF should pass through for this user or not */
2797 if (ast_test_flag(&user.u_profile, USER_OPT_DTMF_PASS)) {
2798 user.features.dtmf_passthrough = 1;
2799 } else {
2800 user.features.dtmf_passthrough = 0;
2801 }
2802
2803 /* Set if text messaging is enabled for this user or not */
2804 if (ast_test_flag(&user.u_profile, USER_OPT_TEXT_MESSAGING)) {
2805 user.features.text_messaging = 1;
2806 } else {
2807 user.features.text_messaging = 0;
2808 }
2809
2810 /* Set dsp threshold values if present */
2811 if (user.u_profile.talking_threshold) {
2812 user.tech_args.talking_threshold = user.u_profile.talking_threshold;
2813 }
2814 if (user.u_profile.silence_threshold) {
2815 user.tech_args.silence_threshold = user.u_profile.silence_threshold;
2816 }
2817
2818 /* Set a talker indicate call back if talking detection is requested */
2819 if (ast_test_flag(&user.u_profile, USER_OPT_TALKER_DETECT)) {
2820 if (ast_bridge_talk_detector_hook(&user.features, conf_handle_talker_cb,
2821 &user, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
2822 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2823 res = -1;
2824 goto confbridge_cleanup;
2825 }
2826 }
2827
2828 /* Look for a conference bridge matching the provided name */
2829 if (!(conference = join_conference_bridge(args.conf_name, &user))) {
2830 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
2831 res = -1;
2832 goto confbridge_cleanup;
2833 }
2834
2835 /* Keep a copy of volume adjustments so we can restore them later if need be */
2836 volume_adjustments[0] = ast_audiohook_volume_get(chan, AST_AUDIOHOOK_DIRECTION_READ);
2837 volume_adjustments[1] = ast_audiohook_volume_get(chan, AST_AUDIOHOOK_DIRECTION_WRITE);
2838
2839 if (ast_test_flag(&user.u_profile, USER_OPT_DROP_SILENCE)) {
2840 user.tech_args.drop_silence = 1;
2841 }
2842
2843 if (ast_test_flag(&user.u_profile, USER_OPT_JITTERBUFFER)) {
2844 ast_func_write(chan, "JITTERBUFFER(adaptive)", "default");
2845 }
2846
2847 if (ast_test_flag(&user.u_profile, USER_OPT_DENOISE)) {
2848 ast_func_write(chan, "DENOISE(rx)", "on");
2849 }
2850
2851 /* if this user has a intro, play it before entering */
2852 if (!ast_strlen_zero(user.name_rec_location)) {
2853 ast_autoservice_start(chan);
2854 play_sound_file(conference, user.name_rec_location);
2855 play_sound_file(conference,
2856 conf_get_sound(CONF_SOUND_HAS_JOINED, conference->b_profile.sounds));
2857 ast_autoservice_stop(chan);
2858 }
2859
2860 if (!quiet) {
2861 const char *join_sound = conf_get_sound(CONF_SOUND_JOIN, conference->b_profile.sounds);
2862
2863 /* if hear_own_join_sound is enabled play the Join sound to everyone */
2864 if (ast_test_flag(&user.u_profile, USER_OPT_HEAR_OWN_JOIN_SOUND) ) {
2865 if (strcmp(conference->b_profile.language, ast_channel_language(chan))) {
2866 ast_stream_and_wait(chan, join_sound, "");
2867 ast_autoservice_start(chan);
2868 play_sound_file(conference, join_sound);
2869 ast_autoservice_stop(chan);
2870 } else {
2871 async_play_sound_file(conference, join_sound, chan);
2872 }
2873 /* if hear_own_join_sound is disabled only play the Join sound to just the conference */
2874 } else {
2875 ast_autoservice_start(chan);
2876 play_sound_file(conference, join_sound);
2877 ast_autoservice_stop(chan);
2878 }
2879 }
2880
2881 if (user.u_profile.timeout) {
2882 ast_bridge_interval_hook(&user.features,
2883 0,
2884 user.u_profile.timeout * 1000,
2885 user_timeout,
2886 NULL,
2887 NULL,
2888 AST_BRIDGE_HOOK_REMOVE_ON_PULL);
2889 }
2890
2891 /* See if we need to automatically set this user as a video source or not */
2892 handle_video_on_join(conference, user.chan, ast_test_flag(&user.u_profile, USER_OPT_MARKEDUSER));
2893
2894 conf_moh_unsuspend(&user);
2895
2896 join_hook_data = ast_malloc(sizeof(*join_hook_data));
2897 if (!join_hook_data) {
2898 res = -1;
2899 goto confbridge_cleanup;
2900 }
2901 join_hook_data->user = &user;
2902 join_hook_data->conference = conference;
2903 join_hook_data->hook_type = AST_BRIDGE_HOOK_TYPE_JOIN;
2904 res = ast_bridge_join_hook(&user.features, send_event_hook_callback,
2905 join_hook_data, ast_free_ptr, 0);
2906 if (res) {
2907 ast_free(join_hook_data);
2908 ast_log(LOG_ERROR, "Couldn't add bridge join hook for channel '%s'\n", ast_channel_name(chan));
2909 goto confbridge_cleanup;
2910 }
2911
2912 leave_hook_data = ast_malloc(sizeof(*leave_hook_data));
2913 if (!leave_hook_data) {
2914 /* join_hook_data is cleaned up by ast_bridge_features_cleanup via the goto */
2915 res = -1;
2916 goto confbridge_cleanup;
2917 }
2918 leave_hook_data->user = &user;
2919 leave_hook_data->conference = conference;
2920 leave_hook_data->hook_type = AST_BRIDGE_HOOK_TYPE_LEAVE;
2921 res = ast_bridge_leave_hook(&user.features, send_event_hook_callback,
2922 leave_hook_data, ast_free_ptr, 0);
2923 if (res) {
2924 /* join_hook_data is cleaned up by ast_bridge_features_cleanup via the goto */
2925 ast_free(leave_hook_data);
2926 ast_log(LOG_ERROR, "Couldn't add bridge leave hook for channel '%s'\n", ast_channel_name(chan));
2927 goto confbridge_cleanup;
2928 }
2929
2930 if (ast_bridge_join_hook(&user.features, join_callback, NULL, NULL, 0)) {
2931 async_play_sound_ready(user.chan);
2932 }
2933
2934 ast_bridge_join(conference->bridge,
2935 chan,
2936 NULL,
2937 &user.features,
2938 &user.tech_args,
2939 0);
2940
2941 /* This is a catch-all in case joining the bridge failed or for some reason
2942 * an async announcement got queued up and hasn't been told to play yet
2943 */
2944 async_play_sound_ready(chan);
2945
2946 if (!user.kicked && ast_check_hangup(chan)) {
2947 pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "HANGUP");
2948 }
2949
2950 /* if we're shutting down, don't attempt to do further processing */
2951 if (ast_shutting_down()) {
2952 /*
2953 * Not taking any new calls at this time. We cannot create
2954 * the announcer channel if this is the first channel into
2955 * the conference and we certainly cannot create any
2956 * recording channel.
2957 */
2958 leave_conference(&user);
2959 conference = NULL;
2960 goto confbridge_cleanup;
2961 }
2962
2963 /* If this user was a video source, we need to clean up and possibly pick a new source. */
2964 handle_video_on_exit(conference, user.chan);
2965
2966 /* if this user has a intro, play it when leaving */
2967 if (!quiet && !ast_strlen_zero(user.name_rec_location)) {
2968 async_play_sound_file(conference, user.name_rec_location, NULL);
2969 async_play_sound_file(conference,
2970 conf_get_sound(CONF_SOUND_HAS_LEFT, conference->b_profile.sounds), NULL);
2971 async_delete_name_rec(conference, user.name_rec_location);
2972 async_delete_task_pushed = 1;
2973 }
2974
2975 /* play the leave sound */
2976 if (!quiet) {
2977 const char *leave_sound = conf_get_sound(CONF_SOUND_LEAVE, conference->b_profile.sounds);
2978 async_play_sound_file(conference, leave_sound, NULL);
2979 }
2980
2981 /* If the user was kicked from the conference play back the audio prompt for it */
2982 if (!quiet && user.kicked) {
2983 res = ast_stream_and_wait(chan,
2984 conf_get_sound(CONF_SOUND_KICKED, conference->b_profile.sounds),
2985 "");
2986 }
2987
2988 /* Easy as pie, depart this channel from the conference bridge */
2989 leave_conference(&user);
2990 conference = NULL;
2991
2992 /* Restore volume adjustments to previous values in case they were changed */
2993 if (volume_adjustments[0]) {
2994 ast_audiohook_volume_set(chan, AST_AUDIOHOOK_DIRECTION_READ, volume_adjustments[0]);
2995 }
2996 if (volume_adjustments[1]) {
2997 ast_audiohook_volume_set(chan, AST_AUDIOHOOK_DIRECTION_WRITE, volume_adjustments[1]);
2998 }
2999
3000 confbridge_cleanup:
3001 if (!async_delete_task_pushed && !ast_strlen_zero(user.name_rec_location)) {
3002 ast_filedelete(user.name_rec_location, NULL);
3003 }
3004 ast_bridge_features_cleanup(&user.features);
3005 conf_bridge_profile_destroy(&user.b_profile);
3006 return res;
3007 }
3008
3009 static int action_toggle_mute(struct confbridge_conference *conference,
3010 struct confbridge_user *user,
3011 struct ast_bridge_channel *bridge_channel)
3012 {
3013 int mute;
3014
3015 /* Toggle user level mute request. */
3016 mute = !user->muted;
3017 generic_mute_unmute_user(conference, user, mute);
3018
3019 return play_file(bridge_channel, NULL,
3020 conf_get_sound(mute ? CONF_SOUND_MUTED : CONF_SOUND_UNMUTED,
3021 conference->b_profile.sounds)) < 0;
3022 }
3023
3024 static int action_toggle_binaural(struct confbridge_conference *conference,
3025 struct confbridge_user *user,
3026 struct ast_bridge_channel *bridge_channel)
3027 {
3028 unsigned int binaural;
3029 ast_bridge_channel_lock_bridge(bridge_channel);
3030 binaural = !bridge_channel->binaural_suspended;
3031 bridge_channel->binaural_suspended = binaural;
3032 ast_bridge_unlock(bridge_channel->bridge);
3033 return play_file(bridge_channel, NULL, (binaural ?
3034 conf_get_sound(CONF_SOUND_BINAURAL_OFF, user->b_profile.sounds) :
3035 conf_get_sound(CONF_SOUND_BINAURAL_ON, user->b_profile.sounds))) < 0;
3036 }
3037
3038 static int action_toggle_mute_participants(struct confbridge_conference *conference, struct confbridge_user *user)
3039 {
3040 struct confbridge_user *cur_user = NULL;
3041 const char *sound_to_play;
3042 int mute;
3043
3044 ao2_lock(conference);
3045
3046 /* Toggle bridge level mute request. */
3047 mute = !conference->muted;
3048 conference->muted = mute;
3049
3050 AST_LIST_TRAVERSE(&conference->active_list, cur_user, list) {
3051 if (!ast_test_flag(&cur_user->u_profile, USER_OPT_ADMIN)) {
3052 /* Set user level to bridge level mute request. */
3053 cur_user->muted = mute;
3054 conf_update_user_mute(cur_user);
3055 }
3056 }
3057
3058 ao2_unlock(conference);
3059
3060 sound_to_play = conf_get_sound(
3061 mute ? CONF_SOUND_PARTICIPANTS_MUTED : CONF_SOUND_PARTICIPANTS_UNMUTED,
3062 conference->b_profile.sounds);
3063
3064 if (strcmp(conference->b_profile.language, ast_channel_language(user->chan))) {
3065 /* The host needs to hear it seperately, as they don't get the audio from play_sound_helper */
3066 ast_stream_and_wait(user->chan, sound_to_play, "");
3067
3068 /* Announce to the group that all participants are muted */
3069 ast_autoservice_start(user->chan);
3070 play_sound_file(conference, sound_to_play);
3071 ast_autoservice_stop(user->chan);
3072 } else {
3073 /* Playing the sound asynchronously lets the sound be heard by everyone at once */
3074 async_play_sound_file(conference, sound_to_play, user->chan);
3075 }
3076
3077 return 0;
3078 }
3079
3080 static int action_playback(struct ast_bridge_channel *bridge_channel, const char *playback_file)
3081 {
3082 char *file_copy = ast_strdupa(playback_file);
3083 char *file = NULL;
3084
3085 while ((file = ast_strsep(&file_copy, '&', AST_STRSEP_STRIP | AST_STRSEP_TRIM))) {
3086 if (ast_stream_and_wait(bridge_channel->chan, file, "")) {
3087 ast_log(LOG_WARNING, "Failed to playback file %s to channel\n", file);
3088 return -1;
3089 }
3090 }
3091 return 0;
3092 }
3093
3094 static int action_playback_and_continue(struct confbridge_conference *conference,
3095 struct confbridge_user *user,
3096 struct ast_bridge_channel *bridge_channel,
3097 struct conf_menu *menu,
3098 const char *playback_file,
3099 const char *cur_dtmf,
3100 int *stop_prompts)
3101 {
3102 int i;
3103 int digit = 0;
3104 char dtmf[MAXIMUM_DTMF_FEATURE_STRING];
3105 struct conf_menu_entry new_menu_entry = { { 0, }, };
3106 char *file_copy = ast_strdupa(playback_file);
3107 char *file = NULL;
3108
3109 while ((file = ast_strsep(&file_copy, '&', AST_STRSEP_STRIP | AST_STRSEP_TRIM))) {
3110 if (ast_streamfile(bridge_channel->chan, file, ast_channel_language(bridge_channel->chan))) {
3111 ast_log(LOG_WARNING, "Failed to playback file %s to channel\n", file);
3112 return -1;
3113 }
3114
3115 /* now wait for more digits. */
3116 if (!(digit = ast_waitstream(bridge_channel->chan, AST_DIGIT_ANY))) {
3117 /* streaming finished and no DTMF was entered */
3118 continue;
3119 } else if (digit == -1) {
3120 /* error */
3121 return -1;
3122 } else {
3123 break; /* dtmf was entered */
3124 }
3125 }
3126 if (!digit) {
3127 /* streaming finished on all files and no DTMF was entered */
3128 return -1;
3129 }
3130 ast_stopstream(bridge_channel->chan);
3131
3132 /* If we get here, then DTMF has been entered, This means no
3133 * additional prompts should be played for this menu entry */
3134 *stop_prompts = 1;
3135
3136 /* If a digit was pressed during the payback, update
3137 * the dtmf string and look for a new menu entry in the
3138 * menu structure */
3139 ast_copy_string(dtmf, cur_dtmf, sizeof(dtmf));
3140 for (i = 0; i < (MAXIMUM_DTMF_FEATURE_STRING - 1); i++) {
3141 dtmf[i] = cur_dtmf[i];
3142 if (!dtmf[i]) {
3143 dtmf[i] = (char) digit;
3144 dtmf[i + 1] = '\0';
3145 i = -1;
3146 break;
3147 }
3148 }
3149 /* If i is not -1 then the new dtmf digit was _NOT_ added to the string.
3150 * If this is the case, no new DTMF sequence should be looked for. */
3151 if (i != -1) {
3152 return 0;
3153 }
3154
3155 if (conf_find_menu_entry_by_sequence(dtmf, menu, &new_menu_entry)) {
3156 execute_menu_entry(conference,
3157 user,
3158 bridge_channel,
3159 &new_menu_entry, menu);
3160 conf_menu_entry_destroy(&new_menu_entry);
3161 }
3162 return 0;
3163 }
3164
3165 static int action_kick_last(struct confbridge_conference *conference,
3166 struct ast_bridge_channel *bridge_channel,
3167 struct confbridge_user *user)
3168 {
3169 struct confbridge_user *last_user = NULL;
3170 int isadmin = ast_test_flag(&user->u_profile, USER_OPT_ADMIN);
3171
3172 if (!isadmin) {
3173 play_file(bridge_channel, NULL,
3174 conf_get_sound(CONF_SOUND_ERROR_MENU, conference->b_profile.sounds));
3175 ast_log(LOG_WARNING, "Only admin users can use the kick_last menu action. Channel %s of conf %s is not an admin.\n",
3176 ast_channel_name(bridge_channel->chan),
3177 conference->name);
3178 return -1;
3179 }
3180
3181 ao2_lock(conference);
3182 last_user = AST_LIST_LAST(&conference->active_list);
3183 if (!last_user) {
3184 ao2_unlock(conference);
3185 return 0;
3186 }
3187
3188 if (last_user == user || ast_test_flag(&last_user->u_profile, USER_OPT_ADMIN)) {
3189 ao2_unlock(conference);
3190 play_file(bridge_channel, NULL,
3191 conf_get_sound(CONF_SOUND_ERROR_MENU, conference->b_profile.sounds));
3192 } else if (!last_user->kicked) {
3193 last_user->kicked = 1;
3194 pbx_builtin_setvar_helper(last_user->chan, "CONFBRIDGE_RESULT", "KICKED");
3195 ast_bridge_remove(conference->bridge, last_user->chan);
3196 ao2_unlock(conference);
3197 }
3198
3199 return 0;
3200 }
3201
3202 static int action_dialplan_exec(struct ast_bridge_channel *bridge_channel, struct conf_menu_action *menu_action)
3203 {
3204 struct ast_pbx_args args;
3205 struct ast_pbx *pbx;
3206 char *exten;
3207 char *context;
3208 int priority;
3209 int res;
3210
3211 memset(&args, 0, sizeof(args));
3212 args.no_hangup_chan = 1;
3213
3214 ast_channel_lock(bridge_channel->chan);
3215
3216 /*save off*/
3217 exten = ast_strdupa(ast_channel_exten(bridge_channel->chan));
3218 context = ast_strdupa(ast_channel_context(bridge_channel->chan));
3219 priority = ast_channel_priority(bridge_channel->chan);
3220 pbx = ast_channel_pbx(bridge_channel->chan);
3221 ast_channel_pbx_set(bridge_channel->chan, NULL);
3222
3223 /*set new*/
3224 ast_channel_exten_set(bridge_channel->chan, menu_action->data.dialplan_args.exten);
3225 ast_channel_context_set(bridge_channel->chan, menu_action->data.dialplan_args.context);
3226 ast_channel_priority_set(bridge_channel->chan, menu_action->data.dialplan_args.priority);
3227
3228 ast_channel_unlock(bridge_channel->chan);
3229
3230 /*execute*/
3231 res = ast_pbx_run_args(bridge_channel->chan, &args);
3232
3233 /*restore*/
3234 ast_channel_lock(bridge_channel->chan);
3235
3236 ast_channel_exten_set(bridge_channel->chan, exten);
3237 ast_channel_context_set(bridge_channel->chan, context);
3238 ast_channel_priority_set(bridge_channel->chan, priority);
3239 ast_channel_pbx_set(bridge_channel->chan, pbx);
3240
3241 ast_channel_unlock(bridge_channel->chan);
3242
3243 return res;
3244 }
3245
3246 static int execute_menu_entry(struct confbridge_conference *conference,
3247 struct confbridge_user *user,
3248 struct ast_bridge_channel *bridge_channel,
3249 struct conf_menu_entry *menu_entry,
3250 struct conf_menu *menu)
3251 {
3252 struct conf_menu_action *menu_action;
3253 int isadmin = ast_test_flag(&user->u_profile, USER_OPT_ADMIN);
3254 int stop_prompts = 0;
3255 int res = 0;
3256
3257 AST_LIST_TRAVERSE(&menu_entry->actions, menu_action, action) {
3258 switch (menu_action->id) {
3259 case MENU_ACTION_TOGGLE_MUTE:
3260 res |= action_toggle_mute(conference, user, bridge_channel);
3261 break;
3262 case MENU_ACTION_TOGGLE_BINAURAL:
3263 action_toggle_binaural(conference, user, bridge_channel);
3264 break;
3265 case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
3266 if (!isadmin) {
3267 break;
3268 }
3269 action_toggle_mute_participants(conference, user);
3270 break;
3271 case MENU_ACTION_PARTICIPANT_COUNT:
3272 announce_user_count(conference, user, bridge_channel);
3273 break;
3274 case MENU_ACTION_PLAYBACK:
3275 if (!stop_prompts) {
3276 res |= action_playback(bridge_channel, menu_action->data.playback_file);
3277 ast_test_suite_event_notify("CONF_MENU_PLAYBACK",
3278 "Message: %s\r\nChannel: %s",
3279 menu_action->data.playback_file, ast_channel_name(bridge_channel->chan));
3280 }
3281 break;
3282 case MENU_ACTION_RESET_LISTENING:
3283 ast_audiohook_volume_set(user->chan, AST_AUDIOHOOK_DIRECTION_WRITE, 0);
3284 break;
3285 case MENU_ACTION_RESET_TALKING:
3286 ast_audiohook_volume_set(user->chan, AST_AUDIOHOOK_DIRECTION_READ, 0);
3287 break;
3288 case MENU_ACTION_INCREASE_LISTENING:
3289 ast_audiohook_volume_adjust(user->chan,
3290 AST_AUDIOHOOK_DIRECTION_WRITE, 1);
3291 break;
3292 case MENU_ACTION_DECREASE_LISTENING:
3293 ast_audiohook_volume_adjust(user->chan,
3294 AST_AUDIOHOOK_DIRECTION_WRITE, -1);
3295 break;
3296 case MENU_ACTION_INCREASE_TALKING:
3297 ast_audiohook_volume_adjust(user->chan,
3298 AST_AUDIOHOOK_DIRECTION_READ, 1);
3299 break;
3300 case MENU_ACTION_DECREASE_TALKING:
3301 ast_audiohook_volume_adjust(user->chan,
3302 AST_AUDIOHOOK_DIRECTION_READ, -1);
3303 break;
3304 case MENU_ACTION_PLAYBACK_AND_CONTINUE:
3305 if (!(stop_prompts)) {
3306 res |= action_playback_and_continue(conference,
3307 user,
3308 bridge_channel,
3309 menu,
3310 menu_action->data.playback_file,
3311 menu_entry->dtmf,
3312 &stop_prompts);
3313 }
3314 break;
3315 case MENU_ACTION_DIALPLAN_EXEC:
3316 res |= action_dialplan_exec(bridge_channel, menu_action);
3317 break;
3318 case MENU_ACTION_ADMIN_TOGGLE_LOCK:
3319 if (!isadmin) {
3320 break;
3321 }
3322 conference->locked = (!conference->locked ? 1 : 0);
3323 res |= play_file(bridge_channel, NULL,
3324 conf_get_sound(
3325 conference->locked ? CONF_SOUND_LOCKED_NOW : CONF_SOUND_UNLOCKED_NOW,
3326 conference->b_profile.sounds)) < 0;
3327 break;
3328 case MENU_ACTION_ADMIN_KICK_LAST:
3329 res |= action_kick_last(conference, bridge_channel, user);
3330 break;
3331 case MENU_ACTION_LEAVE:
3332 pbx_builtin_setvar_helper(bridge_channel->chan, "CONFBRIDGE_RESULT", "DTMF");
3333 ao2_lock(conference);
3334 ast_bridge_remove(conference->bridge, bridge_channel->chan);
3335 ast_test_suite_event_notify("CONF_MENU_LEAVE",
3336 "Channel: %s",
3337 ast_channel_name(bridge_channel->chan));
3338 ao2_unlock(conference);
3339 break;
3340 case MENU_ACTION_NOOP:
3341 break;
3342 case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
3343 ao2_lock(conference);
3344 if (!ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_SFU)) {
3345 ast_bridge_set_single_src_video_mode(conference->bridge, bridge_channel->chan);
3346 }
3347 ao2_unlock(conference);
3348 break;
3349 case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
3350 handle_video_on_exit(conference, bridge_channel->chan);
3351 break;
3352 }
3353 }
3354 return res;
3355 }
3356
3357 int conf_handle_dtmf(struct ast_bridge_channel *bridge_channel,
3358 struct confbridge_user *user,
3359 struct conf_menu_entry *menu_entry,
3360 struct conf_menu *menu)
3361 {
3362 /* See if music on hold is playing */
3363 conf_moh_suspend(user);
3364
3365 /* execute the list of actions associated with this menu entry */
3366 execute_menu_entry(user->conference, user, bridge_channel, menu_entry, menu);
3367
3368 /* See if music on hold needs to be started back up again */
3369 conf_moh_unsuspend(user);
3370
3371 async_play_sound_ready(bridge_channel->chan);
3372
3373 return 0;
3374 }
3375
3376 static int kick_conference_participant(struct confbridge_conference *conference,
3377 const char *channel)
3378 {
3379 int res = -1;
3380 int match;
3381 struct confbridge_user *user = NULL;
3382 int all = !strcasecmp("all", channel);
3383 int participants = !strcasecmp("participants", channel);
3384
3385 SCOPED_AO2LOCK(bridge_lock, conference);
3386
3387 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
3388 if (user->kicked) {
3389 continue;
3390 }
3391 match = !strcasecmp(channel, ast_channel_name(user->chan));
3392 if (match || all
3393 || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
3394 user->kicked = 1;
3395 pbx_builtin_setvar_helper(user->chan, "CONFBRIDGE_RESULT", "KICKED");
3396 ast_bridge_remove(conference->bridge, user->chan);
3397 res = 0;
3398 if (match) {
3399 return res;
3400 }
3401 }
3402 }
3403 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
3404 if (user->kicked) {
3405 continue;
3406 }
3407 match = !strcasecmp(channel, ast_channel_name(user->chan));
3408 if (match || all
3409 || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
3410 user->kicked = 1;
3411 pbx_builtin_setvar_helper(user->chan, "CONFBRIDGE_RESULT", "KICKED");
3412 ast_bridge_remove(conference->bridge, user->chan);
3413 res = 0;
3414 if (match) {
3415 return res;
3416 }
3417 }
3418 }
3419
3420 return res;
3421 }
3422
3423 static char *complete_confbridge_name(const char *line, const char *word, int pos, int state)
3424 {
3425 int which = 0;
3426 struct confbridge_conference *conference;
3427 char *res = NULL;
3428 int wordlen = strlen(word);
3429 struct ao2_iterator iter;
3430
3431 iter = ao2_iterator_init(conference_bridges, 0);
3432 while ((conference = ao2_iterator_next(&iter))) {
3433 if (!strncasecmp(conference->name, word, wordlen) && ++which > state) {
3434 res = ast_strdup(conference->name);
3435 ao2_ref(conference, -1);
3436 break;
3437 }
3438 ao2_ref(conference, -1);
3439 }
3440 ao2_iterator_destroy(&iter);
3441
3442 return res;
3443 }
3444
3445 static char *complete_confbridge_participant(const char *conference_name, const char *line, const char *word, int pos, int state)
3446 {
3447 int which = 0;
3448 RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
3449 struct confbridge_user *user;
3450 char *res = NULL;
3451 int wordlen = strlen(word);
3452
3453 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
3454 if (!conference) {
3455 return NULL;
3456 }
3457
3458 if (!strncasecmp("all", word, wordlen) && ++which > state) {
3459 return ast_strdup("all");
3460 }
3461
3462 if (!strncasecmp("participants", word, wordlen) && ++which > state) {
3463 return ast_strdup("participants");
3464 }
3465
3466 {
3467 SCOPED_AO2LOCK(bridge_lock, conference);
3468 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
3469 if (!strncasecmp(ast_channel_name(user->chan), word, wordlen) && ++which > state) {
3470 res = ast_strdup(ast_channel_name(user->chan));
3471 return res;
3472 }
3473 }
3474 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
3475 if (!strncasecmp(ast_channel_name(user->chan), word, wordlen) && ++which > state) {
3476 res = ast_strdup(ast_channel_name(user->chan));
3477 return res;
3478 }
3479 }
3480 }
3481
3482 return NULL;
3483 }
3484
3485 static char *handle_cli_confbridge_kick(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3486 {
3487 struct confbridge_conference *conference;
3488 int not_found;
3489
3490 switch (cmd) {
3491 case CLI_INIT:
3492 e->command = "confbridge kick";
3493 e->usage =
3494 "Usage: confbridge kick <conference> <channel>\n"
3495 " Kicks a channel out of the conference bridge.\n"
3496 " (all to kick everyone, participants to kick non-admins).\n";
3497 return NULL;
3498 case CLI_GENERATE:
3499 if (a->pos == 2) {
3500 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3501 }
3502 if (a->pos == 3) {
3503 return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
3504 }
3505 return NULL;
3506 }
3507
3508 if (a->argc != 4) {
3509 return CLI_SHOWUSAGE;
3510 }
3511
3512 conference = ao2_find(conference_bridges, a->argv[2], OBJ_KEY);
3513 if (!conference) {
3514 ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
3515 return CLI_SUCCESS;
3516 }
3517 not_found = kick_conference_participant(conference, a->argv[3]);
3518 ao2_ref(conference, -1);
3519 if (not_found) {
3520 if (!strcasecmp("all", a->argv[3]) || !strcasecmp("participants", a->argv[3])) {
3521 ast_cli(a->fd, "No participants found!\n");
3522 } else {
3523 ast_cli(a->fd, "No participant named '%s' found!\n", a->argv[3]);
3524 }
3525 return CLI_SUCCESS;
3526 }
3527 ast_cli(a->fd, "Kicked '%s' out of conference '%s'\n", a->argv[3], a->argv[2]);
3528 return CLI_SUCCESS;
3529 }
3530
3531 static void handle_cli_confbridge_list_item(struct ast_cli_args *a, struct confbridge_user *user, int waiting)
3532 {
3533 char flag_str[6 + 1];/* Max flags + terminator */
3534 int pos = 0;
3535
3536 /* Build flags column string. */
3537 if (ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
3538 flag_str[pos++] = 'A';
3539 }
3540 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
3541 flag_str[pos++] = 'M';
3542 }
3543 if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
3544 flag_str[pos++] = 'W';
3545 }
3546 if (ast_test_flag(&user->u_profile, USER_OPT_ENDMARKED)) {
3547 flag_str[pos++] = 'E';
3548 }
3549 if (user->muted) {
3550 flag_str[pos++] = 'm';
3551 }
3552 if (waiting) {
3553 flag_str[pos++] = 'w';
3554 }
3555 flag_str[pos] = '\0';
3556
3557 ast_cli(a->fd, "%-30s %-6s %-16s %-16s %-16s %s\n",
3558 ast_channel_name(user->chan),
3559 flag_str,
3560 user->u_profile.name,
3561 user->conference->b_profile.name,
3562 user->menu_name,
3563 S_COR(ast_channel_caller(user->chan)->id.number.valid,
3564 ast_channel_caller(user->chan)->id.number.str, "<unknown>"));
3565 }
3566
3567 static char *handle_cli_confbridge_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3568 {
3569 struct confbridge_conference *conference;
3570
3571 switch (cmd) {
3572 case CLI_INIT:
3573 e->command = "confbridge list";
3574 e->usage =
3575 "Usage: confbridge list [<name>]\n"
3576 " Lists all currently active conference bridges or a specific conference bridge.\n"
3577 "\n"
3578 " When a conference bridge name is provided, flags may be shown for users. Below\n"
3579 " are the flags and what they represent.\n"
3580 "\n"
3581 " Flags:\n"
3582 " A - The user is an admin\n"
3583 " M - The user is a marked user\n"
3584 " W - The user must wait for a marked user to join\n"
3585 " E - The user will be kicked after the last marked user leaves the conference\n"
3586 " m - The user is muted\n"
3587 " w - The user is waiting for a marked user to join\n";
3588 return NULL;
3589 case CLI_GENERATE:
3590 if (a->pos == 2) {
3591 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3592 }
3593 return NULL;
3594 }
3595
3596 if (a->argc == 2) {
3597 struct ao2_iterator iter;
3598
3599 ast_cli(a->fd, "Conference Bridge Name Users Marked Locked Muted\n");
3600 ast_cli(a->fd, "================================ ====== ====== ====== =====\n");
3601 iter = ao2_iterator_init(conference_bridges, 0);
3602 while ((conference = ao2_iterator_next(&iter))) {
3603 ast_cli(a->fd, "%-32s %6u %6u %-6s %s\n",
3604 conference->name,
3605 conference->activeusers + conference->waitingusers,
3606 conference->markedusers,
3607 AST_CLI_YESNO(conference->locked),
3608 AST_CLI_YESNO(conference->muted));
3609 ao2_ref(conference, -1);
3610 }
3611 ao2_iterator_destroy(&iter);
3612 return CLI_SUCCESS;
3613 }
3614
3615 if (a->argc == 3) {
3616 struct confbridge_user *user;
3617
3618 conference = ao2_find(conference_bridges, a->argv[2], OBJ_KEY);
3619 if (!conference) {
3620 ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
3621 return CLI_SUCCESS;
3622 }
3623 ast_cli(a->fd, "Channel Flags User Profile Bridge Profile Menu CallerID\n");
3624 ast_cli(a->fd, "============================== ====== ================ ================ ================ ================\n");
3625 ao2_lock(conference);
3626 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
3627 handle_cli_confbridge_list_item(a, user, 0);
3628 }
3629 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
3630 handle_cli_confbridge_list_item(a, user, 1);
3631 }
3632 ao2_unlock(conference);
3633 ao2_ref(conference, -1);
3634 return CLI_SUCCESS;
3635 }
3636
3637 return CLI_SHOWUSAGE;
3638 }
3639
3640 /*! \internal
3641 * \brief finds a conference by name and locks/unlocks.
3642 *
3643 * \retval 0 success
3644 * \retval -1 conference not found
3645 */
3646 static int generic_lock_unlock_helper(int lock, const char *conference_name)
3647 {
3648 struct confbridge_conference *conference;
3649 int res = 0;
3650
3651 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
3652 if (!conference) {
3653 return -1;
3654 }
3655 ao2_lock(conference);
3656 conference->locked = lock;
3657 ast_test_suite_event_notify("CONF_LOCK", "Message: conference %s\r\nConference: %s", conference->locked ? "locked" : "unlocked", conference->b_profile.name);
3658 ao2_unlock(conference);
3659 ao2_ref(conference, -1);
3660
3661 return res;
3662 }
3663
3664 /*! \internal
3665 * \brief finds a conference user by channel name and mutes/unmutes them.
3666 *
3667 * \retval 0 success
3668 * \retval -1 conference not found
3669 * \retval -2 user not found
3670 */
3671 static int generic_mute_unmute_helper(int mute, const char *conference_name,
3672 const char *chan_name)
3673 {
3674 RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
3675 struct confbridge_user *user;
3676 int all = !strcasecmp("all", chan_name);
3677 int participants = !strcasecmp("participants", chan_name);
3678 int res = -2;
3679
3680 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
3681 if (!conference) {
3682 return -1;
3683 }
3684
3685 {
3686 SCOPED_AO2LOCK(bridge_lock, conference);
3687 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
3688 int match = !strncasecmp(chan_name, ast_channel_name(user->chan),
3689 strlen(chan_name));
3690 if (match || all
3691 || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
3692 generic_mute_unmute_user(conference, user, mute);
3693 res = 0;
3694 if (match) {
3695 return res;
3696 }
3697 }
3698 }
3699
3700 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
3701 int match = !strncasecmp(chan_name, ast_channel_name(user->chan),
3702 strlen(chan_name));
3703 if (match || all
3704 || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
3705 generic_mute_unmute_user(conference, user, mute);
3706 res = 0;
3707 if (match) {
3708 return res;
3709 }
3710 }
3711 }
3712 }
3713
3714 return res;
3715 }
3716
3717 static int cli_mute_unmute_helper(int mute, struct ast_cli_args *a)
3718 {
3719 int res = generic_mute_unmute_helper(mute, a->argv[2], a->argv[3]);
3720
3721 if (res == -1) {
3722 ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
3723 return -1;
3724 } else if (res == -2) {
3725 if (!strcasecmp("all", a->argv[3]) || !strcasecmp("participants", a->argv[3])) {
3726 ast_cli(a->fd, "No participants found in conference %s\n", a->argv[2]);
3727 } else {
3728 ast_cli(a->fd, "No channel named '%s' found in conference %s\n", a->argv[3], a->argv[2]);
3729 }
3730 return -1;
3731 }
3732 ast_cli(a->fd, "%s %s from confbridge %s\n", mute ? "Muting" : "Unmuting", a->argv[3], a->argv[2]);
3733 return 0;
3734 }
3735
3736 static char *handle_cli_confbridge_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3737 {
3738 switch (cmd) {
3739 case CLI_INIT:
3740 e->command = "confbridge mute";
3741 e->usage =
3742 "Usage: confbridge mute <conference> <channel>\n"
3743 " Mute a channel in a conference.\n"
3744 " (all to mute everyone, participants to mute non-admins)\n"
3745 " If the specified channel is a prefix,\n"
3746 " the action will be taken on the first\n"
3747 " matching channel.\n";
3748 return NULL;
3749 case CLI_GENERATE:
3750 if (a->pos == 2) {
3751 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3752 }
3753 if (a->pos == 3) {
3754 return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
3755 }
3756 return NULL;
3757 }
3758 if (a->argc != 4) {
3759 return CLI_SHOWUSAGE;
3760 }
3761
3762 cli_mute_unmute_helper(1, a);
3763
3764 return CLI_SUCCESS;
3765 }
3766
3767 static char *handle_cli_confbridge_unmute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3768 {
3769 switch (cmd) {
3770 case CLI_INIT:
3771 e->command = "confbridge unmute";
3772 e->usage =
3773 "Usage: confbridge unmute <conference> <channel>\n"
3774 " Unmute a channel in a conference.\n"
3775 " (all to unmute everyone, participants to unmute non-admins)\n"
3776 " If the specified channel is a prefix,\n"
3777 " the action will be taken on the first\n"
3778 " matching channel.\n";
3779 return NULL;
3780 case CLI_GENERATE:
3781 if (a->pos == 2) {
3782 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3783 }
3784 if (a->pos == 3) {
3785 return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
3786 }
3787 return NULL;
3788 }
3789 if (a->argc != 4) {
3790 return CLI_SHOWUSAGE;
3791 }
3792
3793 cli_mute_unmute_helper(0, a);
3794
3795 return CLI_SUCCESS;
3796 }
3797
3798 static char *handle_cli_confbridge_lock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3799 {
3800 switch (cmd) {
3801 case CLI_INIT:
3802 e->command = "confbridge lock";
3803 e->usage =
3804 "Usage: confbridge lock <conference>\n"
3805 " Lock a conference. While locked, no new non-admins\n"
3806 " may join the conference.\n";
3807 return NULL;
3808 case CLI_GENERATE:
3809 if (a->pos == 2) {
3810 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3811 }
3812 return NULL;
3813 }
3814 if (a->argc != 3) {
3815 return CLI_SHOWUSAGE;
3816 }
3817 if (generic_lock_unlock_helper(1, a->argv[2])) {
3818 ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
3819 } else {
3820 ast_cli(a->fd, "Conference %s is locked.\n", a->argv[2]);
3821 }
3822 return CLI_SUCCESS;
3823 }
3824
3825 static char *handle_cli_confbridge_unlock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3826 {
3827 switch (cmd) {
3828 case CLI_INIT:
3829 e->command = "confbridge unlock";
3830 e->usage =
3831 "Usage: confbridge unlock <conference>\n"
3832 " Unlock a previously locked conference.\n";
3833 return NULL;
3834 case CLI_GENERATE:
3835 if (a->pos == 2) {
3836 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3837 }
3838 return NULL;
3839 }
3840 if (a->argc != 3) {
3841 return CLI_SHOWUSAGE;
3842 }
3843 if (generic_lock_unlock_helper(0, a->argv[2])) {
3844 ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
3845 } else {
3846 ast_cli(a->fd, "Conference %s is unlocked.\n", a->argv[2]);
3847 }
3848 return CLI_SUCCESS;
3849 }
3850
3851 static char *handle_cli_confbridge_start_record(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3852 {
3853 const char *rec_file = NULL;
3854 struct confbridge_conference *conference;
3855
3856 switch (cmd) {
3857 case CLI_INIT:
3858 e->command = "confbridge record start";
3859 e->usage =
3860 "Usage: confbridge record start <conference> <file>\n"
3861 " <file> is optional, Otherwise the bridge profile\n"
3862 " record file will be used. If the bridge profile\n"
3863 " has no record file specified, a file will automatically\n"
3864 " be generated in the monitor directory\n";
3865 return NULL;
3866 case CLI_GENERATE:
3867 if (a->pos == 3) {
3868 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3869 }
3870 return NULL;
3871 }
3872 if (a->argc < 4) {
3873 return CLI_SHOWUSAGE;
3874 }
3875 if (a->argc == 5) {
3876 rec_file = a->argv[4];
3877 }
3878
3879 conference = ao2_find(conference_bridges, a->argv[3], OBJ_KEY);
3880 if (!conference) {
3881 ast_cli(a->fd, "Conference not found.\n");
3882 return CLI_FAILURE;
3883 }
3884 ao2_lock(conference);
3885 if (conf_is_recording(conference)) {
3886 ast_cli(a->fd, "Conference is already being recorded.\n");
3887 ao2_unlock(conference);
3888 ao2_ref(conference, -1);
3889 return CLI_SUCCESS;
3890 }
3891 if (!ast_strlen_zero(rec_file)) {
3892 ast_copy_string(conference->b_profile.rec_file, rec_file, sizeof(conference->b_profile.rec_file));
3893 }
3894
3895 if (conf_start_record(conference)) {
3896 ast_cli(a->fd, "Could not start recording due to internal error.\n");
3897 ao2_unlock(conference);
3898 ao2_ref(conference, -1);
3899 return CLI_FAILURE;
3900 }
3901 ao2_unlock(conference);
3902
3903 ast_cli(a->fd, "Recording started\n");
3904 ao2_ref(conference, -1);
3905 return CLI_SUCCESS;
3906 }
3907
3908 static char *handle_cli_confbridge_stop_record(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3909 {
3910 struct confbridge_conference *conference;
3911 int ret;
3912
3913 switch (cmd) {
3914 case CLI_INIT:
3915 e->command = "confbridge record stop";
3916 e->usage =
3917 "Usage: confbridge record stop <conference>\n"
3918 " Stop a previously started recording.\n";
3919 return NULL;
3920 case CLI_GENERATE:
3921 if (a->pos == 3) {
3922 return complete_confbridge_name(a->line, a->word, a->pos, a->n);
3923 }
3924 return NULL;
3925 }
3926 if (a->argc != 4) {
3927 return CLI_SHOWUSAGE;
3928 }
3929
3930 conference = ao2_find(conference_bridges, a->argv[3], OBJ_KEY);
3931 if (!conference) {
3932 ast_cli(a->fd, "Conference not found.\n");
3933 return CLI_SUCCESS;
3934 }
3935 ao2_lock(conference);
3936 ret = conf_stop_record(conference);
3937 ao2_unlock(conference);
3938 ast_cli(a->fd, "Recording %sstopped.\n", ret ? "could not be " : "");
3939 ao2_ref(conference, -1);
3940 return CLI_SUCCESS;
3941 }
3942
3943 static struct ast_cli_entry cli_confbridge[] = {
3944 AST_CLI_DEFINE(handle_cli_confbridge_list, "List conference bridges and participants."),
3945 AST_CLI_DEFINE(handle_cli_confbridge_kick, "Kick participants out of conference bridges."),
3946 AST_CLI_DEFINE(handle_cli_confbridge_mute, "Mute participants."),
3947 AST_CLI_DEFINE(handle_cli_confbridge_unmute, "Unmute participants."),
3948 AST_CLI_DEFINE(handle_cli_confbridge_lock, "Lock a conference."),
3949 AST_CLI_DEFINE(handle_cli_confbridge_unlock, "Unlock a conference."),
3950 AST_CLI_DEFINE(handle_cli_confbridge_start_record, "Start recording a conference"),
3951 AST_CLI_DEFINE(handle_cli_confbridge_stop_record, "Stop recording a conference."),
3952 };
3953 static struct ast_custom_function confbridge_function = {
3954 .name = "CONFBRIDGE",
3955 .write = func_confbridge_helper,
3956 };
3957
3958 static int func_confbridge_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len);
3959 static struct ast_custom_function confbridge_info_function = {
3960 .name = "CONFBRIDGE_INFO",
3961 .read = func_confbridge_info,
3962 };
3963
3964 static int func_confbridge_channels(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
3965 {
3966 char *parse, *outbuf;
3967 struct confbridge_conference *conference;
3968 struct confbridge_user *user;
3969 int bytes, count = 0;
3970 size_t outlen;
3971 AST_DECLARE_APP_ARGS(args,
3972 AST_APP_ARG(type);
3973 AST_APP_ARG(confno);
3974 );
3975
3976 /* parse all the required arguments and make sure they exist. */
3977 if (ast_strlen_zero(data)) {
3978 return -1;
3979 }
3980 parse = ast_strdupa(data);
3981 AST_STANDARD_APP_ARGS(args, parse);
3982 if (ast_strlen_zero(args.confno) || ast_strlen_zero(args.type)) {
3983 ast_log(LOG_WARNING, "Usage: %s(category,confno)", cmd);
3984 return -1;
3985 }
3986 conference = ao2_find(conference_bridges, args.confno, OBJ_KEY);
3987 if (!conference) {
3988 ast_debug(1, "No such conference: %s\n", args.confno);
3989 return -1;
3990 }
3991
3992 outbuf = buf;
3993 outlen = len;
3994
3995 ao2_lock(conference);
3996 if (!strcasecmp(args.type, "parties")) {
3997 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
3998 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
3999 outbuf += bytes;
4000 outlen -= bytes;
4001 }
4002 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
4003 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
4004 outbuf += bytes;
4005 outlen -= bytes;
4006 }
4007 } else if (!strcasecmp(args.type, "active")) {
4008 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4009 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
4010 outbuf += bytes;
4011 outlen -= bytes;
4012 }
4013 } else if (!strcasecmp(args.type, "waiting")) {
4014 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
4015 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
4016 outbuf += bytes;
4017 outlen -= bytes;
4018 }
4019 } else if (!strcasecmp(args.type, "admins")) {
4020 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4021 if (ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
4022 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
4023 outbuf += bytes;
4024 outlen -= bytes;
4025 }
4026 }
4027 } else if (!strcasecmp(args.type, "marked")) {
4028 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4029 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
4030 bytes = snprintf(outbuf, outlen, "%s%s", count++ ? "," : "", ast_channel_name(user->chan));
4031 outbuf += bytes;
4032 outlen -= bytes;
4033 }
4034 }
4035 } else {
4036 ast_log(LOG_ERROR, "Invalid keyword '%s' passed to %s.\n", args.type, cmd);
4037 }
4038 ao2_unlock(conference);
4039 ao2_ref(conference, -1);
4040 return 0;
4041 }
4042
4043 static struct ast_custom_function confbridge_channels_function = {
4044 .name = "CONFBRIDGE_CHANNELS",
4045 .read = func_confbridge_channels,
4046 };
4047
4048 static int action_confbridgelist_item(struct mansession *s, const char *id_text, struct confbridge_conference *conference, struct confbridge_user *user, int waiting)
4049 {
4050 struct ast_channel_snapshot *snapshot;
4051 struct ast_str *snap_str;
4052
4053 snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(user->chan));
4054 if (!snapshot) {
4055 return 0;
4056 }
4057
4058 snap_str = ast_manager_build_channel_state_string(snapshot);
4059 if (!snap_str) {
4060 ao2_ref(snapshot, -1);
4061 return 0;
4062 }
4063
4064 astman_append(s,
4065 "Event: ConfbridgeList\r\n"
4066 "%s"
4067 "Conference: %s\r\n"
4068 "Admin: %s\r\n"
4069 "MarkedUser: %s\r\n"
4070 "WaitMarked: %s\r\n"
4071 "EndMarked: %s\r\n"
4072 "EndMarkedAny: %s\r\n"
4073 "Waiting: %s\r\n"
4074 "Muted: %s\r\n"
4075 "Talking: %s\r\n"
4076 "AnsweredTime: %d\r\n"
4077 "%s"
4078 "\r\n",
4079 id_text,
4080 conference->name,
4081 AST_YESNO(ast_test_flag(&user->u_profile, USER_OPT_ADMIN)),
4082 AST_YESNO(ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)),
4083 AST_YESNO(ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)),
4084 AST_YESNO(ast_test_flag(&user->u_profile, USER_OPT_ENDMARKED)),
4085 AST_YESNO(ast_test_flag(&user->u_profile, USER_OPT_ENDMARKEDANY)),
4086 AST_YESNO(waiting),
4087 AST_YESNO(user->muted),
4088 AST_YESNO(user->talking),
4089 ast_channel_get_up_time(user->chan),
4090 ast_str_buffer(snap_str));
4091
4092 ast_free(snap_str);
4093 ao2_ref(snapshot, -1);
4094
4095 return 1;
4096 }
4097
4098 static int action_confbridgelist(struct mansession *s, const struct message *m)
4099 {
4100 const char *actionid = astman_get_header(m, "ActionID");
4101 const char *conference_name = astman_get_header(m, "Conference");
4102 struct confbridge_user *user;
4103 struct confbridge_conference *conference;
4104 char id_text[80];
4105 int total = 0;
4106
4107 id_text[0] = '\0';
4108 if (!ast_strlen_zero(actionid)) {
4109 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", actionid);
4110 }
4111 if (ast_strlen_zero(conference_name)) {
4112 astman_send_error(s, m, "No Conference name provided.");
4113 return 0;
4114 }
4115 if (!ao2_container_count(conference_bridges)) {
4116 astman_send_error(s, m, "No active conferences.");
4117 return 0;
4118 }
4119 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
4120 if (!conference) {
4121 astman_send_error(s, m, "No Conference by that name found.");
4122 return 0;
4123 }
4124
4125 astman_send_listack(s, m, "Confbridge user list will follow", "start");
4126
4127 ao2_lock(conference);
4128 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4129 total += action_confbridgelist_item(s, id_text, conference, user, 0);
4130 }
4131 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
4132 total += action_confbridgelist_item(s, id_text, conference, user, 1);
4133 }
4134 ao2_unlock(conference);
4135 ao2_ref(conference, -1);
4136
4137 astman_send_list_complete_start(s, m, "ConfbridgeListComplete", total);
4138 astman_send_list_complete_end(s);
4139
4140 return 0;
4141 }
4142
4143 static int action_confbridgelistrooms(struct mansession *s, const struct message *m)
4144 {
4145 const char *actionid = astman_get_header(m, "ActionID");
4146 struct confbridge_conference *conference;
4147 struct ao2_iterator iter;
4148 char id_text[512] = "";
4149 int totalitems = 0;
4150
4151 if (!ast_strlen_zero(actionid)) {
4152 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", actionid);
4153 }
4154
4155 if (!ao2_container_count(conference_bridges)) {
4156 astman_send_error(s, m, "No active conferences.");
4157 return 0;
4158 }
4159
4160 astman_send_listack(s, m, "Confbridge conferences will follow", "start");
4161
4162 /* Traverse the conference list */
4163 iter = ao2_iterator_init(conference_bridges, 0);
4164 while ((conference = ao2_iterator_next(&iter))) {
4165 totalitems++;
4166
4167 ao2_lock(conference);
4168 astman_append(s,
4169 "Event: ConfbridgeListRooms\r\n"
4170 "%s"
4171 "Conference: %s\r\n"
4172 "Parties: %u\r\n"
4173 "Marked: %u\r\n"
4174 "Locked: %s\r\n"
4175 "Muted: %s\r\n"
4176 "\r\n",
4177 id_text,
4178 conference->name,
4179 conference->activeusers + conference->waitingusers,
4180 conference->markedusers,
4181 AST_YESNO(conference->locked),
4182 AST_YESNO(conference->muted));
4183 ao2_unlock(conference);
4184
4185 ao2_ref(conference, -1);
4186 }
4187 ao2_iterator_destroy(&iter);
4188
4189 /* Send final confirmation */
4190 astman_send_list_complete_start(s, m, "ConfbridgeListRoomsComplete", totalitems);
4191 astman_send_list_complete_end(s);
4192 return 0;
4193 }
4194
4195 static int action_mute_unmute_helper(struct mansession *s, const struct message *m, int mute)
4196 {
4197 const char *conference_name = astman_get_header(m, "Conference");
4198 const char *channel_name = astman_get_header(m, "Channel");
4199 int res = 0;
4200
4201 if (ast_strlen_zero(conference_name)) {
4202 astman_send_error(s, m, "No Conference name provided.");
4203 return 0;
4204 }
4205 if (ast_strlen_zero(channel_name)) {
4206 astman_send_error(s, m, "No channel name provided.");
4207 return 0;
4208 }
4209 if (!ao2_container_count(conference_bridges)) {
4210 astman_send_error(s, m, "No active conferences.");
4211 return 0;
4212 }
4213
4214 res = generic_mute_unmute_helper(mute, conference_name, channel_name);
4215
4216 if (res == -1) {
4217 astman_send_error(s, m, "No Conference by that name found.");
4218 return 0;
4219 } else if (res == -2) {
4220 astman_send_error(s, m, "No Channel by that name found in Conference.");
4221 return 0;
4222 }
4223
4224 astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
4225 return 0;
4226 }
4227
4228 static int action_confbridgeunmute(struct mansession *s, const struct message *m)
4229 {
4230 return action_mute_unmute_helper(s, m, 0);
4231 }
4232 static int action_confbridgemute(struct mansession *s, const struct message *m)
4233 {
4234 return action_mute_unmute_helper(s, m, 1);
4235 }
4236
4237 static int action_lock_unlock_helper(struct mansession *s, const struct message *m, int lock)
4238 {
4239 const char *conference_name = astman_get_header(m, "Conference");
4240 int res = 0;
4241
4242 if (ast_strlen_zero(conference_name)) {
4243 astman_send_error(s, m, "No Conference name provided.");
4244 return 0;
4245 }
4246 if (!ao2_container_count(conference_bridges)) {
4247 astman_send_error(s, m, "No active conferences.");
4248 return 0;
4249 }
4250 if ((res = generic_lock_unlock_helper(lock, conference_name))) {
4251 astman_send_error(s, m, "No Conference by that name found.");
4252 return 0;
4253 }
4254 astman_send_ack(s, m, lock ? "Conference locked" : "Conference unlocked");
4255 return 0;
4256 }
4257 static int action_confbridgeunlock(struct mansession *s, const struct message *m)
4258 {
4259 return action_lock_unlock_helper(s, m, 0);
4260 }
4261 static int action_confbridgelock(struct mansession *s, const struct message *m)
4262 {
4263 return action_lock_unlock_helper(s, m, 1);
4264 }
4265
4266 static int action_confbridgekick(struct mansession *s, const struct message *m)
4267 {
4268 const char *conference_name = astman_get_header(m, "Conference");
4269 const char *channel = astman_get_header(m, "Channel");
4270 struct confbridge_conference *conference;
4271 int found;
4272
4273 if (ast_strlen_zero(conference_name)) {
4274 astman_send_error(s, m, "No Conference name provided.");
4275 return 0;
4276 }
4277 if (!ao2_container_count(conference_bridges)) {
4278 astman_send_error(s, m, "No active conferences.");
4279 return 0;
4280 }
4281
4282 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
4283 if (!conference) {
4284 astman_send_error(s, m, "No Conference by that name found.");
4285 return 0;
4286 }
4287
4288 found = !kick_conference_participant(conference, channel);
4289 ao2_ref(conference, -1);
4290
4291 if (found) {
4292 astman_send_ack(s, m, !strcmp("all", channel) ? "All participants kicked" : "User kicked");
4293 } else {
4294 astman_send_error(s, m, "No Channel by that name found in Conference.");
4295 }
4296 return 0;
4297 }
4298
4299 static int action_confbridgestartrecord(struct mansession *s, const struct message *m)
4300 {
4301 const char *conference_name = astman_get_header(m, "Conference");
4302 const char *recordfile = astman_get_header(m, "RecordFile");
4303 struct confbridge_conference *conference;
4304
4305 if (ast_strlen_zero(conference_name)) {
4306 astman_send_error(s, m, "No Conference name provided.");
4307 return 0;
4308 }
4309 if (!ao2_container_count(conference_bridges)) {
4310 astman_send_error(s, m, "No active conferences.");
4311 return 0;
4312 }
4313
4314 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
4315 if (!conference) {
4316 astman_send_error(s, m, "No Conference by that name found.");
4317 return 0;
4318 }
4319
4320 ao2_lock(conference);
4321 if (conf_is_recording(conference)) {
4322 astman_send_error(s, m, "Conference is already being recorded.");
4323 ao2_unlock(conference);
4324 ao2_ref(conference, -1);
4325 return 0;
4326 }
4327
4328 if (!ast_strlen_zero(recordfile)) {
4329 ast_copy_string(conference->b_profile.rec_file, recordfile, sizeof(conference->b_profile.rec_file));
4330 }
4331
4332 if (conf_start_record(conference)) {
4333 astman_send_error(s, m, "Internal error starting conference recording.");
4334 ao2_unlock(conference);
4335 ao2_ref(conference, -1);
4336 return 0;
4337 }
4338 ao2_unlock(conference);
4339
4340 ao2_ref(conference, -1);
4341 astman_send_ack(s, m, "Conference Recording Started.");
4342 return 0;
4343 }
4344 static int action_confbridgestoprecord(struct mansession *s, const struct message *m)
4345 {
4346 const char *conference_name = astman_get_header(m, "Conference");
4347 struct confbridge_conference *conference;
4348
4349 if (ast_strlen_zero(conference_name)) {
4350 astman_send_error(s, m, "No Conference name provided.");
4351 return 0;
4352 }
4353 if (!ao2_container_count(conference_bridges)) {
4354 astman_send_error(s, m, "No active conferences.");
4355 return 0;
4356 }
4357
4358 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
4359 if (!conference) {
4360 astman_send_error(s, m, "No Conference by that name found.");
4361 return 0;
4362 }
4363
4364 ao2_lock(conference);
4365 if (conf_stop_record(conference)) {
4366 ao2_unlock(conference);
4367 astman_send_error(s, m, "Internal error while stopping recording.");
4368 ao2_ref(conference, -1);
4369 return 0;
4370 }
4371 ao2_unlock(conference);
4372
4373 ao2_ref(conference, -1);
4374 astman_send_ack(s, m, "Conference Recording Stopped.");
4375 return 0;
4376 }
4377
4378 static int action_confbridgesetsinglevideosrc(struct mansession *s, const struct message *m)
4379 {
4380 const char *conference_name = astman_get_header(m, "Conference");
4381 const char *channel = astman_get_header(m, "Channel");
4382 struct confbridge_user *user;
4383 struct confbridge_conference *conference;
4384
4385 if (ast_strlen_zero(conference_name)) {
4386 astman_send_error(s, m, "No Conference name provided.");
4387 return 0;
4388 }
4389 if (ast_strlen_zero(channel)) {
4390 astman_send_error(s, m, "No channel name provided.");
4391 return 0;
4392 }
4393 if (!ao2_container_count(conference_bridges)) {
4394 astman_send_error(s, m, "No active conferences.");
4395 return 0;
4396 }
4397
4398 conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
4399 if (!conference) {
4400 astman_send_error(s, m, "No Conference by that name found.");
4401 return 0;
4402 }
4403
4404 /* find channel and set as video src. */
4405 ao2_lock(conference);
4406 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4407 if (!strncmp(channel, ast_channel_name(user->chan), strlen(channel))) {
4408 ast_bridge_set_single_src_video_mode(conference->bridge, user->chan);
4409 break;
4410 }
4411 }
4412 ao2_unlock(conference);
4413 ao2_ref(conference, -1);
4414
4415 /* do not access user after conference unlock. We are just
4416 * using this check to see if it was found or not */
4417 if (!user) {
4418 astman_send_error(s, m, "No channel by that name found in conference.");
4419 return 0;
4420 }
4421 astman_send_ack(s, m, "Conference single video source set.");
4422 return 0;
4423 }
4424
4425 static int func_confbridge_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
4426 {
4427 char *parse;
4428 struct confbridge_conference *conference;
4429 struct confbridge_user *user;
4430 int count = 0;
4431 AST_DECLARE_APP_ARGS(args,
4432 AST_APP_ARG(type);
4433 AST_APP_ARG(confno);
4434 );
4435
4436 /* parse all the required arguments and make sure they exist. */
4437 if (ast_strlen_zero(data)) {
4438 return -1;
4439 }
4440 parse = ast_strdupa(data);
4441 AST_STANDARD_APP_ARGS(args, parse);
4442 if (ast_strlen_zero(args.confno) || ast_strlen_zero(args.type)) {
4443 return -1;
4444 }
4445 conference = ao2_find(conference_bridges, args.confno, OBJ_KEY);
4446 if (!conference) {
4447 snprintf(buf, len, "0");
4448 return 0;
4449 }
4450
4451 /* get the correct count for the type requested */
4452 ao2_lock(conference);
4453 if (!strcasecmp(args.type, "parties")) {
4454 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4455 count++;
4456 }
4457 AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
4458 count++;
4459 }
4460 } else if (!strcasecmp(args.type, "admins")) {
4461 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4462 if (ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
4463 count++;
4464 }
4465 }
4466 } else if (!strcasecmp(args.type, "marked")) {
4467 AST_LIST_TRAVERSE(&conference->active_list, user, list) {
4468 if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
4469 count++;
4470 }
4471 }
4472 } else if (!strcasecmp(args.type, "locked")) {
4473 count = conference->locked;
4474 } else if (!strcasecmp(args.type, "muted")) {
4475 count = conference->muted;
4476 } else {
4477 ast_log(LOG_ERROR, "Invalid keyword '%s' passed to CONFBRIDGE_INFO.\n", args.type);
4478 }
4479 snprintf(buf, len, "%d", count);
4480 ao2_unlock(conference);
4481 ao2_ref(conference, -1);
4482 return 0;
4483 }
4484
4485 static int confkick_exec(struct ast_channel *chan, const char *data)
4486 {
4487 char *parse;
4488 struct confbridge_conference *conference;
4489 int not_found;
4490
4491 AST_DECLARE_APP_ARGS(args,
4492 AST_APP_ARG(confbridge);
4493 AST_APP_ARG(channel);
4494 );
4495
4496 if (ast_strlen_zero(data)) {
4497 ast_log(LOG_WARNING, "No conference bridge specified.\n");
4498 pbx_builtin_setvar_helper(chan, "CONFKICKSTATUS", "FAILURE");
4499 return 0;
4500 }
4501
4502 parse = ast_strdupa(data);
4503 AST_STANDARD_APP_ARGS(args, parse);
4504
4505 conference = ao2_find(conference_bridges, args.confbridge, OBJ_KEY);
4506 if (!conference) {
4507 ast_log(LOG_WARNING, "No conference bridge named '%s' found!\n", args.confbridge);
4508 pbx_builtin_setvar_helper(chan, "CONFKICKSTATUS", "FAILURE");
4509 return 0;
4510 }
4511 if (ast_strlen_zero(args.channel)) {
4512 not_found = kick_conference_participant(conference, "all");
4513 } else {
4514 not_found = kick_conference_participant(conference, args.channel);
4515 }
4516
4517 ao2_ref(conference, -1);
4518 if (not_found) {
4519 if (ast_strlen_zero(args.channel) || !strcasecmp("all", args.channel) || !strcasecmp("participants", args.channel)) {
4520 ast_log(LOG_WARNING, "No participants found in conference bridge '%s'!\n", args.confbridge);
4521 } else {
4522 ast_log(LOG_WARNING, "No participant named '%s' found in conference bridge '%s'!\n", args.channel, args.confbridge);
4523 }
4524 pbx_builtin_setvar_helper(chan, "CONFKICKSTATUS", "FAILURE");
4525 return 0;
4526 }
4527 ast_debug(1, "Kicked '%s' out of conference '%s'\n", args.channel, args.confbridge);
4528 pbx_builtin_setvar_helper(chan, "CONFKICKSTATUS", "SUCCESS");
4529 return 0;
4530 }
4531
4532 void conf_add_user_active(struct confbridge_conference *conference, struct confbridge_user *user)
4533 {
4534 AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
4535 conference->activeusers++;
4536 }
4537
4538 void conf_add_user_marked(struct confbridge_conference *conference, struct confbridge_user *user)
4539 {
4540 AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
4541 conference->activeusers++;
4542 conference->markedusers++;
4543 }
4544
4545 void conf_add_user_waiting(struct confbridge_conference *conference, struct confbridge_user *user)
4546 {
4547 AST_LIST_INSERT_TAIL(&conference->waiting_list, user, list);
4548 conference->waitingusers++;
4549 }
4550
4551 void conf_remove_user_active(struct confbridge_conference *conference, struct confbridge_user *user)
4552 {
4553 AST_LIST_REMOVE(&conference->active_list, user, list);
4554 conference->activeusers--;
4555 }
4556
4557 void conf_remove_user_marked(struct confbridge_conference *conference, struct confbridge_user *user)
4558 {
4559 AST_LIST_REMOVE(&conference->active_list, user, list);
4560 conference->activeusers--;
4561 conference->markedusers--;
4562 }
4563
4564 void conf_mute_only_active(struct confbridge_conference *conference)
4565 {
4566 struct confbridge_user *only_user = AST_LIST_FIRST(&conference->active_list);
4567
4568 /* Turn on MOH if the single participant is set up for it */
4569 if (ast_test_flag(&only_user->u_profile, USER_OPT_MUSICONHOLD)) {
4570 conf_moh_start(only_user);
4571 }
4572 conf_update_user_mute(only_user);
4573 }
4574
4575 void conf_remove_user_waiting(struct confbridge_conference *conference, struct confbridge_user *user)
4576 {
4577 AST_LIST_REMOVE(&conference->waiting_list, user, list);
4578 conference->waitingusers--;
4579 }
4580
4581 /*!
4582 * \internal
4583 * \brief Unregister a ConfBridge channel technology.
4584 * \since 12.0.0
4585 *
4586 * \param tech What to unregister.
4587 */
4588 static void unregister_channel_tech(struct ast_channel_tech *tech)
4589 {
4590 ast_channel_unregister(tech);
4591 ao2_cleanup(tech->capabilities);
4592 }
4593
4594 /*!
4595 * \internal
4596 * \brief Register a ConfBridge channel technology.
4597 * \since 12.0.0
4598 *
4599 * \param tech What to register.
4600 *
4601 * \retval 0 on success.
4602 * \retval -1 on error.
4603 */
4604 static int register_channel_tech(struct ast_channel_tech *tech)
4605 {
4606 tech->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
4607 if (!tech->capabilities) {
4608 return -1;
4609 }
4610 ast_format_cap_append_by_type(tech->capabilities, AST_MEDIA_TYPE_UNKNOWN);
4611 if (ast_channel_register(tech)) {
4612 ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",
4613 tech->type, tech->description);
4614 return -1;
4615 }
4616 return 0;
4617 }
4618
4619 /*! \brief Called when module is being unloaded */
4620 static int unload_module(void)
4621 {
4622 ast_unregister_application(app);
4623 ast_unregister_application(app2);
4624
4625 ast_custom_function_unregister(&confbridge_function);
4626 ast_custom_function_unregister(&confbridge_info_function);
4627 ast_custom_function_unregister(&confbridge_channels_function);
4628
4629 ast_cli_unregister_multiple(cli_confbridge, ARRAY_LEN(cli_confbridge));
4630
4631 ast_manager_unregister("ConfbridgeList");
4632 ast_manager_unregister("ConfbridgeListRooms");
4633 ast_manager_unregister("ConfbridgeMute");
4634 ast_manager_unregister("ConfbridgeUnmute");
4635 ast_manager_unregister("ConfbridgeKick");
4636 ast_manager_unregister("ConfbridgeUnlock");
4637 ast_manager_unregister("ConfbridgeLock");
4638 ast_manager_unregister("ConfbridgeStartRecord");
4639 ast_manager_unregister("ConfbridgeStopRecord");
4640 ast_manager_unregister("ConfbridgeSetSingleVideoSrc");
4641
4642 /* Unsubscribe from stasis confbridge message type and clean it up. */
4643 manager_confbridge_shutdown();
4644
4645 /* Get rid of the conference bridges container. Since we only allow dynamic ones none will be active. */
4646 ao2_cleanup(conference_bridges);
4647 conference_bridges = NULL;
4648
4649 conf_destroy_config();
4650
4651 unregister_channel_tech(conf_announce_get_tech());
4652 unregister_channel_tech(conf_record_get_tech());
4653
4654 return 0;
4655 }
4656
4657 /*!
4658 * \brief Load the module
4659 *
4660 * Module loading including tests for configuration or dependencies.
4661 * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
4662 * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
4663 * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
4664 * configuration file or other non-critical problem return
4665 * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
4666 */
4667 static int load_module(void)
4668 {
4669 int res = 0;
4670
4671 if (conf_load_config()) {
4672 ast_log(LOG_ERROR, "Unable to load config. Not loading module.\n");
4673 return AST_MODULE_LOAD_DECLINE;
4674 }
4675
4676 if (register_channel_tech(conf_record_get_tech())
4677 || register_channel_tech(conf_announce_get_tech())) {
4678 unload_module();
4679 return AST_MODULE_LOAD_DECLINE;
4680 }
4681
4682 /* Create a container to hold the conference bridges */
4683 conference_bridges = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
4684 CONFERENCE_BRIDGE_BUCKETS,
4685 conference_bridge_hash_cb, NULL, conference_bridge_cmp_cb);
4686 if (!conference_bridges) {
4687 unload_module();
4688 return AST_MODULE_LOAD_DECLINE;
4689 }
4690
4691 /* Setup manager stasis subscriptions */
4692 res |= manager_confbridge_init();
4693
4694 res |= ast_register_application_xml(app, confbridge_exec);
4695 res |= ast_register_application_xml(app2, confkick_exec);
4696
4697 res |= ast_custom_function_register_escalating(&confbridge_function, AST_CFE_WRITE);
4698 res |= ast_custom_function_register(&confbridge_info_function);
4699 res |= ast_custom_function_register(&confbridge_channels_function);
4700
4701 res |= ast_cli_register_multiple(cli_confbridge, ARRAY_LEN(cli_confbridge));
4702
4703 res |= ast_manager_register_xml("ConfbridgeList", EVENT_FLAG_REPORTING, action_confbridgelist);
4704 res |= ast_manager_register_xml("ConfbridgeListRooms", EVENT_FLAG_REPORTING, action_confbridgelistrooms);
4705 res |= ast_manager_register_xml("ConfbridgeMute", EVENT_FLAG_CALL, action_confbridgemute);
4706 res |= ast_manager_register_xml("ConfbridgeUnmute", EVENT_FLAG_CALL, action_confbridgeunmute);
4707 res |= ast_manager_register_xml("ConfbridgeKick", EVENT_FLAG_CALL, action_confbridgekick);
4708 res |= ast_manager_register_xml("ConfbridgeUnlock", EVENT_FLAG_CALL, action_confbridgeunlock);
4709 res |= ast_manager_register_xml("ConfbridgeLock", EVENT_FLAG_CALL, action_confbridgelock);
4710 res |= ast_manager_register_xml("ConfbridgeStartRecord", EVENT_FLAG_SYSTEM, action_confbridgestartrecord);
4711 res |= ast_manager_register_xml("ConfbridgeStopRecord", EVENT_FLAG_SYSTEM, action_confbridgestoprecord);
4712 res |= ast_manager_register_xml("ConfbridgeSetSingleVideoSrc", EVENT_FLAG_CALL, action_confbridgesetsinglevideosrc);
4713 if (res) {
4714 unload_module();
4715 return AST_MODULE_LOAD_DECLINE;
4716 }
4717
4718 return AST_MODULE_LOAD_SUCCESS;
4719 }
4720
4721 static int reload(void)
4722 {
4723 return conf_reload_config();
4724 }
4725
4726 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Conference Bridge Application",
4727 .support_level = AST_MODULE_SUPPORT_CORE,
4728 .load = load_module,
4729 .unload = unload_module,
4730 .reload = reload,
4731 .load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
4732 .optional_modules = "codec_speex,func_jitterbuffer",
4733 );