[sr-dev] git:master:3dfc7242: core: added $envn(name) - return environment variable as int number

Daniel-Constantin Mierla miconda at gmail.com
Mon Jan 4 10:42:49 CET 2021


Module: kamailio
Branch: master
Commit: 3dfc7242e0fdf16555ddf6d3cf06a82014fc4268
URL: https://github.com/kamailio/kamailio/commit/3dfc7242e0fdf16555ddf6d3cf06a82014fc4268

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-01-02T16:10:07+01:00

core: added $envn(name) - return environment variable as int number

---

Modified: src/core/pv_core.c

---

Diff:  https://github.com/kamailio/kamailio/commit/3dfc7242e0fdf16555ddf6d3cf06a82014fc4268.diff
Patch: https://github.com/kamailio/kamailio/commit/3dfc7242e0fdf16555ddf6d3cf06a82014fc4268.patch

---

diff --git a/src/core/pv_core.c b/src/core/pv_core.c
index 2b3132ccb4..d1274dc3e4 100644
--- a/src/core/pv_core.c
+++ b/src/core/pv_core.c
@@ -82,6 +82,45 @@ static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
 	return pv_get_null(msg, param, res);
 }
 
+static int pv_parse_envn_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;
+}
+
+static int pv_get_envn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+	str val;
+	int r = 0;
+	char *csname = (char *) param->pvn.u.dname;
+
+	if (csname) {
+		val.s = getenv(csname);
+		if (val.s) {
+			val.len = strlen(val.s);
+			str2sint(&val, &r);
+			return pv_get_intstrval(msg, param, res, r, &val);
+		}
+	}
+	return pv_get_null(msg, param, res);
+}
+
 static int pv_parse_def_name(pv_spec_p sp, str *in)
 {
 	if (in == NULL || in->s == NULL || sp == NULL) {
@@ -142,6 +181,8 @@ static pv_export_t core_pvs[] = {
 	{ STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
 	{ STR_STATIC_INIT("env"), PVT_OTHER, pv_get_env, 0,
 		pv_parse_env_name, 0, 0, 0 },
+	{ STR_STATIC_INIT("envn"), PVT_OTHER, pv_get_envn, 0,
+		pv_parse_envn_name, 0, 0, 0 },
 	{ STR_STATIC_INIT("def"), PVT_OTHER, pv_get_def, 0,
 		pv_parse_def_name, 0, 0, 0 },
 	{ STR_STATIC_INIT("defn"), PVT_OTHER, pv_get_defn, 0,




More information about the sr-dev mailing list