Re: [asterisk-users] ExecIf and empty variables (early evaluation)
Benny Amorsen wrote: 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! Try this, as I think the IF() function works differently (I could be wrong though): exten = _X!,n,Exec(${IF($[${QueueName} != ]?Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}:NoOp())}) Leif Madsen. http://www.leifmadsen.com http://www.oreilly.com/catalog/asterisk ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
On Thursday 23 July 2009 07:24:46 Leif Madsen wrote: Benny Amorsen wrote: 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! Try this, as I think the IF() function works differently (I could be wrong though): exten = _X!,n,Exec(${IF($[${QueueName} != ]?Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}:NoOp())}) You're incorrect. The same problem follows this one. Separating the evaluation out into multiple steps is the only way I know to make this work as expected: exten = _X!,n,GosubIf(${LEN(${QueueName})}?waitingcount(foo,${QueueName})) ... exten = _X!,1000 (waitingcount),Set(${${ARG1}}=${QUEUE_WAITING_COUNT(${ARG2})}) exten = _X!,n,Return -- Tilghman Teryl with Peter, Cottontail, Midnight, Thumper, Johnny (bunnies) and Harry, BB, George (dogs) ___ -- 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
[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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
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-boun...@lists.digium.com [mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Benny Amorsen Sent: Wednesday, July 22, 2009 7:44 AM To: asterisk-users@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 ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
Benny Amorsen schrieb: 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. You could split it up into multiple statements: if (${QueueName} != ) { Set(foo=${QUEUE_WAITING_COUNT(${QueueName})}); } else { Set(foo=-1); // or whatever } (don't remember how to write that in extensions.conf format) Pros: - conditional evaluation - more readable (ExecIf() looks ugly) Cons: - more statements - less readable then a ternary conditional expression in real programming languages: foo = ($queuename != ? queue_waiting_count($queuename) : -1) 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()} Ban ExecIf(). Use AEL. Use if(){} blocks. :-) In order to use control structures like if .. else/switch .. case it's almost necessary to write your dialplan in AEL because the same thing is so incredibly hard to read and write in extensions.conf format (GotoIf()). Although very basic dialplans look good in extensions.conf my suggestion is to use AEL and let the AEL compiler figure out how to translate that into an Asterisk dialplan. Philipp Kempgen -- AMOOMA GmbH - Bachstr. 126 - 56566 Neuwied - http://www.amooma.de Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998 Asterisk: http://the-asterisk-book.com - http://das-asterisk-buch.de Videos of the AMOOCON VoIP conference 2009 - http://www.amoocon.de -- ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
On Wednesday 22 July 2009 08:30:03 Danny Nicholas wrote: 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. Don't bother. It's not fixable. -- Tilghman Teryl with Peter, Cottontail, Midnight, Thumper, Johnny (bunnies) and Harry, BB, George (dogs) ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
I see your name enough to know this must be a true statement; Can you elaborate a little on why? -Original Message- From: asterisk-users-boun...@lists.digium.com [mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Tilghman Lesher Sent: Wednesday, July 22, 2009 12:35 PM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: Re: [asterisk-users] ExecIf and empty variables (early evaluation) On Wednesday 22 July 2009 08:30:03 Danny Nicholas wrote: 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. Don't bother. It's not fixable. -- Tilghman Teryl with Peter, Cottontail, Midnight, Thumper, Johnny (bunnies) and Harry, BB, George (dogs) ___ -- 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 ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
While I can't be sure this is correct, I'd assume there are 2 pieces to executing a line of code, the first one does all the expansion and variable replacement, and the second one actually executes the line. From the behavior I'd have to guess that INC() is handled by first part and not the second. Ira I see your name enough to know this must be a true statement; Can you elaborate a little on why? On Wednesday 22 July 2009 08:30:03 Danny Nicholas wrote: 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. Don't bother. It's not fixable. ___ -- 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
Re: [asterisk-users] ExecIf and empty variables (early evaluation)
On Wednesday 22 July 2009 13:56:39 Ira wrote: Danny Nicholas wrote: Tilghman Lesher wrote: On Wednesday 22 July 2009 08:30:03 Danny Nicholas wrote: 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. Don't bother. It's not fixable. I see your name enough to know this must be a true statement; Can you elaborate a little on why? While I can't be sure this is correct, I'd assume there are 2 pieces to executing a line of code, the first one does all the expansion and variable replacement, and the second one actually executes the line. From the behavior I'd have to guess that INC() is handled by first part and not the second. That is precisely the reason. I could not have said it better myself. -- Tilghman Teryl with Peter, Cottontail, Midnight, Thumper, Johnny (bunnies) and Harry, BB, George (dogs) ___ -- 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