From f7f1a2cbb797f67a83826de2a9d47425a1b7ebe7 Mon Sep 17 00:00:00 2001
From: Sean Bright <sean.bright@gmail.com>
Date: Thu, 11 Apr 2019 16:29:20 -0400
Subject: [PATCH] res_ael: Use Gosub in for loop expressions

In AEL2, if a 'for' statement contains macro* calls, like:

    for (&iterator(${TRY},A); "${A}" != ""; &iterate(A)) {

The AEL2 parser will translate these into calls to the deprecated Macro
dialplan application and use the antiquated pipe delimiter.

Instead, convert these into calls to the Gosub dialplan application and
use commas as argument separators.

ASTERISK-18593 #close
Reported by: Luke-Jr

* 'macro' in this context means AEL2 macros, not the 'Macro' application

Change-Id: I3d73716033b8e3e42e0209d355bf5f10c97045fc
---
 res/ael/pval.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/res/ael/pval.c b/res/ael/pval.c
index f927077a83..4e9a5255ed 100644
--- a/res/ael/pval.c
+++ b/res/ael/pval.c
@@ -3540,18 +3540,14 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
 					strcpy(buf2, strp3);
 					strp3 = strchr(buf2,'(');
 					if (strp3) {
-						*strp3 = '|';
-					}
-					while ((strp3=strchr(buf2,','))) {
-						*strp3 = '|';
+						*strp3 = ',';
 					}
 					strp3 = strrchr(buf2, ')');
 					if (strp3)
 						*strp3 = 0; /* remove the closing paren */
-
 					for_init->appargs = strdup(buf2);
 					free(for_init->app);
-					for_init->app = strdup("Macro");
+					for_init->app = strdup("Gosub");
 				} else {  /* must be a regular app call */
 					char *strp3;
 					strcpy(buf2, strp2);
@@ -3598,7 +3594,7 @@ static int gen_prios(struct ael_extension *exten, char *label, pval *statement,
 
 					for_inc->appargs = strdup(buf2);
 
-					for_inc->app = strdup("Macro");
+					for_inc->app = strdup("Gosub");
 				} else {  /* must be a regular app call */
 					char *strp3;
 					strcpy(buf2, strp2);
-- 
GitLab