]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
patch from MODAPP-46
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 2 Nov 2007 22:09:28 +0000 (22:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 2 Nov 2007 22:09:28 +0000 (22:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6155 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_commands/mod_commands.c

index 1df0efbd5005111f8a191d1ff5155ed8a445830d..ac6ad31816db99df1737759ddafe999ac9d84d69 100644 (file)
@@ -1394,9 +1394,11 @@ SWITCH_STANDARD_API(uuid_setvar_function)
 
                                if (switch_strlen_zero(var_name)) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
+                                       stream->write_function(stream, "No variable specified\n");
                                } else {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var_name, var_value ? var_value : "UNDEF");
                                        switch_channel_set_variable(channel, var_name, var_value);
+                                       stream->write_function(stream, "OK\n");
                                }
 
                                switch_core_session_rwunlock(psession);
@@ -1415,6 +1417,58 @@ done:
        return SWITCH_STATUS_SUCCESS;
 } 
 
+#define GETVAR_SYNTAX "<uuid> <var>"
+SWITCH_STANDARD_API(uuid_getvar_function)
+{
+       switch_core_session_t *psession = NULL;
+       char *mycmd = NULL, *argv[4] = { 0 };
+       int argc = 0;
+
+       if (session) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+               argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+               if (argc >= 2) {
+                       char *uuid = argv[0];
+                       char *var_name = argv[1];
+                       const char *var_value = NULL;
+
+                       if ((psession = switch_core_session_locate(uuid))) {
+                               switch_channel_t *channel;
+                               channel = switch_core_session_get_channel(psession);
+                               
+                               assert(channel != NULL);
+
+                               if (switch_strlen_zero(var_name)) {
+                                       stream->write_function(stream, "No variable name specified!\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
+                               } else {
+                                       var_value = switch_channel_get_variable(channel, var_name);
+                                       if (var_value != NULL) {
+                                               stream->write_function(stream, "%s", var_value);
+                                       } else {
+                                               stream->write_function(stream, "_undef_");
+                                       }
+                               }
+
+                               switch_core_session_rwunlock(psession);
+
+                       } else {
+                               stream->write_function(stream, "No Such Channel!\n");
+                       }
+                       goto done;
+               }
+       }
+
+       stream->write_function(stream, "USAGE: %s\n", GETVAR_SYNTAX);
+
+ done:
+       switch_safe_free(mycmd);
+       return SWITCH_STATUS_SUCCESS;
+}
 SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
 {
        switch_api_interface_t *commands_api_interface;
@@ -1433,6 +1487,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "status", "status", status_function, "");
        SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, "");
        SWITCH_ADD_API(commands_api_interface, "uuid_setvar", "uuid_setvar", uuid_setvar_function, SETVAR_SYNTAX);
+       SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "session_displace", "session displace", session_displace_function, "<uuid> [start|stop] <path> [<limit>] [mux]");
        SWITCH_ADD_API(commands_api_interface, "session_record", "session record", session_record_function, SESS_REC_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX);