From 9626393ef8f39f7e8e8eddd49f28b280edf08ee7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Feb 2007 20:07:35 +0000 Subject: [PATCH] add export app (set + adding to export_vars) in 1 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4299 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 1 + .../applications/mod_dptools/mod_dptools.c | 48 ++++++++++++++++++- src/switch_core.c | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index b72faa317c..d3799cf719 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -76,6 +76,7 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_GRAMMAR_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "grammar" #endif +#define SWITCH_EXPORT_VARS_VARIABLE "export_vars" #define SWITCH_R_SDP_VARIABLE "switch_r_sdp" #define SWITCH_L_SDP_VARIABLE "switch_l_sdp" #define SWITCH_B_SDP_VARIABLE "switch_m_sdp" diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 0630963b4b..7b0d2e9faa 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -210,6 +210,43 @@ static void set_function(switch_core_session_t *session, char *data) } } +static void export_function(switch_core_session_t *session, char *data) +{ + switch_channel_t *channel; + char *exports, *new_exports = NULL, *new_exports_d = NULL, *var, *val = NULL; + + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + + if (switch_strlen_zero(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); + } else { + exports = switch_channel_get_variable(channel, SWITCH_EXPORT_VARS_VARIABLE); + var = switch_core_session_strdup(session, data); + val = strchr(var, '='); + + if (val) { + *val++ = '\0'; + if (switch_strlen_zero(val)) { + val = NULL; + } + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT [%s]=[%s]\n", var, val ? val : "UNDEF"); + switch_channel_set_variable(channel, var, val); + + if (var && val) { + if (exports) { + new_exports_d = switch_mprintf("%s,%s", exports, var); + new_exports = new_exports_d; + } else { + new_exports = var; + } + switch_channel_set_variable(channel, SWITCH_EXPORT_VARS_VARIABLE, new_exports); + switch_safe_free(new_exports_d); + } + } +} static void unset_function(switch_core_session_t *session, char *data) { @@ -567,13 +604,22 @@ static const switch_application_interface_t set_application_interface = { /*.next */ &unset_application_interface }; +static const switch_application_interface_t export_application_interface = { + /*.interface_name */ "export", + /*.application_function */ export_function, + /* long_desc */ "Set and export a channel varaible for the channel calling the application.", + /* short_desc */ "Export a channel varaible across a bridge", + /* syntax */ "=", + /*.next */ &set_application_interface +}; + static const switch_application_interface_t info_application_interface = { /*.interface_name */ "info", /*.application_function */ info_function, /* long_desc */ "Display Call Info", /* short_desc */ "Display Call Info", /* syntax */ "", - /*.next */ &set_application_interface + /*.next */ &export_application_interface }; static const switch_application_interface_t log_application_interface = { diff --git a/src/switch_core.c b/src/switch_core.c index 3b3c6b9976..d250ce18f4 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1641,7 +1641,7 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_ switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session)); /* A comma (,) separated list of variable names that should ne propagated from originator to originatee */ - if ((export_vars = switch_channel_get_variable(channel, "export_vars"))) { + if ((export_vars = switch_channel_get_variable(channel, SWITCH_EXPORT_VARS_VARIABLE))) { char *cptmp = switch_core_session_strdup(session, export_vars); int argc; char *argv[256];