[Home]

Summary:ASTERISK-04540: [patch] if-else statements in extensions.ael does not work as documented
Reporter:Bradley Watkins (marquis)Labels:
Date Opened:2005-07-08 16:29:51Date Closed:2008-01-15 15:48:47.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:PBX/pbx_ael
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) ael_gotofix.patch
( 1) README.ael.txt
Description:If you put the example from the README.ael into extensions.ael it will report "WARNING[4185]: pbx_ael.c:129 __grab_token: Syntax error at line 14 of 'extensions.ael', too many closing braces!"

Here is the entirety of the extensions.ael that gives this:

context ael-demo {

       s => {
           Wait(1);
       };
       100 => {
               Dial(SIP/${EXTEN});
               if (${DIALSTATUS} = "BUSY") {
                       Voicemail(${EXTEN}|b);
               } else
                        Voicemail(${EXTEN}|u);
       };
};


And here is the resulting dialplan:

*CLI> show dialplan ael-demo
[ Context 'ael-demo' created by 'pbx_ael' ]
 '100' =>          1. Dial(SIP/${EXTEN})                         [pbx_ael]
                   2. Goto(${IF($[ ${DIALSTATUS} = "BUSY" ]?3:4)}) [pbx_ael]
                   3. Voicemail(${EXTEN}|b)                      [pbx_ael]
                   4. NoOp(Finish if-100-2)                      [pbx_ael]
 's' =>            1. Wait(1)                                    [pbx_ael]

-= 2 extensions (5 priorities) in 1 contexts. =-

Comments:By: Michael Jerris (mikej) 2005-07-08 16:34:33

Looks like it is missing the braces around the else.  Could you provide a patch to fix this please?

By: Paul Belanger (pabelanger) 2005-07-09 11:24:56

This should do the trick.  Are disclamiers required on READMEs?  Anyways, disclamier will be sent in.

By: Clod Patry (junky) 2005-07-09 11:55:59

I disagree with this patch, cause if you just adding the braces for the else: here's what you got:
debian*CLI> show dialplan ael-demo
[ Context 'ael-demo' created by 'pbx_ael' ]
 '100' =>          1. Dial(SIP/${EXTEN})                         [pbx_ael]
 's' =>            1. Wait(1)                                    [pbx_ael]
debian*CLI>

There's no conditional route here.

Another alternative to that is to remove the brace for the if condition:
context ael-demo2 {

       s => {
           Wait(1);
       };
       100 => {
               Dial(SIP/${EXTEN});
               if (${DIALSTATUS} = "BUSY")
                       Voicemail(${EXTEN}|b);
               else
                        Voicemail(${EXTEN}|u);
       };
};
works fine.

and :
...
       100 => {
               Dial(SIP/${EXTEN});
               if (${DIALSTATUS} = "BUSY")
                       Voicemail(${EXTEN}|b);
               else {
                        Voicemail(${EXTEN}|u);
               }
       };
...

works fine too.

but that whole context doesn't work.
context ael-demo2 {

       s => {
           Wait(1);
       };
       100 => {
               Dial(SIP/${EXTEN});
               if (${DIALSTATUS} = "BUSY") {
                       Voicemail(${EXTEN}|b);
                       Noop(foo);
               } else {
                       Voicemail(${EXTEN}|u);
                       NoOp(bar);
               }
       };
};

there's no error on reload, but see the dialplan:
[ Context 'ael-demo2' created by 'pbx_ael' ]
 '100' =>          1. Dial(SIP/${EXTEN})                         [pbx_ael]
 's' =>            1. Wait(1)                                    [pbx_ael]

-= 2 extensions (2 priorities) in 1 contexts. =-
debian*CLI>


There's nothing about my conditional here.

So i think another patch is needed.

By: Michael Jerris (mikej) 2005-07-09 12:17:08

After testing, junky is right, however, I was under the impression that braces around if clauses were supported.  Was I wrong, or is there a bug in the parser?

By: Clod Patry (junky) 2005-07-09 12:21:47

