[asterisk-users] ExecIf and empty variables (early evaluation)

Danny Nicholas danny at debsinc.com
Wed Jul 22 08:30:03 CDT 2009


You should submit this as a bug.  It may or may not get fixed, but it
definitely won't until someone reports it or takes it upon themselves to fix
it.  

-----Original Message-----
From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Benny Amorsen
Sent: Wednesday, July 22, 2009 7:44 AM
To: asterisk-users at lists.digium.com
Subject: [asterisk-users] ExecIf and empty variables (early evaluation)

Imagine that you have this code:

exten => _X!,n,Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}))

If ${QueueName} happens to be unset, this will cause a warning:

[Jul 22 14:26:17] ERROR[8114]: app_queue.c:5187
queue_function_queuewaitingcount: QUEUE_WAITING_COUNT requires an
argument: queuename

The obvious solution:

exten => _X!,n,ExecIf($["${QueueName}" !=
""]?Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}))

However, this doesn't actually work! Functions and variables on the
right hand side are evaluated BEFORE it is decided whether it needs to
be executed at all!

This is fairly harmless in this case, in that it just causes a warning.
However, what about this case?

exten => _X!,n,ExecIf($[${bar} < 10]?Set(foo=${INC(bar)}))

Which you can argue that this code is in poor taste, it is definitely
surprising that INC is evaluated in this case, changing ${bar} even if
${bar} >= 10.

It probably isn't possible to do something about this, but now you have
all been warned... This could be a good reason for avoiding side effects
in functions, and thereby banning ${INC()}


/Benny



_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users




More information about the asterisk-users mailing list