Module: sip-router
Branch: master
Commit: 28942a00bc7be5194625b9ed08facd2f95ebea81
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=28942a0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri May 24 00:36:57 2013 +0200
pv: added $_s(format) variable
- evaluate the format as a dynamic string
$var(x) = "sip:" + $rU + "@" + $fd;
is equivalent of:
$var(x) = $_s(sip:$rU@$fd);
- it can be more compact sometimes in config
---
modules/pv/pv.c | 2 ++
modules/pv/pv_core.c | 41 +++++++++++++++++++++++++++++++++++++++++
modules/pv/pv_core.h | 5 +++++
3 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/modules/pv/pv.c b/modules/pv/pv.c
index 44d35e0..fcfea11 100644
--- a/modules/pv/pv.c
+++ b/modules/pv/pv.c
@@ -63,6 +63,8 @@ static tr_export_t mod_trans[] = {
};
static pv_export_t mod_pvs[] = {
+ { {"_s", (sizeof("_s")-1)}, PVT_OTHER, pv_get__s, 0,
+ pv_parse__s_name, 0, 0, 0 },
{ {"af", (sizeof("af")-1)}, PVT_OTHER, pv_get_af, 0,
pv_parse_af_name, 0, 0, 0 },
{ {"branch", sizeof("branch")-1}, /* branch attributes */
diff --git a/modules/pv/pv_core.c b/modules/pv/pv_core.c
index 4225f21..1b5a1f5 100644
--- a/modules/pv/pv_core.c
+++ b/modules/pv/pv_core.c
@@ -2898,3 +2898,44 @@ int pv_get_K(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_uintval(msg, param, res, AF_INET);
}
}
+
+/**
+ *
+ */
+int pv_parse__s_name(pv_spec_p sp, str *in)
+{
+ pv_elem_t *fmt = NULL;
+
+ if(in->s==NULL || in->len<=0)
+ return -1;
+ if(pv_parse_format(in, &fmt)<0 || fmt==NULL)
+ {
+ LM_ERR("wrong format[%.*s]\n", in->len, in->s);
+ return -1;
+ }
+ sp->pvp.pvn.u.dname = (void*)fmt;
+ sp->pvp.pvn.type = PV_NAME_OTHER;
+ return 0;
+}
+
+/**
+ *
+ */
+int pv_get__s(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res)
+{
+ str sdata = {0};
+ pv_elem_t *fmt = NULL;
+ fmt = (pv_elem_t*)param->pvn.u.dname;
+
+ if(fmt==NULL)
+ {
+ return pv_get_null(msg, param, res);
+ }
+ if(pv_printf_s(msg, fmt, &sdata)!=0)
+ {
+ LM_ERR("cannot evaluate the string\n");
+ return -1;
+ }
+ return pv_get_strval(msg, param, res, &sdata);
+}
diff --git a/modules/pv/pv_core.h b/modules/pv/pv_core.h
index 193185b..83eac5a 100644
--- a/modules/pv/pv_core.h
+++ b/modules/pv/pv_core.h
@@ -315,5 +315,10 @@ int pv_get_K(sip_msg_t *msg, pv_param_t *param,
int pv_parse_flag_param(pv_spec_p sp, str *in);
+int pv_parse__s_name(pv_spec_p sp, str *in);
+
+int pv_get__s(sip_msg_t *msg, pv_param_t *param,
+ pv_value_t *res);
+
#endif