[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:05:05 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:                     acknowledged
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:05 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).
====================================================================== 

---------------------------------------------------------------------- 
 Corydon76 - 02-11-08 12:05  
---------------------------------------------------------------------- 
blitzrage: no, you would have only executed the SET once.  putnopvut was
initially correct, the values are all evaluated before the application is
run.  If you want to conditionally evaluate something, then you need to use
two functions, i.e.

NoOp(${SET(TIME_USED=${IF($[${DIALSTATUS} =
ANSWER]?$[0${ANSWEREDTIME}/60]:0)})})

The innermost section is evaluated first, followed by each enclosing
section in turn, and the final string is passed back to the application to
run.

This is an evaluation language, not an interpreted language, so the
behavior is to be expected. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
02-11-08 12:05  Corydon76      Note Added: 0082025                          
======================================================================




More information about the asterisk-bugs mailing list