Hello,
we can control/decide how to interpret returned codes on our config
language interpreter written from scratch, but not how it is done by an
external interpreter written by others.
Cheers,
Daniel
On 03.04.23 00:20, Chaigneau, Nicolas wrote:
Thanks Alex :)
I searched for $rc and found this:
The definition of the sub-route block follows the general rules, with a name in between
square brackets and actions between curly braces. A sub-route can return an integer value
back to the routing block that executed it. The return code can be retrieved via $rc
variables.
Evaluation of the return of a subroute is done with following rules:
negative value is evaluated as false
0 - is interpreted as exit
positive value is evaluated as true
I assume this also applies to command functions, not just "route" blocks.
But this only applies to Kamailio script, not to KEMI, is that correct ?
If so, do you know why the behavior is not the same in KEMI script ?
Regards,
Nicolas.
-----Message d'origine-----
De : Alex Balashov <abalashov(a)evaristesys.com>
Consider $rc.
On Apr 2, 2023, at 1:01 PM, Chaigneau, Nicolas
<nicolas.chaigneau(a)capgemini.com> wrote:
Hello,
I have a question regarding Kamailio script and how the return code from a command export
is handled as a boolean.
In Kamailio script, see this example:
if (!jansson_get("method", $rb, "$var(method)")) {
xhttp_reply("400", "Bad Request", "",
"");
exit;
}
This code works, but I'm not sure why.
Command "jansson_get" returns 1 if successful, and -1 if fails. Both values
should be false.
Which I can see when testing with this:
$var(r) = jansson_get("method", $rb, "$var(method)");
xlog("L_INFO", "jansson_get r: [$var(r)]\n");
if (!$var(r)) {
xlog("L_INFO", "jansson_get r: [$var(r)] =>
FALSE\n");
} else {
xlog("L_INFO", "jansson_get r: [$var(r)] => TRUE\n");
}
In all cases, the result is always TRUE.
Is there some kind of "magic" conversion when directly checking the return of a
command in Kamailio script ?
With KEMI python, the equivalent does not work:
if not KSR.jansson.get("method", KSR.pv.get("$rb"),
"$var(method)"):
KSR.xhttp.xhttp_reply(400, "Bad Request", "",
"")
return 1
So I have to do the following instead:
if KSR.jansson.get("method", KSR.pv.get("$rb"),
"$var(method)") < 0:
KSR.xhttp.xhttp_reply(400, "Bad Request", "",
"")
return 1
Thank you for your help.
Regards,
Nicolas.
This message contains information that may be privileged or confidential and is
the property of the Capgemini Group. It is intended only for the person to whom it is
addressed. If you are not the intended recipient, you are not authorized to read, print,
retain, copy, disseminate, distribute, or use this message or any part thereof. If you
receive this message in error, please notify the sender immediately and delete all copies
of this message.
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-leave(a)lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe: