[asterisk-dev] (ASTERISK-19336) h exten is not run in the context that calls a AEL macro

Tilghman Lesher tilghman at meg.abyt.es
Tue Feb 28 19:59:23 CST 2012


On Mon, Feb 27, 2012 at 10:33 AM, Johan Wilfer <lists at jttech.se> wrote:
> 2012-02-23 15:26, Matthew Jordan skrev:
>>> But if I change the code to scenario 1, no h-exten is run, is this
>>> the intended behaviour?
>> Yes.  From https://wiki.asterisk.org/wiki/display/AST/Handling+Special+Extensions:
>>
>> "When a call is hung up, Asterisk executes the h extension in the current context."
>
> This is a change in functionality to the less from 1.4 (which I'm
> converting my dialplan from)
>
> In 1.4 an AEL macro was implemented with the Macro-application and not
> gosub, and my example works.
> The h-exten is run in the calling context, despite that hangup occurs in
> the Macro.
>
>    -- Executing [incoming at conference:2] Macro("SIP/trunk-00000000",
> "testmacro") in new stack
>    -- Executing [s at macro-testmacro:1] NoOp("SIP/trunk-00000000",
> "Running testmacro!") in new stack
>    -- Executing [s at macro-testmacro:2] Wait("SIP/trunk-00000000", "20")
> in new stack
>  == Spawn extension (macro-testmacro, s, 2) exited non-zero on
> 'SIP/trunk-00000000' in macro 'testmacro'
>  == Spawn extension (conference, incoming, 2) exited non-zero on
> 'SIP/trunk-00000000'
>    -- Executing [h at conference:1] NoOp("SIP/trunk-00000000", "Called
> from the context that invokes the macro - THIS DOESN'T WORK") in new stack
>
> This change in >1.6 makes it hard to actually use macros for anything
> complex as I have to duplicate hangup-code in every macro, and even
> duplicate the same macro for different contexts calling the macro!
>
> To add to that, in 1.4 there was channel variables to know the context
> invoking the macro. This is also less functionality in newer versions.
> For the call above these variables are set in 1.4:
>
> MACRO_DEPTH=1
> MACRO_PRIORITY=2
> MACRO_CONTEXT=conference
> MACRO_EXTEN=incoming
>
> None of these variables are present anymore.

I have created a function called STACK_PEEK() which would provide the
equivalent values.  It is on reviewboard here:
https://reviewboard.asterisk.org/r/1776/

> If these variables were present in 1.8 and forward you could make a work
> around like this:
>
> catch h {
>  if (!${DIALPLAN_EXISTS(${MACRO_CONTEXT},h,1)}) {
>    goto ${MACRO_CONTEXT}, h, 1;
>  }
> }

catch h {
  for (i=1;${STACK_PEEK(${i},p)};i=${i}+1) {
    if (${DIALPLAN_EXISTS(${STACK_PEEK(${i},c)},h,1)}) {
      goto ${STACK_PEEK(${i},c)},h,1;
    }
  }
}

> I would argue that this should be inserted by default by the ael-parser
> to make asterisk behave like in 1.4.
> This way macro's would be much more flexible and useful even in complex
> dialplans.

You are more than welcome to try to modify the AEL compile code
in res/ael/pval.c to get that code inserted.  Or, alternatively, you're
welcome to try to persuade Steve Murphy (the author) to insert it for
you.  That code is deep juju, and I'm not going there if I don't have to.

-Tilghman



More information about the asterisk-dev mailing list