Added support for blind transfer notification of negative responses

This commit is contained in:
Moises Silva 2013-06-26 23:17:49 -04:00
parent 3879a85bfb
commit 5324063f44
2 changed files with 33 additions and 4 deletions

View File

@ -1199,13 +1199,35 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
char *xdest;
if (event && uuid) {
char payload_str[255] = "SIP/2.0 403 Forbidden\r\n";
if (msg->numeric_arg) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%s Completing blind transfer with success\n", switch_channel_get_name(channel));
switch_set_string(payload_str, "SIP/2.0 200 OK\r\n");
} else if (uuid) {
switch_core_session_t *other_session = switch_core_session_locate(uuid);
if (other_session) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
const char *invite_failure_status = switch_channel_get_variable(other_channel, "sip_invite_failure_status");
const char *invite_failure_str = switch_channel_get_variable(other_channel, "sip_invite_failure_status");
if (!zstr(invite_failure_status) && !zstr(invite_failure_str)) {
snprintf(payload_str, sizeof(payload_str), "SIP/2.0 %s %s\r\n", invite_failure_status, invite_failure_str);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%s Completing blind transfer with custom failure: %s %s\n",
switch_channel_get_name(channel), invite_failure_status, invite_failure_str);
}
switch_core_session_rwunlock(other_session);
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%s Completing blind transfer with status: %s\n", switch_channel_get_name(channel), payload_str);
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
NUTAG_SUBSTATE(nua_substate_terminated),
SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
SIPTAG_PAYLOAD_STR(msg->numeric_arg ? "SIP/2.0 200 OK\r\n" : "SIP/2.0 403 Forbidden\r\n"),
SIPTAG_EVENT_STR(event), TAG_END());
SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
SIPTAG_PAYLOAD_STR(payload_str),
SIPTAG_EVENT_STR(event), TAG_END());
if (!msg->numeric_arg) {
xdest = switch_core_session_sprintf(session, "intercept:%s", uuid);
switch_ivr_session_transfer(session, xdest, "inline", NULL);

View File

@ -4985,6 +4985,13 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
switch_channel_set_variable(channel, "sip_hangup_disposition", "recv_refuse");
}
if (status >= 400) {
char status_str[5];
switch_snprintf(status_str, sizeof(status_str), "%d", status);
switch_channel_set_variable_partner(channel, "sip_invite_failure_status", status_str);
switch_channel_set_variable_partner(channel, "sip_invite_failure_phrase", phrase);
}
if (status >= 400 && sip->sip_reason && sip->sip_reason->re_protocol && (!strcasecmp(sip->sip_reason->re_protocol, "Q.850")
|| !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")
|| !strcasecmp(sip->sip_reason->re_protocol, profile->sdp_username)) && sip->sip_reason->re_cause) {