Skip to content
Snippets Groups Projects
bridge_basic.c 117 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * Asterisk -- An open source telephony toolkit.
     *
     * Copyright (C) 2013 Digium, Inc.
     *
     * Richard Mudgett <rmudgett@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 Basic bridge class.  It is a subclass of struct ast_bridge.
     *
     * \author Richard Mudgett <rmudgett@digium.com>
     *
     * See Also:
     * \arg \ref AstCREDITS
     */
    
    
    #include "asterisk.h"
    
    
    ASTERISK_REGISTER_FILE()
    
    
    #include "asterisk/channel.h"
    #include "asterisk/utils.h"
    #include "asterisk/linkedlists.h"
    
    #include "asterisk/bridge.h"
    #include "asterisk/bridge_internal.h"
    #include "asterisk/bridge_basic.h"
    #include "asterisk/bridge_after.h"
    
    #include "asterisk/features_config.h"
    #include "asterisk/pbx.h"
    #include "asterisk/file.h"
    #include "asterisk/app.h"
    #include "asterisk/dial.h"
    
    #include "asterisk/stasis_bridges.h"
    
    #include "asterisk/stasis_channels.h"
    
    #include "asterisk/features.h"
    
    
    #define NORMAL_FLAGS	(AST_BRIDGE_FLAG_DISSOLVE_HANGUP | AST_BRIDGE_FLAG_DISSOLVE_EMPTY \
    			| AST_BRIDGE_FLAG_SMART)
    
    #define TRANSFER_FLAGS AST_BRIDGE_FLAG_SMART
    
    struct attended_transfer_properties;
    
    enum bridge_basic_personality_type {
    	/*! Index for "normal" basic bridge personality */
    	BRIDGE_BASIC_PERSONALITY_NORMAL,
    	/*! Index for attended transfer basic bridge personality */
    	BRIDGE_BASIC_PERSONALITY_ATXFER,
    	/*! Indicates end of enum. Must always remain the last element */
    	BRIDGE_BASIC_PERSONALITY_END,
    };
    
    /*!
     * \brief Change basic bridge personality
     *
     * Changing personalities allows for the bridge to remain in use but have
     * properties such as its v_table and its flags change.
     *
     * \param bridge The bridge
     * \param type The personality to change the bridge to
     * \user_data Private data to attach to the personality.
     */
    static void bridge_basic_change_personality(struct ast_bridge *bridge,
    		enum bridge_basic_personality_type type, void *user_data);
    
    
    /* ------------------------------------------------------------------- */
    
    static const struct ast_datastore_info dtmf_features_info = {
    	.type = "bridge-dtmf-features",
    	.destroy = ast_free_ptr,
    };
    
    
    /*!
     * \internal
     * \since 12.0.0
     * \brief read a feature code character and set it on for the give feature_flags struct
     *
     * \param feature_flags flags being modifed
     * \param feature feature code provided - should be an uppercase letter
     *
     * \retval 0 if the feature was set successfully
     * \retval -1 failure because the requested feature code isn't handled by this function
     */
    static int set_feature_flag_from_char(struct ast_flags *feature_flags, char feature)
    {
    	switch (feature) {
    	case 'T':
    		ast_set_flag(feature_flags, AST_FEATURE_REDIRECT);
    		return 0;
    	case 'K':
    		ast_set_flag(feature_flags, AST_FEATURE_PARKCALL);
    		return 0;
    	case 'H':
    		ast_set_flag(feature_flags, AST_FEATURE_DISCONNECT);
    		return 0;
    	case 'W':
    		ast_set_flag(feature_flags, AST_FEATURE_AUTOMON);
    		return 0;
    	case 'X':
    		ast_set_flag(feature_flags, AST_FEATURE_AUTOMIXMON);
    		return 0;
    	default:
    		return -1;
    	}
    }
    
    /*!
     * \internal
     * \since 12.0.0
     * \brief Write a features string to a string buffer based on the feature flags provided
     *
     * \param feature_flags pointer to the feature flags to write from.
     * \param buffer pointer to a string buffer to write the features
     * \param buffer_size size of the buffer provided (should be able to fit all feature codes)
     *
     * \retval 0 on successful write
     * \retval -1 failure due to running out of buffer space
     */
    static int dtmf_features_flags_to_string(struct ast_flags *feature_flags, char *buffer, size_t buffer_size)
    {
    	size_t buffer_expended = 0;
    	unsigned int cur_feature;
    	static const struct {
    		char letter;
    		unsigned int flag;
    	} associations[] = {
    		{ 'T', AST_FEATURE_REDIRECT },
    		{ 'K', AST_FEATURE_PARKCALL },
    		{ 'H', AST_FEATURE_DISCONNECT },
    		{ 'W', AST_FEATURE_AUTOMON },
    		{ 'X', AST_FEATURE_AUTOMIXMON },
    	};
    
    	for (cur_feature = 0; cur_feature < ARRAY_LEN(associations); cur_feature++) {
    		if (ast_test_flag(feature_flags, associations[cur_feature].flag)) {
    			if (buffer_expended == buffer_size - 1) {
    				buffer[buffer_expended] = '\0';
    				return -1;
    			}
    			buffer[buffer_expended++] = associations[cur_feature].letter;
    		}
    	}
    
    	buffer[buffer_expended] = '\0';
    	return 0;
    }
    
    static int build_dtmf_features(struct ast_flags *flags, const char *features)
    {
    	const char *feature;
    
    	char missing_features[strlen(features) + 1];
    	size_t number_of_missing_features = 0;
    
    	for (feature = features; *feature; feature++) {
    		if (!isupper(*feature)) {
    			ast_log(LOG_ERROR, "Features string '%s' rejected because it contains non-uppercase feature.\n", features);
    			return -1;
    		}
    
    		if (set_feature_flag_from_char(flags, *feature)) {
    			missing_features[number_of_missing_features++] = *feature;
    		}
    	}
    
    	missing_features[number_of_missing_features] = '\0';
    
    	if (number_of_missing_features) {
    		ast_log(LOG_WARNING, "Features '%s' from features string '%s' can not be applied.\n", missing_features, features);
    	}
    
    	return 0;
    }
    
    int ast_bridge_features_ds_set_string(struct ast_channel *chan, const char *features)
    {
    	struct ast_flags flags = {0};
    
    	if (build_dtmf_features(&flags, features)) {
    		return -1;
    	}
    
    	ast_channel_lock(chan);
    	if (ast_bridge_features_ds_set(chan, &flags)) {
    		ast_channel_unlock(chan);
    		ast_log(LOG_ERROR, "Failed to apply features datastore for '%s' to channel '%s'\n", features, ast_channel_name(chan));
    		return -1;
    	}
    	ast_channel_unlock(chan);
    
    	return 0;
    }
    
    int ast_bridge_features_ds_get_string(struct ast_channel *chan, char *buffer, size_t buf_size)
    {
    	struct ast_flags *channel_flags;
    	struct ast_flags held_copy;
    
    	ast_channel_lock(chan);
    	if (!(channel_flags = ast_bridge_features_ds_get(chan))) {
    		ast_channel_unlock(chan);
    		return -1;
    	}
    	held_copy = *channel_flags;
    	ast_channel_unlock(chan);
    
    	return dtmf_features_flags_to_string(&held_copy, buffer, buf_size);
    }
    
    
    static int bridge_features_ds_set_full(struct ast_channel *chan, struct ast_flags *flags, int replace)
    
    {
    	struct ast_datastore *datastore;
    	struct ast_flags *ds_flags;
    
    	datastore = ast_channel_datastore_find(chan, &dtmf_features_info, NULL);
    	if (datastore) {
    		ds_flags = datastore->data;
    
    		if (replace) {
    			*ds_flags = *flags;
    		} else {
    			flags->flags = flags->flags | ds_flags->flags;
    			*ds_flags = *flags;
    		}
    
    		return 0;
    	}
    
    	datastore = ast_datastore_alloc(&dtmf_features_info, NULL);
    	if (!datastore) {
    		return -1;
    	}
    
    	ds_flags = ast_malloc(sizeof(*ds_flags));
    	if (!ds_flags) {
    		ast_datastore_free(datastore);
    		return -1;
    	}
    
    	*ds_flags = *flags;
    	datastore->data = ds_flags;
    	ast_channel_datastore_add(chan, datastore);
    	return 0;
    }
    
    
    int ast_bridge_features_ds_set(struct ast_channel *chan, struct ast_flags *flags)
    {
    	return bridge_features_ds_set_full(chan, flags, 1);
    }
    
    int ast_bridge_features_ds_append(struct ast_channel *chan, struct ast_flags *flags)
    {
    	return bridge_features_ds_set_full(chan, flags, 0);
    }
    
    
    struct ast_flags *ast_bridge_features_ds_get(struct ast_channel *chan)
    {
    	struct ast_datastore *datastore;
    
    	datastore = ast_channel_datastore_find(chan, &dtmf_features_info, NULL);
    	if (!datastore) {
    		return NULL;
    	}
    	return datastore->data;
    }
    
    /*!
     * \internal
     * \brief Determine if we should dissolve the bridge from a hangup.
     * \since 12.0.0
     *
     * \param bridge_channel Channel executing the feature
     * \param hook_pvt Private data passed in when the hook was created
     *
     * \retval 0 Keep the callback hook.
     * \retval -1 Remove the callback hook.
     */
    
    static int basic_hangup_hook(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
    
    	int bridge_count = 0;
    	struct ast_bridge_channel *iter;
    
    
    	ast_bridge_channel_lock_bridge(bridge_channel);
    
    	AST_LIST_TRAVERSE(&bridge_channel->bridge->channels, iter, entry) {
    
    		if (iter != bridge_channel && iter->state == BRIDGE_CHANNEL_STATE_WAIT) {
    
    			++bridge_count;
    		}
    	}
    	if (2 <= bridge_count) {
    
    		/* Just allow this channel to leave the multi-party bridge. */
    
    		ast_bridge_channel_leave_bridge(bridge_channel,
    			BRIDGE_CHANNEL_STATE_END_NO_DISSOLVE, 0);
    
    /*!
     * \brief Details for specific basic bridge personalities
     */
    struct personality_details {
    	/*! The v_table to use for this personality */
    	struct ast_bridge_methods *v_table;
    	/*! Flags to set on this type of bridge */
    	unsigned int bridge_flags;
    	/*! User data for this personality. If used, must be an ao2 object */
    	void *pvt;
    	/*! Callback to be called when changing to the personality */
    	void (*on_personality_change)(struct ast_bridge *bridge);
    };
    
    /*!
     * \brief structure that organizes different personalities for basic bridges.
     */
    struct bridge_basic_personality {
    	/*! The current bridge personality in use */
    	enum bridge_basic_personality_type current;
    	/*! Array of details for the types of bridge personalities supported */
    	struct personality_details details[BRIDGE_BASIC_PERSONALITY_END];
    };
    
    
    /*
     * \internal
     * \brief Get the extension for a given builtin feature.
     *
     * \param chan Get the feature extension for this channel.
     * \param feature_name features.conf name of feature.
     * \param buf Where to put the extension.
     * \param len Length of the given extension buffer.
     *
     * \retval 0 success
     * \retval non-zero failiure
     */
    static int builtin_feature_get_exten(struct ast_channel *chan, const char *feature_name, char *buf, size_t len)
    {
    	SCOPED_CHANNELLOCK(lock, chan);
    
    	return ast_get_builtin_feature(chan, feature_name, buf, len);
    }
    
    /*!
     * \internal
     * \brief Helper to add a builtin DTMF feature hook to the features struct.
     * \since 12.0.0
     *
     * \param features Bridge features to setup.
     * \param chan Get features from this channel.
     * \param flags Feature flags on the channel.
     * \param feature_flag Feature flag to test.
     * \param feature_name features.conf name of feature.
     * \param feature_bridge Bridge feature enum to get hook callback.
     *
     * \retval 0 on success.
     * \retval -1 on error.
     */
    static int builtin_features_helper(struct ast_bridge_features *features, struct ast_channel *chan,
    	struct ast_flags *flags, unsigned int feature_flag, const char *feature_name, enum ast_bridge_builtin_feature feature_bridge)
    {
    	char dtmf[AST_FEATURE_MAX_LEN];
    	int res;
    
    	res = 0;
    	if (ast_test_flag(flags, feature_flag)
    		&& !builtin_feature_get_exten(chan, feature_name, dtmf, sizeof(dtmf))
    		&& !ast_strlen_zero(dtmf)) {
    		res = ast_bridge_features_enable(features, feature_bridge, dtmf, NULL, NULL,
    			AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
    		if (res) {
    			ast_log(LOG_ERROR, "Channel %s: Requested DTMF feature %s not available.\n",
    				ast_channel_name(chan), feature_name);
    		}
    	}
    
    	return res;
    }
    
    /*!
     * \internal
     * \brief Setup bridge builtin features.
     * \since 12.0.0
     *
     * \param features Bridge features to setup.
     * \param chan Get features from this channel.
     *
     * \retval 0 on success.
     * \retval -1 on error.
     */
    static int setup_bridge_features_builtin(struct ast_bridge_features *features, struct ast_channel *chan)
    {
    	struct ast_flags *flags;
    	int res;
    
    	ast_channel_lock(chan);
    	flags = ast_bridge_features_ds_get(chan);
    	ast_channel_unlock(chan);
    	if (!flags) {
    		return 0;
    	}
    
    	res = 0;
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_REDIRECT, "blindxfer", AST_BRIDGE_BUILTIN_BLINDTRANSFER);
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_REDIRECT, "atxfer", AST_BRIDGE_BUILTIN_ATTENDEDTRANSFER);
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_DISCONNECT, "disconnect", AST_BRIDGE_BUILTIN_HANGUP);
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_PARKCALL, "parkcall", AST_BRIDGE_BUILTIN_PARKCALL);
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_AUTOMON, "automon", AST_BRIDGE_BUILTIN_AUTOMON);
    	res |= builtin_features_helper(features, chan, flags, AST_FEATURE_AUTOMIXMON, "automixmon", AST_BRIDGE_BUILTIN_AUTOMIXMON);
    
    	return res ? -1 : 0;
    }
    
    struct dynamic_dtmf_hook_run {
    	/*! Offset into app_name[] where the channel name that activated the hook starts. */
    	int activated_offset;
    	/*! Offset into app_name[] where the dynamic feature name starts. */
    	int feature_offset;
    	/*! Offset into app_name[] where the MOH class name starts.  (zero if no MOH) */
    	int moh_offset;
    	/*! Offset into app_name[] where the application argument string starts. (zero if no arguments) */
    	int app_args_offset;
    	/*! Application name to run. */
    	char app_name[0];
    };
    
    static void dynamic_dtmf_hook_callback(struct ast_bridge_channel *bridge_channel,
    	const void *payload, size_t payload_size)
    {
    	struct ast_channel *chan = bridge_channel->chan;
    	const struct dynamic_dtmf_hook_run *run_data = payload;
    
    	pbx_builtin_setvar_helper(chan, "DYNAMIC_FEATURENAME",
    		&run_data->app_name[run_data->feature_offset]);
    	pbx_builtin_setvar_helper(chan, "DYNAMIC_WHO_ACTIVATED",
    		&run_data->app_name[run_data->activated_offset]);
    
    	ast_bridge_channel_run_app(bridge_channel, run_data->app_name,
    		run_data->app_args_offset ? &run_data->app_name[run_data->app_args_offset] : NULL,
    		run_data->moh_offset ? &run_data->app_name[run_data->moh_offset] : NULL);
    }
    
    struct dynamic_dtmf_hook_data {
    	/*! Which side of bridge to run app (AST_FEATURE_FLAG_ONSELF/AST_FEATURE_FLAG_ONPEER) */
    	unsigned int flags;
    	/*! Offset into app_name[] where the dynamic feature name starts. */
    	int feature_offset;
    	/*! Offset into app_name[] where the MOH class name starts.  (zero if no MOH) */
    	int moh_offset;
    	/*! Offset into app_name[] where the application argument string starts. (zero if no arguments) */
    	int app_args_offset;
    	/*! Application name to run. */
    	char app_name[0];
    };
    
    /*!
     * \internal
     * \brief Activated dynamic DTMF feature hook.
     * \since 12.0.0
     *
     * \param bridge_channel Channel executing the feature
     * \param hook_pvt Private data passed in when the hook was created
     *
     * \retval 0 Keep the callback hook.
     * \retval -1 Remove the callback hook.
     */
    static int dynamic_dtmf_hook_trip(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
    {
    	struct dynamic_dtmf_hook_data *pvt = hook_pvt;
    	struct dynamic_dtmf_hook_run *run_data;
    	const char *activated_name;
    	size_t len_name;
    	size_t len_args;
    	size_t len_moh;
    	size_t len_feature;
    	size_t len_activated;
    	size_t len_data;
    
    	/* Determine lengths of things. */
    	len_name = strlen(pvt->app_name) + 1;
    	len_args = pvt->app_args_offset ? strlen(&pvt->app_name[pvt->app_args_offset]) + 1 : 0;
    	len_moh = pvt->moh_offset ? strlen(&pvt->app_name[pvt->moh_offset]) + 1 : 0;
    	len_feature = strlen(&pvt->app_name[pvt->feature_offset]) + 1;
    	ast_channel_lock(bridge_channel->chan);
    	activated_name = ast_strdupa(ast_channel_name(bridge_channel->chan));
    	ast_channel_unlock(bridge_channel->chan);
    	len_activated = strlen(activated_name) + 1;
    	len_data = sizeof(*run_data) + len_name + len_args + len_moh + len_feature + len_activated;
    
    	/* Fill in dynamic feature run hook data. */
    	run_data = ast_alloca(len_data);
    	run_data->app_args_offset = len_args ? len_name : 0;
    	run_data->moh_offset = len_moh ? len_name + len_args : 0;
    	run_data->feature_offset = len_name + len_args + len_moh;
    	run_data->activated_offset = len_name + len_args + len_moh + len_feature;
    	strcpy(run_data->app_name, pvt->app_name);/* Safe */
    	if (len_args) {
    		strcpy(&run_data->app_name[run_data->app_args_offset],
    			&pvt->app_name[pvt->app_args_offset]);/* Safe */
    	}
    	if (len_moh) {
    		strcpy(&run_data->app_name[run_data->moh_offset],
    			&pvt->app_name[pvt->moh_offset]);/* Safe */
    	}
    	strcpy(&run_data->app_name[run_data->feature_offset],
    		&pvt->app_name[pvt->feature_offset]);/* Safe */
    	strcpy(&run_data->app_name[run_data->activated_offset], activated_name);/* Safe */
    
    	if (ast_test_flag(pvt, AST_FEATURE_FLAG_ONPEER)) {
    		ast_bridge_channel_write_callback(bridge_channel,
    			AST_BRIDGE_CHANNEL_CB_OPTION_MEDIA,
    			dynamic_dtmf_hook_callback, run_data, len_data);
    	} else {
    		dynamic_dtmf_hook_callback(bridge_channel, run_data, len_data);
    	}
    	return 0;
    }
    
    /*!
     * \internal
     * \brief Add a dynamic DTMF feature hook to the bridge features.
     * \since 12.0.0
     *
     * \param features Bridge features to setup.
     * \param flags Which side of bridge to run app (AST_FEATURE_FLAG_ONSELF/AST_FEATURE_FLAG_ONPEER).
     * \param dtmf DTMF trigger sequence.
     * \param feature_name Name of the dynamic feature.
     * \param app_name Dialplan application name to run.
     * \param app_args Dialplan application arguments. (Empty or NULL if no arguments)
     * \param moh_class MOH class to play to peer. (Empty or NULL if no MOH played)
     *
     * \retval 0 on success.
     * \retval -1 on error.
     */
    static int dynamic_dtmf_hook_add(struct ast_bridge_features *features, unsigned int flags, const char *dtmf, const char *feature_name, const char *app_name, const char *app_args, const char *moh_class)
    {
    	struct dynamic_dtmf_hook_data *hook_data;
    	size_t len_name = strlen(app_name) + 1;
    	size_t len_args = ast_strlen_zero(app_args) ? 0 : strlen(app_args) + 1;
    	size_t len_moh = ast_strlen_zero(moh_class) ? 0 : strlen(moh_class) + 1;
    	size_t len_feature = strlen(feature_name) + 1;
    	size_t len_data = sizeof(*hook_data) + len_name + len_args + len_moh + len_feature;
    	int res;
    
    	/* Fill in application run hook data. */
    	hook_data = ast_malloc(len_data);
    	if (!hook_data) {
    		return -1;
    	}
    	hook_data->flags = flags;
    	hook_data->app_args_offset = len_args ? len_name : 0;
    	hook_data->moh_offset = len_moh ? len_name + len_args : 0;
    	hook_data->feature_offset = len_name + len_args + len_moh;
    	strcpy(hook_data->app_name, app_name);/* Safe */
    	if (len_args) {
    		strcpy(&hook_data->app_name[hook_data->app_args_offset], app_args);/* Safe */
    	}
    	if (len_moh) {
    		strcpy(&hook_data->app_name[hook_data->moh_offset], moh_class);/* Safe */
    	}
    	strcpy(&hook_data->app_name[hook_data->feature_offset], feature_name);/* Safe */
    
    	res = ast_bridge_dtmf_hook(features, dtmf, dynamic_dtmf_hook_trip, hook_data,
    		ast_free_ptr,
    		AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
    	if (res) {
    		ast_free(hook_data);
    	}
    	return res;
    }
    
    static int setup_dynamic_feature(void *obj, void *arg, void *data, int flags)
    {
    	struct ast_applicationmap_item *item = obj;
    	struct ast_bridge_features *features = arg;
    	int *res = data;
    
    	*res |= dynamic_dtmf_hook_add(features,
    		item->activate_on_self ? AST_FEATURE_FLAG_ONSELF : AST_FEATURE_FLAG_ONPEER,
    		item->dtmf, item->name, item->app, item->app_data, item->moh_class);
    
    	return 0;
    }
    
    /*!
     * \internal
     * \brief Setup bridge dynamic features.
     * \since 12.0.0
     *
     * \param features Bridge features to setup.
     * \param chan Get features from this channel.
     *
     * \retval 0 on success.
     * \retval -1 on error.
     */
    static int setup_bridge_features_dynamic(struct ast_bridge_features *features, struct ast_channel *chan)
    {
    
    	int res = 0;
    
    	ast_channel_lock(chan);
    	applicationmap = ast_get_chan_applicationmap(chan);
    	ast_channel_unlock(chan);
    
    	if (applicationmap) {
    		ao2_callback_data(applicationmap, 0, setup_dynamic_feature, features, &res);
    		ao2_ref(applicationmap, -1);
    
    	}
    
    	return res;
    }
    
    /*!
     * \internal
     * \brief Setup DTMF feature hooks using the channel features datastore property.
     * \since 12.0.0
     *
     * \param bridge_channel What to setup DTMF features on.
     *
     * \retval 0 on success.
     * \retval -1 on error.
     */
    static int bridge_basic_setup_features(struct ast_bridge_channel *bridge_channel)
    {
    	int res = 0;
    
    	res |= setup_bridge_features_builtin(bridge_channel->features, bridge_channel->chan);
    	res |= setup_bridge_features_dynamic(bridge_channel->features, bridge_channel->chan);
    
    	return res;
    }
    
    
    static int add_normal_hooks(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
    {
    	return ast_bridge_hangup_hook(bridge_channel->features, basic_hangup_hook,
    			NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL)
    
    		|| bridge_basic_setup_features(bridge_channel);
    
    /*!
     * \internal
     * \brief ast_bridge basic push method.
     * \since 12.0.0
     *
     * \param self Bridge to operate upon.
     * \param bridge_channel Bridge channel to push.
     * \param swap Bridge channel to swap places with if not NULL.
     *
     * \note On entry, self is already locked.
     *
     * \retval 0 on success
     * \retval -1 on failure
     */
    
    static int bridge_personality_normal_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
    
    	if (add_normal_hooks(self, bridge_channel)) {
    
    	return 0;
    }
    
    static int bridge_basic_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
    {
    	struct bridge_basic_personality *personality = self->personality;
    
    	ast_assert(personality != NULL);
    
    
    	if (personality->details[personality->current].v_table->push
    		&& personality->details[personality->current].v_table->push(self, bridge_channel, swap)) {
    
    	ast_bridge_channel_update_linkedids(bridge_channel, swap);
    	ast_bridge_channel_update_accountcodes(bridge_channel, swap);
    
    
    	return ast_bridge_base_v_table.push(self, bridge_channel, swap);
    }
    
    
    static void bridge_basic_pull(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel)
    {
    	struct bridge_basic_personality *personality = self->personality;
    
    	ast_assert(personality != NULL);
    
    	if (personality->details[personality->current].v_table->pull) {
    		personality->details[personality->current].v_table->pull(self, bridge_channel);
    	}
    
    
    	ast_bridge_channel_update_accountcodes(NULL, bridge_channel);
    
    
    	ast_bridge_base_v_table.pull(self, bridge_channel);
    }
    
    static void bridge_basic_destroy(struct ast_bridge *self)
    
    	struct bridge_basic_personality *personality = self->personality;
    
    	ao2_cleanup(personality);
    
    	ast_bridge_base_v_table.destroy(self);
    
    /*!
     * \brief Remove appropriate hooks when basic bridge personality changes
     *
     * Hooks that have the AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE flag
     * set will be removed from all bridge channels in the bridge.
     *
     * \param bridge Basic bridge undergoing personality change
     */
    static void remove_hooks_on_personality_change(struct ast_bridge *bridge)
    
    	struct ast_bridge_channel *iter;
    
    	AST_LIST_TRAVERSE(&bridge->channels, iter, entry) {
    		SCOPED_LOCK(lock, iter, ast_bridge_channel_lock, ast_bridge_channel_unlock);
    		ast_bridge_features_remove(iter->features, AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
    	}
    }
    
    /*!
     * \brief Attended transfer superstates.
     *
     * An attended transfer's progress is facilitated by a state machine.
     * The individual states of the state machine fall into the realm of
     * one of two superstates.
     */
    enum attended_transfer_superstate {
    	/*!
    	 * \brief Transfer superstate
    	 *
    	 * The attended transfer state machine begins in this superstate. The
    	 * goal of this state is for a transferer channel to facilitate a
    	 * transfer from a transferee to a transfer target.
    	 *
    	 * There are two bridges used in this superstate. The transferee bridge is
    	 * the bridge that the transferer and transferee channels originally
    	 * communicate in, and the target bridge is the bridge where the transfer
    	 * target is being dialed.
    	 *
    	 * The transferer channel is capable of moving between the bridges using
    	 * the DTMF swap sequence.
    	 */
    	SUPERSTATE_TRANSFER,
    	/*!
    	 * \brief Recall superstate
    	 *
    	 * The attended transfer state machine moves to this superstate if
    	 * atxferdropcall is set to "no" and the transferer channel hangs up
    	 * during a transfer. The goal in this superstate is to call back either
    	 * the transfer target or transferer and rebridge with the transferee
    	 * channel(s).
    	 *
    	 * In this superstate, there is only a single bridge used, the original
    	 * transferee bridge. Rather than distinguishing between a transferer
    	 * and transfer target, all outbound calls are toward a "recall_target"
    	 * channel.
    	 */
    	SUPERSTATE_RECALL,
    };
    
    /*!
     * The states in the attended transfer state machine.
     */
    enum attended_transfer_state {
    	/*!
    	 * \brief Calling Target state
    	 *
    	 * This state describes the initial state of a transfer. The transferer
    	 * waits in the transfer target's bridge for the transfer target to answer.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target is RINGING
    	 * 2) Transferer is in transferee bridge
    	 * 3) Transferee is on hold
    	 *
    	 * Transitions to TRANSFER_CALLING_TARGET:
    	 * 1) This is the initial state for an attended transfer.
    	 * 2) TRANSFER_HESITANT: Transferer presses DTMF swap sequence
    	 *
    	 * State operation:
    	 * The transferer is moved from the transferee bridge into the transfer
    	 * target bridge.
    	 *
    	 * Transitions from TRANSFER_CALLING_TARGET:
    	 * 1) TRANSFER_FAIL: Transferee hangs up.
    	 * 2) TRANSFER_BLOND: Transferer hangs up or presses DTMF swap sequence
    	 * and configured atxferdropcall setting is yes.
    	 * 3) TRANSFER_BLOND_NONFINAL: Transferer hangs up or presses DTMF swap
    	 * sequence and configured atxferdroppcall setting is no.
    	 * 4) TRANSFER_CONSULTING: Transfer target answers the call.
    	 * 5) TRANSFER_REBRIDGE: Transfer target hangs up, call to transfer target
    	 * times out, or transferer presses DTMF abort sequence.
    	 * 6) TRANSFER_THREEWAY: Transferer presses DTMF threeway sequence.
    	 * 7) TRANSFER_HESITANT: Transferer presses DTMF swap sequence.
    	 */
    	TRANSFER_CALLING_TARGET,
    	/*!
    	 * \brief Hesitant state
    	 *
    	 * This state only arises if when waiting for the transfer target to
    	 * answer, the transferer presses the DTMF swap sequence. This will
    	 * cause the transferer to be rebridged with the transferee temporarily.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target is in ringing state
    	 * 2) Transferer is in transfer target bridge
    	 * 3) Transferee is on hold
    	 *
    	 * Transitions to TRANSFER_HESITANT:
    	 * 1) TRANSFER_CALLING_TARGET: Transferer presses DTMF swap sequence.
    	 *
    	 * State operation:
    	 * The transferer is moved from the transfer target bridge into the
    	 * transferee bridge, and the transferee is taken off hold.
    	 *
    	 * Transitions from TRANSFER_HESITANT:
    	 * 1) TRANSFER_FAIL: Transferee hangs up
    	 * 2) TRANSFER_BLOND: Transferer hangs up or presses DTMF swap sequence
    	 * and configured atxferdropcall setting is yes.
    	 * 3) TRANSFER_BLOND_NONFINAL: Transferer hangs up or presses DTMF swap
    	 * sequence and configured atxferdroppcall setting is no.
    	 * 4) TRANSFER_DOUBLECHECKING: Transfer target answers the call
    	 * 5) TRANSFER_RESUME: Transfer target hangs up, call to transfer target
    	 * times out, or transferer presses DTMF abort sequence.
    	 * 6) TRANSFER_THREEWAY: Transferer presses DTMF threeway sequence.
    	 * 7) TRANSFER_CALLING_TARGET: Transferer presses DTMF swap sequence.
    	 */
    	TRANSFER_HESITANT,
    	/*!
    	 * \brief Rebridge state
    	 *
    	 * This is a terminal state that indicates that the transferer needs
    	 * to move back to the transferee's bridge. This is a failed attended
    	 * transfer result.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transferer is in transfer target bridge
    	 * 2) Transferee is on hold
    	 *
    	 * Transitions to TRANSFER_REBRIDGE:
    	 * 1) TRANSFER_CALLING_TARGET: Transfer target hangs up, call to transfer target
    	 * times out, or transferer presses DTMF abort sequence.
    	 * 2) TRANSFER_STATE_CONSULTING: Transfer target hangs up, or transferer presses
    	 * DTMF abort sequence.
    	 *
    	 * State operation:
    	 * The transferer channel is moved from the transfer target bridge to the
    	 * transferee bridge. The transferee is taken off hold. A stasis transfer
    	 * message is published indicating a failed attended transfer.
    	 *
    	 * Transitions from TRANSFER_REBRIDGE:
    	 * None
    	 */
    	TRANSFER_REBRIDGE,
    	/*!
    	 * \brief Resume state
    	 *
    	 * This is a terminal state that indicates that the party bridged with the
    	 * transferee is the final party to be bridged with that transferee. This state
    	 * may come about due to a successful recall or due to a failed transfer.
    	 *
    	 * Superstate: Transfer or Recall
    	 *
    	 * Preconditions:
    	 * In Transfer Superstate:
    	 * 1) Transferer is in transferee bridge
    	 * 2) Transferee is not on hold
    	 * In Recall Superstate:
    	 * 1) The recall target is in the transferee bridge
    	 * 2) Transferee is not on hold
    	 *
    	 * Transitions to TRANSFER_RESUME:
    	 * TRANSFER_HESITANT: Transfer target hangs up, call to transfer target times out,
    	 * or transferer presses DTMF abort sequence.
    	 * TRANSFER_DOUBLECHECKING: Transfer target hangs up or transferer presses DTMF
    	 * abort sequence.
    	 * TRANSFER_BLOND_NONFINAL: Recall target answers
    	 * TRANSFER_RECALLING: Recall target answers
    	 * TRANSFER_RETRANSFER: Recall target answers
    	 *
    	 * State operations:
    	 * None
    	 *
    	 * Transitions from TRANSFER_RESUME:
    	 * None
    	 */
    	TRANSFER_RESUME,
    	/*!
    	 * \brief Threeway state
    	 *
    	 * This state results when the transferer wishes to have all parties involved
    	 * in a transfer to be in the same bridge together.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target state is either RINGING or UP
    	 * 2) Transferer is in either bridge
    	 * 3) Transferee is not on hold
    	 *
    	 * Transitions to TRANSFER_THREEWAY:
    	 * 1) TRANSFER_CALLING_TARGET: Transferer presses DTMF threeway sequence.
    	 * 2) TRANSFER_HESITANT: Transferer presses DTMF threeway sequence.
    	 * 3) TRANSFER_CONSULTING: Transferer presses DTMF threeway sequence.
    	 * 4) TRANSFER_DOUBLECHECKING: Transferer presses DTMF threeway sequence.
    	 *
    	 * State operation:
    	 * The transfer target bridge is merged into the transferee bridge.
    	 *
    	 * Transitions from TRANSFER_THREEWAY:
    	 * None.
    	 */
    	TRANSFER_THREEWAY,
    	/*!
    	 * \brief Consulting state
    	 *
    	 * This state describes the case where the transferer and transfer target
    	 * are able to converse in the transfer target's bridge prior to completing
    	 * the transfer.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target is UP
    	 * 2) Transferer is in target bridge
    	 * 3) Transferee is on hold
    	 *
    	 * Transitions to TRANSFER_CONSULTING:
    	 * 1) TRANSFER_CALLING_TARGET: Transfer target answers.
    	 * 2) TRANSFER_DOUBLECHECKING: Transferer presses DTMF swap sequence.
    	 *
    	 * State operations:
    	 * None.
    	 *
    	 * Transitions from TRANSFER_CONSULTING:
    	 * TRANSFER_COMPLETE: Transferer hangs up or transferer presses DTMF complete sequence.
    	 * TRANSFER_REBRIDGE: Transfer target hangs up or transferer presses DTMF abort sequence.
    	 * TRANSFER_THREEWAY: Transferer presses DTMF threeway sequence.
    	 * TRANSFER_DOUBLECHECKING: Transferer presses DTMF swap sequence.
    	 */
    	TRANSFER_CONSULTING,
    	/*!
    	 * \brief Double-checking state
    	 *
    	 * This state describes the case where the transferer and transferee are
    	 * able to converse in the transferee's bridge prior to completing the transfer. The
    	 * difference between this and TRANSFER_HESITANT is that the transfer target is
    	 * UP in this case.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target is UP and on hold
    	 * 2) Transferer is in transferee bridge
    	 * 3) Transferee is off hold
    	 *
    	 * Transitions to TRANSFER_DOUBLECHECKING:
    	 * 1) TRANSFER_HESITANT: Transfer target answers.
    	 * 2) TRANSFER_CONSULTING: Transferer presses DTMF swap sequence.
    	 *
    	 * State operations:
    	 * None.
    	 *
    	 * Transitions from TRANSFER_DOUBLECHECKING:
    	 * 1) TRANSFER_FAIL: Transferee hangs up.
    	 * 2) TRANSFER_COMPLETE: Transferer hangs up or presses DTMF complete sequence.
    	 * 3) TRANSFER_RESUME: Transfer target hangs up or transferer presses DTMF abort sequence.
    	 * 4) TRANSFER_THREEWAY: Transferer presses DTMF threeway sequence.
    	 * 5) TRANSFER_CONSULTING: Transferer presses the DTMF swap sequence.
    	 */
    	TRANSFER_DOUBLECHECKING,
    	/*!
    	 * \brief Complete state
    	 *
    	 * This is a terminal state where a transferer has successfully completed an attended
    	 * transfer. This state's goal is to get the transfer target and transferee into
    	 * the same bridge and the transferer off the call.
    	 *
    	 * Superstate: Transfer
    	 *
    	 * Preconditions:
    	 * 1) Transfer target is UP and off hold.