From 16bcb7e1e625ace325dda16a0aafde586505d85f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 12 Nov 2008 11:46:44 +0000 Subject: [PATCH] (FSCORE-217) Add support for passing the cause of hangup to the uuid_kill command git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10347 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index ea41d04982..f0e4a48146 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -921,26 +921,39 @@ SWITCH_STANDARD_API(reload_xml_function) return SWITCH_STATUS_SUCCESS; } -#define KILL_SYNTAX "" +#define KILL_SYNTAX " [cause]" SWITCH_STANDARD_API(kill_function) { switch_core_session_t *ksession = NULL; + char *mycmd = NULL, *kcause = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; if (session) { return SWITCH_STATUS_FALSE; } - if (!cmd) { + if (switch_strlen_zero(cmd) || !(mycmd = strdup(cmd))) { stream->write_function(stream, "-USAGE: %s\n", KILL_SYNTAX); - } else if ((ksession = switch_core_session_locate(cmd))) { - switch_channel_t *channel = switch_core_session_get_channel(ksession); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(ksession); - stream->write_function(stream, "+OK\n"); - } else { - stream->write_function(stream, "-ERR No Such Channel!\n"); + return SWITCH_STATUS_SUCCESS; } + if ((kcause = strchr(mycmd, ' '))) { + *kcause++ = '\0'; + } + + if (switch_strlen_zero(mycmd) || !(ksession = switch_core_session_locate(mycmd))) { + stream->write_function(stream, "-ERR No Such Channel!\n"); + } else { + switch_channel_t *channel = switch_core_session_get_channel(ksession); + if (!switch_strlen_zero(kcause)){ + cause = switch_channel_str2cause(kcause); + } + switch_channel_hangup(channel, cause); + switch_core_session_rwunlock(ksession); + stream->write_function(stream, "+OK\n"); + } + + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; }