[Asterisk-Users] AEL scripting, CUT use and string concatenation

Marcello Lupo lupo at itspecialist.it
Mon Jun 26 08:30:17 MST 2006


Hi to all,
i'm wondering to realize a dynamic macro that can take the number of 
extensions to RING,the ring type and all the parameter in a dynamic way.

I have done this code to test it:

macro pbx-ring-group-ael(pbx_id,num_int,ring_type,timeout,ext_string) {
//; pbx_id = Id of PBX in the DB
//; num_int = Quantity of extensions to ring
//; ring_type = Kind of RING (C=contemporaneous S=sequential)
//; timeout = Amount of time to ring
//; ext_string = String with extension numbers like 101-102-103-104-105

         if(${ring_type}=C) {
                 for (x=1 ; ${x} <= ${num_int} ; x=${x} + 1) {
                         int=${CUT(ext_string,,${x})};
                         if(${x} = 1) {
                                 dialstring=SIP/${pbx_id}-${int};
                         } else {
 
dialstring=${dialstring}&SIP/${pbx_id}-${int};
                         };
                         if(${x} = ${num_int}) {
                                 dialstring=${dialstring}|${timeout};
                         };

                         NoOp(STRING ${dialstring});
                 };
         };
         Hangup();
};

I'm getting problems both in the CUT expression and the concatenation of 
strings due to the presence of &,/,- in it. I think something can be 
done with double quote but it will be inserted as part of the string, so 
the concatenation will fail.
For the CUT i don't know what is the problem. I tried with 
CUT(int=(ext_string,,${x}) too but without success.

This is the dialplan resulting from the expansion of the ael script:

show dialplan macro-pbx-ring-group-ael
[ Context 'macro-pbx-ring-group-ael' created by 'pbx_ael' ]
   's' =>            1. Set(pbx_id=${ARG1})                [pbx_ael]
                     2. Set(num_int=${ARG2})               [pbx_ael]
                     3. Set(ring_type=${ARG3})             [pbx_ael]
                     4. Set(timeout=${ARG4})               [pbx_ael]
                     5. Set(ext_string=${ARG5})            [pbx_ael]
                     6. GotoIf($[ ${ring_type}=C ]?7:22)   [pbx_ael]
                     7. Set(x=$[ 1 ])                      [pbx_ael]
                     8. GotoIf($[ ${x} <= ${num_int} ]?9:21)   [pbx_ael]
                     9. Set(x=$[ ${x} + 1 ])               [pbx_ael]
                     10. Set(int=$[ ${CUT(ext_string,,${x})} ]) [pbx_ael]
                     11. GotoIf($[ ${x} = 1 ]?12:14)       [pbx_ael]
                     12. Set(dialstring=$[ SIP/${pbx_id}-${int} ]) [pbx_ael]
                     13. Goto(15)                          [pbx_ael]
                     14. Set(dialstring=$[ 
${dialstring}&SIP/${pbx_id}-${int} ]) [pbx_ael]
                     15. NoOp(Finish 
if-for-if-pbx-ring-group-ael-6-7-11) [pbx_ael]
                     16. GotoIf($[ ${x} = ${num_int} ]?17:18) [pbx_ael]
                     17. Set(dialstring=$[ ${dialstring}|${timeout} ]) 
[pbx_ael]
                     18. NoOp(Finish 
if-for-if-pbx-ring-group-ael-6-7-16) [pbx_ael]
                     19. NoOp(STRING ${dialstring})         [pbx_ael]
                     20. Goto(8)                            [pbx_ael]
                     21. NoOp(Finish for-if-pbx-ring-group-ael-6-7) 
[pbx_ael]
                     22. NoOp(Finish if-pbx-ring-group-ael-6)      [pbx_ael]
                     23. Hangup()                            [pbx_ael]

-= 1 extension (23 priorities) in 1 context. =-

This is the log of errors:

     -- Executing Macro("SIP/1234-100-b263", 
"pbx-ring-group-ael|1234|5|C|20|101-102-103-104-105") in new stack
     -- Executing Set("SIP/1234-100-b263", "pbx_id=1234") in new stack
     -- Executing Set("SIP/1234-100-b263", "num_int=5") in new stack
     -- Executing Set("SIP/1234-100-b263", "ring_type=C") in new stack
     -- Executing Set("SIP/1234-100-b263", "timeout=20") in new stack
     -- Executing Set("SIP/1234-100-b263", 
"ext_string=101-102-103-104-105") in new stack
     -- Executing GotoIf("SIP/1234-100-b263", "1?7:22") in new stack
     -- Goto (macro-pbx-ring-group-ael,s,7)
     -- Executing Set("SIP/1234-100-b263", "x=1") in new stack
     -- Executing GotoIf("SIP/1234-100-b263", "1?9:21") in new stack
     -- Goto (macro-pbx-ring-group-ael,s,9)
     -- Executing Set("SIP/1234-100-b263", "x=2") in new stack
Jun 26 17:17:24 WARNING[31282]: ast_expr2.fl:176 ast_yyerror: 
ast_yyerror(): syntax error: syntax error, unexpected $end, expecting 
TOK_MINUS or TOK_COMPL or TOK_LP or TOKEN; Input:

   ^
Jun 26 17:17:24 WARNING[31282]: ast_expr2.fl:180 ast_yyerror: If you 
have questions, please refer to doc/README.variables in the asterisk source.
     -- Executing Set("SIP/1234-100-b263", "int=0") in new stack
     -- Executing GotoIf("SIP/1234-100-b263", "0?12:14") in new stack
     -- Goto (macro-pbx-ring-group-ael,s,14)
Jun 26 17:17:24 WARNING[31282]: ast_expr2.fl:176 ast_yyerror: 
ast_yyerror(): syntax error: syntax error, unexpected TOK_AND, expecting 
TOK_MINUS or TOK_COMPL or TOK_LP or TOKEN; Input:
  &SIP/1234-0
  ^
Jun 26 17:17:24 WARNING[31282]: ast_expr2.fl:180 ast_yyerror: If you 
have questions, please refer to doc/README.variables in the asterisk source.
     -- Executing Set("SIP/1234-100-b263", "dialstring=0") in new stack
     -- Executing NoOp("SIP/1234-100-b263", "Finish 
if-for-if-pbx-ring-group-ael-6-7-11") in new stack
     -- Executing GotoIf("SIP/1234-100-b263", "0?17:18") in new stack
     -- Goto (macro-pbx-ring-group-ael,s,18)
     -- Executing NoOp("SIP/1234-100-b263", "Finish 
if-for-if-pbx-ring-group-ael-6-7-16") in new stack
     -- Executing NoOp("SIP/1234-100-b263", "STRING 0") in new stack



If you have any allernative idea to reach my goal please let me know or 
if you can help me debugging this issue i will be thank you.
Bye,
Marcello







More information about the asterisk-users mailing list