From 69f7a9a95590da3f83fcff39ab532575d23c1037 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 13 Nov 2007 03:47:07 +0000 Subject: [PATCH] add missing "execute" handler to phrase macro. (not yet tested) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6234 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 1 + src/switch_ivr_play_say.c | 15 +++++++++++++++ src/switch_utils.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 94fa05005e..b60ef2171c 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -300,6 +300,7 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str); SWITCH_DECLARE(char *) switch_strip_spaces(const char *str); +SWITCH_DECLARE(char *) switch_separate_paren_args(char *str); SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr); SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip); SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch_bool_t dup); diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index a01eb37dde..df884060fd 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -260,7 +260,22 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s done = 1; break; } else if (!strcasecmp(func, "execute")) { + switch_application_interface_t *app; + char *cmd, *cmd_args; + status = SWITCH_STATUS_FALSE; + cmd = switch_core_session_strdup(session, odata); + cmd_args = switch_separate_paren_args(cmd); + + if (!cmd_args ) { + cmd_args = ""; + } + + if ((app = switch_loadable_module_get_application_interface(cmd)) != NULL) { + status = switch_core_session_exec(session, app, cmd_args); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Application %s\n", cmd); + } } else if (!strcasecmp(func, "say")) { switch_say_interface_t *si; if ((si = switch_loadable_module_get_say_interface(module_name))) { diff --git a/src/switch_utils.c b/src/switch_utils.c index 95534d2eb4..64ccc5e1b3 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -288,6 +288,36 @@ SWITCH_DECLARE(char *) switch_strip_spaces(const char *str) return s; } + +SWITCH_DECLARE(char *) switch_separate_paren_args(char *str) +{ + char *e, *args; + switch_size_t br; + + if ((args = strchr(str, '('))) { + e = args - 1; + *args++ = '\0'; + while(*e == ' ') { + *e-- = '\0'; + } + e = args; + br = 1; + while(e && *e) { + if (*e == '(') { + br++; + } else if (br > 1 && *e == ')') { + br--; + } else if (br == 1 && *e == ')') { + *e = '\0'; + break; + } + e++; + } + } + + return args; +} + SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str) { const char *p;