[core] expand vars on execute_on and api_on

This commit is contained in:
Anthony Minessale 2020-04-19 22:59:42 +00:00 committed by Andrey Volk
parent 35f1afa144
commit 0d463a2b42
1 changed files with 26 additions and 3 deletions

View File

@ -3699,6 +3699,7 @@ static void do_api_on(switch_channel_t *channel, const char *variable)
{ {
char *app; char *app;
char *arg = NULL; char *arg = NULL;
char *expanded = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
app = switch_core_session_strdup(channel->session, variable); app = switch_core_session_strdup(channel->session, variable);
@ -3707,10 +3708,21 @@ static void do_api_on(switch_channel_t *channel, const char *variable)
*arg++ = '\0'; *arg++ = '\0';
} }
if (zstr(arg)) {
expanded = arg;
} else {
expanded = switch_channel_expand_variables(channel, arg);
}
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_api_execute(app, expanded, NULL, &stream);
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s process %s: %s(%s)\n%s\n", 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); channel->name, variable, app, switch_str_nil(expanded), (char *) stream.data);
switch_api_execute(app, arg, NULL, &stream);
if (expanded && expanded != arg) {
free(expanded);
}
free(stream.data); free(stream.data);
} }
@ -3753,7 +3765,8 @@ static void do_execute_on(switch_channel_t *channel, const char *variable)
char *p; char *p;
int bg = 0; int bg = 0;
char *app; char *app;
char *expanded = NULL;
app = switch_core_session_strdup(channel->session, variable); app = switch_core_session_strdup(channel->session, variable);
for(p = app; p && *p; p++) { for(p = app; p && *p; p++) {
@ -3772,11 +3785,21 @@ static void do_execute_on(switch_channel_t *channel, const char *variable)
bg++; bg++;
} }
if (zstr(arg)) {
expanded = arg;
} else {
expanded = switch_channel_expand_variables(channel, arg);
}
if (bg) { if (bg) {
switch_core_session_execute_application_async(channel->session, app, arg); switch_core_session_execute_application_async(channel->session, app, arg);
} else { } else {
switch_core_session_execute_application(channel->session, app, arg); switch_core_session_execute_application(channel->session, app, arg);
} }
if (expanded && expanded != arg) {
free(expanded);
}
} }
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)