[Asterisk-code-review] app macro: Consider '~~s~~' as a macro start extension. (asterisk[master])

Anonymous Coward asteriskteam at digium.com
Mon Aug 29 13:16:45 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: app_macro: Consider '~~s~~' as a macro start extension.
......................................................................


app_macro: Consider '~~s~~' as a macro start extension.

As described in issue ASTERISK-26282 the AEL parser creates macros with
extension '~~s~~'.  app_macro searches only for extension 's' so the
created extension cannot be found.  with this patch app_macro searches for
both extensions and performs the right extension.

ASTERISK-26282 #close

Change-Id: I939aa2a694148cc1054dd75ec0c47c47f47c90fb
---
M apps/app_macro.c
1 file changed, 28 insertions(+), 8 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/apps/app_macro.c b/apps/app_macro.c
index 26e4262..61f3ab7 100644
--- a/apps/app_macro.c
+++ b/apps/app_macro.c
@@ -245,7 +245,7 @@
 	int setmacrocontext=0;
 	int autoloopflag, inhangup = 0;
 	struct ast_str *tmp_subst = NULL;
-  
+	const char *my_macro_exten = NULL;
 	char *save_macro_exten;
 	char *save_macro_context;
 	char *save_macro_priority;
@@ -306,12 +306,32 @@
 	}
 
 	snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro);
-	if (!ast_exists_extension(chan, fullmacro, "s", 1,
-		S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
-		if (!ast_context_find(fullmacro)) 
-			ast_log(LOG_WARNING, "No such context '%s' for macro '%s'. Was called by %s@%s\n", fullmacro, macro, ast_channel_exten(chan), ast_channel_context(chan));
-		else
-			ast_log(LOG_WARNING, "Context '%s' for macro '%s' lacks 's' extension, priority 1\n", fullmacro, macro);
+
+	/* first search for the macro */
+	if (!ast_context_find(fullmacro)) {
+		ast_log(LOG_WARNING, "No such context '%s' for macro '%s'. Was called by %s@%s\n",
+			fullmacro, macro, ast_channel_exten(chan), ast_channel_context(chan));
+		return 0;
+	}
+
+	/* now search for the right extension */
+	if (ast_exists_extension(chan, fullmacro, "s", 1,
+		S_COR(ast_channel_caller(chan)->id.number.valid,
+			ast_channel_caller(chan)->id.number.str, NULL))) {
+		/* We have a normal macro */
+		my_macro_exten = "s";
+	} else if (ast_exists_extension(chan, fullmacro, "~~s~~", 1,
+		S_COR(ast_channel_caller(chan)->id.number.valid,
+			ast_channel_caller(chan)->id.number.str, NULL))) {
+		/* We have an AEL generated macro */
+		my_macro_exten = "~~s~~";
+	}
+
+	/* do we have a valid exten? */
+	if (!my_macro_exten) {
+		ast_log(LOG_WARNING,
+			"Context '%s' for macro '%s' lacks 's' extension, priority 1\n",
+			fullmacro, macro);
 		return 0;
 	}
 
@@ -363,7 +383,7 @@
 	ast_set_flag(ast_channel_flags(chan), AST_FLAG_SUBROUTINE_EXEC);
 
 	/* Setup environment for new run */
-	ast_channel_exten_set(chan, "s");
+	ast_channel_exten_set(chan, my_macro_exten);
 	ast_channel_context_set(chan, fullmacro);
 	ast_channel_priority_set(chan, 1);
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I939aa2a694148cc1054dd75ec0c47c47f47c90fb
Gerrit-PatchSet: 5
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: chris de rock <chris at derock.de>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: chris de rock <chris at derock.de>



More information about the asterisk-code-review mailing list