Module: kamailio Branch: master Commit: f1630caf691aa1e5b92086af08d49be38cf6c82f URL: https://github.com/kamailio/kamailio/commit/f1630caf691aa1e5b92086af08d49be38cf6c82f
Author: Camille Oudot <camille.ou...@orange.com> Committer: Victor Seva <linuxman...@torreviejawireless.org> Date: 2017-02-09T15:24:37+01:00 pv: add the $env() PV class to read env vars (#978) * pv: add the $env() PV class to read env vars * pv: $env() code style improvements --- Modified: src/modules/pv/pv.c Modified: src/modules/pv/pv_core.c Modified: src/modules/pv/pv_core.h --- Diff: https://github.com/kamailio/kamailio/commit/f1630caf691aa1e5b92086af08d49be38cf6c82f.diff Patch: https://github.com/kamailio/kamailio/commit/f1630caf691aa1e5b92086af08d49be38cf6c82f.patch --- diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c index 8f69b94..f1e1f41 100644 --- a/src/modules/pv/pv.c +++ b/src/modules/pv/pv.c @@ -208,6 +208,8 @@ static pv_export_t mod_pvs[] = { {{"duri", (sizeof("duri")-1)}, /* */ PVT_DSTURI, pv_get_dsturi, pv_set_dsturi, 0, 0, 0, 0}, + {{"env", (sizeof("env")-1)}, PVT_OTHER, pv_get_env, 0, + pv_parse_env_name, 0, 0, 0}, {{"err.class", (sizeof("err.class")-1)}, /* */ PVT_OTHER, pv_get_errinfo_attr, 0, 0, 0, 0, 0}, diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c index e82c1e0..f1d264b 100644 --- a/src/modules/pv/pv_core.c +++ b/src/modules/pv/pv_core.c @@ -50,6 +50,8 @@ #include "pv_core.h" #include "pv_svar.h" +#include <string.h> +#include <stdlib.h> static str str_udp = { "UDP", 3 }; static str str_5060 = { "5060", 4 }; @@ -3233,3 +3235,41 @@ 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) +{ + char *csname; + + if(in->s==NULL || in->len<=0) + return -1; + + csname = pkg_malloc(in->len + 1); + + if (csname == NULL) { + LM_ERR("no more pkg memory"); + return -1; + } + + memcpy(csname, in->s, in->len); + csname[in->len] = '\0'; + + 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); + } + } + return pv_get_null(msg, param, res); +} + diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h index 58fe262..27c13bb 100644 --- a/src/modules/pv/pv_core.h +++ b/src/modules/pv/pv_core.h @@ -334,5 +334,9 @@ int pv_parse_msg_attrs_name(pv_spec_p sp, str *in); 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); + +int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res); #endif _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev