add selective challenge to sofia via reject app

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5297 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-06-08 22:28:32 +00:00
parent 989f0b61fc
commit 724de2b52d
7 changed files with 79 additions and 30 deletions
+22 -6
View File
@@ -806,17 +806,21 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_REJECT:
if (msg->string_arg) {
int code = 0;
char *reason;
char *reason = NULL;
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++;
if (!switch_strlen_zero(msg->string_arg)){
code = atoi(msg->string_arg);
} else {
if ((reason = strchr(msg->string_arg, ' '))) {
reason++;
}
}
if (!reason && code != 407) {
reason = "Call Refused";
}
@@ -824,8 +828,20 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
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());
if (code == 407) {
const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
const char *to_host = reason;
if (switch_strlen_zero(to_host)) {
to_host = switch_channel_get_variable(channel, "sip_to_host");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Challanging call %s\n", to_uri);
sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
} else {
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;