]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Added support for blind transfer notification of negative responses
authorMoises Silva <moy@sangoma.com>
Thu, 27 Jun 2013 03:17:49 +0000 (23:17 -0400)
committerMoises Silva <moy@sangoma.com>
Thu, 27 Jun 2013 03:17:49 +0000 (23:17 -0400)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c

index 98d2228e967db335b90dba73838eb3b678e29368..716587cdbbd407dd74b5d067587dc85fd2296852 100644 (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);
index e9f5b9fea44598c43d089915d1a865218ef7b7f9..a4dd9e24bb213f5cbb06085126c8a64d00d694a0 100644 (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) {