]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
MODAPP-138 with tweaks
authorBrian West <brian@freeswitch.org>
Fri, 5 Sep 2008 04:09:50 +0000 (04:09 +0000)
committerBrian West <brian@freeswitch.org>
Fri, 5 Sep 2008 04:09:50 +0000 (04:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9459 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_dptools/mod_dptools.c

index d0ef245200659ffb35546b58773c127c3745263d..04ad0e8d7bcfaf61d5b93ad5000c286f8210e096 100644 (file)
@@ -2505,6 +2505,23 @@ SWITCH_STANDARD_API(global_getvar_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
+#define SYSTEM_SYNTAX "<command>"
+SWITCH_STANDARD_API(system_function)
+{
+    if (switch_strlen_zero(cmd)) {
+        stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX);
+        return SWITCH_STATUS_SUCCESS;
+    } 
+
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
+    if (system(cmd) < 0) {
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
+    }
+    stream->write_function(stream, "+OK\n");
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
 {
        switch_api_interface_t *commands_api_interface;
@@ -2589,6 +2606,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, "<module>");
        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, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
 
        /* indicate that the module should continue to be loaded */
        return SWITCH_STATUS_NOUNLOAD;
index 0d6578b6e668c5da54f11d8b2b444197515f6279..51e608556616fd3c7bd7692881c9f7e76b609941 100644 (file)
@@ -1185,7 +1185,7 @@ SWITCH_STANDARD_APP(fax_detect_session_function)
 SWITCH_STANDARD_APP(system_session_function)
 {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", data);
-       if (!system(data)) {
+       if (system(data) < 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", data);
        }
 }