From b7606ea4ea5f3b1da9dd1e81e269e9b7dccfd2b1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 21 Apr 2007 15:04:01 +0000 Subject: [PATCH] add reject app to do custom sip rejects git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4997 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 4 ++- .../applications/mod_dptools/mod_dptools.c | 24 ++++++++++++++++- src/mod/endpoints/mod_sofia/mod_sofia.c | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 0f5669ca56..7f494d532e 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -363,6 +363,7 @@ typedef enum { SWITCH_MESSAGE_INDICATE_HOLD - indicate hold SWITCH_MESSAGE_INDICATE_UNHOLD - indicate unhold SWITCH_MESSAGE_INDICATE_REDIRECT - indicate redirect + SWITCH_MESSAGE_INDICATE_REJECT - indicate reject */ typedef enum { @@ -378,7 +379,8 @@ typedef enum { SWITCH_MESSAGE_INDICATE_NOMEDIA, SWITCH_MESSAGE_INDICATE_HOLD, SWITCH_MESSAGE_INDICATE_UNHOLD, - SWITCH_MESSAGE_INDICATE_REDIRECT + SWITCH_MESSAGE_INDICATE_REDIRECT, + SWITCH_MESSAGE_INDICATE_REJECT } switch_core_session_message_types_t; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 6770a933aa..4c6807526b 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -298,6 +298,18 @@ static void redirect_function(switch_core_session_t *session, char *data) } +static void reject_function(switch_core_session_t *session, char *data) +{ + switch_core_session_message_t msg = { 0 }; + + /* Tell the channel to reject the call */ + msg.from = __FILE__; + msg.string_arg = data; + msg.message_id = SWITCH_MESSAGE_INDICATE_REJECT; + switch_core_session_receive_message(session, &msg); + +} + static void set_function(switch_core_session_t *session, char *data) { @@ -711,6 +723,16 @@ static const switch_application_interface_t queuedtmf_application_interface = { /*.next */ &sched_hangup_application_interface }; +static const switch_application_interface_t reject_application_interface = { + /*.interface_name */ "reject", + /*.application_function */ reject_function, + /* long_desc */ "Send a reject message to a session.", + /* short_desc */ "Send session reject", + /* syntax */ "", + /* flags */ SAF_SUPPORT_NOMEDIA, + /*.next */ &queuedtmf_application_interface +}; + static const switch_application_interface_t redirect_application_interface = { /*.interface_name */ "redirect", /*.application_function */ redirect_function, @@ -718,7 +740,7 @@ static const switch_application_interface_t redirect_application_interface = { /* short_desc */ "Send session redirect", /* syntax */ "", /* flags */ SAF_SUPPORT_NOMEDIA, - /*.next */ &queuedtmf_application_interface + /*.next */ &reject_application_interface }; static const switch_application_interface_t ivr_application_interface = { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8e9c9260e0..983f04177a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -767,6 +767,32 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END()); } break; + case SWITCH_MESSAGE_INDICATE_REJECT: + if (msg->string_arg) { + int code = 0; + char *reason; + + if (switch_channel_test_flag(channel, CF_ANSWERED)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call is already answered, Rejecting with hangup\n"); + switch_channel_hangup(channel, SWITCH_CAUSE_CALL_REJECTED); + } else { + + if ((reason = strchr(msg->string_arg, ' '))) { + reason++; + code = atoi(msg->string_arg); + } else { + reason = "Call Refused"; + } + + if (!(code > 400 && code < 600)) { + code = 488; + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Rejecting with %d %s\n", code, reason); + nua_respond(tech_pvt->nh, code, reason, TAG_END()); + } + } + break; case SWITCH_MESSAGE_INDICATE_RINGING: nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END()); switch_channel_mark_ring_ready(channel);