From 850f2e3cffda1f6df53e109599749f82da06c357 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 18 Aug 2011 09:11:45 -0500 Subject: [PATCH] FS-3510 --resolve make all instances of execute_on_X uniform with api_on_X and support both prefix vars as before and usage of arrays to push several exexute_on or api_on records into one variable --- src/include/switch_channel.h | 2 +- src/include/switch_types.h | 11 +- src/mod/endpoints/mod_sofia/sofia_glue.c | 17 +-- src/switch_channel.c | 142 ++++++++++++++++------- src/switch_ivr_async.c | 2 + src/switch_ivr_originate.c | 3 +- 6 files changed, 114 insertions(+), 63 deletions(-) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 176b841147..8fa0439b47 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -625,7 +625,7 @@ 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_DECLARE(switch_status_t) switch_channel_api_on(switch_channel_t *channel, const char *variable_prefix); SWITCH_END_EXTERN_C #endif diff --git a/src/include/switch_types.h b/src/include/switch_types.h index f6183e6018..dd36b7f680 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -131,12 +131,21 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_COPY_XML_CDR_VARIABLE "copy_xml_cdr" #define SWITCH_CURRENT_APPLICATION_VARIABLE "current_application" #define SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE "proto_specific_hangup_cause" + #define SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE "execute_on_answer" #define SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE "execute_on_pre_answer" #define SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE "execute_on_media" -#define SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE "api_on_answer" #define SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE "execute_on_ring" #define SWITCH_CHANNEL_EXECUTE_ON_TONE_DETECT_VARIABLE "execute_on_tone_detect" +#define SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE "execute_on_originate" + +#define SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE "api_on_answer" +#define SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE "api_on_pre_answer" +#define SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE "api_on_media" +#define SWITCH_CHANNEL_API_ON_RING_VARIABLE "api_on_ring" +#define SWITCH_CHANNEL_API_ON_TONE_DETECT_VARIABLE "api_on_tone_detect" +#define SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE "api_on_originate" + #define SWITCH_CALL_TIMEOUT_VARIABLE "call_timeout" #define SWITCH_HOLDING_UUID_VARIABLE "holding_uuid" #define SWITCH_SOFT_HOLDING_UUID_VARIABLE "soft_holding_uuid" diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 006f002334..b7b139e52d 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -3989,7 +3989,6 @@ static switch_t38_options_t *tech_process_udptl(private_object_t *tech_pvt, sdp_ { switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options"); sdp_attribute_t *attr; - const char *var; if (!t38_options) { t38_options = switch_core_session_alloc(tech_pvt->session, sizeof(switch_t38_options_t)); @@ -4069,20 +4068,8 @@ static switch_t38_options_t *tech_process_udptl(private_object_t *tech_pvt, sdp_ switch_channel_set_private(tech_pvt->channel, "t38_options", t38_options); switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); - if ((var = switch_channel_get_variable(tech_pvt->channel, "sip_execute_on_image"))) { - char *app, *arg = NULL; - app = switch_core_session_strdup(tech_pvt->session, var); - - if (strstr(app, "::")) { - switch_core_session_execute_application_async(tech_pvt->session, app, arg); - } else { - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - switch_core_session_execute_application(tech_pvt->session, app, arg); - } - } + switch_channel_execute_on(tech_pvt->channel, "sip_execute_on_image"); + switch_channel_api_on(tech_pvt->channel, "sip_api_on_image"); return t38_options; } diff --git a/src/switch_channel.c b/src/switch_channel.c index 308d29f858..0a6071105f 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -2830,6 +2830,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi } switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE); + switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_RING_VARIABLE); return SWITCH_STATUS_SUCCESS; } @@ -2877,7 +2878,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_ switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE); switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE); - + switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_PRE_ANSWER_VARIABLE); + switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE); if ((var = switch_channel_get_variable(channel, SWITCH_PASSTHRU_PTIME_MISMATCH_VARIABLE))) { switch_channel_set_flag(channel, CF_PASSTHRU_PTIME_MISMATCH); @@ -2969,43 +2971,108 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready_value(switch_c return status; } +static void do_api_on(switch_channel_t *channel, const char *variable) +{ + char *app; + char *arg = NULL; + switch_stream_handle_t stream = { 0 }; + + app = switch_core_session_strdup(channel->session, variable); + + if ((arg = strchr(app, ' '))) { + *arg++ = '\0'; + } + + SWITCH_STANDARD_STREAM(stream); + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s process %s: %s(%s)\n%s\n", + channel->name, variable, app, switch_str_nil(arg), (char *) stream.data); + switch_api_execute(app, arg, NULL, &stream); + free(stream.data); +} + + +SWITCH_DECLARE(switch_status_t) switch_channel_api_on(switch_channel_t *channel, const char *variable_prefix) +{ + switch_event_header_t *hp; + switch_event_t *event; + int x = 0; + + + switch_channel_get_variables(channel, &event); + + for (hp = event->headers; hp; hp = hp->next) { + char *var = hp->name; + char *val = hp->value; + + if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) { + if (hp->idx) { + int i; + for (i = 0; i < hp->idx; i++) { + x++; + do_api_on(channel, hp->array[i]); + } + } else { + x++; + do_api_on(channel, val); + } + } + } + + switch_event_destroy(&event); + + return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; +} + +static void do_execute_on(switch_channel_t *channel, const char *variable) +{ + char *arg = NULL; + char *p; + int bg = 0; + char *app; + + app = switch_core_session_strdup(channel->session, variable); + + for(p = app; p && *p; p++) { + if (*p == ' ') { + *p++ = '\0'; + arg = p; + break; + } else if (*p == ':' && (*(p+1) == ':')) { + bg++; + break; + } + } + + + if (bg) { + switch_core_session_execute_application_async(channel->session, app, arg); + } else { + switch_core_session_execute_application(channel->session, app, arg); + } +} + SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix) { - switch_event_header_t *hi; + switch_event_header_t *hp; switch_event_t *event; int x = 0; switch_channel_get_variables(channel, &event); - for (hi = event->headers; hi; hi = hi->next) { - char *var = hi->name; - char *val = hi->value; - char *app; - + for (hp = event->headers; hp; hp = hp->next) { + char *var = hp->name; + char *val = hp->value; + if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) { - char *arg = NULL; - char *p; - int bg = 0; - x++; - - app = switch_core_session_strdup(channel->session, val); - - for(p = app; p && *p; p++) { - if (*p == ' ') { - *p++ = '\0'; - arg = p; - break; - } else if (*p == ':' && (*(p+1) == ':')) { - bg++; - break; + if (hp->idx) { + int i; + for (i = 0; i < hp->idx; i++) { + x++; + do_execute_on(channel, hp->array[i]); } - } - - - if (bg) { - switch_core_session_execute_application_async(channel->session, app, arg); } else { - switch_core_session_execute_application(channel->session, app, arg); + x++; + do_execute_on(channel, val); } } } @@ -3021,7 +3088,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan const char *uuid; switch_core_session_t *other_session; const char *var; - char *app; switch_assert(channel != NULL); @@ -3087,24 +3153,10 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) { switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE); + switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_MEDIA_VARIABLE); } - if ((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE)) && !zstr(var)) { - switch_stream_handle_t stream = { 0 }; - char *arg = NULL; - - app = switch_core_session_strdup(channel->session, var); - if ((arg = strchr(app, ' '))) { - *arg++ = '\0'; - } - - SWITCH_STANDARD_STREAM(stream); - switch_api_execute(app, arg, NULL, &stream); - - switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s api on answer: %s(%s)\n%s\n", - channel->name, app, switch_str_nil(arg), (char *) stream.data); - free(stream.data); - } + switch_channel_api_on(channel, SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE); switch_channel_presence(channel, "unknown", "answered", NULL); diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index a47cfbd0c0..b55413f007 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -2458,6 +2458,8 @@ static switch_status_t tone_on_dtmf(switch_core_session_t *session, const switch cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data); } else { switch_channel_execute_on(switch_core_session_get_channel(cont->session), SWITCH_CHANNEL_EXECUTE_ON_TONE_DETECT_VARIABLE); + switch_channel_api_on(switch_core_session_get_channel(cont->session), SWITCH_CHANNEL_API_ON_TONE_DETECT_VARIABLE); + if (cont->list[i].app) { switch_core_session_execute_application_async(cont->session, cont->list[i].app, cont->list[i].data); } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 262d6d7a91..9ab1c1b1da 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -2561,7 +2561,8 @@ 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)); } - switch_channel_execute_on(originate_status[i].peer_channel, "execute_on_originate"); + switch_channel_execute_on(originate_status[i].peer_channel, SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE); + switch_channel_api_on(originate_status[i].peer_channel, SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE); } if (table) {