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
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(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:
*
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
--
Daniel-Constantin Mierla --
www.asipto.com
www.twitter.com/miconda --
www.linkedin.com/in/miconda
Kamailio Advanced Training - Online
Feb 21-24, 2022 (America Timezone)
*
https://www.asipto.com/sw/kamailio-advanced-training-online/