]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7922 Add uuid_redirect API command
authorDave Olszewski <dolszewski@marchex.com>
Tue, 28 Jul 2015 19:17:40 +0000 (12:17 -0700)
committerDave Olszewski <dolszewski@marchex.com>
Thu, 30 Jul 2015 20:26:05 +0000 (13:26 -0700)
This provides the equivalent functionality of the dptools "redirect"
application as an api command

src/mod/applications/mod_commands/mod_commands.c

index a415c8c7f0d6c69da147a12d79a858e919efb2b3..05a045b07fd4ab5391a059b143b08f7c4847e896 100644 (file)
@@ -3088,6 +3088,40 @@ SWITCH_STANDARD_API(uuid_deflect)
        return SWITCH_STATUS_SUCCESS;
 }
 
+#define UUID_REDIRECT_SYNTAX "<uuid> <uri>"
+SWITCH_STANDARD_API(uuid_redirect)
+{
+       switch_core_session_t *tsession = NULL;
+       char *uuid = NULL, *text = NULL;
+
+       if (!zstr(cmd) && (uuid = strdup(cmd))) {
+               if ((text = strchr(uuid, ' '))) {
+                       *text++ = '\0';
+               }
+       }
+
+       if (zstr(uuid) || zstr(text)) {
+               stream->write_function(stream, "-USAGE: %s\n", UUID_REDIRECT_SYNTAX);
+       } else {
+               if ((tsession = switch_core_session_locate(uuid))) {
+                       switch_core_session_message_t msg = { 0 };
+
+                       /* Tell the channel to redirect the call */
+                       msg.from = __FILE__;
+                       msg.string_arg = text;
+                       msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
+                       msg.numeric_arg = 1;
+                       switch_core_session_receive_message(tsession, &msg);
+                       stream->write_function(stream, "+OK:%s\n", msg.string_reply);
+                       switch_core_session_rwunlock(tsession);
+               } else {
+                       stream->write_function(stream, "-ERR No such channel %s!\n", uuid);
+               }
+       }
+
+       switch_safe_free(uuid);
+       return SWITCH_STATUS_SUCCESS;
+}
 
 #define UUID_MEDIA_STATS_SYNTAX "<uuid>"
 SWITCH_STANDARD_API(uuid_set_media_stats)
@@ -6919,6 +6953,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "uuid_record", "Record session audio", session_record_function, SESS_REC_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_recovery_refresh", "Send a recovery_refresh", uuid_recovery_refresh, UUID_RECOVERY_REFRESH_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_recv_dtmf", "Receive dtmf digits", uuid_recv_dtmf_function, UUID_RECV_DTMF_SYNTAX);
+       SWITCH_ADD_API(commands_api_interface, "uuid_redirect", "Send a redirect", uuid_redirect, UUID_REDIRECT_SYNTAX);
        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, "uuid_session_heartbeat", "uuid_session_heartbeat", uuid_session_heartbeat_function, HEARTBEAT_SYNTAX);
        SWITCH_ADD_API(commands_api_interface, "uuid_setvar_multi", "Set multiple variables", uuid_setvar_multi_function, SETVAR_MULTI_SYNTAX);
@@ -7100,6 +7135,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        switch_console_set_complete("add uuid_record ::console::list_uuid ::[start:stop");
        switch_console_set_complete("add uuid_recovery_refresh ::console::list_uuid");
        switch_console_set_complete("add uuid_recv_dtmf ::console::list_uuid");
+       switch_console_set_complete("add uuid_redirect ::console::list_uuid");
        switch_console_set_complete("add uuid_send_dtmf ::console::list_uuid");
        switch_console_set_complete("add uuid_session_heartbeat ::console::list_uuid");
        switch_console_set_complete("add uuid_setvar_multi ::console::list_uuid");