My feel is a problem with the parser.

By: Bradley Watkins (marquis) 2005-07-09 12:49:54

I agree that this is an issue with the parser.  Irrespective of what syntax is "correct", none of them work properly.  My feeling, however, is that braces should be required around both the if and the else clauses if an else is present.

By: Terry Wilson (twilson) 2005-08-01 14:28:28

Anyone know where we are on getting this fixed in CVS?

By: Tilghman Lesher (tilghman) 2005-08-01 15:13:59

twilson:  if you can fix it, you're welcome to submit a patch.

By: Michael Jerris (mikej) 2005-08-26 18:49:48

Can somone please re-test this with current head.  If handling was changed a bit today.

By: J.W.Hoogervorst (jeroenho) 2005-09-05 06:29:24

Tested with 1.20beta last weekend, got something similar:

  _40X. => {
     System(/usr/local/bin/asterisk2heyu ${EXTEN:2});
     Playback(num-was-successfully);
     if (${EXTEN:3} = 0) {
        Playback(disabled);
     } else
        Playback(enabled);
     Hangup;


 '_40X.' =>        1. System(/usr/local/bin/asterisk2heyu ${EXTEN:2}) [pbx_ael]
                   2. Playback(num-was-successfully)             [pbx_ael]
                   3. Goto(${IF($[ ${EXTEN:3} = 0 ]?4:6)})       [pbx_ael]
                   4. Playback(disabled)                         [pbx_ael]
                   5. GotoIf(7)                                  [pbx_ael]
                   6. Playback(enabled)                          [pbx_ael]
                   7. NoOp(Finish if-_40X.-3)                    [pbx_ael]
                   8. Hangup()                                   [pbx_ael]

This results in both disabled and enabled being played.
Braces don't change behaviour, tried every combination.
For now I revesed the GotoIf patch, so it uses plain Goto's on line 5.

By: Russell Bryant (russell) 2005-09-16 13:46:58

So that example looks like it is really close to being correct, except for the GotoIf instead of Goto on line 5.  Is that what you are seeing here?

By: Russell Bryant (russell) 2005-09-16 14:04:18

I believe that this patch is all that is needed to fix this problem.

While the change was made from Goto to GotoIf to define the if clause, the Goto that ends the if section needs to still use a Goto.

By: Russell Bryant (russell) 2005-09-16 14:06:35

Example using this patch:

context ael_test {
 _40X. => {
     System(/usr/local/bin/asterisk2heyu ${EXTEN:2});
     Playback(num-was-successfully);
     if (${EXTEN:3} = 0) {
        Playback(disabled);
     } else
        Playback(enabled);
     Hangup;
 };
};

[ Context 'ael_test' created by 'pbx_ael' ]
 '_40X.' =>        1. System(/usr/local/bin/asterisk2heyu ${EXTEN:2}) [pbx_ael]
                   2. Playback(num-was-successfully)             [pbx_ael]
                   3. GotoIf($[ ${EXTEN:3} = 0 ]?4:6)            [pbx_ael]
                   4. Playback(disabled)                         [pbx_ael]
                   5. Goto(7)                                    [pbx_ael]
                   6. Playback(enabled)                          [pbx_ael]
                   7. NoOp(Finish if-_40X.-3)                    [pbx_ael]
                   8. Hangup()                                   [pbx_ael]

-= 1 extensions (8 priorities) in 1 contexts. =-

By: J.W.Hoogervorst (jeroenho) 2005-09-17 02:54:19

Yes, that fixes the problem. Thanks!

By: Russell Bryant (russell) 2005-09-22 23:00:11

fixed in cvs head

By: Digium Subversion (svnbot) 2008-01-15 15:48:47.000-0600

Repository: asterisk
Revision: 6629

U   trunk/pbx/pbx_ael.c

------------------------------------------------------------------------
r6629 | russell | 2008-01-15 15:48:47 -0600 (Tue, 15 Jan 2008) | 2 lines

Use Goto instead of GotoIf when jumping over the else block (issue ASTERISK-4540)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=6629