[commit] r13101 - in freeswitch/trunk/src: . mod/applications/mod_commands
Author: anthm Date: Tue Apr 21 09:57:43 2009 New Revision: 13101 Log: 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} Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c freeswitch/trunk/src/switch_channel.c Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original) +++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Tue Apr 21 09:57:43 2009 @@ -515,6 +515,64 @@ 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_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, "<module>"); SWITCH_ADD_API(commands_api_interface, "domain_exists", "check if a domain exists", domain_exists_function, "<domain>"); 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, "<expression>"); + SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, "[uuid:<uuid> ]<expression>"); + SWITCH_ADD_API(commands_api_interface, "expand", "expand vars and exexute", expand_function, "[uuid:<uuid> ]<cmd> <args>"); + SWITCH_ADD_API(commands_api_interface, "echo", "echo", echo_function, "<data>"); 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, "<mss>"); Modified: freeswitch/trunk/src/switch_channel.c ============================================================================== --- freeswitch/trunk/src/switch_channel.c (original) +++ freeswitch/trunk/src/switch_channel.c Tue Apr 21 09:57:43 2009 @@ -1321,6 +1321,7 @@ 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 ) {
participants (1)
-
FreeSWITCH SVN