Module: kamailio
Branch: master
Commit: d19a68be381fea741afe520340849cafd437d929
URL:
https://github.com/kamailio/kamailio/commit/d19a68be381fea741afe520340849ca…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-04-20T12:28:39+02:00
pv: new function - xavp_params_implode(xname, pv)
- serialize the subbfields of $xavp(xname) in params format (name=value;)
and set the output to variable pv
---
Modified: src/modules/pv/pv.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d19a68be381fea741afe520340849ca…
Patch:
https://github.com/kamailio/kamailio/commit/d19a68be381fea741afe520340849ca…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index 258be56399..bdb4e17834 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -24,6 +24,7 @@
#include "../../core/sr_module.h"
#include "../../core/pvar.h"
+#include "../../core/pvapi.h"
#include "../../core/lvalue.h"
#include "../../core/mod_fix.h"
#include "../../core/xavp.h"
@@ -528,6 +529,7 @@ static int is_int(struct sip_msg* msg, char* pvar, char* s2);
static int pv_typeof(sip_msg_t *msg, char *pv, char *t);
static int pv_not_empty(sip_msg_t *msg, char *pv, char *s2);
static int w_xavp_params_explode(sip_msg_t *msg, char *pparams, char *pxname);
+static int w_xavp_params_implode(sip_msg_t *msg, char *pxname, char *pvname);
static int w_sbranch_set_ruri(sip_msg_t *msg, char p1, char *p2);
static int w_sbranch_append(sip_msg_t *msg, char p1, char *p2);
static int w_sbranch_reset(sip_msg_t *msg, char p1, char *p2);
@@ -564,6 +566,9 @@ static cmd_export_t cmds[]={
{"xavp_params_explode", (cmd_function)w_xavp_params_explode,
2, fixup_spve_spve, fixup_free_spve_spve,
ANY_ROUTE},
+ {"xavp_params_implode", (cmd_function)w_xavp_params_implode,
+ 2, fixup_spve_str, fixup_free_spve_str,
+ ANY_ROUTE},
{"sbranch_set_ruri", (cmd_function)w_sbranch_set_ruri, 0, 0, 0,
ANY_ROUTE },
{"sbranch_append", (cmd_function)w_sbranch_append, 0, 0, 0,
@@ -816,6 +821,63 @@ static int ki_xavp_params_explode(sip_msg_t *msg, str *sparams, str
*sxname)
return 1;
}
+/**
+ *
+ */
+static int ki_xavp_params_implode(sip_msg_t *msg, str *sxname, str *svname)
+{
+ pv_spec_t *vspec=NULL;
+ pv_value_t val;
+
+ if(sxname==NULL || sxname->s==NULL || sxname->len<=0) {
+ LM_ERR("invalid xavp name\n");
+ return -1;
+ }
+ if(svname==NULL || svname->s==NULL || svname->len<=0) {
+ LM_ERR("invalid output var name\n");
+ return -1;
+ }
+
+ vspec = pv_cache_get(svname);
+ if(vspec==NULL) {
+ LM_ERR("cannot get pv spec for [%.*s]\n", svname->len, svname->s);
+ return -1;
+ }
+ if(vspec->setf==NULL) {
+ LM_ERR("read only output variable [%.*s]\n", svname->len, svname->s);
+ return -1;
+ }
+
+ val.rs.s = pv_get_buffer();
+ val.rs.len = xavp_serialize_fields(sxname, val.rs.s, pv_get_buffer_size());
+ if(val.rs.len<=0) {
+ return -1;
+ }
+
+ val.flags = PV_VAL_STR;
+ if(vspec->setf(msg, &vspec->pvp, EQ_T, &val)<0) {
+ LM_ERR("setting PV failed [%.*s]\n", svname->len, svname->s);
+ return -1;
+ }
+
+ return 1;
+}
+
+/**
+ *
+ */
+static int w_xavp_params_implode(sip_msg_t *msg, char *pxname, char *pvname)
+{
+ str sxname;
+
+ if(fixup_get_svalue(msg, (gparam_t*)pxname, &sxname)!=0) {
+ LM_ERR("cannot get the xavp name\n");
+ return -1;
+ }
+
+ return ki_xavp_params_implode(msg, &sxname, (str*)pvname);
+}
+
/**
*
*/