add execute_on_answer magic variable

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8003 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-04-02 15:11:07 +00:00
parent 1c52292c9b
commit d3be2ae749
5 changed files with 75 additions and 96 deletions
+56 -50
View File
@@ -950,6 +950,57 @@ SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(switch_core_s
return session->app_log;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_core_session_t *session, const char *app, const char *arg)
{
const switch_application_interface_t *application_interface;
char *expanded = NULL;
if ((application_interface = switch_loadable_module_get_application_interface(app)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n", app);
switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
if (!application_interface->application_function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", app);
switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && !switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA)) {
switch_ivr_media(session->uuid_str, SMF_NONE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Application %s Requires media on channel %s!\n",
app, switch_channel_get_name(session->channel));
} else if (!switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA) && !switch_channel_media_ready(session->channel)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Application %s Requires media! pre_answering channel %s\n",
app, switch_channel_get_name(session->channel));
if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Well, that didn't work very well did it? ...\n");
return SWITCH_STATUS_FALSE;
}
}
if ((expanded = switch_channel_expand_variables(session->channel, arg)) != arg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Expanded String %s(%s)\n", switch_channel_get_name(session->channel), app, expanded);
}
if (switch_channel_get_variable(session->channel, "presence_id")) {
char *arg = switch_mprintf("%s(%s)", app, expanded);
if (arg) {
switch_channel_presence(session->channel, "unknown", arg);
switch_safe_free(arg);
}
}
switch_core_session_exec(session, application_interface, expanded);
if (expanded != arg) {
switch_safe_free(expanded);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session,
const switch_application_interface_t *application_interface, const char *arg) {
switch_app_log_t *log, *lp;
@@ -1000,13 +1051,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
char *dp[25];
char *dpstr;
int argc, x, count = 0;
char *expanded = NULL;
switch_caller_profile_t *profile, *new_profile, *pp = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_dialplan_interface_t *dialplan_interface = NULL;
switch_caller_extension_t *extension = NULL;
const switch_application_interface_t *application_interface;
switch_event_t *event;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!(profile = switch_channel_get_caller_profile(channel))) {
@@ -1076,55 +1124,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
while (switch_channel_ready(channel) && extension->current_application) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Execute %s(%s)\n",
extension->current_application->application_name, switch_str_nil(extension->current_application->application_data));
if ((application_interface = switch_loadable_module_get_application_interface(extension->current_application->application_name)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n", extension->current_application->application_name);
status = SWITCH_STATUS_FALSE;
if (switch_core_session_execute_application(session,
extension->current_application->application_name,
extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) {
goto done;
}
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && !switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Application %s Cannot be used with NO_MEDIA mode!\n",
extension->current_application->application_name);
status = SWITCH_STATUS_FALSE;
goto done;
}
if (!application_interface->application_function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", extension->current_application->application_name);
status = SWITCH_STATUS_FALSE;
goto done;
}
if ((expanded =
switch_channel_expand_variables(session->channel,
extension->current_application->application_data)) != extension->current_application->application_data) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Expanded String %s(%s)\n", extension->current_application->application_name,
expanded);
}
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", extension->current_application->application_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data-Orig", "%s", extension->current_application->application_data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", expanded);
switch_event_fire(&event);
}
if (switch_channel_get_variable(session->channel, "presence_id")) {
char *arg = switch_mprintf("%s(%s)", extension->current_application->application_name, expanded);
if (arg) {
switch_channel_presence(session->channel, "unknown", arg);
switch_safe_free(arg);
}
}
switch_core_session_exec(session, application_interface, expanded);
if (expanded != extension->current_application->application_data) {
switch_safe_free(expanded);
}
extension->current_application = extension->current_application->next;
}