[asterisk-bugs] [Asterisk 0011957]: Dialplan functions are executed before conditions are evaluated

noreply at bugs.digium.com noreply at bugs.digium.com
Mon Feb 11 12:51:53 CST 2008


A NOTE has been added to this issue. 
====================================================================== 
http://bugs.digium.com/view.php?id=11957 
====================================================================== 
Reported By:                blitzrage
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   11957
Category:                   Applications/app_exec
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     feedback
Asterisk Version:           1.4.17 
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Disclaimer on File?:        N/A 
Request Review:              
====================================================================== 
Date Submitted:             02-08-2008 11:29 CST
Last Modified:              02-11-2008 12:51 CST
====================================================================== 
Summary:                    Dialplan functions are executed before conditions
are evaluated
Description: 
I'm opening this for a bit of discussion as I believe the following
conditions could result in inefficiencies in the dialplan.

I have the following bit of dialplan code:

exten => h,n,Verbose(1,DIALSTATUS = ${DIALSTATUS})
exten => h,n,ExecIf($[${DIALSTATUS} =
ANSWER],Set,TIME_USED=${MATH(${ANSWEREDTIME}/60,f)})


But when I execute it in the dialplan, I end up with this:

    -- Executing [h at subPlaceCall:2] Verbose("SIP/4918847473-1565e170",
"1|DIALSTATUS = CANCEL") in new stack
 DIALSTATUS = CANCEL
[Feb  8 12:21:51] WARNING[19032]: func_math.c:169 math: '' is not a valid
number
    -- Executing [h at subPlaceCall:3] ExecIf("SIP/4918847473-1565e170",
"0|Set|TIME_USED=") in new stack


Which appears to be that the MATH() function is being executed before the
condition is checked. That seems backwards to me in that the condition
should be checked before any action is taken on the arguments provided.

I've seen the same behaviour with the IF() function as well:

exten => h,n,Exec(${IF(${DIALSTATUS} =
ANSWER]?Set(TIME_USED=${MATH(${ANSWEREDTIME}/60,f)}):NoOp())})

Same behaviour happens where MATH() returns an error because
${ANSWEREDTIME} is not populated (and it shouldn't be -- the call was not
answered).
====================================================================== 

---------------------------------------------------------------------- 
 blitzrage - 02-11-08 12:51  
---------------------------------------------------------------------- 
OK... but in your example, you're not using the MATH() function... which I
was using because I needed a floating point number back. But even with your
example, since the inner most function is being executed, then MATH()
always gets executed,  even when ${ANSWEREDTIME} is NULL.

I'd just use a Goto() to skip over it if ANSWEREDTIME was NULL, but you
can't do that in the 'h' extension without changing the CDR record... 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
02-11-08 12:51  blitzrage      Note Added: 0082034                          
======================================================================




More information about the asterisk-bugs mailing list