Summary: | ASTERISK-10431: AEL & CUT | ||
Reporter: | non-poster (non-poster) | Labels: | |
Date Opened: | 2007-10-02 14:16:04 | Date Closed: | 2007-10-03 12:59:48 |
Priority: | Minor | Regression? | No |
Status: | Closed/Complete | Components: | PBX/pbx_ael |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) aelswitchfuncfix.patch | |
Description: | CUT doesn't seem to work like I would expect. This works: macro route-enum-2(exten, Timeout, DialOpts, dns) { Set(ENLCOUNT=${ENUMLOOKUP(+${exten},ALL,c,,${dns})}); if (${ENLCOUNT} > 0 ) { for(count=1;${count} <= ${ENLCOUNT};count=${count} + 1) { Set(ENL=${ENUMLOOKUP(+${exten},ALL,,${count},${dns})}); if (${LEN(${ENL})} > 0) { if ("${ENL:0:3}" = "sip") { Dial(SIP/${ENL:4},${Timeout},o${DialOpts}); } else if ("${ENL:0:4}" = "iax2") { Dial(IAX2/${ENL:5},${Timeout},o${DialOpts}); } else if ("${ENL:0:4}" = "h323") { Dial(H323/${ENL:5},${Timeout},o${DialOpts}); }; }; }; }; }; This doesn't work: switch (${CUT(ENL,:,1)}) { case sip: Dial(SIP/${ENL:4},${Timeout},o${DialOpts}); break; case iax2: Dial(IAX2/${ENL:5},${Timeout},o${DialOpts}); break; case h323: Dial(H323/${ENL:5},${Timeout},o${DialOpts}); break; default: NoOp(blah); }; Asterisk 1.4.11, gcc 4.1.2, glibc 2.5, amd64 | ||
Comments: | By: Jason Parker (jparker) 2007-10-02 14:25:28 How is it that you expect it to work? By: non-poster (non-poster) 2007-10-02 14:53:22 > core show function CUT -= Info about function 'CUT' =- [Syntax] CUT(<varname>,<char-delim>,<range-spec>) [Synopsis] Slices and dices strings, based upon a named delimiter. [Description] varname - variable you want cut char-delim - defaults to '-' range-spec - number of the field you want (1-based offset) may also be specified as a range (with -) or group of ranges and fields (with &) I would expect my example (eg ${CUT(ENL,:,1)} ) to return the first group of characters that precede the ":" character. By: Steve Murphy (murf) 2007-10-02 15:01:16 Pardon me, I'm a total noob with ENUM. So, please, try: Set(x291=${CUT(ENL,:,1)}); NoOp(the result of cut is '${x291}'...); switch(${x291}) { ... and so on... and tell me what that NoOp displays on the console...? By: non-poster (non-poster) 2007-10-02 19:45:18 Hmm. NoOp(the result of cut is '${x291}'...) gives "sip", as expected. Then this works: Set(x291=${CUT(ENL,:,1)}); switch (${x291}) { case sip: ... But this doesn't: switch (${CUT(ENL,:,1)}) { case sip: ... Here's the trace: -- Executing [s@macro-route-enum-2:10] NoOp("SIP/nonposter-006f7da0", "ENL is sip:16416418003733411@sip.tollfreegateway.com") in new stack -- Executing [s@macro-route-enum-2:11] Set("SIP/nonposter-006f7da0", "x291=sip") in new stack -- Executing [s@macro-route-enum-2:12] NoOp("SIP/nonposter-006f7da0", "the result of cut is 'sip'...") in new stack -- Executing [s@macro-route-enum-2:13] Goto("SIP/nonposter-006f7da0", "sw-27-|10") in new stack -- Goto (macro-route-enum-2,sw-27-,10) 10. NoOp(ENL is ${ENL}) [pbx_ael] 11. Set(x291=${CUT(ENL|:|1)}) [pbx_ael] 12. NoOp(the result of cut is '${x291}'...) [pbx_ael] 13. Goto(sw-27-${CUT(ENL,:,1)}|10) [pbx_ael] 14. NoOp(Finish switch-for-if-route-enum-2-25-26-27) [pbx_ael] 15. Set(count=$[${count} + 1]) [pbx_ael] 16. Goto(8) [pbx_ael] 17. NoOp(Finish for-if-route-enum-2-25-26) [pbx_ael] 18. NoOp(Finish if-route-enum-2-25) [pbx_ael] 'sw-27-h323' => 10. Dial(H323/${ENL:5}|${Timeout}|o${DialOpts}) [pbx_ael] 11. Goto(s|14) [pbx_ael] 'sw-27-iax2' => 10. Dial(IAX2/${ENL:5}|${Timeout}|o${DialOpts}) [pbx_ael] 11. Goto(s|14) [pbx_ael] 'sw-27-sip' => 10. Dial(SIP/${ENL:4}|${Timeout}|o${DialOpts}) [pbx_ael] 11. Goto(s|14) [pbx_ael] '_sw-27-.' => 10. NoOp(blah) [pbx_ael] 11. Goto(s|14) [pbx_ael] I guess I'll assign the result from CUT to a variable in my dialplan instead of using CUT directly. (I thought I tried this already... lack of sleep...) By: Steve Murphy (murf) 2007-10-03 09:57:27 Uh, one last thing: Try: switch(${CUT(ENL|:|1)}) { ... instead, and see if that works. I suspect it will. The issue is the separators, it appears, and AEL is not turning commas in such a case into vertical bars. Hmmm. Do I need to worry about this in AEL? and not turn '\,' into a vertical bar, but rather into just ',' so that you can pass commas into funcs if need be? By: Steve Murphy (murf) 2007-10-03 12:51:54 OK, I'm reproducing this and I see: [Oct 3 12:00:21] ERROR[15838]: func_cut.c:246 acf_cut_exec: Syntax: CUT(<varname>,<char-delim>,<range-spec>) - missing argument! on the console (I do have verbose set > 3 ) don't you? It's complaining that I'm using commas instead of vertbars for arg separators. I'll publish my patch here... actually, I'm going to commit this to 1.4 in a few moments, but you are welcome to use the patch if you desire. By: Digium Subversion (svnbot) 2007-10-03 12:59:47 Repository: asterisk Revision: 84544 U branches/1.4/pbx/pbx_ael.c ------------------------------------------------------------------------ r84544 | murf | 2007-10-03 12:59:46 -0500 (Wed, 03 Oct 2007) | 1 line closes issue ASTERISK-10431 ; where a CUT() function call in a switch expr doesn't execute correctly, because the commas in the function args are not converted to vertbars before the func is called. I modified just the switch code to convert the commas to vertbars if there, but if more of these sort of probs are found, I may have to resort to something a little more fundamental. We'll see, I guess. ------------------------------------------------------------------------ |