From e815841de6bf4e43b58e227e39fa565977fac201 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 15 Aug 2008 15:05:48 +0000 Subject: [PATCH] add eval function git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9303 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index eaaf8c1a47..7ec8848225 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -197,6 +197,52 @@ SWITCH_STANDARD_API(url_decode_function) } + +SWITCH_STANDARD_API(eval_function) +{ + char *expanded; + switch_event_t *event; + char uuid[80] = ""; + const char *p, *input = cmd; + + if (switch_strlen_zero(cmd)) { + stream->write_function(stream, "%s", ""); + return SWITCH_STATUS_SUCCESS; + } + + if (!strncasecmp(cmd, "uuid:", 5)) { + p = cmd + 5; + if ((input = strchr(p, ' ')) && *input++) { + switch_copy_string(uuid, p, input - p); + } + } + + if (switch_strlen_zero(input)) { + stream->write_function(stream, "%s", ""); + return SWITCH_STATUS_SUCCESS; + } + + + switch_event_create(&event, SWITCH_EVENT_MESSAGE); + if (*uuid) { + if ((session = switch_core_session_locate(uuid))) { + switch_channel_event_set_data(switch_core_session_get_channel(session), event); + switch_core_session_rwunlock(session); + } + } + + expanded = switch_event_expand_headers(event, input); + + stream->write_function(stream, "%s", expanded); + + if (expanded != input) { + free(expanded); + } + + return SWITCH_STATUS_SUCCESS; + +} + SWITCH_STANDARD_API(module_exists_function) { if (!switch_strlen_zero(cmd)) { @@ -2535,6 +2581,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "url_decode", "url decode a string", url_decode_function, ""); SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_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, ""); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_NOUNLOAD;