Quellcode durchsuchen

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

Daniel-Constantin Mierla vor 4 Jahren
Ursprung
Commit
d1b982cbeb
1 geänderte Dateien mit 69 neuen und 17 gelöschten Zeilen
  1. 69 17
      src/core/pv_core.c

+ 69 - 17
src/core/pv_core.c

@@ -28,27 +28,12 @@
 
 
 #include "pv_core.h"
 #include "pv_core.h"
 #include "pvar.h"
 #include "pvar.h"
+#include "ppcfg.h"
 #include "str.h"
 #include "str.h"
 #include "mem/pkg.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 */
  * about the script context */
 extern int _last_returned_code;
 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);
 	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.
  * register built-in core pvars.