Consider $rc.

—
Sent from mobile, apologies for brevity and errors.

> On Apr 2, 2023, at 1:01 PM, Chaigneau, Nicolas 
> <nicolas.chaign...@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-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:
__________________________________________________________
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