[sr-dev] git:master:e97c7c8b: pv: exported pvx.evalx() to kemi framework

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 18 09:03:00 CEST 2017


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-09-18T09:02:02+02:00

pv: exported pvx.evalx() to kemi framework

- the equivalent of pv_evalx()

---

Modified: src/modules/pv/pv.c

---

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

---

diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 8dccdb3a0b..e7afac57b9 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -906,6 +906,9 @@ int pv_evalx_fixup(void** param, int param_no)
 	return 0;
 }
 
+/**
+ *
+ */
 int w_pv_evalx(struct sip_msg *msg, char *dst, str *fmt)
 {
 	pv_spec_t *ispec=NULL;
@@ -943,6 +946,41 @@ int w_pv_evalx(struct sip_msg *msg, char *dst, str *fmt)
 /**
  *
  */
+int ki_pv_evalx(sip_msg_t *msg, str *dst, str *fmt)
+{
+	pv_value_t val;
+	pv_spec_t *ispec=NULL;
+
+	if(dst==NULL || dst->s==NULL || dst->len<=0) {
+		LM_ERR("invalid destination var name\n");
+		return -1;
+	}
+	ispec = pv_cache_get(dst);
+	if(ispec==NULL) {
+		LM_ERR("cannot get pv spec for [%.*s]\n", dst->len, dst->s);
+		return -1;
+	}
+
+	memset(&val, 0, sizeof(pv_value_t));
+	if(pv_eval_str(msg, &val.rs, fmt)<0) {
+		LM_ERR("cannot eval reparsed value of second parameter\n");
+		return -1;
+	}
+
+	val.flags = PV_VAL_STR;
+	if(ispec->setf(msg, &ispec->pvp, EQ_T, &val)<0) {
+		LM_ERR("setting PV failed\n");
+		goto error;
+	}
+
+	return 1;
+error:
+	return -1;
+}
+
+/**
+ *
+ */
 static const char* rpc_shv_set_doc[2] = {
 	"Set a shared variable (args: name type value)",
 	0
@@ -1010,6 +1048,11 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("pvx"), str_init("evalx"),
+		SR_KEMIP_INT, ki_pv_evalx,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };
@@ -1027,4 +1070,4 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
 		return -1;
 	}
 	return register_trans_mod(path, mod_trans);
-}
\ No newline at end of file
+}




More information about the sr-dev mailing list