[sr-dev] git:master:2b0c7213: kemix: exported functions to get env values

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


Module: kamailio
Branch: master
Commit: 2b0c7213700c64a762939f9b39111f902eeab9e8
URL: https://github.com/kamailio/kamailio/commit/2b0c7213700c64a762939f9b39111f902eeab9e8

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-01-04T10:35:42+01:00

kemix: exported functions to get env values

---

Modified: src/modules/kemix/kemix_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/2b0c7213700c64a762939f9b39111f902eeab9e8.diff
Patch: https://github.com/kamailio/kamailio/commit/2b0c7213700c64a762939f9b39111f902eeab9e8.patch

---

diff --git a/src/modules/kemix/kemix_mod.c b/src/modules/kemix/kemix_mod.c
index 269dbd3dee..fc4c6a2a69 100644
--- a/src/modules/kemix/kemix_mod.c
+++ b/src/modules/kemix/kemix_mod.c
@@ -1093,6 +1093,52 @@ static int ki_kx_get_defn(sip_msg_t *msg, str *dname)
 	return n;
 }
 
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_get_env(sip_msg_t *msg, str *envname)
+{
+	char *val;
+
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
+	if(envname==NULL || envname->s==NULL || envname->len<=0) {
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
+		return &_sr_kemi_kx_xval;
+	}
+
+	val = getenv(envname->s);
+	if (val == NULL) {
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
+		return &_sr_kemi_kx_xval;
+	}
+
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
+	_sr_kemi_kx_xval.v.s.s = val;
+	_sr_kemi_kx_xval.v.s.len = strlen(val);
+	return &_sr_kemi_kx_xval;
+}
+
+/**
+ *
+ */
+static int ki_kx_get_envn(sip_msg_t *msg, str *envname)
+{
+	str val;
+	int r = 0;
+
+	if(envname==NULL || envname->s==NULL || envname->len<=0) {
+		return 0;
+	}
+
+	val.s = getenv(envname->s);
+	if (val.s) {
+		val.len = strlen(val.s);
+		str2sint(&val, &r);
+		return r;
+	}
+
+	return r;
+}
 
 /**
  *
@@ -1404,6 +1450,16 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("kx"), str_init("get_env"),
+		SR_KEMIP_XVAL, ki_kx_get_env,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("kx"), str_init("get_envn"),
+		SR_KEMIP_INT, ki_kx_get_envn,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }




More information about the sr-dev mailing list