[asterisk-commits] mjordan: branch mjordan/cdrs-of-doom r386319 - in /team/mjordan/cdrs-of-doom:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 22 14:17:37 CDT 2013
Author: mjordan
Date: Mon Apr 22 14:17:33 2013
New Revision: 386319
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386319
Log:
Merge more stuff
Added:
team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h (with props)
team/mjordan/cdrs-of-doom/main/bridging_roles.c (with props)
Modified:
team/mjordan/cdrs-of-doom/apps/app_confbridge.c
team/mjordan/cdrs-of-doom/channels/chan_local.c
Modified: team/mjordan/cdrs-of-doom/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/apps/app_confbridge.c?view=diff&rev=386319&r1=386318&r2=386319
==============================================================================
--- team/mjordan/cdrs-of-doom/apps/app_confbridge.c (original)
+++ team/mjordan/cdrs-of-doom/apps/app_confbridge.c Mon Apr 22 14:17:33 2013
@@ -649,6 +649,7 @@
struct ast_channel *chan;
struct ast_str *filename = ast_str_alloca(PATH_MAX);
struct ast_str *orig_rec_file = NULL;
+ struct ast_bridge_features features;
ast_mutex_lock(&conference->record_lock);
if (!mixmonapp) {
@@ -658,20 +659,27 @@
ao2_ref(conference, -1);
return NULL;
}
+ if (ast_bridge_features_init(&features)) {
+ conference->record_thread = AST_PTHREADT_NULL;
+ ast_mutex_unlock(&conference->record_lock);
+ ao2_ref(conference, -1);
+ return NULL;
+ }
/* XXX If we get an EXIT right here, START will essentially be a no-op */
while (conference->record_state != CONF_RECORD_EXIT) {
set_rec_filename(conference, &filename,
- is_new_rec_file(conference->b_profile.rec_file, &orig_rec_file));
+ is_new_rec_file(conference->b_profile.rec_file, &orig_rec_file));
chan = ast_channel_ref(conference->record_chan);
ast_answer(chan);
pbx_exec(chan, mixmonapp, ast_str_buffer(filename));
- ast_bridge_join(conference->bridge, chan, NULL, NULL, NULL);
+ ast_bridge_join(conference->bridge, chan, NULL, &features, NULL, 0);
ast_hangup(chan); /* This will eat this thread's reference to the channel as well */
/* STOP has been called. Wait for either a START or an EXIT */
ast_cond_wait(&conference->record_cond, &conference->record_lock);
}
+ ast_bridge_features_cleanup(&features);
ast_free(orig_rec_file);
ast_mutex_unlock(&conference->record_lock);
ao2_ref(conference, -1);
@@ -1285,7 +1293,9 @@
conf_bridge_profile_copy(&conference->b_profile, &user->b_profile);
/* Create an actual bridge that will do the audio mixing */
- if (!(conference->bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_MULTIMIX, 0))) {
+ conference->bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_MULTIMIX,
+ AST_BRIDGE_FLAG_MASQUERADE_ONLY);
+ if (!conference->bridge) {
ao2_ref(conference, -1);
conference = NULL;
ao2_unlock(conference_bridges);
@@ -1490,7 +1500,7 @@
}
ast_debug(1, "Departing underlying channel '%s' from bridge '%p'\n", ast_channel_name(underlying_channel), conference->bridge);
- ast_bridge_depart(conference->bridge, underlying_channel);
+ ast_bridge_depart(underlying_channel);
ast_mutex_unlock(&conference->playback_lock);
@@ -1521,21 +1531,9 @@
ast_free(pvt_data);
}
-static void conf_handle_talker_cb(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *pvt_data)
-{
- char *conf_name = pvt_data;
- int talking;
-
- switch (bridge_channel->state) {
- case AST_BRIDGE_CHANNEL_STATE_START_TALKING:
- talking = 1;
- break;
- case AST_BRIDGE_CHANNEL_STATE_STOP_TALKING:
- talking = 0;
- break;
- default:
- return; /* uhh this shouldn't happen, but bail if it does. */
- }
+static void conf_handle_talker_cb(struct ast_bridge_channel *bridge_channel, void *pvt_data, int talking)
+{
+ const char *conf_name = pvt_data;
/* notify AMI someone is has either started or stopped talking */
/*** DOCUMENTATION
@@ -1553,11 +1551,14 @@
</managerEventInstance>
***/
ast_manager_event(bridge_channel->chan, EVENT_FLAG_CALL, "ConfbridgeTalking",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Conference: %s\r\n"
- "TalkingStatus: %s\r\n",
- ast_channel_name(bridge_channel->chan), ast_channel_uniqueid(bridge_channel->chan), conf_name, talking ? "on" : "off");
+ "Channel: %s\r\n"
+ "Uniqueid: %s\r\n"
+ "Conference: %s\r\n"
+ "TalkingStatus: %s\r\n",
+ ast_channel_name(bridge_channel->chan),
+ ast_channel_uniqueid(bridge_channel->chan),
+ conf_name,
+ talking ? "on" : "off");
}
static int conf_get_pin(struct ast_channel *chan, struct confbridge_user *user)
@@ -1652,10 +1653,14 @@
AST_APP_ARG(u_profile_name);
AST_APP_ARG(menu_name);
);
- ast_bridge_features_init(&user.features);
if (ast_channel_state(chan) != AST_STATE_UP) {
ast_answer(chan);
+ }
+
+ if (ast_bridge_features_init(&user.features)) {
+ res = -1;
+ goto confbridge_cleanup;
}
if (ast_strlen_zero(data)) {
@@ -1808,7 +1813,8 @@
chan,
NULL,
&user.features,
- &user.tech_args);
+ &user.tech_args,
+ 0);
send_leave_event(user.chan, conference->name);
/* if we're shutting down, don't attempt to do further processing */
Modified: team/mjordan/cdrs-of-doom/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/channels/chan_local.c?view=diff&rev=386319&r1=386318&r2=386319
==============================================================================
--- team/mjordan/cdrs-of-doom/channels/chan_local.c (original)
+++ team/mjordan/cdrs-of-doom/channels/chan_local.c Mon Apr 22 14:17:33 2013
@@ -776,7 +776,6 @@
ast_channel_language_set(chan, ast_channel_language(owner));
ast_channel_accountcode_set(chan, ast_channel_accountcode(owner));
ast_channel_musicclass_set(chan, ast_channel_musicclass(owner));
- ast_cdr_update(chan);
ast_channel_cc_params_init(chan, ast_channel_get_cc_config_params(owner));
Added: team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h?view=auto&rev=386319
==============================================================================
--- team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h (added)
+++ team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h Mon Apr 22 14:17:33 2013
@@ -1,0 +1,135 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jonathan Rose <jrose at 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 Channel Bridging Roles API
+ * \author Jonathan Rose <jrose at digium.com>
+ */
+
+#ifndef _ASTERISK_BRIDGING_ROLES_H
+#define _ASTERISK_BRIDGING_ROLES_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+#include "asterisk/linkedlists.h"
+
+#define AST_ROLE_LEN 32
+
+/*!
+ * \brief Adds a bridge role to a channel
+ *
+ * \param chan Acquirer of the requested role
+ * \param role_name Name of the role being attached
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name);
+
+/*!
+ * \brief Removes a bridge role from a channel
+ *
+ * \param chan Channel the role is being removed from
+ * \param role_name Name of the role being removed
+ */
+void ast_channel_remove_bridge_role(struct ast_channel *chan, const char *role_name);
+
+/*!
+ * \brief Set a role option on a channel
+ * \param channel Channel receiving the role option
+ * \param role_name Role the role option is applied to
+ * \param option Name of the option
+ * \param value Value of the option
+ *
+ * \param 0 on success
+ * \retval -1 on failure
+ */
+int ast_channel_set_bridge_role_option(struct ast_channel *channel, const char *role_name, const char *option, const char *value);
+
+/*!
+ * \brief Check to see if a bridge channel inherited a specific role from its channel
+ *
+ * \param bridge_channel The bridge channel being checked
+ * \param role_name Name of the role being checked
+ *
+ * \retval 0 The bridge channel does not have the requested role
+ * \retval 1 The bridge channel does have the requested role
+ *
+ * \note Before a bridge_channel can effectively check roles against a bridge, ast_bridge_roles_bridge_channel_establish_roles
+ * should be called on the bridge_channel so that roles and their respective role options can be copied from the channel
+ * datastore into the bridge_channel roles list. Otherwise this function will just return 0 because the list will be NULL.
+ */
+int ast_bridge_channel_has_role(struct ast_bridge_channel *bridge_channel, const char *role_name);
+
+/*!
+ * \brief Retrieve the value of a requested role option from a bridge channel
+ *
+ * \param bridge_channel The bridge channel we are retrieving the option from
+ * \param role_name Name of the role the option will be retrieved from
+ * \param option Name of the option we are retrieving the value of
+ *
+ * \retval NULL If either the role does not exist on the bridge_channel or the role does exist but the option has not been set
+ * \retval The value of the option
+ *
+ * \note See ast_bridge_roles_channel_set_role_option note about the need to call ast_bridge_roles_bridge_channel_establish_roles.
+ *
+ * \note The returned character pointer is only valid as long as the bridge_channel is guaranteed to be alive and hasn't had
+ * ast_bridge_roles_bridge_channel_clear_roles called against it (as this will free all roles and role options in the bridge
+ * channel). If you need this value after one of these destruction events occurs, you must make a local copy while it is
+ * still valid.
+ */
+const char *ast_bridge_channel_get_role_option(struct ast_bridge_channel *bridge_channel, const char *role_name, const char *option);
+
+/*!
+ * \brief Clone the roles from a bridge_channel's attached ast_channel onto the bridge_channel's role list
+ *
+ * \param bridge_channel The bridge channel that we are preparing
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
+ * \details
+ * This function should always be called when the bridge_channel binds to an ast_channel at some point before the bridge_channel
+ * joins or is imparted onto a bridge. Failure to do so will result in an empty role list. While the list remains established,
+ * changes to roles on the ast_channel will not propogate to the bridge channel and roles can not be re-established on the bridge
+ * channel without first clearing the roles with ast_bridge_roles_bridge_channel_clear_roles.
+ */
+int ast_bridge_channel_establish_roles(struct ast_bridge_channel *bridge_channel);
+
+/*!
+ * \brief Clear all roles from a bridge_channel's role list
+ *
+ * \param bridge_channel the bridge channel that we are scrubbing
+ *
+ * \details
+ * If roles are already established on a bridge channel, ast_bridge_roles_bridge_channel_establish_roles will fail unconditionally
+ * without changing any roles. In order to update a bridge channel's roles, they must first be cleared from the bridge channel using
+ * this function.
+ *
+ * \note
+ * ast_bridge_roles_bridge_channel_clear_roles also serves as the destructor for the role list of a bridge channel.
+ */
+void ast_bridge_channel_clear_roles(struct ast_bridge_channel *bridge_channel);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* _ASTERISK_BRIDGING_ROLES_H */
Propchange: team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mjordan/cdrs-of-doom/include/asterisk/bridging_roles.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: team/mjordan/cdrs-of-doom/main/bridging_roles.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/main/bridging_roles.c?view=auto&rev=386319
==============================================================================
--- team/mjordan/cdrs-of-doom/main/bridging_roles.c (added)
+++ team/mjordan/cdrs-of-doom/main/bridging_roles.c Mon Apr 22 14:17:33 2013
@@ -1,0 +1,453 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jonathan Rose <jrose at 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 Channel Bridging Roles API
+ *
+ * \author Jonathan Rose <jrose at digium.com>
+ *
+ * \ingroup bridges
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <signal.h>
+
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/datastore.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/bridging.h"
+#include "asterisk/bridging_roles.h"
+
+struct bridge_role_option {
+ AST_LIST_ENTRY(bridge_role_option) list;
+ char option[AST_ROLE_LEN];
+ char value[1];
+};
+
+struct bridge_role {
+ AST_LIST_ENTRY(bridge_role) list;
+ AST_LIST_HEAD(, bridge_role_option) options;
+ char role[AST_ROLE_LEN];
+};
+
+struct bridge_roles_datastore {
+ AST_LIST_HEAD(, bridge_role) role_list;
+};
+
+/*!
+ * \internal
+ * \brief Destructor function for a bridge role
+ * \since 12.0.0
+ *
+ * \param role bridge_role being destroyed
+ *
+ * \return Nothing
+ */
+static void bridge_role_destroy(struct bridge_role *role)
+{
+ struct bridge_role_option *role_option;
+ while ((role_option = AST_LIST_REMOVE_HEAD(&role->options, list))) {
+ ast_free(role_option);
+ }
+ ast_free(role);
+}
+
+/*!
+ * \internal
+ * \brief Destructor function for bridge role datastores
+ * \since 12.0.0
+ *
+ * \param data Pointer to the datastore being destroyed
+ *
+ * \return Nothing
+ */
+static void bridge_role_datastore_destroy(void *data)
+{
+ struct bridge_roles_datastore *roles_datastore = data;
+ struct bridge_role *role;
+
+ while ((role = AST_LIST_REMOVE_HEAD(&roles_datastore->role_list, list))) {
+ bridge_role_destroy(role);
+ }
+
+ ast_free(roles_datastore);
+}
+
+static const struct ast_datastore_info bridge_role_info = {
+ .type = "bridge roles",
+ .destroy = bridge_role_datastore_destroy,
+};
+
+/*!
+ * \internal
+ * \brief Setup a bridge role datastore on a channel
+ * \since 12.0.0
+ *
+ * \param chan Chan the datastore is being setup on
+ *
+ * \retval NULL if failed
+ * \retval pointer to the newly created datastore
+ */
+static struct bridge_roles_datastore *setup_bridge_roles_datastore(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore = NULL;
+ struct bridge_roles_datastore *roles_datastore = NULL;
+
+ if (!(datastore = ast_datastore_alloc(&bridge_role_info, NULL))) {
+ return NULL;
+ }
+
+ if (!(roles_datastore = ast_calloc(1, sizeof(*roles_datastore)))) {
+ ast_datastore_free(datastore);
+ return NULL;
+ }
+
+ datastore->data = roles_datastore;
+ ast_channel_datastore_add(chan, datastore);
+ return roles_datastore;
+}
+
+/*!
+ * \internal
+ * \brief Get the bridge_roles_datastore from a channel if it exists. Don't create one if it doesn't.
+ * \since 12.0.0
+ *
+ * \param chan Channel we want the bridge_roles_datastore from
+ *
+ * \retval NULL if we can't find the datastore
+ * \retval pointer to the bridge_roles_datastore
+ */
+static struct bridge_roles_datastore *fetch_bridge_roles_datastore(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore = NULL;
+
+ ast_channel_lock(chan);
+ if (!(datastore = ast_channel_datastore_find(chan, &bridge_role_info, NULL))) {
+ ast_channel_unlock(chan);
+ return NULL;
+ }
+ ast_channel_unlock(chan);
+
+ return datastore->data;
+}
+
+/*!
+ * \internal
+ * \brief Get the bridge_roles_datastore from a channel if it exists. If not, create one.
+ * \since 12.0.0
+ *
+ * \param chan Channel we want the bridge_roles_datastore from
+ *
+ * \retval NULL If we can't find and can't create the datastore
+ * \retval pointer to the bridge_roles_datastore
+ */
+static struct bridge_roles_datastore *fetch_or_create_bridge_roles_datastore(struct ast_channel *chan)
+{
+ struct bridge_roles_datastore *roles_datastore;
+
+ ast_channel_lock(chan);
+ roles_datastore = fetch_bridge_roles_datastore(chan);
+ if (!roles_datastore) {
+ roles_datastore = setup_bridge_roles_datastore(chan);
+ }
+ ast_channel_unlock(chan);
+
+ return roles_datastore;
+}
+
+/*!
+ * \internal
+ * \brief Obtain a role from a bridge_roles_datastore if the datastore has it
+ * \since 12.0.0
+ *
+ * \param roles_datastore The bridge_roles_datastore we are looking for the role of
+ * \param role_name Name of the role being sought
+ *
+ * \retval NULL if the datastore does not have the requested role
+ * \retval pointer to the requested role
+ */
+static struct bridge_role *get_role_from_datastore(struct bridge_roles_datastore *roles_datastore, const char *role_name)
+{
+ struct bridge_role *role;
+
+ AST_LIST_TRAVERSE(&roles_datastore->role_list, role, list) {
+ if (!strcmp(role->role, role_name)) {
+ return role;
+ }
+ }
+
+ return NULL;
+}
+
+/*!
+ * \internal
+ * \brief Obtain a role from a channel structure if the channel's datastore has it
+ * \since 12.0.0
+ *
+ * \param channel The channel we are checking the role of
+ * \param role_name Name of the role sought
+ *
+ * \retval NULL if the channel's datastore does not have the requested role
+ * \retval pointer to the requested role
+ */
+static struct bridge_role *get_role_from_channel(struct ast_channel *channel, const char *role_name)
+{
+ struct bridge_roles_datastore *roles_datastore = fetch_bridge_roles_datastore(channel);
+ return roles_datastore ? get_role_from_datastore(roles_datastore, role_name) : NULL;
+}
+
+/*!
+ * \internal
+ * \brief Obtain a role option from a bridge role if it exists in the bridge role's option list
+ * \since 12.0.0
+ *
+ * \param role a pointer to the bridge role wea re searching for the option of
+ * \param option Name of the option sought
+ *
+ * \retval NULL if the bridge role doesn't have the requested option
+ * \retval pointer to the requested option
+ */
+static struct bridge_role_option *get_role_option(struct bridge_role *role, const char *option)
+{
+ struct bridge_role_option *role_option = NULL;
+ AST_LIST_TRAVERSE(&role->options, role_option, list) {
+ if (!strcmp(role_option->option, option)) {
+ return role_option;
+ }
+ }
+ return NULL;
+}
+
+/*!
+ * \internal
+ * \brief Setup a bridge role on an existing bridge role datastore
+ * \since 12.0.0
+ *
+ * \param roles_datastore bridge_roles_datastore receiving the new role
+ * \param role_name Name of the role being received
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+static int setup_bridge_role(struct bridge_roles_datastore *roles_datastore, const char *role_name)
+{
+ struct bridge_role *role;
+ role = ast_calloc(1, sizeof(*role));
+
+ if (!role) {
+ return -1;
+ }
+
+ ast_copy_string(role->role, role_name, sizeof(role->role));
+
+ AST_LIST_INSERT_TAIL(&roles_datastore->role_list, role, list);
+ ast_debug(3, "Set role '%s'\n", role_name);
+
+ return 0;
+}
+
+/*!
+ * \internal
+ * \brief Setup a bridge role option on an existing bridge role
+ * \since 12.0.0
+ *
+ * \param role The role receiving the option
+ * \param option Name of the option
+ * \param value the option's value
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+static int setup_bridge_role_option(struct bridge_role *role, const char *option, const char *value)
+{
+ struct bridge_role_option *role_option;
+
+ if (!value) {
+ value = "";
+ }
+
+ role_option = ast_calloc(1, sizeof(*role_option) + strlen(value));
+ if (!role_option) {
+ return -1;
+ }
+
+ ast_copy_string(role_option->option, option, sizeof(role_option->option));
+ strcpy(role_option->value, value);
+
+ AST_LIST_INSERT_TAIL(&role->options, role_option, list);
+
+ return 0;
+}
+
+int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name)
+{
+ struct bridge_roles_datastore *roles_datastore = fetch_or_create_bridge_roles_datastore(chan);
+
+ if (!roles_datastore) {
+ ast_log(LOG_WARNING, "Unable to set up bridge role datastore on channel %s\n", ast_channel_name(chan));
+ return -1;
+ }
+
+ /* Check to make sure we aren't adding a redundant role */
+ if (get_role_from_datastore(roles_datastore, role_name)) {
+ ast_debug(2, "Bridge role %s is already applied to the channel %s\n", role_name, ast_channel_name(chan));
+ return 0;
+ }
+
+ /* It wasn't already there, so we can just finish setting it up now. */
+ return setup_bridge_role(roles_datastore, role_name);
+}
+
+void ast_channel_remove_bridge_role(struct ast_channel *chan, const char *role_name)
+{
+ struct bridge_roles_datastore *roles_datastore = fetch_bridge_roles_datastore(chan);
+ struct bridge_role *role;
+
+ if (!roles_datastore) {
+ /* The roles datastore didn't already exist, so there is no need to remove a role */
+ ast_debug(2, "Role %s did not exist on channel %s\n", role_name, ast_channel_name(chan));
+ return;
+ }
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&roles_datastore->role_list, role, list) {
+ if (!strcmp(role->role, role_name)) {
+ ast_debug(2, "Removing bridge role %s from channel %s\n", role_name, ast_channel_name(chan));
+ AST_LIST_REMOVE_CURRENT(list);
+ bridge_role_destroy(role);
+ return;
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
+ ast_debug(2, "Role %s did not exist on channel %s\n", role_name, ast_channel_name(chan));
+}
+
+int ast_channel_set_bridge_role_option(struct ast_channel *channel, const char *role_name, const char *option, const char *value)
+{
+ struct bridge_role *role = get_role_from_channel(channel, role_name);
+ struct bridge_role_option *role_option;
+
+ if (!role) {
+ return -1;
+ }
+
+ role_option = get_role_option(role, option);
+
+ if (role_option) {
+ /* We need to clear the option out and recreate it. There is no way to do this yet. Implement it later. XXX */
+ return -1;
+ }
+
+ setup_bridge_role_option(role, option, value);
+
+ return 0;
+}
+
+int ast_bridge_channel_has_role(struct ast_bridge_channel *bridge_channel, const char *role_name)
+{
+ if (!bridge_channel->bridge_roles) {
+ return 0;
+ }
+
+ return get_role_from_datastore(bridge_channel->bridge_roles, role_name) ? 1 : 0;
+}
+
+const char *ast_bridge_channel_get_role_option(struct ast_bridge_channel *bridge_channel, const char *role_name, const char *option)
+{
+ struct bridge_role *role;
+ struct bridge_role_option *role_option = NULL;
+
+ if (!bridge_channel->bridge_roles) {
+ return NULL;
+ }
+
+ role = get_role_from_datastore(bridge_channel->bridge_roles, role_name);
+
+ if (!role) {
+ return NULL;
+ }
+
+ role_option = get_role_option(role, option);
+
+ return role_option ? role_option->value : NULL;
+}
+
+int ast_bridge_channel_establish_roles(struct ast_bridge_channel *bridge_channel)
+{
+ struct bridge_roles_datastore *roles_datastore;
+ struct bridge_role *role = NULL;
+ struct bridge_role_option *role_option;
+
+ if (!bridge_channel->chan) {
+ ast_debug(2, "Attempted to set roles on a bridge channel that has no associated channel. That's a bad idea.\n");
+ return -1;
+ }
+
+ if (bridge_channel->bridge_roles) {
+ ast_debug(2, "Attempted to reset roles while roles were already established. Purge existing roles first.\n");
+ return -1;
+ }
+
+ roles_datastore = fetch_bridge_roles_datastore(bridge_channel->chan);
+ if (!roles_datastore) {
+ /* No roles to establish. */
+ return 0;
+ }
+
+ if (!(bridge_channel->bridge_roles = ast_calloc(1, sizeof(*bridge_channel->bridge_roles)))) {
+ return -1;
+ }
+
+ AST_LIST_TRAVERSE(&roles_datastore->role_list, role, list) {
+ struct bridge_role *this_role_copy;
+
+ if (setup_bridge_role(bridge_channel->bridge_roles, role->role)) {
+ /* We need to abandon the copy because we couldn't setup a role */
+ ast_bridge_channel_clear_roles(bridge_channel);
+ return -1;
+ }
+ this_role_copy = AST_LIST_LAST(&bridge_channel->bridge_roles->role_list);
+
+ AST_LIST_TRAVERSE(&role->options, role_option, list) {
+ if (setup_bridge_role_option(this_role_copy, role_option->option, role_option->value)) {
+ /* We need to abandon the copy because we couldn't setup a role option */
+ ast_bridge_channel_clear_roles(bridge_channel);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void ast_bridge_channel_clear_roles(struct ast_bridge_channel *bridge_channel)
+{
+ if (bridge_channel->bridge_roles) {
+ bridge_role_datastore_destroy(bridge_channel->bridge_roles);
+ bridge_channel->bridge_roles = NULL;
+ }
+}
Propchange: team/mjordan/cdrs-of-doom/main/bridging_roles.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mjordan/cdrs-of-doom/main/bridging_roles.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mjordan/cdrs-of-doom/main/bridging_roles.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list