[Asterisk-code-review] chan sip: Support parsing of Q.850 reason header in SIP BYE ... (asterisk[master])

Christof Lauber asteriskteam at digium.com
Wed Dec 2 02:19:36 CST 2015


Christof Lauber has uploaded a new change for review.

  https://gerrit.asterisk.org/1750

Change subject: chan_sip: Support parsing of Q.850 reason header in SIP BYE and CANCEL requests.
......................................................................

chan_sip: Support parsing of Q.850 reason header in SIP BYE and CANCEL requests.

Current support for reason header did work only in SIP responses.
According to RFC3336 the reason header might appear in any SIP request.
But it seems to make most sence in BYE and CANCEL so parasing is done
there too (if use_q850_reason=yes).

Change-Id: Ib6be7b34c23a76d0e98dfd0816c89931000ac790
---
M channels/chan_sip.c
1 file changed, 19 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/50/1750/1

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 8eb281c..e32f719 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -16124,28 +16124,32 @@
  */
 static int use_reason_header(struct sip_pvt *pvt, struct sip_request *req)
 {
-	int ret;
+	int ret, cause;
 	const char *rp, *rh;
 
 	if (!pvt->owner) {
 		return -1;
 	}
 
+	if (!ast_test_flag(&pvt->flags[1], SIP_PAGE2_Q850_REASON) ||
+		!(rh = sip_get_header(req, "Reason"))) {
+		return -1;
+	}
+
+	rh = ast_skip_blanks(rh);
+	if (strncasecmp(rh, "Q.850", 5)) {
+		return -1;
+	}
+
 	ret = -1;
-	if (ast_test_flag(&pvt->flags[1], SIP_PAGE2_Q850_REASON) &&
-		(rh = sip_get_header(req, "Reason"))) {
-		rh = ast_skip_blanks(rh);
-		if (!strncasecmp(rh, "Q.850", 5)) {
-			int cause = ast_channel_hangupcause(pvt->owner);
-			rp = strstr(rh, "cause=");
-			if (rp && sscanf(rp + 6, "%3d", &cause) == 1) {
-				ret = 0;
-				ast_channel_hangupcause_set(pvt->owner, cause & 0x7f);
-				if (req->debug) {
-					ast_verbose("Using Reason header for cause code: %d\n",
-								ast_channel_hangupcause(pvt->owner));
-				}
-			}
+	cause = ast_channel_hangupcause(pvt->owner);
+	rp = strstr(rh, "cause=");
+	if (rp && sscanf(rp + 6, "%3d", &cause) == 1) {
+		ret = 0;
+		ast_channel_hangupcause_set(pvt->owner, cause & 0x7f);
+		if (req->debug) {
+			ast_verbose("Using Reason header for cause code: %d\n",
+						ast_channel_hangupcause(pvt->owner));
 		}
 	}
 	return ret;

-- 
To view, visit https://gerrit.asterisk.org/1750
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib6be7b34c23a76d0e98dfd0816c89931000ac790
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Christof Lauber <christof.lauber at annax.ch>



More information about the asterisk-code-review mailing list