[SR-Users] Unquoted values from #!defenv

Ben Kaufman bkaufman at bcmone.com
Tue Dec 7 16:12:07 CET 2021


Thank you.  I've been using -A to set values thus far as CMD arguments to the container's ENTRYPOINT.  If submitting a pull request, would it be preferrable to allow #!defenv/#!defenvs to accept undefined values, or to add new keywords like #!ifdefenv/#!ifdefenvs ?

Ben Kaufman

From: Daniel-Constantin Mierla <miconda at gmail.com>
Sent: Tuesday, December 7, 2021 2:22 AM
To: Ben Kaufman <bkaufman at bcmone.com>; Kamailio (SER) - Users Mailing List <sr-users at lists.kamailio.org>
Subject: Re: [SR-Users] Unquoted values from #!defenv


The current behaviour targets the use of existing values from the environment variables. If you need other kind of features, you can propose pull requests. Or you can eventually have a start script that sets defines with -A cli parameter based on env variables.

Cheers,
Daniel
On 06.12.21 21:56, Ben Kaufman wrote:
Thank you :)

A follow up question would be on the usability of the #!defenv (and probably #!defenvs) usability with #!ifdef.  In the scenario below, if the environmental variable WITH_DEBUGGER is not defined, then Kamailio will fail to start, thus the #!ifdef is somewhat limited.  It makes sense for scenarios where someone might toggle the setting editing the config file, but it would be very convenient to toggle the environmental variable instead, particularly in containerized environments.   Any thoughts on how best to control this?

#!defenv WITH_DEBUGGER

#!ifdef WITH_DEBUGGER
loadmodule "debugger"
. . .
#!endif




Ben Kaufman

From: Daniel-Constantin Mierla <miconda at gmail.com><mailto:miconda at gmail.com>
Sent: Monday, December 6, 2021 3:55 AM
To: Kamailio (SER) - Users Mailing List <sr-users at lists.kamailio.org><mailto:sr-users at lists.kamailio.org>; Ben Kaufman <bkaufman at nexvortex.com><mailto:bkaufman at nexvortex.com>
Subject: Re: [SR-Users] Unquoted values from #!defenv


Hello,

#!substdef does not set the value inside quoted string, it replaces inside a string value, so it does not put quotes around replacement part. So it does it it is written in the docs. There is #!substdefs witch can create a define with quoted value.

Note that defines are standalone-token replacement, you can define an ID to a number, to a keyword (e.g., src_ip), to a quoted string or even a multi-line script snippet, like:

#!define IDLOOP $var(i) = 0; \
                while($var(i)<5) { \
                    xlog("++++ $var(i)\n"); \
                    $var(i) = $var(i) + 1; \
                }

See the core cookbook for more details.

Anyhow, as using env variable values as quoted string is useful and setting them with quotes might look odd, I added #!defenvs:

  * https://www.kamailio.org/wiki/cookbooks/devel/core#defenvs<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kamailio.org%2Fwiki%2Fcookbooks%2Fdevel%2Fcore%23defenvs&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006480569%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=5B%2FgzQZTVhvrCUWvrRh5YkFkKnX%2BGTA1Wy2M2L1nFQ4%3D&reserved=0>

Cheers,
Daniel
On 30.11.21 22:40, Ben Kaufman wrote:
Hello all,

Looking for some clarification regarding quoting and !#defenv .  I understand that the example below fails because the environmental variable HOME is not quoted, thus when used in the xlog() call it fails.  How is it possible to evaluate and/or use the value of the environmental variable if defined as a preprocessor variable?  Looking at the documentation the reason for this directive is "It is a simplified alternative of using #!substdef with $env(NAME) in the replacement part." But #!substdef would allow setting the value inside of a quoted string, so does it really meet that requirement?

I'm aware that I could use $env(HOME) rather than a preprocessor directive of HOME.  I'm just trying to understand the usage of the #!defenv feature.


#!KAMAILIO
## Tested in 5.5.2
loadmodule "xlog"
loadmodule "pv"
loadmodule "evrexec"

modparam("evrexec", "exec", "name=evrexec:timer;wait=1000;workers=1;")

#!defenv HOME

request_route{
    forward();
}

event_route[evrexec:timer] {
    xlog("L_N", "HOME: " + HOME + "\n");
}


Ben Kaufman






__________________________________________________________

Kamailio - Users Mailing List - Non Commercial Discussions

  * sr-users at lists.kamailio.org<mailto:sr-users at lists.kamailio.org>

Important: keep the mailing list in the recipients, do not reply only to the sender!

Edit mailing list options or unsubscribe:

  * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.kamailio.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fsr-users&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006480569%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=DKXdl%2BamQ56gwczinuP30QdCzA%2Bu9w%2BrznJ6CDU4j54%3D&reserved=0>

--

Daniel-Constantin Mierla -- www.asipto.com<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.asipto.com%2F&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006490521%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=G5z3WOwoE7RZp452Ep%2Fv439jKdM%2FyT4vp7NijzkZyNE%3D&reserved=0>

www.twitter.com/miconda<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.twitter.com%2Fmiconda&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006500482%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=fqzs23JnsKFc5dhry%2F9OX%2BWLBAb93aF0blIPjMhp5Fw%3D&reserved=0> -- www.linkedin.com/in/miconda<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fmiconda&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006500482%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=amTtFC19Fmdp%2FaLJ0M2csgXP6dspTBcWX9ecjwX6C6c%3D&reserved=0>

Kamailio Advanced Training - Online

  Feb 21-24, 2022 (America Timezone)

  * https://www.asipto.com/sw/kamailio-advanced-training-online/<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.asipto.com%2Fsw%2Fkamailio-advanced-training-online%2F&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006510433%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YKnoSY1hWoHV%2B%2F%2Fu2dyxiuHPTjMFsWKdkP%2BEJyyqtH4%3D&reserved=0>

--

Daniel-Constantin Mierla -- www.asipto.com<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.asipto.com%2F&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006510433%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=w3axlWEpxvKKM0OxDvZEm1e6v8iHaBYqcBKAHyRV0Nc%3D&reserved=0>

www.twitter.com/miconda<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.twitter.com%2Fmiconda&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006520395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=M90CGK7fa0FLI1x9XiHn0pdRgW5zgOWweh5%2F2rsVtn4%3D&reserved=0> -- www.linkedin.com/in/miconda<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fmiconda&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006520395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=KSGCqQTyNzjugyxycScxlAmn6dy414Xj2XiEcozSQng%3D&reserved=0>

Kamailio Advanced Training - Online

  Feb 21-24, 2022 (America Timezone)

  * https://www.asipto.com/sw/kamailio-advanced-training-online/<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.asipto.com%2Fsw%2Fkamailio-advanced-training-online%2F&data=04%7C01%7Cbkaufman%40bcmone.com%7Cbe35f30c00944bc8f2fe08d9b95a962b%7Cafc1818e7b6848568913201b9396c4fc%7C1%7C0%7C637744621006530350%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=HxYGUiXlv6FAnKX9K6N3DmtBY%2FuIQ7s5MTd7QG1Ozz0%3D&reserved=0>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20211207/c71faa0a/attachment.htm>


More information about the sr-users mailing list