-
Notifications
You must be signed in to change notification settings - Fork 982
/
app_confbridge.c
4686 lines (4153 loc) · 141 KB
/
app_confbridge.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2007-2008, Digium, Inc.
*
* Joshua Colp <jcolp@digium.com>
* David Vossel <dvossel@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Conference Bridge application
*
* \author\verbatim Joshua Colp <jcolp@digium.com> \endverbatim
* \author\verbatim David Vossel <dvossel@digium.com> \endverbatim
*
* This is a conference bridge application utilizing the bridging core.
* \ingroup applications
*/
/*! \li \ref app_confbridge.c uses the configuration file \ref confbridge.conf
* \addtogroup configuration_file Configuration Files
*/
/*!
* \page confbridge.conf confbridge.conf
* \verbinclude confbridge.conf.sample
*/
/*** MODULEINFO
<support_level>core</support_level>
***/
#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include "asterisk/cli.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/bridge.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/audiohook.h"
#include "asterisk/astobj2.h"
#include "confbridge/include/confbridge.h"
#include "asterisk/paths.h"
#include "asterisk/manager.h"
#include "asterisk/test.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/json.h"
#include "asterisk/format_cache.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/stream.h"
#include "asterisk/message.h"
/*** DOCUMENTATION
<application name="ConfBridge" language="en_US">
<synopsis>
Conference bridge application.
</synopsis>
<syntax>
<parameter name="conference" required="true">
<para>Name of the conference bridge. You are not limited to just
numbers.</para>
</parameter>
<parameter name="bridge_profile">
<para>The bridge profile name from confbridge.conf. When left blank,
a dynamically built bridge profile created by the CONFBRIDGE dialplan
function is searched for on the channel and used. If no dynamic
profile is present, the 'default_bridge' profile found in
confbridge.conf is used. </para>
<para>It is important to note that while user profiles may be unique
for each participant, mixing bridge profiles on a single conference
is _NOT_ recommended and will produce undefined results.</para>
</parameter>
<parameter name="user_profile">
<para>The user profile name from confbridge.conf. When left blank,
a dynamically built user profile created by the CONFBRIDGE dialplan
function is searched for on the channel and used. If no dynamic
profile is present, the 'default_user' profile found in
confbridge.conf is used.</para>
</parameter>
<parameter name="menu">
<para>The name of the DTMF menu in confbridge.conf to be applied to
this channel. When left blank, a dynamically built menu profile
created by the CONFBRIDGE dialplan function is searched for on
the channel and used. If no dynamic profile is present, the
'default_menu' profile found in confbridge.conf is used.</para>
</parameter>
</syntax>
<description>
<para>Enters the user into a specified conference bridge. The user can
exit the conference by hangup or DTMF menu option.</para>
<para>This application sets the following channel variable upon completion:</para>
<variablelist>
<variable name="CONFBRIDGE_RESULT">
<value name="FAILED">The channel encountered an error and could not enter the conference.</value>
<value name="HANGUP">The channel exited the conference by hanging up.</value>
<value name="KICKED">The channel was kicked from the conference.</value>
<value name="ENDMARKED">The channel left the conference as a result of the last marked user leaving.</value>
<value name="DTMF">The channel pressed a DTMF sequence to exit the conference.</value>
<value name="TIMEOUT">The channel reached its configured timeout.</value>
</variable>
</variablelist>
</description>
<see-also>
<ref type="application">ConfKick</ref>
<ref type="function">CONFBRIDGE</ref>
<ref type="function">CONFBRIDGE_INFO</ref>
<ref type="function">CONFBRIDGE_CHANNELS</ref>
</see-also>
</application>
<application name="ConfKick" language="en_US">
<since>
<version>16.19.0</version>
<version>18.5.0</version>
<version>19.0.0</version>
</since>
<synopsis>
Kicks channel(s) from the requested ConfBridge.
</synopsis>
<syntax>
<parameter name="conference" required="true" />
<parameter name="channel">
<para>The channel to kick, <literal>all</literal>
to kick all users, or <literal>participants</literal>
to kick all non-admin participants. Default is all.</para>
</parameter>
</syntax>
<description>
<para>Kicks the requested channel(s) from a conference bridge.</para>
<variablelist>
<variable name="CONFKICKSTATUS">
<value name="FAILURE">
Could not kick any users with the provided arguments.
</value>
<value name="SUCCESS">
Successfully kicked users from specified conference bridge.
</value>
</variable>
</variablelist>
</description>
<see-also>
<ref type="application">ConfBridge</ref>
<ref type="function">CONFBRIDGE</ref>
<ref type="function">CONFBRIDGE_INFO</ref>
<ref type="function">CONFBRIDGE_CHANNELS</ref>
</see-also>
</application>
<function name="CONFBRIDGE" language="en_US">
<synopsis>
Set a custom dynamic bridge, user, or menu profile on a channel for the
ConfBridge application using the same options available in confbridge.conf.
</synopsis>
<syntax>
<parameter name="type" required="true">
<para>To what type of conference profile the option applies.</para>
<enumlist>
<enum name="bridge"></enum>
<enum name="menu"></enum>
<enum name="user"></enum>
</enumlist>
</parameter>
<parameter name="option" required="true">
<para>Option refers to a <filename>confbridge.conf</filename> option
that is being set dynamically on this channel, or <literal>clear</literal>
to remove already applied profile options from the channel.</para>
</parameter>
</syntax>
<description>
<para>A custom profile uses the default profile type settings defined in
<filename>confbridge.conf</filename> as defaults if the profile template
is not explicitly specified first.</para>
<para>For <literal>bridge</literal> profiles the default template is <literal>default_bridge</literal>.</para>
<para>For <literal>menu</literal> profiles the default template is <literal>default_menu</literal>.</para>
<para>For <literal>user</literal> profiles the default template is <literal>default_user</literal>.</para>
<para>---- Example 1 ----</para>
<para>In this example the custom user profile set on the channel will
automatically be used by the ConfBridge application.</para>
<example title="Example 1">
exten => 1,1,Answer()
</example>
<para>; In this example the effect of the following line is</para>
<para>; implied:</para>
<example title="Example 1b">
same => n,Set(CONFBRIDGE(user,template)=default_user)
same => n,Set(CONFBRIDGE(user,announce_join_leave)=yes)
same => n,Set(CONFBRIDGE(user,startmuted)=yes)
same => n,ConfBridge(1)
</example>
<para>---- Example 2 ----</para>
<para>This example shows how to use a predefined user profile in
<filename>confbridge.conf</filename> as a template for a dynamic profile.
Here we make an admin/marked user out of the <literal>my_user</literal>
profile that you define in <filename>confbridge.conf</filename>.</para>
<example title="Example 2">
exten => 1,1,Answer()
same => n,Set(CONFBRIDGE(user,template)=my_user)
same => n,Set(CONFBRIDGE(user,admin)=yes)
same => n,Set(CONFBRIDGE(user,marked)=yes)
same => n,ConfBridge(1)
</example>
</description>
</function>
<function name="CONFBRIDGE_INFO" language="en_US">
<synopsis>
Get information about a ConfBridge conference.
</synopsis>
<syntax>
<parameter name="type" required="true">
<para>What conference information is requested.</para>
<enumlist>
<enum name="admins">
<para>Get the number of admin users in the conference.</para>
</enum>
<enum name="locked">
<para>Determine if the conference is locked. (0 or 1)</para>
</enum>
<enum name="marked">
<para>Get the number of marked users in the conference.</para>
</enum>
<enum name="muted">
<para>Determine if the conference is muted. (0 or 1)</para>
</enum>
<enum name="parties">
<para>Get the number of users in the conference.</para>
</enum>
</enumlist>
</parameter>
<parameter name="conf" required="true">
<para>The name of the conference being referenced.</para>
</parameter>
</syntax>
<description>
<para>This function returns a non-negative integer for valid conference
names and an empty string for invalid conference names.</para>
</description>
<see-also>
<ref type="function">CONFBRIDGE_CHANNELS</ref>
</see-also>
</function>
<function name="CONFBRIDGE_CHANNELS" language="en_US">
<since>
<version>16.26.0</version>
<version>18.12.0</version>
<version>19.4.0</version>
</since>
<synopsis>
Get a list of channels in a ConfBridge conference.
</synopsis>
<syntax>
<parameter name="type" required="true">
<para>What conference information is requested.</para>
<enumlist>
<enum name="admins">
<para>Get the number of admin users in the conference.</para>
</enum>
<enum name="marked">
<para>Get the number of marked users in the conference.</para>
</enum>
<enum name="parties">
<para>Get the number of total users in the conference.</para>
</enum>
<enum name="active">
<para>Get the number of active users in the conference.</para>
</enum>
<enum name="waiting">
<para>Get the number of waiting users in the conference.</para>
</enum>
</enumlist>
</parameter>
<parameter name="conf" required="true">
<para>The name of the conference being referenced.</para>
</parameter>
</syntax>
<description>
<para>This function returns a comma-separated list of channels in a ConfBridge conference, optionally filtered by a type of participant.</para>
</description>
<see-also>
<ref type="function">CONFBRIDGE_INFO</ref>
</see-also>
</function>
<manager name="ConfbridgeList" language="en_US">
<synopsis>
List participants in a conference.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true">
<para>Conference number.</para>
</parameter>
</syntax>
<description>
<para>Lists all users in a particular ConfBridge conference.
ConfbridgeList will follow as separate events, followed by a final event called
ConfbridgeListComplete.</para>
</description>
</manager>
<managerEvent language="en_US" name="ConfbridgeList">
<managerEventInstance class="EVENT_FLAG_REPORTING">
<synopsis>Raised as part of the ConfbridgeList action response list.</synopsis>
<syntax>
<parameter name="Conference">
<para>The name of the Confbridge conference.</para>
</parameter>
<parameter name="Admin">
<para>Identifies this user as an admin user.</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="MarkedUser">
<para>Identifies this user as a marked user.</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="WaitMarked">
<para>Must this user wait for a marked user to join?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="EndMarked">
<para>Does this user get kicked after the last marked user leaves?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="Waiting">
<para>Is this user waiting for a marked user to join?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="Muted">
<para>The current mute status.</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="Talking">
<para>Is this user talking?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="AnsweredTime">
<para>The number of seconds the channel has been up.</para>
</parameter>
<channel_snapshot/>
</syntax>
</managerEventInstance>
</managerEvent>
<manager name="ConfbridgeListRooms" language="en_US">
<synopsis>
List active conferences.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
</syntax>
<description>
<para>Lists data about all active conferences.
ConfbridgeListRooms will follow as separate events, followed by a final event called
ConfbridgeListRoomsComplete.</para>
</description>
</manager>
<managerEvent language="en_US" name="ConfbridgeListRooms">
<managerEventInstance class="EVENT_FLAG_REPORTING">
<synopsis>Raised as part of the ConfbridgeListRooms action response list.</synopsis>
<syntax>
<parameter name="Conference">
<para>The name of the Confbridge conference.</para>
</parameter>
<parameter name="Parties">
<para>Number of users in the conference.</para>
<para>This includes both active and waiting users.</para>
</parameter>
<parameter name="Marked">
<para>Number of marked users in the conference.</para>
</parameter>
<parameter name="Locked">
<para>Is the conference locked?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
<parameter name="Muted">
<para>Is the conference muted?</para>
<enumlist>
<enum name="Yes"/>
<enum name="No"/>
</enumlist>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<manager name="ConfbridgeMute" language="en_US">
<synopsis>
Mute a Confbridge user.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
<parameter name="Channel" required="true">
<para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
<para>If this parameter is "all", all channels will be muted.</para>
<para>If this parameter is "participants", all non-admin channels will be muted.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeUnmute" language="en_US">
<synopsis>
Unmute a Confbridge user.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
<parameter name="Channel" required="true">
<para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
<para>If this parameter is "all", all channels will be unmuted.</para>
<para>If this parameter is "participants", all non-admin channels will be unmuted.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeKick" language="en_US">
<synopsis>
Kick a Confbridge user.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
<parameter name="Channel" required="true" >
<para>If this parameter is "all", all channels will be kicked from the conference.</para>
<para>If this parameter is "participants", all non-admin channels will be kicked from the conference.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeLock" language="en_US">
<synopsis>
Lock a Confbridge conference.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeUnlock" language="en_US">
<synopsis>
Unlock a Confbridge conference.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeStartRecord" language="en_US">
<synopsis>
Start recording a Confbridge conference.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
<parameter name="RecordFile" required="false" />
</syntax>
<description>
<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>
</description>
</manager>
<manager name="ConfbridgeStopRecord" language="en_US">
<synopsis>
Stop recording a Confbridge conference.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
</syntax>
<description>
</description>
</manager>
<manager name="ConfbridgeSetSingleVideoSrc" language="en_US">
<synopsis>
Set a conference user as the single video source distributed to all other participants.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Conference" required="true" />
<parameter name="Channel" required="true">
<para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
</parameter>
</syntax>
<description>
</description>
</manager>
***/
/*!
* \par Playing back a file to a channel in a conference
* You might notice in this application that while playing a sound file
* to a channel the actual conference bridge lock is not held. This is done so
* that other channels are not blocked from interacting with the conference bridge.
* Unfortunately because of this it is possible for things to change after the sound file
* is done being played. Data must therefore be checked after reacquiring the conference
* bridge lock if it is important.
*/
static const char app[] = "ConfBridge";
static const char app2[] = "ConfKick";
/*! Number of buckets our conference bridges container can have */
#define CONFERENCE_BRIDGE_BUCKETS 53
/*! Initial recording filename space. */
#define RECORD_FILENAME_INITIAL_SPACE 128
/*! \brief Container to hold all conference bridges in progress */
struct ao2_container *conference_bridges;
static void leave_conference(struct confbridge_user *user);
static int play_sound_number(struct confbridge_conference *conference, int say_number);
static int execute_menu_entry(struct confbridge_conference *conference,
struct confbridge_user *user,
struct ast_bridge_channel *bridge_channel,
struct conf_menu_entry *menu_entry,
struct conf_menu *menu);
/*! \brief Hashing function used for conference bridges container */
static int conference_bridge_hash_cb(const void *obj, const int flags)
{
const struct confbridge_conference *conference = obj;
const char *name = obj;
int hash;
switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
default:
case OBJ_POINTER:
name = conference->name;
/* Fall through */
case OBJ_KEY:
hash = ast_str_case_hash(name);
break;
case OBJ_PARTIAL_KEY:
/* Should never happen in hash callback. */
ast_assert(0);
hash = 0;
break;
}
return hash;
}
/*! \brief Comparison function used for conference bridges container */
static int conference_bridge_cmp_cb(void *obj, void *arg, int flags)
{
const struct confbridge_conference *left = obj;
const struct confbridge_conference *right = arg;
const char *right_name = arg;
int cmp;
switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
default:
case OBJ_POINTER:
right_name = right->name;
/* Fall through */
case OBJ_KEY:
cmp = strcasecmp(left->name, right_name);
break;
case OBJ_PARTIAL_KEY:
cmp = strncasecmp(left->name, right_name, strlen(right_name));
break;
}
return cmp ? 0 : CMP_MATCH;
}
const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds)
{
switch (sound) {
case CONF_SOUND_HAS_JOINED:
return S_OR(custom_sounds->hasjoin, "conf-hasjoin");
case CONF_SOUND_HAS_LEFT:
return S_OR(custom_sounds->hasleft, "conf-hasleft");
case CONF_SOUND_KICKED:
return S_OR(custom_sounds->kicked, "conf-kicked");
case CONF_SOUND_MUTED:
return S_OR(custom_sounds->muted, "conf-muted");
case CONF_SOUND_UNMUTED:
return S_OR(custom_sounds->unmuted, "conf-unmuted");
case CONF_SOUND_BINAURAL_ON:
return S_OR(custom_sounds->binauralon, "confbridge-binaural-on");
case CONF_SOUND_BINAURAL_OFF:
return S_OR(custom_sounds->binauraloff, "confbridge-binaural-off");
case CONF_SOUND_ONLY_ONE:
return S_OR(custom_sounds->onlyone, "conf-onlyone");
case CONF_SOUND_THERE_ARE:
return S_OR(custom_sounds->thereare, "conf-thereare");
case CONF_SOUND_OTHER_IN_PARTY:
return S_OR(custom_sounds->otherinparty, "conf-otherinparty");
case CONF_SOUND_PLACE_IN_CONF:
return S_OR(custom_sounds->placeintoconf, "conf-placeintoconf");
case CONF_SOUND_WAIT_FOR_LEADER:
return S_OR(custom_sounds->waitforleader, "conf-waitforleader");
case CONF_SOUND_LEADER_HAS_LEFT:
return S_OR(custom_sounds->leaderhasleft, "conf-leaderhasleft");
case CONF_SOUND_GET_PIN:
return S_OR(custom_sounds->getpin, "conf-getpin");
case CONF_SOUND_INVALID_PIN:
return S_OR(custom_sounds->invalidpin, "conf-invalidpin");
case CONF_SOUND_ONLY_PERSON:
return S_OR(custom_sounds->onlyperson, "conf-onlyperson");
case CONF_SOUND_LOCKED:
return S_OR(custom_sounds->locked, "conf-locked");
case CONF_SOUND_LOCKED_NOW:
return S_OR(custom_sounds->lockednow, "conf-lockednow");
case CONF_SOUND_UNLOCKED_NOW:
return S_OR(custom_sounds->unlockednow, "conf-unlockednow");
case CONF_SOUND_ERROR_MENU:
return S_OR(custom_sounds->errormenu, "conf-errormenu");
case CONF_SOUND_JOIN:
return S_OR(custom_sounds->join, "confbridge-join");
case CONF_SOUND_LEAVE:
return S_OR(custom_sounds->leave, "confbridge-leave");
case CONF_SOUND_PARTICIPANTS_MUTED:
return S_OR(custom_sounds->participantsmuted, "conf-now-muted");
case CONF_SOUND_PARTICIPANTS_UNMUTED:
return S_OR(custom_sounds->participantsunmuted, "conf-now-unmuted");
case CONF_SOUND_BEGIN:
return S_OR(custom_sounds->begin, "confbridge-conf-begin");
}
return "";
}
static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan,
struct stasis_message_type *type, struct ast_json *extras, int channel_topic)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
json_object = ast_json_pack("{s: s}",
"conference", conference->name);
if (!json_object) {
return;
}
if (extras) {
ast_json_object_update(json_object, extras);
}
ast_bridge_lock(conference->bridge);
msg = ast_bridge_blob_create(type,
conference->bridge,
chan,
json_object);
ast_bridge_unlock(conference->bridge);
if (!msg) {
return;
}
if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_ENABLE_EVENTS)) {
conf_send_event_to_participants(conference, chan, msg);
}
if (channel_topic) {
stasis_publish(ast_channel_topic(chan), msg);
} else {
stasis_publish(ast_bridge_topic(conference->bridge), msg);
}
}
static void send_conf_stasis_snapshots(struct confbridge_conference *conference,
struct ast_channel_snapshot *chan_snapshot, struct stasis_message_type *type,
struct ast_json *extras)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
RAII_VAR(struct ast_bridge_snapshot *, bridge_snapshot, NULL, ao2_cleanup);
json_object = ast_json_pack("{s: s}",
"conference", conference->name);
if (!json_object) {
return;
}
if (extras) {
ast_json_object_update(json_object, extras);
}
ast_bridge_lock(conference->bridge);
bridge_snapshot = ast_bridge_snapshot_create(conference->bridge);
ast_bridge_unlock(conference->bridge);
if (!bridge_snapshot) {
return;
}
msg = ast_bridge_blob_create_from_snapshots(type,
bridge_snapshot,
chan_snapshot,
json_object);
if (!msg) {
return;
}
stasis_publish(ast_bridge_topic(conference->bridge), msg);
}
static void send_conf_start_event(struct confbridge_conference *conference)
{
send_conf_stasis(conference, NULL, confbridge_start_type(), NULL, 0);
}
static void send_conf_end_event(struct confbridge_conference *conference)
{
send_conf_stasis(conference, NULL, confbridge_end_type(), NULL, 0);
}
static void send_join_event(struct confbridge_user *user, struct confbridge_conference *conference)
{
struct ast_json *json_object;
json_object = ast_json_pack("{s: b, s: b}",
"admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN),
"muted", user->muted);
if (!json_object) {
return;
}
send_conf_stasis(conference, user->chan, confbridge_join_type(), json_object, 0);
ast_json_unref(json_object);
}
static void send_leave_event(struct confbridge_user *user, struct confbridge_conference *conference)
{
struct ast_json *json_object;
json_object = ast_json_pack("{s: b}",
"admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
);
if (!json_object) {
return;
}
send_conf_stasis(conference, user->chan, confbridge_leave_type(), json_object, 0);
ast_json_unref(json_object);
}
static void send_start_record_event(struct confbridge_conference *conference)
{
send_conf_stasis(conference, NULL, confbridge_start_record_type(), NULL, 0);
}
static void send_stop_record_event(struct confbridge_conference *conference)
{
send_conf_stasis(conference, NULL, confbridge_stop_record_type(), NULL, 0);
}
static void send_mute_event(struct confbridge_user *user, struct confbridge_conference *conference)
{
struct ast_json *json_object;
json_object = ast_json_pack("{s: b}",
"admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
);
if (!json_object) {
return;
}
send_conf_stasis(conference, user->chan, confbridge_mute_type(), json_object, 1);
ast_json_unref(json_object);
}
static void send_unmute_event(struct confbridge_user *user, struct confbridge_conference *conference)
{
struct ast_json *json_object;
json_object = ast_json_pack("{s: b}",
"admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
);
if (!json_object) {
return;
}
send_conf_stasis(conference, user->chan, confbridge_unmute_type(), json_object, 1);
ast_json_unref(json_object);
}
static void set_rec_filename(struct confbridge_conference *conference, struct ast_str **filename, int is_new)
{
char *rec_file = conference->b_profile.rec_file;
char *ext;
time_t now;
if (ast_str_strlen(*filename)
&& ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND)
&& !is_new) {
return;
}
time(&now);
ast_str_reset(*filename);
if (ast_strlen_zero(rec_file)) {
ast_str_set(filename, 0, "confbridge-%s-%u.wav", conference->name,
(unsigned int) now);
} else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_TIMESTAMP)) {
/* insert time before file extension */
ext = strrchr(rec_file, '.');
if (ext) {
ast_str_set_substr(filename, 0, rec_file, ext - rec_file);
ast_str_append(filename, 0, "-%u%s", (unsigned int) now, ext);
} else {
ast_str_set(filename, 0, "%s-%u", rec_file, (unsigned int) now);
}
} else {
ast_str_set(filename, 0, "%s", rec_file);
}
ast_str_append(filename, 0, ",%s%s,%s",
ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND) ? "a" : "",
conference->b_profile.rec_options,
conference->b_profile.rec_command);
}
static int is_new_rec_file(const char *rec_file, struct ast_str **orig_rec_file)
{
if (!ast_strlen_zero(rec_file)) {
if (!*orig_rec_file) {
*orig_rec_file = ast_str_create(RECORD_FILENAME_INITIAL_SPACE);
}
if (*orig_rec_file
&& strcmp(ast_str_buffer(*orig_rec_file), rec_file)) {
ast_str_set(orig_rec_file, 0, "%s", rec_file);
return 1;
}
}
return 0;
}
struct confbridge_conference *conf_find_bridge(const char *conference_name)
{
return ao2_find(conference_bridges, conference_name, OBJ_KEY);
}
/*!
* \internal
* \brief Returns whether or not conference is being recorded.
*
* \param conference The bridge to check for recording
*
* \note Must be called with the conference locked
*
* \retval 1 conference is recording.
* \retval 0 conference is NOT recording.
*/
static int conf_is_recording(struct confbridge_conference *conference)
{
return conference->record_chan != NULL;
}
/*!
* \internal
* \brief Stop recording a conference bridge
*
* \param conference The conference bridge on which to stop the recording
*
* \note Must be called with the conference locked
*
* \retval -1 Failure
* \retval 0 Success
*/
static int conf_stop_record(struct confbridge_conference *conference)
{
struct ast_channel *chan;
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
if (!conf_is_recording(conference)) {
return -1;
}
/* Remove the recording channel from the conference bridge. */
chan = conference->record_chan;
conference->record_chan = NULL;
ast_queue_frame(chan, &f);
ast_channel_unref(chan);
ast_test_suite_event_notify("CONF_STOP_RECORD", "Message: stopped conference recording channel\r\nConference: %s", conference->b_profile.name);
send_stop_record_event(conference);
return 0;
}
/*!
* \internal
* \brief Start recording the conference
*
* \param conference The conference bridge to start recording
*
* \note Must be called with the conference locked
*
* \retval 0 success
* \retval non-zero failure
*/
static int conf_start_record(struct confbridge_conference *conference)
{
struct ast_app *mixmonapp;
struct ast_channel *chan;
struct ast_format_cap *cap;
struct ast_bridge_features *features;
if (conf_is_recording(conference)) {
return -1;
}
mixmonapp = pbx_findapp("MixMonitor");
if (!mixmonapp) {
ast_log(LOG_WARNING, "Cannot record ConfBridge, MixMonitor app is not installed\n");
return -1;
}
features = ast_bridge_features_new();
if (!features) {
return -1;
}
ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE);
cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
ast_bridge_features_destroy(features);
return -1;
}
ast_format_cap_append(cap, ast_format_slin, 0);
/* Create the recording channel. */
chan = ast_request("CBRec", cap, NULL, NULL, conference->name, NULL);
ao2_ref(cap, -1);
if (!chan) {
ast_bridge_features_destroy(features);
return -1;
}
/* Start recording. */
set_rec_filename(conference, &conference->record_filename,
is_new_rec_file(conference->b_profile.rec_file, &conference->orig_rec_file));
ast_answer(chan);
pbx_exec(chan, mixmonapp, ast_str_buffer(conference->record_filename));
/* Put the channel into the conference bridge. */
ast_channel_ref(chan);
conference->record_chan = chan;
if (ast_bridge_impart(conference->bridge, chan, NULL, features,
AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
ast_hangup(chan);
ast_channel_unref(chan);
conference->record_chan = NULL;
return -1;
}
ast_test_suite_event_notify("CONF_START_RECORD", "Message: started conference recording channel\r\nConference: %s", conference->b_profile.name);
send_start_record_event(conference);
return 0;
}
/*! \brief Playback the given filename and monitor for any dtmf interrupts.