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