Hello,

false is 0 and it was actually designed for setting global parameters,
not for use as comparison with functions return code or as parameter for
return from route blocks. Like:

log_stderror = false

The grammar of the language defines a coupe of token variants for same
purpose:


   YES         "yes"|"true"|"on"|"enable"
   NO          "no"|"false"|"off"|"disable"

Where YES is replaced by 1 and NO is replaced by 0:

   <INITIAL>{YES}          { count(); yylval.intval=1;
                               yy_number_str=yytext; return NUMBER; }
   <INITIAL>{NO}           { count(); yylval.intval=0;
                               yy_number_str=yytext; return NUMBER; }

In the devel version (upcoming 5.7.0), the evaluation of return mode can
be controlled by core parameter return_mode, allowing to switch to a
more "standard" mode, similar to other scripting languages -- see:

  - https://www.kamailio.org/wikidocs/cookbooks/devel/core/#return_mode

Cheers,
Daniel

On 28.04.23 08:14, Patrick Wakano wrote:
> Hi list,
> Hope you are all well!
>
> I'm using Kamailio version 5.6.4 (installed from the repo
> rpm.kamailio.org/centos/7 <http://rpm.kamailio.org/centos/7>) and
> noticed that every route that uses "return false" is exiting the
> script, instead of returning.... This was not the case on version
> 5.4.6 as the same script is running fine..... 
> From this page
> https://www.kamailio.org/wikidocs/tutorials/faq/main/#how-is-the-function-return-code-evaluated,
> I would think that when a route returns false, it would return -1 and
> not stop execution, since negative is equal to false, but it is
> actually stopping (same as return 0)...
> So, as an example, this test code doesn't work as expected. In case
> the source is a public IP, the script doesn't print the "SRC public"
> it just exits and then of course every other logic meant to be done is
> not executed....
>
> route[is_src_private]
> {
>         if (is_ip_rfc1918("$si")) {
>                 return true;
>         }
>         return false;
>         #return is_ip_rfc1918("$si"); *# this doesn't work too in case
> the $si is a public IP*
> }
> request_route
> {
> ...
>         if (route(is_src_private)) {
>                 xlog("L_NOTICE", "SRC private\n");
>         } else {
>                 xlog("L_NOTICE", "SRC public\n");
>         }
> ...
> }
> If is_src_private is changed to return -1 instead of false, then it
> all works fine.
>
> Also, I noticed that the following code will print "TEST: 0" in case
> the $si is public and then stop execution. So looks like false is
> really being converted to 0, but I guess that's unexpected... anyway
> apologies if I'm missing something obvious....
> route[is_src_private]
> {
>         $var(t) = false;
>         if (is_ip_rfc1918("$si")) {
>                 $var(t) = true;
>         }
>         xlog("L_ERR", "TEST: $var(t)\n");
>         return $var(t);
> }
>
> I could not find a recent ticket or email related to this situation
> and I've already spent hours trying to understand what is the
> logic/problem here, so would anyone have been across a similar case
> that could provide some insight and clarify what is the expected
> behaviour of the *false* usage (and boolean in general if possible)?
>
> Thank you,
> Kind regards,
> Patrick Wakano
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions
> To unsubscribe send an email to sr-users-le...@lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the 
> sender!
> Edit mailing list options or unsubscribe:


-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio World Conference - June 5-7, 2023 - www.kamailioworld.com
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:

Reply via email to