add switch_core_get_variables and allow execute_on funcs to see global vars too

This commit is contained in:
Anthony Minessale 2013-03-27 14:54:01 -05:00
parent eed868af6c
commit 861c3e3ccc
4 changed files with 19 additions and 6 deletions

View File

@ -811,6 +811,7 @@ SWITCH_DECLARE(const char *) switch_core_get_switchname(void);
\param value the value of the variable \param value the value of the variable
*/ */
SWITCH_DECLARE(void) switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value); SWITCH_DECLARE(void) switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value);
SWITCH_DECLARE(switch_status_t) switch_core_get_variables(switch_event_t **event);
/*! /*!
\brief Conditionally add a global variable to the core \brief Conditionally add a global variable to the core

View File

@ -3337,7 +3337,7 @@ static void do_execute_on(switch_channel_t *channel, const char *variable)
char *app; char *app;
app = switch_core_session_strdup(channel->session, variable); app = switch_core_session_strdup(channel->session, variable);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "EXEC %s\n", app);
for(p = app; p && *p; p++) { for(p = app; p && *p; p++) {
if (*p == ' ' || (*p == ':' && (*(p+1) != ':'))) { if (*p == ' ' || (*p == ':' && (*(p+1) != ':'))) {
*p++ = '\0'; *p++ = '\0';
@ -3360,10 +3360,12 @@ static void do_execute_on(switch_channel_t *channel, const char *variable)
SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix) SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
{ {
switch_event_header_t *hp; switch_event_header_t *hp;
switch_event_t *event; switch_event_t *event, *cevent;
int x = 0; int x = 0;
switch_channel_get_variables(channel, &event); switch_core_get_variables(&event);
switch_channel_get_variables(channel, &cevent);
switch_event_merge(event, cevent);
for (hp = event->headers; hp; hp = hp->next) { for (hp = event->headers; hp; hp = hp->next) {
char *var = hp->name; char *var = hp->name;
@ -3384,6 +3386,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *chan
} }
switch_event_destroy(&event); switch_event_destroy(&event);
switch_event_destroy(&cevent);
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
} }

View File

@ -307,6 +307,15 @@ SWITCH_DECLARE(const char *) switch_core_get_switchname(void)
} }
SWITCH_DECLARE(switch_status_t) switch_core_get_variables(switch_event_t **event)
{
switch_status_t status;
switch_thread_rwlock_rdlock(runtime.global_var_rwlock);
status = switch_event_dup(event, runtime.global_vars);
switch_thread_rwlock_unlock(runtime.global_var_rwlock);
return status;
}
SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname) SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
{ {
char *val; char *val;

View File

@ -358,8 +358,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
} }
#endif #endif
if (read_frame_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a)) { if (read_frame_count == DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a)) {
switch_channel_execute_on(chan_a, SWITCH_CHANNEL_EXECUTE_ON_PRE_BRIDGE_VARIABLE); switch_channel_execute_on(chan_a, SWITCH_CHANNEL_EXECUTE_ON_PRE_BRIDGE_VARIABLE);
if (!inner_bridge) { if (!inner_bridge) {
@ -373,8 +372,9 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
switch_core_session_execute_application_async(session_a, exec_app, exec_data); switch_core_session_execute_application_async(session_a, exec_app, exec_data);
exec_app = exec_data = NULL; exec_app = exec_data = NULL;
} }
}
if (read_frame_count >= DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a)) {
if ((bypass_media_after_bridge || switch_channel_test_flag(chan_b, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED) if ((bypass_media_after_bridge || switch_channel_test_flag(chan_b, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED)
&& switch_channel_test_flag(chan_b, CF_ANSWERED)) { && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE); switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE);