Browse code

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

Daniel-Constantin Mierla authored on 27/12/2020 17:19:49
Showing 1 changed files
... ...
@@ -28,27 +28,12 @@
28 28
 
29 29
 #include "pv_core.h"
30 30
 #include "pvar.h"
31
+#include "ppcfg.h"
31 32
 #include "str.h"
32 33
 #include "mem/pkg.h"
33 34
 
34
-static int pv_get_retcode(struct sip_msg*, pv_param_t*, pv_value_t*);
35
-static int pv_parse_env_name(pv_spec_p sp, str *in);
36
-static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
37 35
 
38
-
39
-static pv_export_t core_pvs[] = {
40
-	/* return code, various synonims */
41
-	{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
42
-	{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
43
-	{ STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
44
-	{ STR_STATIC_INIT("env"), PVT_OTHER, pv_get_env, 0,
45
-		pv_parse_env_name, 0, 0, 0},
46
-
47
-	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
48
-};
49
-
50
-
51
-/** ugly hack to get the return code, needed because the PVs do not know (yet)
36
+/** needed to get the return code, because the PVs do not know (yet)
52 37
  * about the script context */
53 38
 extern int _last_returned_code;
54 39
 
... ...
@@ -97,6 +82,73 @@ static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
97 82
 	return pv_get_null(msg, param, res);
98 83
 }
99 84
 
85
+static int pv_parse_def_name(pv_spec_p sp, str *in)
86
+{
87
+	if (in == NULL || in->s == NULL || sp == NULL) {
88
+		LM_ERR("INVALID DEF NAME\n");
89
+		return -1;
90
+	}
91
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
92
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
93
+	sp->pvp.pvn.u.isname.name.s = *in;
94
+	return 0;
95
+
96
+}
97
+
98
+static int pv_get_def(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
99
+{
100
+	str *val = pp_define_get(param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s);
101
+
102
+	if (val) {
103
+		return pv_get_strval(msg, param, res, val);
104
+	}
105
+	return pv_get_null(msg, param, res);
106
+}
107
+
108
+static int pv_parse_defn_name(pv_spec_p sp, str *in)
109
+{
110
+	if (in == NULL || in->s == NULL || sp == NULL) {
111
+		LM_ERR("INVALID DEF NAME\n");
112
+		return -1;
113
+	}
114
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
115
+	sp->pvp.pvn.u.isname.type = AVP_NAME_STR;
116
+	sp->pvp.pvn.u.isname.name.s = *in;
117
+	return 0;
118
+
119
+}
120
+
121
+static int pv_get_defn(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
122
+{
123
+	int n = 0;
124
+	str *val = pp_define_get(param->pvn.u.isname.name.s.len,
125
+			param->pvn.u.isname.name.s.s);
126
+
127
+	if (val) {
128
+		str2sint(val, &n);
129
+		return pv_get_intstrval(msg, param, res, n, val);
130
+	} else {
131
+		return pv_get_sintval(msg, param, res, n);
132
+	}
133
+}
134
+
135
+/**
136
+ *
137
+ */
138
+static pv_export_t core_pvs[] = {
139
+	/* return code, various synonims */
140
+	{ STR_STATIC_INIT("?"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
141
+	{ STR_STATIC_INIT("rc"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
142
+	{ STR_STATIC_INIT("retcode"), PVT_OTHER, pv_get_retcode, 0, 0, 0, 0, 0 },
143
+	{ STR_STATIC_INIT("env"), PVT_OTHER, pv_get_env, 0,
144
+		pv_parse_env_name, 0, 0, 0},
145
+	{{"def", (sizeof("def")-1)}, PVT_OTHER, pv_get_def, 0,
146
+		pv_parse_def_name, 0, 0, 0},
147
+	{{"defn", (sizeof("defn")-1)}, PVT_OTHER, pv_get_defn, 0,
148
+		pv_parse_defn_name, 0, 0, 0},
149
+
150
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
151
+};
100 152
 
101 153
 /**
102 154
  * register built-in core pvars.