Skip to content
Snippets Groups Projects
app_confbridge.c 133 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * 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
    
    Andrew Latham's avatar
    Andrew Latham committed
     * \addtogroup configuration_file Configuration Files
     */
    
    
    Andrew Latham's avatar
    Andrew Latham committed
     * \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/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/stasis_bridges.h"
    
    #include "asterisk/taskprocessor.h"
    
    #include "asterisk/stream.h"
    #include "asterisk/message.h"
    
    	<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>
    
    		</description>
    		<see-also>
    			<ref type="application">ConfBridge</ref>
    			<ref type="function">CONFBRIDGE</ref>
    			<ref type="function">CONFBRIDGE_INFO</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 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>
    			<para>exten => 1,1,Answer()</para>
    			<para>; In this example the effect of the following line is</para>
    			<para>; implied:</para>
    			<para>; same => n,Set(CONFBRIDGE(user,template)=default_user)</para>
    			<para>same => n,Set(CONFBRIDGE(user,announce_join_leave)=yes)</para>
    			<para>same => n,Set(CONFBRIDGE(user,startmuted)=yes)</para>
    			<para>same => n,ConfBridge(1) </para>
    
    			<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>
    			<para>exten => 1,1,Answer()</para>
    			<para>same => n,Set(CONFBRIDGE(user,template)=my_user)</para>
    			<para>same => n,Set(CONFBRIDGE(user,admin)=yes)</para>
    			<para>same => n,Set(CONFBRIDGE(user,marked)=yes)</para>
    			<para>same => n,ConfBridge(1)</para>
    
    		</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>
    	</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>
    	<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>
    
    		</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>
    
    		</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>
    
    		</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";
    
    /*! 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");
    
    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 (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)
    
    	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;
    
    	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);
    
    			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
    
     * \retval 1, conference is recording.
     * \retval 0, conference is NOT recording.
     */
    
    static int conf_is_recording(struct confbridge_conference *conference)
    
     * \param conference The conference bridge on which to stop the recording
    
    static int conf_stop_record(struct confbridge_conference *conference)
    
    	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
    
    	if (!conf_is_recording(conference)) {
    
    
    	/* 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);
    
     * \param conference The conference bridge to start recording
    
    static int conf_start_record(struct confbridge_conference *conference)
    
    	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");
    
    	features = ast_bridge_features_new();
    	if (!features) {
    
    	ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE);
    
    	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
    
    	ast_format_cap_append(cap, ast_format_slin, 0);
    
    	/* Create the recording channel. */
    	chan = ast_request("CBRec", cap, NULL, NULL, conference->name, NULL);
    
    	/* 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;
    
    	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);
    
    
    /* \brief Playback the given filename and monitor for any dtmf interrupts.
     *
     * This function is used to playback sound files on a given channel and optionally
     * allow dtmf interrupts to occur.
     *
     * If the optional bridge_channel parameter is given then sound file playback
     * is played on that channel and dtmf interruptions are allowed. However, if
     * bridge_channel is not set then the channel parameter is expected to be set
     * instead and non interruptible playback is played on that channel.
     *
     * \param bridge_channel Bridge channel to play file on
     * \param channel Optional channel to play file on if bridge_channel not given
     * \param filename The file name to playback
     *
     * \retval -1 failure during playback, 0 on file was fully played, 1 on dtmf interrupt.
     */
    static int play_file(struct ast_bridge_channel *bridge_channel, struct ast_channel *channel,
    		     const char *filename)
    {
    	struct ast_channel *chan;
    	const char *stop_digits;
    	int digit;
    
    	if (bridge_channel) {
    		chan = bridge_channel->chan;
    		stop_digits = AST_DIGIT_ANY;
    	} else {
    		chan = channel;
    		stop_digits = AST_DIGIT_NONE;
    	}
    
    	digit = ast_stream_and_wait(chan, filename, stop_digits);
    	if (digit < 0) {
    		ast_log(LOG_WARNING, "Failed to playback file '%s' to channel\n", filename);
    		return -1;
    	}
    
    	if (digit > 0) {
    		ast_stopstream(bridge_channel->chan);
    		ast_bridge_channel_feature_digit_add(bridge_channel, digit);
    		return 1;
    	}
    
    	return 0;
    }
    
    
    /*!
     * \internal
     * \brief Complain if the given sound file does not exist.
     *
     * \param filename Sound file to check if exists.
     *
     * \retval non-zero if the file exists.
     */
    static int sound_file_exists(const char *filename)
    {
    	if (ast_fileexists(filename, NULL, NULL)) {
    		return -1;
    	}
    	ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename);
    	return 0;
    }
    
    
    /*!
     * \brief Announce number of users in the conference bridge to the caller
     *
    
     * \param conference Conference bridge to peek at
     * \param user Optional Caller
    
     * \param bridge_channel The bridged channel involved
    
     * \note if caller is NULL, the announcment will be sent to all participants in the conference.
    
     * \return Returns 0 on success, -1 if the user hung up
    
    static int announce_user_count(struct confbridge_conference *conference, struct confbridge_user *user,
    			       struct ast_bridge_channel *bridge_channel)
    
    	const char *other_in_party = conf_get_sound(CONF_SOUND_OTHER_IN_PARTY, conference->b_profile.sounds);
    	const char *only_one = conf_get_sound(CONF_SOUND_ONLY_ONE, conference->b_profile.sounds);
    	const char *there_are = conf_get_sound(CONF_SOUND_THERE_ARE, conference->b_profile.sounds);
    
    	if (conference->activeusers <= 1) {
    
    		/* Awww we are the only person in the conference bridge OR we only have waitmarked users */
    
    	} else if (conference->activeusers == 2) {
    		if (user) {
    
    			/* Eep, there is one other person */
    
    			if (play_file(bridge_channel, user->chan, only_one) < 0) {
    
    			play_sound_file(conference, only_one);
    
    		}
    	} else {
    		/* Alas multiple others in here */
    
    		if (user) {
    			if (ast_stream_and_wait(user->chan,
    
    			if (ast_say_number(user->chan, conference->activeusers - 1, "", ast_channel_language(user->chan), NULL)) {
    
    			if (play_file(bridge_channel, user->chan, other_in_party) < 0) {
    
    		} else if (sound_file_exists(there_are) && sound_file_exists(other_in_party)) {
    
    			play_sound_file(conference, there_are);
    			play_sound_number(conference, conference->activeusers - 1);
    			play_sound_file(conference, other_in_party);
    
    }
    
    /*!
     * \brief Play back an audio file to a channel
     *
    
     * \param user User to play audio prompt to