From b6d95bef99d9b0972ae88fabeb6b012c580433c3 Mon Sep 17 00:00:00 2001
From: Olle Johansson <oej@edvina.net>
Date: Wed, 27 May 2009 20:14:00 +0000
Subject: [PATCH] Adding some generic handling of error codes sent to us in
 replys to requests.

Previously they always set hangupcause 0, which is generally wrong. With this
change, we're setting some generic hangup causes. For 5xx errors, which indicate
some sort of problem with the remote server, we're now setting CONGESTION.

EDVX002


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@197266 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_sip.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 20e47a47b2..07b2330d6d 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -5698,6 +5698,16 @@ static int hangup_sip2cause(int cause)
 		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 */
-- 
GitLab