[Asterisk-code-review] res_pjsip_rfc3326: Add SIP causes support for RFC3326 (asterisk[18])
Igor Goncharovsky
asteriskteam at digium.com
Thu Nov 17 21:41:32 CST 2022
Igor Goncharovsky has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19570 )
Change subject: res_pjsip_rfc3326: Add SIP causes support for RFC3326
......................................................................
res_pjsip_rfc3326: Add SIP causes support for RFC3326
Add ability to set HANGUPCAUSE when SIP causecode sent in BYE (additionaly to currently supported Q.850).
ASTERISK-30319 #close
Change-Id: I3f55622dc680ce713a2ffb5a458ef5dd39fcf645
---
M res/res_pjsip_rfc3326.c
1 file changed, 124 insertions(+), 12 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/19570/1
diff --git a/res/res_pjsip_rfc3326.c b/res/res_pjsip_rfc3326.c
index 7d096c1..a3027ad 100644
--- a/res/res_pjsip_rfc3326.c
+++ b/res/res_pjsip_rfc3326.c
@@ -34,6 +34,97 @@
#include "asterisk/causes.h"
#include "asterisk/threadpool.h"
+/*! \brief Convert SIP hangup causes to Asterisk hangup causes */
+static int hangup_sip2cause(int cause)
+{
+ /* Possible values taken from causes.h */
+
+ switch(cause) {
+ case 401: /* Unauthorized */
+ return AST_CAUSE_CALL_REJECTED;
+ case 403: /* Not found */
+ return AST_CAUSE_CALL_REJECTED;
+ case 404: /* Not found */
+ return AST_CAUSE_UNALLOCATED;
+ case 405: /* Method not allowed */
+ return AST_CAUSE_INTERWORKING;
+ case 407: /* Proxy authentication required */
+ return AST_CAUSE_CALL_REJECTED;
+ case 408: /* No reaction */
+ return AST_CAUSE_NO_USER_RESPONSE;
+ case 409: /* Conflict */
+ return AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
+ case 410: /* Gone */
+ return AST_CAUSE_NUMBER_CHANGED;
+ case 411: /* Length required */
+ return AST_CAUSE_INTERWORKING;
+ case 413: /* Request entity too large */
+ return AST_CAUSE_INTERWORKING;
+ case 414: /* Request URI too large */
+ return AST_CAUSE_INTERWORKING;
+ case 415: /* Unsupported media type */
+ return AST_CAUSE_INTERWORKING;
+ case 420: /* Bad extension */
+ return AST_CAUSE_NO_ROUTE_DESTINATION;
+ case 480: /* No answer */
+ return AST_CAUSE_NO_ANSWER;
+ case 481: /* No answer */
+ return AST_CAUSE_INTERWORKING;
+ case 482: /* Loop detected */
+ return AST_CAUSE_INTERWORKING;
+ case 483: /* Too many hops */
+ return AST_CAUSE_NO_ANSWER;
+ case 484: /* Address incomplete */
+ return AST_CAUSE_INVALID_NUMBER_FORMAT;
+ case 485: /* Ambiguous */
+ return AST_CAUSE_UNALLOCATED;
+ case 486: /* Busy everywhere */
+ return AST_CAUSE_BUSY;
+ case 487: /* Request terminated */
+ return AST_CAUSE_INTERWORKING;
+ case 488: /* No codecs approved */
+ return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
+ case 491: /* Request pending */
+ return AST_CAUSE_INTERWORKING;
+ case 493: /* Undecipherable */
+ return AST_CAUSE_INTERWORKING;
+ case 500: /* Server internal failure */
+ return AST_CAUSE_FAILURE;
+ case 501: /* Call rejected */
+ return AST_CAUSE_FACILITY_REJECTED;
+ case 502:
+ return AST_CAUSE_DESTINATION_OUT_OF_ORDER;
+ case 503: /* Service unavailable */
+ return AST_CAUSE_CONGESTION;
+ case 504: /* Gateway timeout */
+ return AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE;
+ case 505: /* SIP version not supported */
+ return AST_CAUSE_INTERWORKING;
+ case 600: /* Busy everywhere */
+ return AST_CAUSE_USER_BUSY;
+ case 603: /* Decline */
+ return AST_CAUSE_CALL_REJECTED;
+ case 604: /* Does not exist anywhere */
+ return AST_CAUSE_UNALLOCATED;
+ case 606: /* Not acceptable */
+ return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
+ default:
+ if (cause < 500 && cause >= 400) {
+ /* 4xx class error that is unknown - someting wrong with our request */
+ return AST_CAUSE_INTERWORKING;
+ } else if (cause < 600 && cause >= 500) {
+ /* 5xx class error - problem in the remote end */
+ return AST_CAUSE_CONGESTION;
+ } else if (cause < 700 && cause >= 600) {
+ /* 6xx - global errors in the 4xx class */
+ return AST_CAUSE_INTERWORKING;
+ }
+ return AST_CAUSE_NORMAL;
+ }
+ /* Never reached */
+ return 0;
+}
+
static void rfc3326_use_reason_header(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
{
static const pj_str_t str_reason = { "Reason", 6 };
@@ -49,21 +140,29 @@
ast_copy_pj_str(buf, &header->hvalue, sizeof(buf));
cause = ast_skip_blanks(buf);
- if (strncasecmp(cause, "Q.850", 5) || !(cause = strstr(cause, "cause="))) {
- continue;
- }
+ if (!strncasecmp(cause, "Q.850", 5) && (cause = strstr(cause, "cause="))) {
+ /* If text is present get rid of it */
+ if ((text = strstr(cause, ";"))) {
+ *text = '\0';
+ }
- /* If text is present get rid of it */
- if ((text = strstr(cause, ";"))) {
- *text = '\0';
- }
+ if (sscanf(cause, "cause=%30d", &code) != 1) {
+ continue;
+ }
+ ast_channel_hangupcause_set(session->channel, code & 0x7f);
+ break;
+ } else if (!strncasecmp(cause, "SIP", 3) && (cause = strstr(cause, "cause="))) {
+ /* If text is present get rid of it */
+ if ((text = strstr(cause, ";"))) {
+ *text = '\0';
+ }
- if (sscanf(cause, "cause=%30d", &code) != 1) {
- continue;
+ if (sscanf(cause, "cause=%30d", &code) != 1) {
+ continue;
+ }
+ ast_channel_hangupcause_set(session->channel, hangup_sip2cause(code));
+ break;
}
-
- ast_channel_hangupcause_set(session->channel, code & 0x7f);
- break;
}
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19570
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I3f55622dc680ce713a2ffb5a458ef5dd39fcf645
Gerrit-Change-Number: 19570
Gerrit-PatchSet: 1
Gerrit-Owner: Igor Goncharovsky <igor.goncharovsky at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221118/bdebacf6/attachment-0001.html>
More information about the asterisk-code-review
mailing list