[sr-dev] git:master:d1b982cb: core: relocated $def(...) and $defn(...)

Daniel-Constantin Mierla miconda at gmail.com
Mon Dec 28 14:11:20 CET 2020


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-12-27T18:19:49+01:00

core: relocated $def(...) and $defn(...)

---

Modified: src/core/pv_core.c

---

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

---

diff --git a/src/core/pv_core.c b/src/core/pv_core.c
index 0998aa18a8..54fc6e6123 100644
--- a/src/core/pv_core.c
+++ b/src/core/pv_core.c
@@ -28,27 +28,12 @@
 
 #include "pv_core.h"
 #include "pvar.h"
+#include "ppcfg.h"
 #include "str.h"
 #include "mem/pkg.h"
 
-static int pv_get_retcode(struct sip_msg*, pv_param_t*, pv_value_t*);
-static int pv_parse_env_name(pv_spec_p sp, str *in);
-static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
 
-
-static pv_export_t core_pvs[] = {
-	/* return code, various synonims */
-	{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
-	{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
-	{ 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},
-
-	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
-};
-
-
-/** ugly hack to get the return code, needed because the PVs do not know (yet)
+/** needed to get the return code, because the PVs do not know (yet)
  * about the script context */
 extern int _last_returned_code;
 
@@ -97,6 +82,73 @@ 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_def_name(pv_spec_p sp, str *in)
+{
+	if (in == NULL || in->s == NULL || sp == NULL) {
+		LM_ERR("INVALID DEF NAME\n");
+		return -1;
+	}
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
+	sp->pvp.pvn.u.isname.name.s = *in;
+	return 0;
+
+}
+
+static int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+	str *val = pp_define_get(param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s);
+
+	if (val) {
+		return pv_get_strval(msg, param, res, val);
+	}
+	return pv_get_null(msg, param, res);
+}
+
+static int pv_parse_defn_name(pv_spec_p sp, str *in)
+{
+	if (in == NULL || in->s == NULL || sp == NULL) {
+		LM_ERR("INVALID DEF NAME\n");
+		return -1;
+	}
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
+	sp->pvp.pvn.u.isname.name.s = *in;
+	return 0;
+
+}
+
+static int pv_get_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+	int n = 0;
+	str *val = pp_define_get(param->pvn.u.isname.name.s.len,
+			param->pvn.u.isname.name.s.s);
+
+	if (val) {
+		str2sint(val, &n);
+		return pv_get_intstrval(msg, param, res, n, val);
+	} else {
+		return pv_get_sintval(msg, param, res, n);
+	}
+}
+
+/**
+ *
+ */
+static pv_export_t core_pvs[] = {
+	/* return code, various synonims */
+	{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
+	{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
+	{ 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},
+	{{"def", (sizeof("def")-1)}, PVT_OTHER, pv_get_def, 0,
+		pv_parse_def_name, 0, 0, 0},
+	{{"defn", (sizeof("defn")-1)}, PVT_OTHER, pv_get_defn, 0,
+		pv_parse_defn_name, 0, 0, 0},
+
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
 
 /**
  * register built-in core pvars.




More information about the sr-dev mailing list