Hi,
we recently stumbled upon the following problem:
We had something like this in our route:
$var(ret) = allow_address("2");
if ($var(ret)) { do_something; }
Turns out, this always evaluates to true, no matter whether the IP address really is in address group 2 or not. The values in $var(ret) are 1 or -1, depending on the outcome of allow_address().
However, if we write it this way
if (allow_address("2")) { do_something; }
the code inside is only executed if the IP address is in address group 2.
Is this some kind of inconsistency? Should negative values in variables evaluate to true or false?
Best Regards, Sebastian
Hi Sebastian,
The existence of this:
https://www.kamailio.org/wiki/cookbooks/5.0.x/pseudovariables#rc_-_returned_...
Makes me think that the return value of functions cannot be captured by assigning an arbitrary variable in this manner:
$var(ret) = func(...);
-- Alex
Hi,
On Wed, Aug 23, 2017 at 9:47 AM, Alex Balashov abalashov@evaristesys.com wrote:
Makes me think that the return value of functions cannot be captured by assigning an arbitrary variable in this manner:
Well, I printed out the content of the variable while debugging and it carried 1 or -1 depending on the outcome of allow_address(), so this basically seems to work.
Best Regards, Sebastian
On Wed, Aug 23, 2017 at 10:34:03AM +0200, Sebastian Damm wrote:
Well, I printed out the content of the variable while debugging and it carried 1 or -1 depending on the outcome of allow_address(), so this basically seems to work.
Fair enough. Then it really is a case of evaluation rules being different for variables than for inline function calls.
Hello,
On 23.08.17 10:36, Alex Balashov wrote:
On Wed, Aug 23, 2017 at 10:34:03AM +0200, Sebastian Damm wrote:
Well, I printed out the content of the variable while debugging and it carried 1 or -1 depending on the outcome of allow_address(), so this basically seems to work.
Fair enough. Then it really is a case of evaluation rules being different for variables than for inline function calls.
this kind of inconsistency it's a bag that had to be carried over the time due to initial version of the scripting language back in 2001-2002 when it was decided how to evaluate the return codes for functions/routing blocks. At that moment there were no config variables, so it was considered to make it simple with:
- evaluate negative return to false - evaluate 0 (zero) return to 'exit' - evaluate positive return to true
Starting with year like 2004-2005, with the addition of the variables, they were evaluated as integer numbers, more or less like in C. Boolean variables are not defined for config, so it is better (and more explicit) to evaluate PVs values against numbers.
In short: boolean evaluation of a return code for a function is done differently that the evaluation of returned value by a variable.
Cheers, Daniel
Hi Daniel,
thanks für the explanation.
Best Regards, Sebastian
On Wed, Aug 23, 2017 at 3:07 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Hello,
On 23.08.17 10:36, Alex Balashov wrote:
On Wed, Aug 23, 2017 at 10:34:03AM +0200, Sebastian Damm wrote:
Well, I printed out the content of the variable while debugging and it carried 1 or -1 depending on the outcome of allow_address(), so this basically seems to work.
Fair enough. Then it really is a case of evaluation rules being different for variables than for inline function calls.
this kind of inconsistency it's a bag that had to be carried over the time due to initial version of the scripting language back in 2001-2002 when it was decided how to evaluate the return codes for functions/routing blocks. At that moment there were no config variables, so it was considered to make it simple with:
- evaluate negative return to false
- evaluate 0 (zero) return to 'exit'
- evaluate positive return to true
Starting with year like 2004-2005, with the addition of the variables, they were evaluated as integer numbers, more or less like in C. Boolean variables are not defined for config, so it is better (and more explicit) to evaluate PVs values against numbers.
In short: boolean evaluation of a return code for a function is done differently that the evaluation of returned value by a variable.
Cheers, Daniel
-- Daniel-Constantin Mierla www.twitter.com/miconda -- www.linkedin.com/in/miconda Kamailio Advanced Training - www.asipto.com Kamailio World Conference - www.kamailioworld.com