From 412fc926ea02bcb08ef4b3e4938e9fbbe2c7f4a2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 20 Nov 2008 02:07:59 +0000 Subject: [PATCH] wait for reply of refer git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10471 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 1 + src/include/switch_types.h | 4 +- .../applications/mod_commands/mod_commands.c | 40 +++++++++++++++++ src/mod/endpoints/mod_sofia/mod_sofia.c | 11 +++++ src/mod/endpoints/mod_sofia/mod_sofia.h | 2 + src/mod/endpoints/mod_sofia/sofia.c | 45 ++++++++++++++++++- 6 files changed, 100 insertions(+), 3 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index b1a15600a1..7f9efc6d9b 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -92,6 +92,7 @@ struct switch_core_session_message { const char *_file; const char *_func; int _line; + }; /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */ diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 2f41b02636..f3eaedd6bc 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -676,7 +676,9 @@ typedef enum { } switch_text_channel_t; typedef enum { - SCSMF_DYNAMIC = (1 << 0) + SCSMF_DYNAMIC = (1 << 0), + SCSMF_FREE_STRING_REPLY = (1 << 1), + SCSMF_FREE_POINTER_REPLY = (1 << 2), } switch_core_session_message_flag_enum_t; typedef uint32_t switch_core_session_message_flag_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 23893e126e..568f76025f 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1259,6 +1259,45 @@ SWITCH_STANDARD_API(uuid_chat) return SWITCH_STATUS_SUCCESS; } + + +#define UUID_DEFLECT_SYNTAX " " +SWITCH_STANDARD_API(uuid_deflect) +{ + switch_core_session_t *tsession = NULL; + char *uuid = NULL, *text = NULL; + + if (!switch_strlen_zero(cmd) && (uuid = strdup(cmd))) { + if ((text = strchr(uuid, ' '))) { + *text++ = '\0'; + } + } + + if (switch_strlen_zero(uuid) || switch_strlen_zero(text)) { + stream->write_function(stream, "-USAGE: %s\n", UUID_DEFLECT_SYNTAX); + } else { + if ((tsession = switch_core_session_locate(uuid))) { + switch_core_session_message_t msg = { 0 }; + + /* Tell the channel to deflect the call */ + msg.from = __FILE__; + msg.string_arg = text; + msg.message_id = SWITCH_MESSAGE_INDICATE_DEFLECT; + switch_core_session_receive_message(tsession, &msg); + stream->write_function(stream, "+OK:%s\n", msg.string_reply); + if (switch_set_flag((&msg), SCSMF_FREE_STRING_REPLY)) { + free(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 SCHED_TRANSFER_SYNTAX "[+]