diff --git a/src/include/switch_event.h b/src/include/switch_event.h index a935c86a35..7064fe4e33 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -199,7 +199,7 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event); \return SWITCH_STATUS_SUCCESS if the event was duplicated */ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup); - +SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *tomerge); /*! \brief Fire an event with full arguement list \param file the calling file diff --git a/src/switch_event.c b/src/switch_event.c index 73739e6737..f39a176bad 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -655,7 +655,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_subclass_detailed(const char memset(*event, 0, sizeof(switch_event_t)); - if (event_id == SWITCH_EVENT_REQUEST_PARAMS) { + if (event_id == SWITCH_EVENT_REQUEST_PARAMS || event_id == SWITCH_EVENT_CHANNEL_DATA) { (*event)->flags |= EF_UNIQ_HEADERS; } @@ -892,6 +892,17 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event) } +SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *tomerge) +{ + switch_event_header_t *hp; + + switch_assert(tomerge && event); + + for (hp = tomerge->headers; hp; hp = hp->next) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, hp->name, hp->value); + } +} + SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup) { switch_event_header_t *hp; @@ -903,7 +914,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_ (*event)->event_id = todup->event_id; (*event)->event_user_data = todup->event_user_data; (*event)->bind_user_data = todup->bind_user_data; - + (*event)->flags = todup->flags; for (hp = todup->headers; hp; hp = hp->next) { if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) { continue; diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 0930f2a797..c962d979a0 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -2293,9 +2293,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess char *vdata; const char *current_variable; char variable_buffer[512] = ""; + switch_event_t *local_var_event = NULL, *originate_var_event = NULL; + end = NULL; chan_type = peer_names[i]; - + while (chan_type && *chan_type && *chan_type == ' ') { chan_type++; } @@ -2486,15 +2488,52 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess current_variable = NULL; switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "originate_early_media", oglobals.early_ok ? "true" : "false"); - if ((reason = switch_core_session_outgoing_channel(oglobals.session, var_event, chan_type, - new_profile, &new_session, NULL, myflags, cancel_cause)) != SWITCH_CAUSE_SUCCESS) { + + if (vdata) { + char *var_array[1024] = { 0 }; + int var_count = 0; + + switch_event_create_plain(&local_var_event, SWITCH_EVENT_CHANNEL_DATA); + + if ((var_count = switch_separate_string(vdata, '|', var_array, (sizeof(var_array) / sizeof(var_array[0]))))) { + int x = 0; + for (x = 0; x < var_count; x++) { + char *inner_var_array[2] = { 0 }; + int inner_var_count; + if ((inner_var_count = + switch_separate_string(var_array[x], '=', + inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { + switch_event_add_header_string(local_var_event, SWITCH_STACK_BOTTOM, inner_var_array[0], inner_var_array[1]); + } + } + } + } + + /* make a special var event with mixture of the {} and the [] vars to pass down as global vars to the outgoing channel + so if something like the user channel does another originate our options will be passed down properly + */ + + switch_event_dup(&originate_var_event, var_event); + + if (local_var_event) { + switch_event_merge(originate_var_event, local_var_event); + } + + reason = switch_core_session_outgoing_channel(oglobals.session, originate_var_event, chan_type, + new_profile, &new_session, NULL, myflags, cancel_cause); + + switch_event_destroy(&originate_var_event); + + if (reason != SWITCH_CAUSE_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n", chan_type, switch_channel_cause2str(reason)); + if (local_var_event) switch_event_destroy(&local_var_event); continue; } if (switch_core_session_read_lock(new_session) != SWITCH_STATUS_SUCCESS) { status = SWITCH_STATUS_FALSE; + if (local_var_event) switch_event_destroy(&local_var_event); goto done; } @@ -2523,22 +2562,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } } - if (vdata) { - char *var_array[1024] = { 0 }; - int var_count = 0; - if ((var_count = switch_separate_string(vdata, '|', var_array, (sizeof(var_array) / sizeof(var_array[0]))))) { - int x = 0; - for (x = 0; x < var_count; x++) { - char *inner_var_array[2] = { 0 }; - int inner_var_count; - if ((inner_var_count = - switch_separate_string(var_array[x], '=', - inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { - - switch_channel_set_variable(originate_status[i].peer_channel, inner_var_array[0], inner_var_array[1]); - } - } + /* copy local originate vars to the channel */ + if (local_var_event) { + switch_event_header_t *header; + for (header = local_var_event->headers; header; header = header->next) { + switch_channel_set_variable(originate_status[i].peer_channel, header->name, header->value); } + switch_event_destroy(&local_var_event); } if (!local_clobber) { @@ -2573,13 +2603,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_timeout"))) { int val = atoi(vvar); + if (val > 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg timeout to %d\n", switch_channel_get_name(originate_status[i].peer_channel), val); originate_status[i].per_channel_timelimit_sec = (uint32_t) val; } } - + if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_progress_timeout"))) { int val = atoi(vvar); if (val > 0) {