From bcd325855570654705b52d4307ba248ead4a0541 Mon Sep 17 00:00:00 2001 From: Antoine Rose Date: Thu, 30 May 2024 17:48:30 +0200 Subject: [PATCH] feat(mod_sofia): read sip_reason in sofia_handle_sip_r_invite --- src/mod/endpoints/mod_sofia/sofia.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 43bd68b923..3e99ddc17e 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6599,6 +6599,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status tagi_t tags[]) { char *call_info = NULL; + char *reason_header = NULL; if (sip && session) { switch_channel_t *channel = switch_core_session_get_channel(session); const char *uuid; @@ -6665,6 +6666,14 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status switch_channel_set_variable_partner(channel, "sip_invite_failure_phrase", NULL); } + if (sip->sip_reason) { + reason_header = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_reason); + if (!zstr(reason_header)) { + switch_channel_set_variable(channel, "sip_reason", reason_header); + switch_channel_set_variable_partner(channel, "sip_reason", reason_header); + } + } + 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) { @@ -7232,6 +7241,9 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status if (call_info) { su_free(nua_handle_home(nh), call_info); } + if (reason_header) { + su_free(nua_handle_home(nh), reason_header); + } if (!session && (status == 180 || status == 183 || status == 200)) { /* nevermind */