From 5b5d8da5714e771c0ec499181eadbe291b2ed5ab Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Apr 2009 14:57:43 +0000 Subject: [PATCH] add echo api command (echo back exact input) add expand api command (executes another api command with variable expansion) e.g. expand originate sofia/default/1000@${some_domain} e.g. expand uuid:958b6c3c-2e82-11de-a717-2731820639f9 echo ${variable_read_codec} git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13101 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 62 ++++++++++++++++++- src/switch_channel.c | 1 + 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 049319846c..d81ff925e1 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -515,6 +515,64 @@ SWITCH_STANDARD_API(url_decode_function) return SWITCH_STATUS_SUCCESS; } +SWITCH_STANDARD_API(echo_function) +{ + stream->write_function(stream, "%s", cmd); + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_STANDARD_API(expand_function) +{ + char *expanded; + char *dup; + char *arg; + char *mycmd; + switch_status_t status; + const char *p; + switch_core_session_t *xsession; + char uuid[80] = ""; + + dup = strdup(cmd); + mycmd = dup; + + if (!strncasecmp(mycmd, "uuid:", 5)) { + p = cmd + 5; + if ((mycmd = strchr(p, ' ')) && *mycmd++) { + switch_copy_string(uuid, p, mycmd - p); + } + } + + if (switch_strlen_zero(mycmd)) { + stream->write_function(stream, "-ERR, no input\n"); + return SWITCH_STATUS_SUCCESS; + } + + if (*uuid) { + if ((xsession = switch_core_session_locate(uuid))) { + switch_channel_event_set_data(switch_core_session_get_channel(xsession), stream->param_event); + switch_core_session_rwunlock(xsession); + } + } + + if ((arg = strchr(mycmd, ' '))) { + *arg++ = '\0'; + } + + expanded = switch_event_expand_headers(stream->param_event, arg); + status = switch_api_execute(mycmd, expanded, session, stream); + + if (expanded != arg) { + free(expanded); + expanded = NULL; + } + + free(dup); + dup = NULL; + + return status; +} + + SWITCH_STANDARD_API(eval_function) { char *expanded; @@ -3332,7 +3390,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, ""); SWITCH_ADD_API(commands_api_interface, "domain_exists", "check if a domain exists", domain_exists_function, ""); SWITCH_ADD_API(commands_api_interface, "uuid_send_dtmf", "send dtmf digits", uuid_send_dtmf_function, UUID_SEND_DTMF_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, ""); + SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, "[uuid: ]"); + SWITCH_ADD_API(commands_api_interface, "expand", "expand vars and exexute", expand_function, "[uuid: ] "); + SWITCH_ADD_API(commands_api_interface, "echo", "echo", echo_function, ""); SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX); SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, ""); diff --git a/src/switch_channel.c b/src/switch_channel.c index aa0f03f74b..50050b277e 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1321,6 +1321,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_extended_data(switch_channel_t *ch event->event_id == SWITCH_EVENT_CHANNEL_DATA || event->event_id == SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE || event->event_id == SWITCH_EVENT_SESSION_HEARTBEAT || + event->event_id == SWITCH_EVENT_API || event->event_id == SWITCH_EVENT_CUSTOM ) {