From 81932c6142f4921c7b303b70245d22a774232c07 Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Thu, 13 Oct 2005 23:52:42 +0000
Subject: [PATCH] make DISA() use 'i' extension if it exists (issue #5439 with
 mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6779 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_disa.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/apps/app_disa.c b/apps/app_disa.c
index 5e9f5ccd8c..173441d467 100755
--- a/apps/app_disa.c
+++ b/apps/app_disa.c
@@ -329,25 +329,35 @@ static int disa_exec(struct ast_channel *chan, void *data)
 		}
 	}
 
-	if (k==3 && ast_exists_extension(chan, ourcontext, exten, 1, chan->cid.cid_num))
-	{
-		ast_playtones_stop(chan);
-		/* We're authenticated and have a valid extension */
-		if (ourcallerid && *ourcallerid)
-		{
-			ast_callerid_split(ourcallerid, ourcidname, sizeof(ourcidname), ourcidnum, sizeof(ourcidnum));
-			ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
+	if (k == 3) {
+		int recheck = 0;
+
+		if (!ast_exists_extension(chan, ourcontext, exten, 1, chan->cid.cid_num)) {
+			exten[0] = 'i';
+			exten[1] = '\0';
+			recheck = 1;
 		}
+		if (!recheck || ast_exists_extension(chan, ourcontext, exten, 1, chan->cid.cid_num)) {
+			ast_playtones_stop(chan);
+			/* We're authenticated and have a target extension */
+			if (ourcallerid && *ourcallerid)
+			{
+				ast_callerid_split(ourcallerid, ourcidname, sizeof(ourcidname), ourcidnum, sizeof(ourcidnum));
+				ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
+			}
+
+			if (!ast_strlen_zero(acctcode))
+				strncpy(chan->accountcode, acctcode, sizeof(chan->accountcode) - 1);
 
-		if (!ast_strlen_zero(acctcode)) {
-			strncpy(chan->accountcode, acctcode, sizeof(chan->accountcode) - 1);
+			ast_cdr_reset(chan->cdr, AST_CDR_FLAG_POSTED);
+			ast_explicit_goto(chan, ourcontext, exten, 1);
+			LOCAL_USER_REMOVE(u);
+			return 0;
 		}
-		ast_cdr_reset(chan->cdr, AST_CDR_FLAG_POSTED);
-		ast_goto_if_exists(chan, ourcontext, exten, 1);
-		LOCAL_USER_REMOVE(u);
-		return 0;
 	}
 
+	/* Received invalid, but no "i" extension exists in the given context */
+
 reorder:
 
 	ast_indicate(chan,AST_CONTROL_CONGESTION);
-- 
GitLab