res_pjsip_rfc3326: Add SIP causes support for RFC3326

Add ability to set HANGUPCAUSE when SIP causecode received in BYE (in addition to currently supported Q.850).

ASTERISK-30319 #close

Change-Id: I3f55622dc680ce713a2ffb5a458ef5dd39fcf645
This commit is contained in:
Igor Goncharovsky
2022-11-18 08:16:50 +06:00
committed by George Joseph
parent 7dc8773178
commit 410150235a
5 changed files with 130 additions and 106 deletions

View File

@@ -42,6 +42,7 @@ static void rfc3326_use_reason_header(struct ast_sip_session *session, struct pj
char *cause;
char *text;
int code;
int cause_q850, cause_sip;
header = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_reason, NULL);
for (; header;
@@ -49,21 +50,27 @@ static void rfc3326_use_reason_header(struct ast_sip_session *session, struct pj
ast_copy_pj_str(buf, &header->hvalue, sizeof(buf));
cause = ast_skip_blanks(buf);
if (strncasecmp(cause, "Q.850", 5) || !(cause = strstr(cause, "cause="))) {
cause_q850 = !strncasecmp(cause, "Q.850", 5);
cause_sip = !strncasecmp(cause, "SIP", 3);
if ((cause_q850 || cause_sip) && (cause = strstr(cause, "cause="))) {
/* If text is present get rid of it */
if ((text = strchr(cause, ';'))) {
*text = '\0';
}
if (sscanf(cause, "cause=%30d", &code) != 1) {
continue;
}
} else {
continue;
}
/* If text is present get rid of it */
if ((text = strstr(cause, ";"))) {
*text = '\0';
if (cause_q850) {
ast_channel_hangupcause_set(session->channel, code & 0x7f);
break;
} else if (cause_sip) {
ast_channel_hangupcause_set(session->channel, ast_sip_hangup_sip2cause(code));
break;
}
if (sscanf(cause, "cause=%30d", &code) != 1) {
continue;
}
ast_channel_hangupcause_set(session->channel, code & 0x7f);
break;
}
}