From 27c6d1111c8eb9929cedf707632b33405019e03a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Apr 2011 17:39:20 -0500 Subject: [PATCH] add execute_on function so you can have execute_on_answer_1 execute_on_answer_2 execute_on_answer_3 etc --- src/include/switch_channel.h | 3 ++ src/switch_channel.c | 87 +++++++++++++++++------------------- src/switch_ivr_originate.c | 18 +------- 3 files changed, 46 insertions(+), 62 deletions(-) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index fdbbc9ab91..febaf40f75 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -615,6 +615,9 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_ /** @} */ +SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix); + + SWITCH_END_EXTERN_C #endif /* For Emacs: diff --git a/src/switch_channel.c b/src/switch_channel.c index 0476981331..19eb92ad8d 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -2588,8 +2588,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi switch_ring_ready_t rv, const char *file, const char *func, int line) { - const char *var; - char *app; switch_event_t *event; if (!switch_channel_test_flag(channel, CF_RING_READY) && @@ -2619,21 +2617,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi switch_event_fire(&event); } - var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE); - if (var) { - char *arg = NULL; - app = switch_core_session_strdup(channel->session, var); - - if (strstr(app, "::")) { - switch_core_session_execute_application_async(channel->session, app, arg); - } else { - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - switch_core_session_execute_application(channel->session, app, arg); - } - } + switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE); return SWITCH_STATUS_SUCCESS; } @@ -2645,7 +2629,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_ { switch_event_t *event; const char *var = NULL; - char *app; if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) { const char *uuid; @@ -2678,20 +2661,9 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_ switch_mutex_unlock(channel->profile_mutex); } - if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE)) || - (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))) && !zstr(var)) { - char *arg = NULL; - app = switch_core_session_strdup(channel->session, var); - - - if (strstr(app, "::")) { - switch_core_session_execute_application_async(channel->session, app, arg); - } else { - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - switch_core_session_execute_application(channel->session, app, arg); + if (switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE) != SWITCH_STATUS_SUCCESS) { + if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) { + switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE); } } @@ -2785,6 +2757,40 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready_value(switch_c return status; } +SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix) +{ + switch_event_header_t *hi; + int x = 0; + + if ((hi = switch_channel_variable_first(channel))) { + for (; hi; hi = hi->next) { + char *var = hi->name; + char *val = hi->value; + char *app; + + if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) { + char *arg = NULL; + x++; + + app = switch_core_session_strdup(channel->session, val); + + if (strstr(app, "::")) { + switch_core_session_execute_application_async(channel->session, app, arg); + } else { + if ((arg = strchr(app, ' '))) { + *arg++ = '\0'; + } + + switch_core_session_execute_application(channel->session, app, arg); + } + } + } + switch_channel_variable_last(channel); + } + + return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; +} + SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, const char *file, const char *func, int line) { switch_event_t *event; @@ -2852,21 +2858,10 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name); - if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE)) || - (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE)))) - && !zstr(var)) { - char *arg = NULL; - app = switch_core_session_strdup(channel->session, var); - - if (strstr(app, "::")) { - switch_core_session_execute_application_async(channel->session, app, arg); - } else { - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - switch_core_session_execute_application(channel->session, app, arg); + if (switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE) != SWITCH_STATUS_SUCCESS) { + if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) { + switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE); } } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 33e9d9a0bc..0c4c336e51 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -2762,23 +2762,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess switch_channel_set_variable(originate_status[i].peer_channel, "originating_leg_uuid", switch_core_session_get_uuid(session)); } - if ((vvar = switch_channel_get_variable_dup(originate_status[i].peer_channel, "execute_on_originate", SWITCH_FALSE))) { - char *app = switch_core_session_strdup(originate_status[i].peer_session, vvar); - char *arg = NULL; - - if (strstr(app, "::")) { - switch_core_session_execute_application_async(originate_status[i].peer_session, app, arg); - } else { - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - switch_core_session_execute_application(originate_status[i].peer_session, app, arg); - } - - } + switch_channel_execute_on(originate_status[i].peer_channel, "execute_on_originate"); } - + if (table) { switch_channel_add_state_handler(originate_status[i].peer_channel, table); }