if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
char reason[128] = "";
- switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
+ if (cause < 128) {
+ switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
+ } else {
+ switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
+ }
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
} else {
if (!session) return;
channel = switch_core_session_get_channel(session);
+
+
+ if (sip->sip_reason && sip->sip_reason->re_protocol &&
+ (!strcasecmp(sip->sip_reason->re_protocol, "Q.850") || !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")) &&
+ sip->sip_reason->re_cause) {
+ private_object_t *tech_pvt = switch_core_session_get_private(session);
+ tech_pvt->q850_cause = atoi(sip->sip_reason->re_cause);
+ }
+
if (sip->sip_user_agent && !switch_strlen_zero(sip->sip_user_agent->g_string)){
switch_channel_set_variable(channel, "sip_user_agent", sip->sip_user_agent->g_string);
}
switch_clear_flag_locked(tech_pvt, TFLAG_NOHUP);
} else {
int cause;
- if (sip->sip_reason && sip->sip_reason->re_protocol && !strcasecmp(sip->sip_reason->re_protocol, "Q.850") && sip->sip_reason->re_cause) {
- cause = atoi(sip->sip_reason->re_cause);
+ if (tech_pvt->q850_cause) {
+ cause = tech_pvt->q850_cause;
} else {
cause = sofia_glue_sip_cause_to_freeswitch(status);
}