From dd21a2b1702b5f2c0bd7d1e557d7d4ed2befdeed Mon Sep 17 00:00:00 2001
From: Russell Bryant <russell@russellbryant.com>
Date: Sun, 6 Nov 2005 18:36:37 +0000
Subject: [PATCH] issue #5614

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6982 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 ChangeLog             |  1 +
 apps/app_enumlookup.c | 40 +++++++++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8882f27e88..195077adca 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
 	* many files: Add doxygen updates to categorize modules into groups. Convert a lot of comments over to doxygen style. Add some text giving a basic overview of channels.
 	* apps/app_chanisavail.c: Make priority jumping optional
 	* apps/app_db.c: Add an exit status variable and make priority jumping optional
+	* apps/app_enumlookup.c: Make priority jumping optional
 
 2005-11-05  Kevin P. Fleming  <kpfleming@digium.com>
 
diff --git a/apps/app_enumlookup.c b/apps/app_enumlookup.c
index 41536b32fd..cc07ea7123 100755
--- a/apps/app_enumlookup.c
+++ b/apps/app_enumlookup.c
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/enum.h"
 #include "asterisk/utils.h"
+#include "asterisk/options.h"
 
 static char *tdesc = "ENUM Lookup";
 
@@ -51,7 +52,7 @@ static char *app = "EnumLookup";
 static char *synopsis = "Lookup number in ENUM";
 
 static char *descrip =
-"  EnumLookup(exten):  Looks up an extension via ENUM and sets\n"
+"  EnumLookup(exten[|option]):  Looks up an extension via ENUM and sets\n"
 "the variable 'ENUM'. For VoIP URIs this variable will \n"
 "look like 'TECHNOLOGY/URI' with the appropriate technology.\n"
 "Returns -1 on hangup, or 0 on completion\n"
@@ -60,11 +61,9 @@ static char *descrip =
 "    ERROR	Failed to do a lookup\n"
 "    <tech>	Technology of the successful lookup: SIP, H323, IAX, IAX2 or TEL\n"
 "    BADURI	Got URI Asterisk does not understand.\n"
-"\nOld, depreciated, behaviour:\n"
-"\nA SIP, H323, IAX or IAX2 entry will result in normal priority handling, \n"
-"whereas a TEL entry will increase the priority by 51 (if existing).\n"
-"If the lookup was *not* successful and there exists a priority n + 101,\n"
-"then that priority will be taken next.\n" ;
+"  The option string may contain zero or the following character:\n"
+"       'j' -- jump to +101 priority if the lookup isn't successful.\n"
+"	       and jump to +51 priority on a TEL entry.\n";
 
 #define ENUM_CONFIG "enum.conf"
 
@@ -78,11 +77,11 @@ LOCAL_USER_DECL;
 /*--- enumlookup_exec: Look up number in ENUM and return result */
 static int enumlookup_exec(struct ast_channel *chan, void *data)
 {
-	int res=0;
+	int res=0,priority_jump=0;
 	char tech[80];
 	char dest[80];
 	char tmp[256];
-	char *c,*t;
+	char *c,*t,*d,*o = NULL;
 	static int dep_warning=0;
 	struct localuser *u;
 
@@ -100,11 +99,24 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
 
 	tech[0] = '\0';
 
-	res = ast_get_enum(chan, data, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
+	if (strchr(data, '|')) {
+		d = strsep(data, "|");
+		o = strsep(data, "\0");
+	} else
+		d = strsep(data, "\0");	
+		
+	if (o) {
+		if (strchr(o, 'j'))
+			priority_jump = 1;
+	}
+
+	res = ast_get_enum(chan, d, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
 	
 	if (!res) {	/* Failed to do a lookup */
-		/* Look for a "busy" place */
-		ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+		if (priority_jump || option_priority_jumping) {
+			/* Look for a "busy" place */
+			ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+		}
 		pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "ERROR");
 		LOCAL_USER_REMOVE(u);
 		return 0;
@@ -159,8 +171,10 @@ static int enumlookup_exec(struct ast_channel *chan, void *data)
 				*t = 0;
 				pbx_builtin_setvar_helper(chan, "ENUM", tmp);
 				ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
-				if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 51))
-					res = 0;
+				if (priority_jump || option_priority_jumping) {
+					if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 51))
+						res = 0;
+				}
 			}
 		} else if (!ast_strlen_zero(tech)) {
 			ast_log(LOG_NOTICE, "Don't know how to handle technology '%s'\n", tech);
-- 
GitLab