this allows kamailio to have read-only (for now) access to environment variables You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/978
-- Commit Summary --
* pv: add the $env() PV class to read env vars
-- File Changes --
M src/modules/pv/pv.c (2) M src/modules/pv/pv_core.c (43) M src/modules/pv/pv_core.h (4)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/978.patch https://github.com/kamailio/kamailio/pull/978.diff
linuxmaniac commented on this pull request.
- sp->pvp.pvn.u.dname = (void*)csname;
+ sp->pvp.pvn.type = PV_NAME_OTHER; + return 0; +} + +int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) +{ + char *val; + char *csname = (char *) param->pvn.u.dname; + + if (csname) { + val = getenv(csname); + + if (val) { + return pv_get_strzval(msg, param, res, val); + } else {
what about
``` if (csname) { val = getenv(csname); if(val) return pv_get_strzval(msg, param, res, val); } return pv_get_null(msg, param, res); ```
linuxmaniac commented on this pull request.
@@ -3233,3 +3235,44 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_null(msg, param, res); } } + +int pv_parse_env_name(pv_spec_p sp, str *in) +{ + if(in->s==NULL || in->len<=0) + return -1; + + char *csname;
can you please move the declaration to the top, please.
camilleoudot commented on this pull request.
- sp->pvp.pvn.u.dname = (void*)csname;
+ sp->pvp.pvn.type = PV_NAME_OTHER; + return 0; +} + +int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) +{ + char *val; + char *csname = (char *) param->pvn.u.dname; + + if (csname) { + val = getenv(csname); + + if (val) { + return pv_get_strzval(msg, param, res, val); + } else {
easier to read, thanks
camilleoudot commented on this pull request.
@@ -3233,3 +3235,44 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_null(msg, param, res); } } + +int pv_parse_env_name(pv_spec_p sp, str *in) +{ + if(in->s==NULL || in->len<=0) + return -1; + + char *csname;
sure
@camilleoudot pushed 1 commit.
04f5465 pv: $env() code style improvements
linuxmaniac commented on this pull request.
@@ -3238,11 +3238,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
int pv_parse_env_name(pv_spec_p sp, str *in) { + char *csname; + if(in->s==NULL || in->len<=0)
I would do ``` if(sp==NULL || in == NULL || in->len <=0) ```
as in the [kamailio-devel-guide](http://www.asipto.com/pub/kamailio-devel-guide/#c16_add_pv)
camilleoudot commented on this pull request.
@@ -3238,11 +3238,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
int pv_parse_env_name(pv_spec_p sp, str *in) { + char *csname; + if(in->s==NULL || in->len<=0)
it does not look like any of the parameters can be null, judging by the checks done before calling this function in https://github.com/kamailio/kamailio/blob/master/src/core/pvapi.c#L873, but I may be missing something else
linuxmaniac commented on this pull request.
@@ -3238,11 +3238,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
int pv_parse_env_name(pv_spec_p sp, str *in) { + char *csname; + if(in->s==NULL || in->len<=0)
and where is the documentation update?
camilleoudot commented on this pull request.
@@ -3238,11 +3238,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
int pv_parse_env_name(pv_spec_p sp, str *in) { + char *csname; + if(in->s==NULL || in->len<=0)
I'll document it on the wiki when/if it makes its way to master eventually (after the feature freeze?)
linuxmaniac commented on this pull request.
@@ -3238,11 +3238,11 @@ int pv_get_msg_attrs(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
int pv_parse_env_name(pv_spec_p sp, str *in) { + char *csname; + if(in->s==NULL || in->len<=0)
FTR, it works nicely ``` route[TEST] { $var(tmp) = $env(FAKE); xlog("L_NOTICE", "PATH=$env(PATH) FAKE=$var(tmp)\n"); return; } ``` ``` 3(1978) NOTICE: <script>: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FAKE=0 ```
Thanks! Can be merged into master.
Merged #978.