Clarification On Gosub, Macros And AEL

Home » Asterisk Users » Clarification On Gosub, Macros And AEL
Asterisk Users 8 Comments

I’m trying to clarify my understand of gosub, macros and AEL.

My understanding is that macros using the Macro() application, which is defined in extensions.conf by:

[macro-foo]

and called in extensions.conf with

exten => _9NXXNXXXXXX.,n,Macro(fastbusy)

is deprecated in favour of Gosub(). True so far?

But then there are “macro”s defined in extensions.ael:

macro foo() { … }

and called in extensions.ael with:

&foo(…)

These are not deprecated because they use Gosub() underneath and not Macro()? Still good so far?

So if macros in extensions.ael are not deprecated because they just use Gosub() underneath them, when why, when I try to use Gosub() and contexts in extensions.ael directly do I get warnings like:

[Oct 11 13:50:55] WARNING[10343]: ael/pval.c:2526 check_pval_item: Warning: file /etc/asterisk/extensions.ael, line 552-552: application call to Gosub affects flow of control, and needs to be re-written using AEL if, while, goto, etc. keywords instead!

but not with these Gosub() implemented “macros”?

Cheers, b.

8 thoughts on - Clarification On Gosub, Macros And AEL

  • Personally, I don’t think MACROS are going anywhere any time soon, so I have not bothered looking into a substitution.

    As for ael; I’ve never used it.

    Doug

  • Sounds more like a question for the developers’ list.

    Antony.


    I think broken pencils are pointless.

    Please reply to the list;
    please *don’t* CC me.

  • I think the WARNING on Gosub() calls from AEL could change to NOTICE; or at least get more specific, such as “instead of calling Gosub()
    directly, please try an AEL macro.”

    A new AEL keyword to eventually replace “macro”, such as “subcontext”, might help clarify things, too.

    But it should work fine even with the WARNING messages — as long as you are careful* — because in modern AEL, these two lines make for equivalent dial plan configuration:

    &some-macro();
    Gosub(some-macro,~~s~~,1);

    I prefer the former because it is less to type. Although in some cases, such as the Dial() application option “b”, the ampersand prefix format won’t work, requiring the longer format with ~~s~~ if you want to enter the macro at the default entry point:

    Dial(PJSIP/1234,,b(some-macro^~~s~~^1));

    * However, auto-conversion of macro parameters to local custom variables is (currently) only handled when entering the default entry point ~~s~~. So the following AEL example will parse with one WARNING but the Dial()
    might not be doing what you expect from just looking at the first line of the macro definition:

    macro mac-test( ext_ ) {
    catch BLEG {
    NoOp(Oops ext_ is blank: ${ext_}. Use ARG1 instead: ${ARG1}.);
    return;
    }
    NoOp(But ext_ is NOT blank at default entry point: ${ext_}.);
    return;
    }

    context ctx-start {
    _XXXX => {
    &mac-test(${EXTEN}); // default entry, $ext_ will be same as $EXTEN
    Gosub(mac-test,~~s~~,1(${EXTEN})); // ditto, with a WARNING
    Dial(PJSIP/${EXTEN},2,b(mac-test^BLEG^1(${EXTEN}))); // ext_ blank
    }
    }

    …a corner case like that is why some level of concern should probably still be raised in the logs on direct Gosub() calls from AEL — but not prohibited.

    Kind Regards,

  • Hello Doug,

    Tuesday, October 15, 2019, 5:07:45 PM, you wrote:

    Haven’t they gone in Asterisk 16? I’ve just upgraded from Asterisk 13
    and had to do some hasty re-writing of my dialplan to convert the Macros into Gosubs because the Macros did not work (I had noticed the deprecation notice previously, but forgot about it). I didn’t have many, so I did them by hand, but it would be easy to script.

    Julian


    Best regards, Julian mailto:jb_soft@trink.co.uk

  • Hello Joshua,

    Wednesday, October 16, 2019, 10:39:27 AM, you wrote:

    I was obviously too concerned about the rebuilding of wanpipe with a new kernel version to notice anything about macros in menuselect! As I
    said, it is not hard to convert from macro to gosub, once I had worked out why my dialplan wasn’t working.


    Best regards, Julian mailto:jb_soft@trink.co.uk