add reject app to do custom sip rejects

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4997 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-04-21 15:04:01 +00:00
parent 8755dea7b8
commit b7606ea4ea
3 changed files with 52 additions and 2 deletions

View File

@ -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
</pre>
*/
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;

View File

@ -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 */ "<reject_data>",
/* 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 */ "<redirect_data>",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &queuedtmf_application_interface
/*.next */ &reject_application_interface
};
static const switch_application_interface_t ivr_application_interface = {

View File

@ -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);