Module: kamailio
Branch: 5.0
Commit: 6171c15069576c0686827d594d512170f187dd6c
URL:
https://github.com/kamailio/kamailio/commit/6171c15069576c0686827d594d51217…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Date: 2017-06-04T13:09:05+02:00
pv: fix pv_var_to_xavp() and pv_xavp_to_var() functions
* xavp was not properly created at pv_var_to_xavp()
* add proper xavp loop for pv_xavp_to_var()
(cherry picked from commit 894d13f226310a6fcf78d0abbb4ea6e5eae903fd)
---
Modified: src/modules/pv/pv_xavp.c
---
Diff:
https://github.com/kamailio/kamailio/commit/6171c15069576c0686827d594d51217…
Patch:
https://github.com/kamailio/kamailio/commit/6171c15069576c0686827d594d51217…
---
diff --git a/src/modules/pv/pv_xavp.c b/src/modules/pv/pv_xavp.c
index e95d48d3e1..d556dda99f 100644
--- a/src/modules/pv/pv_xavp.c
+++ b/src/modules/pv/pv_xavp.c
@@ -622,7 +622,7 @@ int xavp_params_explode(str *params, str *xname)
int pv_var_to_xavp(str *varname, str *xname)
{
script_var_t *it;
- sr_xavp_t *xavp = NULL;
+ sr_xavp_t *avp = NULL;
sr_xval_t xval;
LM_DBG("xname:%.*s varname:%.*s\n", xname->len, xname->s,
@@ -638,18 +638,29 @@ int pv_var_to_xavp(str *varname, str *xname)
{
xval.type = SR_XTYPE_INT;
xval.v.i = it->v.value.n;
+ LM_DBG("[%.*s]: %d\n", it->name.len, it->name.s, xval.v.i);
} else {
if(it->v.value.s.len==0) continue;
xval.type = SR_XTYPE_STR;
xval.v.s.s = it->v.value.s.s;
xval.v.s.len = it->v.value.s.len;
+ LM_DBG("[%.*s]: '%.*s'\n", it->name.len, it->name.s,
+ xval.v.s.len, xval.v.s.s);
}
- xavp = xavp_add_xavp_value(xname, &it->name, &xval, NULL);
- if(xavp==NULL) {
+ if(xavp_add_value(&it->name, &xval, &avp)==NULL) {
LM_ERR("can't copy [%.*s]\n", it->name.len, it->name.s);
goto error;
}
}
+ if(avp) {
+ memset(&xval, 0, sizeof(sr_xval_t));
+ xval.type = SR_XTYPE_XAVP;
+ xval.v.xavp = avp;
+ if(xavp_add_value(xname, &xval, NULL)==NULL) {
+ LM_ERR("Can't create xavp[%.*s]\n", xname->len, xname->s);
+ goto error;
+ }
+ }
}
else {
it = get_var_by_name(varname);
@@ -662,21 +673,23 @@ int pv_var_to_xavp(str *varname, str *xname)
{
xval.type = SR_XTYPE_INT;
xval.v.i = it->v.value.n;
+ LM_DBG("[%.*s]: %d\n", it->name.len, it->name.s, xval.v.i);
} else {
xval.type = SR_XTYPE_STR;
xval.v.s.s = it->v.value.s.s;
xval.v.s.len = it->v.value.s.len;
+ LM_DBG("[%.*s]: '%.*s'\n", it->name.len, it->name.s,
+ xval.v.s.len, xval.v.s.s);
}
- xavp = xavp_add_xavp_value(xname, &it->name, &xval, NULL);
- if(xavp==NULL) {
+ if(xavp_add_xavp_value(xname, &it->name, &xval, NULL)==NULL) {
LM_ERR("can't copy [%.*s]\n", it->name.len, it->name.s);
- goto error;
+ return -1;
}
}
return 1;
error:
- xavp_rm_by_name(xname, 1, NULL);
+ if(avp) xavp_destroy_list(&avp);
return -1;
}
@@ -691,7 +704,7 @@ int pv_xavp_to_var_helper(sr_xavp_t *avp) {
flags |= VAR_VAL_STR;
value.s.len = avp->val.v.s.len;
value.s.s = avp->val.v.s.s;
- LM_DBG("var:[%.*s] STR:[%.*s]\n", avp->name.len, avp->name.s,
+ LM_DBG("var:[%.*s] STR:[%.*s]\n", avp->name.len, avp->name.s,
value.s.len, value.s.s);
}
else if(avp->val.type==SR_XTYPE_INT) {
@@ -723,18 +736,21 @@ int pv_xavp_to_var(str *xname) {
LM_ERR("%.*s not xavp type?\n", xname->len, xname->s);
return -1;
}
- avp = xavp->val.v.xavp;
- if (avp)
- {
- if(pv_xavp_to_var_helper(avp)<0) return -1;
- avp = avp->next;
- }
+ do {
+ avp = xavp->val.v.xavp;
+ if (avp)
+ {
+ if(pv_xavp_to_var_helper(avp)<0) return -1;
+ avp = avp->next;
+ }
- while(avp)
- {
- if(pv_xavp_to_var_helper(avp)<0) return -1;
- avp = avp->next;
- }
+ while(avp)
+ {
+ if(pv_xavp_to_var_helper(avp)<0) return -1;
+ avp = avp->next;
+ }
+ xavp = xavp_get_next(xavp);
+ } while(xavp);
return 1;
}
#endif