|
@@ -24,17 +24,25 @@
|
|
|
* Module: \ref core
|
|
|
*/
|
|
|
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
#include "pv_core.h"
|
|
|
#include "pvar.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 }
|
|
|
};
|
|
@@ -52,6 +60,43 @@ static int pv_get_retcode(struct sip_msg* msg, pv_param_t* p, pv_value_t* res)
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int pv_parse_env_name(pv_spec_p sp, str *in)
|
|
|
+{
|
|
|
+ char *csname;
|
|
|
+
|
|
|
+ if(in->s==NULL || in->len<=0)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ csname = pkg_malloc(in->len + 1);
|
|
|
+
|
|
|
+ if (csname == NULL) {
|
|
|
+ LM_ERR("no more pkg memory");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ memcpy(csname, in->s, in->len);
|
|
|
+ csname[in->len] = '\0';
|
|
|
+
|
|
|
+ sp->pvp.pvn.u.dname = (void*)csname;
|
|
|
+ sp->pvp.pvn.type = PV_NAME_OTHER;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static int pv_get_env(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
|
|
|
+{
|
|
|
+ char *val;
|
|
|
+ char *csname = (char *) param->pvn.u.dname;
|
|
|
+
|
|
|
+ if (csname) {
|
|
|
+ val = getenv(csname);
|
|
|
+
|
|
|
+ if (val) {
|
|
|
+ return pv_get_strzval(msg, param, res, val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pv_get_null(msg, param, res);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* register built-in core pvars.
|