Browse Source

pv_headers: migrate to $xavi

* $x_hdr(HEADER) is case insensitive now as it should be
* rework pvh_set_header():
  use core pv_get_spec_*
  use PV_IDX_NONE to detect no index case
  remove values instead of adding NULL if PV_IDX_ALL
Victor Seva 5 years ago
parent
commit
3b1f5b9c89

+ 10 - 10
src/modules/pv_headers/doc/params.xml

@@ -13,10 +13,10 @@
     </sectioninfo>
 
 	<title>Parameters</title>
-	<section id="pv_headers.p.xavp_name">
-		<title><varname>xavp_name</varname> (string)</title>
+	<section id="pv_headers.p.xavi_name">
+		<title><varname>xavi_name</varname> (string)</title>
 		<para>
-			Name of the XAVP there the collected headers are stored.
+			Name of the XAVI where the collected headers are stored.
 		</para>
 		<para>
 		<emphasis>
@@ -24,24 +24,24 @@
 		</emphasis>
 		</para>
 		<example>
-		<title>Set <varname>xavp_name</varname> parameter</title>
+		<title>Set <varname>xavi_name</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("pv_headers", "xavp_name", "pvh")
+modparam("pv_headers", "xavi_name", "headers")
 ...
 </programlisting>
 		<para>
 		Result:
-			$xavp(headers[0]=>From)
-			$xavp(headers[0]=>To)
-			$xavp(headers[0]=>Call-ID)
+			$xavi(headers[0]=>From)
+			$xavi(headers[0]=>To)
+			$xavi(headers[0]=>Call-ID)
 		</para>
 		</example>
 	</section>
 	<section id="pv_headers.p.header_value_size">
 		<title><varname>header_value_size</varname> (int)</title>
 		<para>
-			Defines an internal maximum SIP header value size. Header values
+			Defines an internal maximum &sip; header value size. Header values
 			longer than this setting will be stripped down when collected or applied.
 		</para>
 		<para>
@@ -178,7 +178,7 @@ modparam("pv_headers", "split_headers", "Diversion")
 		<title>Set <varname>auto_msg</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("pvh", "auto_msg", 1)
+modparam("pv_headers", "auto_msg", 1)
 ...
 </programlisting>
 		</example>

+ 1 - 1
src/modules/pv_headers/doc/pv_headers_admin.xml

@@ -19,7 +19,7 @@
 	<title>Overview</title>
 	<para>
 		The main goal of the module is to offload the intermediate header processing
-	into the XAVP dynamic container as well as provide with high level methods
+	into the XAVI dynamic container as well as provide with high level methods
 	and pseudovariables to simplify &sip; message header modifications.
 	</para>
 	</section>

+ 46 - 17
src/modules/pv_headers/pv_headers.c

@@ -42,9 +42,9 @@ MODULE_VERSION
 uac_api_t uac;
 static tm_api_t tmb;
 
-str xavp_name = str_init(XAVP_NAME);
-str xavp_helper_xname = str_init("modparam_pv_headers");
-str xavp_parsed_xname = str_init("parsed_pv_headers");
+str xavi_name = str_init(XAVP_NAME);
+str xavi_helper_xname = str_init("modparam_pv_headers");
+str xavi_parsed_xname = str_init("parsed_pv_headers");
 unsigned int header_name_size = 255;
 unsigned int header_value_size = 1024;
 int FL_PV_HDRS_COLLECTED = 27;
@@ -71,14 +71,43 @@ static int handle_msg_branch_cb(
 static int handle_msg_reply_cb(
 		struct sip_msg *msg, unsigned int flags, void *cb);
 
+/**
+ *
+ */
+static int pvh_get_branch_index(struct sip_msg *msg, int *br_idx)
+{
+	int os = 0;
+	int len = 0;
+	char parsed_br_idx[header_value_size];
+
+	if(msg->add_to_branch_len > header_value_size) {
+		LM_ERR("branch name is too long\n");
+		return -1;
+	}
+
+	os = msg->add_to_branch_len;
+	while(os > 0 && memcmp(msg->add_to_branch_s + os - 1, ".", 1))
+		os--;
+	len = msg->add_to_branch_len - os;
+	if(os > 0 && len > 0) {
+		memcpy(parsed_br_idx, msg->add_to_branch_s + os, len);
+		parsed_br_idx[len] = '\0';
+		*br_idx = atoi(parsed_br_idx) + 1;
+	} else {
+		*br_idx = 0;
+	}
+
+	return 1;
+}
+
 static int w_pvh_collect_headers(struct sip_msg *msg, char *p1, char *p2)
 {
-	sr_xavp_t **backup_xavps = NULL;
+	sr_xavp_t **backup_xavis = NULL;
 
 	if(pvh_get_branch_index(msg, &_branch) < 0)
 		return -1;
 	if(msg->first_line.type == SIP_REPLY) {
-		if((_reply_counter = pvh_reply_append(backup_xavps)) < 0) {
+		if((_reply_counter = pvh_reply_append(backup_xavis)) < 0) {
 			return -1;
 		}
 	}
@@ -87,12 +116,12 @@ static int w_pvh_collect_headers(struct sip_msg *msg, char *p1, char *p2)
 
 static int ki_pvh_collect_headers(struct sip_msg *msg)
 {
-	sr_xavp_t **backup_xavps = NULL;
+	sr_xavp_t **backup_xavis = NULL;
 
 	if(pvh_get_branch_index(msg, &_branch) < 0)
 		return -1;
 	if(msg->first_line.type == SIP_REPLY) {
-		if((_reply_counter = pvh_reply_append(backup_xavps)) < 0) {
+		if((_reply_counter = pvh_reply_append(backup_xavis)) < 0) {
 			return -1;
 		}
 	}
@@ -230,7 +259,7 @@ static pv_export_t mod_pvs[] = {
 };
 
 static param_export_t params[] = {
-	{"xavp_name", PARAM_STR, &xavp_name},
+	{"xavi_name", PARAM_STR, &xavi_name},
 	{"header_value_size", PARAM_INT, &header_value_size},
 	{"header_collect_flag", PARAM_INT, &FL_PV_HDRS_COLLECTED},
 	{"header_apply_flag", PARAM_INT, &FL_PV_HDRS_APPLIED},
@@ -419,7 +448,7 @@ int handle_msg_branch_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 	if(flags & PRE_SCRIPT_CB) {
 		pvh_get_branch_index(msg, &_branch);
 		LM_DBG("msg:%p set branch:%d\n", msg, _branch);
-		pvh_clone_branch_xavp(msg, &xavp_name);
+		pvh_clone_branch_xavi(msg, &xavi_name);
 	}
 
 	return 1;
@@ -428,7 +457,7 @@ int handle_msg_branch_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 {
 	tm_cell_t *t = NULL;
-	sr_xavp_t **backup_xavps = NULL;
+	sr_xavp_t **backup_xavis = NULL;
 	sr_xavp_t **list = NULL;
 
 	if(pvh_parse_msg(msg) != 0)
@@ -442,10 +471,10 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 		if(t == NULL || t == T_UNDEFINED) {
 			LM_DBG("cannot lookup the transaction\n");
 		} else {
-			LM_DBG("T:%p t_check-branch:%d xavp_list:%p branches:%d\n", t,
-					_branch, &t->xavps_list, t->nr_of_outgoings);
-			list = &t->xavps_list;
-			backup_xavps = xavp_set_list(&t->xavps_list);
+			LM_DBG("T:%p t_check-branch:%d xavi_list:%p branches:%d\n", t,
+					_branch, &t->xavis_list, t->nr_of_outgoings);
+			list = &t->xavis_list;
+			backup_xavis = xavi_set_list(&t->xavis_list);
 		}
 	}
 
@@ -457,9 +486,9 @@ int handle_msg_reply_cb(struct sip_msg *msg, unsigned int flags, void *cb)
 		return -1;
 	}
 	pvh_collect_headers(msg);
-	if(backup_xavps) {
-		xavp_set_list(backup_xavps);
-		LM_DBG("restored backup_xavps:%p\n", *backup_xavps);
+	if(backup_xavis) {
+		xavi_set_list(backup_xavis);
+		LM_DBG("restored backup_xavis:%p\n", *backup_xavis);
 	}
 	if(t) {
 		tmb.unref_cell(t);

+ 3 - 3
src/modules/pv_headers/pv_headers.h

@@ -38,9 +38,9 @@ typedef struct _xavp_c_data
 
 extern uac_api_t uac;
 
-extern str xavp_name;
-extern str xavp_parsed_xname;
-extern str xavp_helper_xname;
+extern str xavi_name;
+extern str xavi_parsed_xname;
+extern str xavi_helper_xname;
 
 extern unsigned int header_name_size;
 extern unsigned int header_value_size;

+ 36 - 36
src/modules/pv_headers/pvh_func.c

@@ -32,7 +32,7 @@
 #include "pvh_hash.h"
 #include "pvh_hdr.h"
 
-static str xavp_helper_name = str_init("xavp_name");
+static str xavi_helper_name = str_init("xavi_name");
 
 int pvh_parse_msg(sip_msg_t *msg)
 {
@@ -96,7 +96,7 @@ int pvh_collect_headers(struct sip_msg *msg)
 		val.s = hf->body.s;
 
 		if(strchr(val.s, ',') != NULL
-				&& str_hash_get(&split_headers, name.s, name.len)) {
+				&& str_hash_case_get(&split_headers, name.s, name.len)) {
 
 			if(pvh_split_values(&val, hvals, &d_size, 1) < 0) {
 				LM_ERR("could not parse %.*s header comma separated "
@@ -108,18 +108,18 @@ int pvh_collect_headers(struct sip_msg *msg)
 			for(idx = 0; idx < d_size; idx++) {
 				val_part.s = hvals[idx];
 				val_part.len = strlen(hvals[idx]);
-				if(pvh_set_xavp(msg, &xavp_name, &name, &val_part, SR_XTYPE_STR,
+				if(pvh_set_xavi(msg, &xavi_name, &name, &val_part, SR_XTYPE_STR,
 						   0, 1)
 						< 0)
 					return -1;
 			}
 			continue;
 		}
-		if(pvh_set_xavp(msg, &xavp_name, &name, &val, SR_XTYPE_STR, 0, 1) < 0)
+		if(pvh_set_xavi(msg, &xavi_name, &name, &val, SR_XTYPE_STR, 0, 1) < 0)
 			return -1;
 	}
 
-	if(pvh_set_xavp(msg, &xavp_helper_xname, &xavp_helper_name, &xavp_name,
+	if(pvh_set_xavi(msg, &xavi_helper_xname, &xavi_helper_name, &xavi_name,
 			   SR_XTYPE_STR, 0, 0)
 			< 0)
 		return -1;
@@ -131,7 +131,7 @@ int pvh_collect_headers(struct sip_msg *msg)
 
 int pvh_apply_headers(struct sip_msg *msg)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	sr_xavp_t *sub = NULL;
 	struct str_hash_table rm_hdrs;
 	int from_cnt = 0, to_cnt = 0;
@@ -155,30 +155,30 @@ int pvh_apply_headers(struct sip_msg *msg)
 		return -1;
 	}
 
-	pvh_get_branch_xname(msg, &xavp_name, &br_xname);
+	pvh_get_branch_xname(msg, &xavi_name, &br_xname);
 
-	if((xavp = xavp_get(&br_xname, NULL)) == NULL
-			&& (xavp = xavp_get(&xavp_name, NULL)) == NULL) {
-		LM_ERR("missing xavp %s, run pv_collect_headers() first\n",
-				xavp_name.s);
+	if((xavi = xavi_get(&br_xname, NULL)) == NULL
+			&& (xavi = xavi_get(&xavi_name, NULL)) == NULL) {
+		LM_ERR("missing xavi %.*s, run pv_collect_headers() first\n",
+				xavi_name.len, xavi_name.s);
 		return -1;
 	}
-	if(xavp->val.type != SR_XTYPE_XAVP) {
-		LM_ERR("not xavp child type %s\n", xavp_name.s);
+	if(xavi->val.type != SR_XTYPE_XAVP) {
+		LM_ERR("not xavp child type %.*s\n", xavi_name.len, xavi_name.s);
 		return -1;
 	}
 
-	if((sub = xavp->val.v.xavp) == NULL) {
-		LM_ERR("invalid xavp structure: %s\n", xavp_name.s);
+	if((sub = xavi->val.v.xavp) == NULL) {
+		LM_ERR("invalid xavp structure: %.*s\n", xavi_name.len, xavi_name.s);
 		return -1;
 	}
-	keys_count = pvh_xavp_keys_count(&sub);
+	keys_count = pvh_xavi_keys_count(&sub);
 	if(str_hash_alloc(&rm_hdrs, keys_count) < 0) {
 		PKG_MEM_ERROR;
 		return -1;
 	}
-	LM_DBG("xavp->name:%.*s br_xname:%.*s keys_count: %d\n", xavp->name.len,
-			xavp->name.s, br_xname.len, br_xname.s, keys_count);
+	LM_DBG("xavi->name:%.*s br_xname:%.*s keys_count: %d\n", xavi->name.len,
+			xavi->name.s, br_xname.len, br_xname.s, keys_count);
 	str_hash_init(&rm_hdrs);
 
 	if(msg->first_line.type == SIP_REPLY
@@ -263,15 +263,15 @@ int pvh_apply_headers(struct sip_msg *msg)
 		}
 
 		if(cmpi_str(&sub->name, &_hdr_reply_reason) == 0) {
-			if(str_hash_get(&rm_hdrs, sub->name.s, sub->name.len))
+			if(str_hash_case_get(&rm_hdrs, sub->name.s, sub->name.len))
 				continue;
 			pvh_real_replace_reply_reason(msg, &sub->val.v.s);
 			pvh_str_hash_add_key(&rm_hdrs, &sub->name);
 			continue;
 		}
 
-		if(!str_hash_get(&rm_hdrs, sub->name.s, sub->name.len)) {
-			if(!pvh_xavp_is_null(sub) && xavp_count(&sub->name, &sub) == 1) {
+		if(!str_hash_case_get(&rm_hdrs, sub->name.s, sub->name.len)) {
+			if(!pvh_avp_is_null(sub) && xavi_count(&sub->name, &sub) == 1) {
 				LM_DBG("replace header[%s]: %s\n", sub->name.s, sub->val.v.s.s);
 				pvh_real_hdr_replace(msg, &sub->name, &sub->val.v.s);
 				pvh_str_hash_add_key(&rm_hdrs, &sub->name);
@@ -282,7 +282,7 @@ int pvh_apply_headers(struct sip_msg *msg)
 			pvh_str_hash_add_key(&rm_hdrs, &sub->name);
 		}
 
-		if(!pvh_xavp_is_null(sub) && !pvh_single_header(&sub->name)) {
+		if(!pvh_avp_is_null(sub) && !pvh_single_header(&sub->name)) {
 			pvh_real_hdr_append(msg, &sub->name, &sub->val.v.s);
 			LM_DBG("append header[%s]: %s\n", sub->name.s, sub->val.v.s.s);
 		}
@@ -303,12 +303,12 @@ int pvh_reset_headers(struct sip_msg *msg)
 	char t[header_name_size];
 	str br_xname = {t, header_name_size};
 
-	pvh_get_branch_xname(msg, &xavp_name, &br_xname);
-	LM_DBG("clean xavp:%.*s\n", br_xname.len, br_xname.s);
-	pvh_free_xavp(&br_xname);
-	pvh_get_branch_xname(msg, &xavp_parsed_xname, &br_xname);
-	LM_DBG("clean xavp:%.*s\n", br_xname.len, br_xname.s);
-	pvh_free_xavp(&br_xname);
+	pvh_get_branch_xname(msg, &xavi_name, &br_xname);
+	LM_DBG("clean xavi:%.*s\n", br_xname.len, br_xname.s);
+	xavi_rm_by_name(&br_xname, 1, NULL);
+	pvh_get_branch_xname(msg, &xavi_parsed_xname, &br_xname);
+	LM_DBG("clean xavi:%.*s\n", br_xname.len, br_xname.s);
+	xavi_rm_by_name(&br_xname, 1, NULL);
 
 	pvh_hdrs_reset_flags(msg);
 
@@ -318,7 +318,7 @@ int pvh_reset_headers(struct sip_msg *msg)
 int pvh_check_header(struct sip_msg *msg, str *hname)
 {
 
-	if(pvh_xavp_get_child(msg, &xavp_name, hname) == NULL)
+	if(pvh_xavi_get_child(msg, &xavi_name, hname) == NULL)
 		return -1;
 
 	return 1;
@@ -326,12 +326,12 @@ int pvh_check_header(struct sip_msg *msg, str *hname)
 
 int pvh_append_header(struct sip_msg *msg, str *hname, str *hvalue)
 {
-	return pvh_set_xavp(msg, &xavp_name, hname, hvalue, SR_XTYPE_STR, 0, 1);
+	return pvh_set_xavi(msg, &xavi_name, hname, hvalue, SR_XTYPE_STR, 0, 1);
 }
 
 int pvh_modify_header(struct sip_msg *msg, str *hname, str *hvalue, int indx)
 {
-	return pvh_set_xavp(msg, &xavp_name, hname, hvalue, SR_XTYPE_STR, indx, 0);
+	return pvh_set_xavi(msg, &xavi_name, hname, hvalue, SR_XTYPE_STR, indx, 0);
 }
 
 int pvh_remove_header(struct sip_msg *msg, str *hname, int indx)
@@ -339,19 +339,19 @@ int pvh_remove_header(struct sip_msg *msg, str *hname, int indx)
 	sr_xavp_t *avp = NULL;
 	int count = 0;
 
-	if((avp = pvh_xavp_get_child(msg, &xavp_name, hname)) == NULL)
+	if((avp = pvh_xavi_get_child(msg, &xavi_name, hname)) == NULL)
 		return 1;
 
 	if(indx < 0) {
-		count = xavp_count(hname, &avp);
+		count = xavi_count(hname, &avp);
 		do {
-			if(pvh_set_xavp(
-					   msg, &xavp_name, hname, NULL, SR_XTYPE_STR, indx++, 0)
+			if(pvh_set_xavi(
+					   msg, &xavi_name, hname, NULL, SR_XTYPE_STR, indx++, 0)
 					< 1)
 				return -1;
 		} while(indx < count);
 	} else {
-		if(pvh_set_xavp(msg, &xavp_name, hname, NULL, SR_XTYPE_STR, indx, 0)
+		if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_STR, indx, 0)
 				< 1)
 			return -1;
 	}

+ 3 - 3
src/modules/pv_headers/pvh_hash.c

@@ -80,7 +80,7 @@ int pvh_str_hash_add_key(struct str_hash_table *ht, str *key)
 		goto err;
 	pvh_str_copy(&e->key, key, key->len + 1);
 
-	str_hash_add(ht, e);
+	str_hash_case_add(ht, e);
 	return 1;
 
 err:
@@ -116,7 +116,7 @@ int pvh_skip_header(str *hname)
 	if(hname == NULL)
 		return 0;
 
-	if(str_hash_get(&skip_headers, hname->s, hname->len))
+	if(str_hash_case_get(&skip_headers, hname->s, hname->len))
 		return 1;
 
 	return 0;
@@ -127,7 +127,7 @@ int pvh_single_header(str *hname)
 	if(hname == NULL)
 		return 0;
 
-	if(str_hash_get(&single_headers, hname->s, hname->len))
+	if(str_hash_case_get(&single_headers, hname->s, hname->len))
 		return 1;
 
 	return 0;

+ 229 - 209
src/modules/pv_headers/pvh_xavp.c

@@ -33,57 +33,60 @@
 
 static str reply_counter = str_init("reply_counter");
 
-sr_xavp_t *pvh_xavp_get_child_with_ival(
+/**
+ *
+ */
+static sr_xavp_t *pvh_xavi_get_child_with_ival(
 		str *rname, str *cname, sr_xavp_t *start)
 {
-	sr_xavp_t *ravp = NULL;
-	sr_xavp_t *vavp = NULL;
+	sr_xavp_t *ravi = NULL;
+	sr_xavp_t *vavi = NULL;
 
-	ravp = xavp_get(rname, start);
-	if(ravp == NULL || ravp->val.type != SR_XTYPE_XAVP)
+	ravi = xavi_get(rname, start);
+	if(ravi == NULL || ravi->val.type != SR_XTYPE_XAVP)
 		return NULL;
 
-	vavp = xavp_get(cname, ravp->val.v.xavp);
-	if(vavp == NULL || vavp->val.type != SR_XTYPE_INT)
+	vavi = xavi_get(cname, ravi->val.v.xavp);
+	if(vavi == NULL || vavi->val.type != SR_XTYPE_INT)
 		return NULL;
 
-	return vavp;
+	return vavi;
 }
 
 /**
- * We keep a $xavp(xavp_helper_xname=>reply_counter) with the number of replies
- * so we will use $xavp(xavp_name.r.<id>) on reply_route
+ * We keep a $xavi(xavi_helper_xname=>reply_counter) with the number of replies
+ * so we will use $xavi(xavi_name.r.<id>) on reply_route
  */
 int pvh_reply_append(sr_xavp_t **start)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	sr_xval_t xval;
 
-	xavp = pvh_xavp_get_child_with_ival(
-			&xavp_helper_xname, &reply_counter, start ? *start : NULL);
-	if(xavp) {
-		xavp->val.v.i++;
-		LM_DBG("reply message: %d\n", xavp->val.v.i);
-		return xavp->val.v.i;
+	xavi = pvh_xavi_get_child_with_ival(
+			&xavi_helper_xname, &reply_counter, start ? *start : NULL);
+	if(xavi) {
+		xavi->val.v.i++;
+		LM_DBG("reply message: %d\n", xavi->val.v.i);
+		return xavi->val.v.i;
 	}
 
 	memset(&xval, 0, sizeof(sr_xval_t));
 	xval.type = SR_XTYPE_INT;
 	xval.v.i = 0;
 
-	xavp = xavp_get(&xavp_helper_xname, start ? *start : NULL);
-	if(xavp == NULL) {
-		if(xavp_add_xavp_value(&xavp_helper_xname, &reply_counter, &xval,
+	xavi = xavi_get(&xavi_helper_xname, start ? *start : NULL);
+	if(xavi == NULL) {
+		if(xavi_add_xavi_value(&xavi_helper_xname, &reply_counter, &xval,
 				   start ? start : NULL)
 				== NULL) {
-			LM_ERR("can't create xavp:%.*s\n", xavp_helper_xname.len,
-					xavp_helper_xname.s);
+			LM_ERR("can't create xavi:%.*s\n", xavi_helper_xname.len,
+					xavi_helper_xname.s);
 			return -1;
 		}
-		LM_DBG("xavp_name:%.*s created\n", xavp_helper_xname.len,
-				xavp_helper_xname.s);
+		LM_DBG("xavi_name:%.*s created\n", xavi_helper_xname.len,
+				xavi_helper_xname.s);
 	} else {
-		if(xavp_add_value(&reply_counter, &xval, &xavp->val.v.xavp) == NULL) {
+		if(xavi_add_value(&reply_counter, &xval, &xavi->val.v.xavp) == NULL) {
 			LM_ERR("can't add reply_counter value\n");
 			return -1;
 		}
@@ -93,7 +96,7 @@ int pvh_reply_append(sr_xavp_t **start)
 	return xval.v.i;
 }
 
-sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
+static sr_xavp_t *pvh_xavi_new_value(str *name, sr_xval_t *val)
 {
 	sr_xavp_t *avp = NULL;
 	int size;
@@ -101,7 +104,7 @@ sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
 
 	if(name == NULL || name->s == NULL || val == NULL)
 		return NULL;
-	id = get_hash1_raw(name->s, name->len);
+	id = get_hash1_case_raw(name->s, name->len);
 
 	size = sizeof(sr_xavp_t) + name->len + 1;
 	if(val->type == SR_XTYPE_STR)
@@ -128,83 +131,82 @@ sr_xavp_t *pvh_xavp_new_value(str *name, sr_xval_t *val)
 	return avp;
 }
 
-int pvh_xavp_append_value(str *name, sr_xval_t *val, sr_xavp_t **start)
+int pvh_xavi_append_value(str *name, sr_xval_t *val, sr_xavp_t **start)
 {
 	sr_xavp_t *last = NULL;
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 
-	if((xavp = pvh_xavp_new_value(name, val)) == NULL)
+	if((xavi = pvh_xavi_new_value(name, val)) == NULL)
 		return -1;
 
 	if(*start == NULL) {
-		xavp->next = *start;
-		*start = xavp;
+		xavi->next = *start;
+		*start = xavi;
 		return 1;
 	}
 
 	last = *start;
 	while(last->next)
 		last = last->next;
-	last->next = xavp;
+	last->next = xavi;
 
 	return 1;
 }
 
-int pvh_xavp_set_value(str *name, sr_xval_t *val, int idx, sr_xavp_t **start)
+/**
+ *
+ */
+static int pvh_xavi_set_value(
+		str *name, sr_xval_t *val, int idx, sr_xavp_t **start)
 {
 	int cnt = 0;
 
 	if(idx < 0) {
-		cnt = xavp_count(name, start);
+		cnt = xavi_count(name, start);
 		idx = idx + cnt;
-		if(idx < 0)
+		if(idx < 0) {
+			LM_ERR("wrong calculated idx:%d\n", idx);
 			return -1;
+		}
 	}
-	LM_DBG("xavp name: %.*s\n", name->len, name->s);
-	if(xavp_set_value(name, idx, val, start) == NULL)
+	LM_DBG("xavi name: %.*s\n", name->len, name->s);
+	if(xavi_set_value(name, idx, val, start) == NULL)
 		return -1;
 
 	return 1;
 }
 
-sr_xavp_t *pvh_xavp_get(struct sip_msg *msg, str *xname)
+/**
+ *
+ */
+static sr_xavp_t *pvh_get_xavi(struct sip_msg *msg, str *xname)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	char t[header_name_size];
 	str br_xname = {t, header_name_size};
 
 	pvh_get_branch_xname(msg, xname, &br_xname);
-	if((xavp = xavp_get(&br_xname, NULL)) == NULL) {
+	if((xavi = xavi_get(&br_xname, NULL)) == NULL) {
 		if(cmp_str(xname, &br_xname) == 0)
 			goto end;
-		if((xavp = xavp_get(xname, NULL)) == NULL)
+		if((xavi = xavi_get(xname, NULL)) == NULL)
 			goto end;
-		if(xname != &xavp_parsed_xname) {
-			LM_DBG("br_xname:%.*s is not there, using xname:%.*s\n",
-					br_xname.len, br_xname.s, xname->len, xname->s);
-		}
 	}
 
-	if(xavp->val.type != SR_XTYPE_XAVP) {
+	if(xavi->val.type != SR_XTYPE_XAVP) {
 		LM_ERR("not xavp child type %s\n", br_xname.s);
-		xavp = NULL;
+		xavi = NULL;
 		goto end;
 	}
 
 end:
-	return xavp;
-}
-
-int pvh_free_xavp(str *xname)
-{
-	sr_xavp_t *xavp = NULL;
-	xavp_rm_by_name(xname, 1, NULL);
-	if((xavp = xavp_get(xname, NULL)) != NULL)
-		xavp_rm(xavp, NULL);
-	return 1;
+	return xavi;
 }
 
-void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
+/**
+ *
+ */
+static void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
 {
 	struct to_param *n = NULL;
 
@@ -216,6 +218,9 @@ void pvh_free_to_params(struct to_param *param, sr_xavp_sfree_f sfree)
 	param = NULL;
 }
 
+/**
+ *
+ */
 int pvh_parse_header_name(pv_spec_p sp, str *hname)
 {
 	pv_spec_p psp = NULL;
@@ -237,13 +242,12 @@ int pvh_parse_header_name(pv_spec_p sp, str *hname)
 			return -1;
 		}
 		if(pv_parse_spec(hname, psp) == NULL) {
-			LM_ERR("invalid avp name [%.*s]\n", hname->len, hname->s);
+			LM_ERR("invalid name [%.*s]\n", hname->len, hname->s);
 			pv_spec_free(psp);
 			return -1;
 		}
 		sp->pvp.pvn.type = PV_NAME_PVAR;
 		sp->pvp.pvn.u.dname = (void *)psp;
-		sp->pvp.pvn.u.isname.name.s = *hname;
 		return 0;
 	}
 
@@ -254,42 +258,51 @@ int pvh_parse_header_name(pv_spec_p sp, str *hname)
 	return 0;
 }
 
-sr_xval_t *pvh_xavp_get_value(
+/**
+ *
+ */
+static sr_xval_t *pvh_xavi_get_value(
 		struct sip_msg *msg, str *xname, str *name, int idx)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	sr_xavp_t *sub = NULL;
 
-	if((xavp = pvh_xavp_get(msg, xname)) != NULL) {
-		/*	LM_DBG("xavp:%.*s name:%.*s idx:%d\n", xavp->name.len, xavp->name.s,
+	if((xavi = pvh_get_xavi(msg, xname)) != NULL) {
+		/*	LM_DBG("xavi:%.*s name:%.*s idx:%d\n", xavi->name.len, xavi->name.s,
 				name->len, name->s, idx); */
-		sub = xavp_get_by_index(name, idx, &xavp->val.v.xavp);
+		sub = xavi_get_by_index(name, idx, &xavi->val.v.xavp);
 	}
 
 	return sub ? &sub->val : NULL;
 }
 
-sr_xavp_t *pvh_xavp_get_child(struct sip_msg *msg, str *xname, str *name)
+/**
+ *
+ */
+sr_xavp_t *pvh_xavi_get_child(struct sip_msg *msg, str *xname, str *name)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	char t[header_name_size];
 	str br_xname = {t, header_name_size};
 
 	pvh_get_branch_xname(msg, xname, &br_xname);
-	xavp = xavp_get_child(&br_xname, name);
-	if(xavp == NULL) {
+	xavi = xavi_get_child(&br_xname, name);
+	if(xavi == NULL) {
 		if(cmp_str(xname, &br_xname) != 0) {
-			xavp = xavp_get_child(xname, name);
-			if(xavp) {
-				LM_DBG("br_xname:%.*s is not there, using xname:%.*s\n",
+			xavi = xavi_get_child(xname, name);
+			if(xavi) {
+				LM_DBG("br_xname:%.*s is not here, using xname:%.*s\n",
 						br_xname.len, br_xname.s, xname->len, xname->s);
 			}
 		}
 	}
-	return xavp;
+	return xavi;
 }
 
-int pvh_xavp_is_null(sr_xavp_t *avp)
+/**
+ *
+ */
+int pvh_avp_is_null(sr_xavp_t *avp)
 {
 	if(avp == NULL)
 		return 1;
@@ -303,7 +316,10 @@ int pvh_xavp_is_null(sr_xavp_t *avp)
 	return 0;
 }
 
-void pvh_xavp_free_data(void *p, sr_xavp_sfree_f sfree)
+/**
+ *
+ */
+static void pvh_xavi_free_data(void *p, sr_xavp_sfree_f sfree)
 {
 	xavp_c_data_t *c_data = NULL;
 
@@ -316,28 +332,34 @@ void pvh_xavp_free_data(void *p, sr_xavp_sfree_f sfree)
 	}
 }
 
-int pvh_xavp_keys_count(sr_xavp_t **start)
+/**
+ *
+ */
+int pvh_xavi_keys_count(sr_xavp_t **start)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	int cnt = 0;
 
 	if(*start == NULL)
 		return 0;
 
-	xavp = *start;
+	xavi = *start;
 
-	while(xavp) {
+	while(xavi) {
 		cnt++;
-		xavp = xavp->next;
+		xavi = xavi->next;
 	}
 
 	return cnt;
 }
 
-int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
+/**
+ *
+ */
+int pvh_set_xavi(struct sip_msg *msg, str *xname, str *name, void *data,
 		sr_xtype_t type, int idx, int append)
 {
-	sr_xavp_t **xavp = NULL;
+	sr_xavp_t **xavi = NULL;
 	sr_xavp_t *root = NULL;
 	sr_xval_t root_xval;
 	sr_xval_t xval;
@@ -345,13 +367,13 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
 	str br_xname = {t, header_name_size};
 
 	if(xname == NULL || name == NULL) {
-		LM_ERR("missing xavp/pv name\n");
+		LM_ERR("missing xavi/pv name\n");
 		return -1;
 	}
 
 	pvh_get_branch_xname(msg, xname, &br_xname);
-	LM_DBG("br_xname: %.*s name: %.*s\n", br_xname.len, br_xname.s, name->len,
-			name->s);
+	LM_DBG("br_xname: %.*s name: %.*s append:%d\n", br_xname.len, br_xname.s,
+			name->len, name->s, append);
 	memset(&xval, 0, sizeof(sr_xval_t));
 	if(data == NULL || SR_XTYPE_NULL) {
 		xval.type = SR_XTYPE_NULL;
@@ -367,17 +389,17 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
 		}
 		memset(xval.v.data, 0, sizeof(sr_data_t));
 		xval.v.data->p = data;
-		xval.v.data->pfree = pvh_xavp_free_data;
+		xval.v.data->pfree = pvh_xavi_free_data;
 	}
 
-	root = xavp_get(&br_xname, NULL);
+	root = xavi_get(&br_xname, NULL);
 
 	if(root == NULL && _branch > 0) {
-		pvh_clone_branch_xavp(msg, xname);
-		root = xavp_get(&br_xname, NULL);
+		pvh_clone_branch_xavi(msg, xname);
+		root = xavi_get(&br_xname, NULL);
 	}
 
-	xavp = root ? &root->val.v.xavp : &root;
+	xavi = root ? &root->val.v.xavp : &root;
 
 	if(root == NULL) {
 		append = 1;
@@ -385,25 +407,25 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
 		root_xval.type = SR_XTYPE_XAVP;
 		root_xval.v.xavp = NULL;
 
-		if((root = xavp_add_value(&br_xname, &root_xval, NULL)) == NULL) {
-			LM_ERR("error create xavp %s\n", br_xname.s);
+		if((root = xavi_add_value(&br_xname, &root_xval, NULL)) == NULL) {
+			LM_ERR("error create xavi %.*s\n", br_xname.len, br_xname.s);
 			return -1;
 		}
-		xavp = &root->val.v.xavp;
-	} else if(xavp_get_child(&br_xname, name) == NULL) {
+		xavi = &root->val.v.xavp;
+	} else if(xavi_get_child(&br_xname, name) == NULL) {
 		append = 1;
 	}
 
 	if(append) {
-		if(pvh_xavp_append_value(name, &xval, xavp) < 0) {
-			LM_ERR("error append xavp=>name %s=>%.*s\n", br_xname.s, name->len,
-					name->s);
+		if(pvh_xavi_append_value(name, &xval, xavi) < 0) {
+			LM_ERR("error append xavi=>name %.*s=>%.*s\n", br_xname.len,
+					br_xname.s, name->len, name->s);
 			return -1;
 		}
 	} else {
-		if(pvh_xavp_set_value(name, &xval, idx, xavp) < 0) {
-			LM_ERR("error modify xavp=>name %s=>%.*s idx=%d\n", br_xname.s,
-					name->len, name->s, idx);
+		if(pvh_xavi_set_value(name, &xval, idx, xavi) < 0) {
+			LM_ERR("error modify xavi=>name %.*s=>%.*s idx=%d\n", br_xname.len,
+					br_xname.s, name->len, name->s, idx);
 			return -1;
 		}
 	}
@@ -411,32 +433,10 @@ int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
 	return 1;
 }
 
-int pvh_get_branch_index(struct sip_msg *msg, int *br_idx)
-{
-	int os = 0;
-	int len = 0;
-	char parsed_br_idx[header_value_size];
-
-	if(msg->add_to_branch_len > header_value_size) {
-		LM_ERR("branch name is too long\n");
-		return -1;
-	}
-
-	os = msg->add_to_branch_len;
-	while(os > 0 && memcmp(msg->add_to_branch_s + os - 1, ".", 1))
-		os--;
-	len = msg->add_to_branch_len - os;
-	if(os > 0 && len > 0) {
-		memcpy(parsed_br_idx, msg->add_to_branch_s + os, len);
-		parsed_br_idx[len] = '\0';
-		*br_idx = atoi(parsed_br_idx) + 1;
-	} else {
-		*br_idx = 0;
-	}
-
-	return 1;
-}
 
+/**
+ *
+ */
 int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst)
 {
 	int os = 0;
@@ -470,28 +470,32 @@ int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst)
 	return 1;
 }
 
-int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
+/**
+ *
+ */
+int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname)
 {
-	sr_xavp_t *xavp = NULL;
-	sr_xavp_t *br_xavp = NULL;
+	sr_xavp_t *xavi = NULL;
+	sr_xavp_t *br_xavi = NULL;
 	sr_xavp_t *sub = NULL;
 	sr_xval_t root_xval;
 	char t[header_name_size];
 	str br_xname = {t, header_name_size};
 	int i = 0;
 
-	if((xavp = xavp_get(xname, NULL)) == NULL) {
-		LM_ERR("cannot clone xavp from non existing %s\n", xname->s);
+	if((xavi = xavi_get(xname, NULL)) == NULL) {
+		LM_ERR("cannot clone xavi from non existing %.*s\n", xname->len,
+				xname->s);
 		return -1;
 	}
 
-	if(xavp->val.type != SR_XTYPE_XAVP) {
-		LM_ERR("not xavp child type %s\n", xavp_name.s);
+	if(xavi->val.type != SR_XTYPE_XAVP) {
+		LM_ERR("not xavp child type %.*s\n", xavi_name.len, xavi_name.s);
 		return -1;
 	}
 
-	if((sub = xavp->val.v.xavp) == NULL) {
-		LM_ERR("invalid xavp structure: %s\n", xavp_name.s);
+	if((sub = xavi->val.v.xavp) == NULL) {
+		LM_ERR("invalid xavi structure: %.*s\n", xavi_name.len, xavi_name.s);
 		return -1;
 	}
 
@@ -501,12 +505,12 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
 	root_xval.type = SR_XTYPE_XAVP;
 	root_xval.v.xavp = NULL;
 
-	if((br_xavp = xavp_add_value(&br_xname, &root_xval, NULL)) == NULL) {
-		LM_ERR("error create xavp %s\n", br_xname.s);
+	if((br_xavi = xavi_add_value(&br_xname, &root_xval, NULL)) == NULL) {
+		LM_ERR("error create xavi %.*s\n", br_xname.len, br_xname.s);
 		return -1;
 	}
 
-	if(cmp_str(xname, &xavp_parsed_xname) == 0) {
+	if(cmp_str(xname, &xavi_parsed_xname) == 0) {
 		return 1;
 	}
 
@@ -515,9 +519,9 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
 			continue;
 		if(sub->val.type == SR_XTYPE_DATA)
 			continue;
-		if(pvh_xavp_append_value(&sub->name, &sub->val, &br_xavp->val.v.xavp)
+		if(pvh_xavi_append_value(&sub->name, &sub->val, &br_xavi->val.v.xavp)
 				< 0) {
-			LM_ERR("cannot clone xavp %s\n", sub->name.s);
+			LM_ERR("cannot clone xavi %.*s\n", sub->name.len, sub->name.s);
 			return -1;
 		}
 		++i;
@@ -527,9 +531,12 @@ int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname)
 	return 1;
 }
 
+/**
+ *
+ */
 int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL;
 	sr_xval_t *xval = NULL;
 	pv_value_t tv;
 	str hname = STR_NULL;
@@ -554,16 +561,16 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 	}
 
 	if(idx < 0) {
-		if((xavp = pvh_xavp_get_child(msg, &xavp_name, &hname)) == NULL)
+		if((xavi = pvh_xavi_get_child(msg, &xavi_name, &hname)) == NULL)
 			cnt = 0;
 		else
-			cnt = xavp_count(&hname, &xavp);
+			cnt = xavi_count(&hname, &xavi);
 		idx = idx + cnt;
 		if(idx < 0)
 			pv_get_null(msg, param, res);
 	}
 
-	xval = pvh_xavp_get_value(msg, &xavp_name, &hname, idx);
+	xval = pvh_xavi_get_value(msg, &xavi_name, &hname, idx);
 
 	if(xval == NULL || !xval->v.s.s)
 		return pv_get_null(msg, param, res);
@@ -571,56 +578,56 @@ int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 	return pv_get_strval(msg, param, res, &xval->v.s);
 }
 
+/**
+ *
+ */
 int pvh_set_header(
 		struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 {
-	sr_xavp_t *xavp = NULL;
+	sr_xavp_t *xavi = NULL, *avi = NULL;
 	pv_elem_p pv_format = NULL;
 	pv_value_t tv;
-	str hname = STR_NULL;
-	str orig_hname = STR_NULL;
-	str fval;
-	int idx = 0;
-	int cnt = 0;
-	int itype;
-
-	idx = param->pvi.u.ival;
-	itype = param->pvi.type;
+	str *hname = NULL;
+	str fval = STR_NULL;
+	int idxf, idx, hname_cnt, cnt;
 
-	if(param->pvn.type == PV_NAME_PVAR) {
-		if(pv_get_spec_value(msg, (pv_spec_p)(param->pvn.u.dname), &tv) != 0) {
-			LM_ERR("cannot get avp value\n");
-			return -1;
-		}
-		if(!(tv.flags & PV_VAL_STR)) {
-			LM_ERR("invalid avp value, must be a string\n");
-			return -1;
-		}
-		hname = tv.rs;
-		orig_hname = param->pvn.u.isname.name.s;
-	} else if(param->pvn.u.isname.type == AVP_NAME_STR) {
-		hname = param->pvn.u.isname.name.s;
-		orig_hname = hname;
-	} else {
+	if(pv_get_spec_name(msg, param, &tv) != 0 || (!(tv.flags & PV_VAL_STR))) {
 		LM_ERR("invalid header name, must be a string\n");
 		return -1;
 	}
+	hname = &tv.rs;
+
+	/* get the index */
+	if(pv_get_spec_index(msg, param, &idx, &idxf) != 0) {
+		LM_ERR("invalid index\n");
+		return -1;
+	}
 
-	if((xavp = pvh_xavp_get_child(msg, &xavp_name, &hname)) == NULL)
+	xavi = pvh_get_xavi(msg, &xavi_name);
+	avi = xavi->val.v.xavp;
+	hname_cnt = xavi_count(hname, &avi);
+	if(hname_cnt == 0) {
 		idx = 0;
-	else if(idx < 0)
-		idx = idx + xavp_count(&hname, &xavp);
+	} else if(idx < 0) {
+		idx = idx + hname_cnt;
+	}
+	if(idx < 0) {
+		LM_ERR("invalid index\n");
+		return -1;
+	}
+	LM_DBG("xavi:%.*s hname:%.*s hname_cnt:%d idx:%d idxf:%d\n", xavi->name.len,
+			xavi->name.s, hname->len, hname->s, hname_cnt, idx, idxf);
 
 	if(val == NULL || (val->flags & PV_VAL_NULL)) {
-		if(itype == PV_IDX_ALL) {
-			for(idx = xavp_count(&hname, &xavp) - 1; idx >= 0; idx--) {
-				if(pvh_set_xavp(
-						   msg, &xavp_name, &hname, NULL, SR_XTYPE_STR, idx, 0)
-						< 0)
-					goto err;
-			}
+		if(idxf == PV_IDX_ALL) {
+			cnt = xavi_rm_by_name(hname, 1, &xavi);
+			LM_DBG("removed %d values of %.*s=>%.*s, set $null\n", cnt,
+					xavi->name.len, xavi->name.s, hname->len, hname->s);
+			if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_NULL, 0, 0)
+					< 0)
+				goto err;
 		} else {
-			if(pvh_set_xavp(msg, &xavp_name, &hname, NULL, SR_XTYPE_STR, idx, 0)
+			if(pvh_set_xavi(msg, &xavi_name, hname, NULL, SR_XTYPE_NULL, idx, 0)
 					< 0)
 				goto err;
 		}
@@ -638,27 +645,22 @@ int pvh_set_header(
 			LM_ERR("cannot parse format: %.*s\n", val->rs.len, val->rs.s);
 			goto err;
 		}
-		if(strlen(orig_hname.s) > 1
-				&& strcmp(orig_hname.s + strlen(orig_hname.s) - 2, "])") != 0) {
-			if(pvh_set_xavp(msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, 0, 1)
+		if(idx == 0 && idxf == PV_IDX_NONE) {
+			if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0, 1)
 					< 0)
 				goto err;
-		} else if(itype == PV_IDX_ALL) {
-			idx = 0;
-			cnt = xavp_count(&hname, &xavp);
-			while(idx < cnt) {
-				if(pvh_set_xavp(msg, &xavp_name, &hname, NULL, SR_XTYPE_STR,
-						   idx++, 0)
-						< 1)
-					goto err;
+		} else if(idxf == PV_IDX_ALL) {
+			if(hname_cnt > 1) {
+				cnt = xavi_rm_by_name(hname, 1, &xavi);
+				LM_DBG("removed %d values of %.*s=>%.*s\n", cnt, xavi->name.len,
+						xavi->name.s, hname->len, hname->s);
 			}
-			if(pvh_set_xavp(msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, 0,
-					   cnt ? 0 : 1)
+			if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, 0,
+					   hname_cnt ? 0 : 1)
 					< 0)
 				goto err;
 		} else {
-			if(pvh_set_xavp(
-					   msg, &xavp_name, &hname, &fval, SR_XTYPE_STR, idx, 0)
+			if(pvh_set_xavi(msg, &xavi_name, hname, &fval, SR_XTYPE_STR, idx, 0)
 					< 0)
 				goto err;
 		}
@@ -666,7 +668,7 @@ int pvh_set_header(
 			pv_elem_free_all(pv_format);
 	} else {
 		LM_ERR("x_hdr %.*s value can be either string, integer or null\n",
-				hname.len, hname.s);
+				hname->len, hname->s);
 		goto err;
 	}
 	return 1;
@@ -677,6 +679,9 @@ err:
 	return -1;
 }
 
+/**
+ *
+ */
 xavp_c_data_t *pvh_set_parsed(
 		struct sip_msg *msg, str *hname, str *cur, str *new)
 {
@@ -693,7 +698,7 @@ xavp_c_data_t *pvh_set_parsed(
 		val = cur;
 	if(pvh_merge_uri(msg, SET_URI_T, cur, val, c_data) < 0)
 		goto err;
-	if(pvh_set_xavp(msg, &xavp_parsed_xname, hname, c_data, SR_XTYPE_DATA, 0, 0)
+	if(pvh_set_xavi(msg, &xavi_parsed_xname, hname, c_data, SR_XTYPE_DATA, 0, 0)
 			< 0)
 		goto err;
 	LM_DBG("c_data from pvh_merge_uri hname:%.*s\n", hname->len, hname->s);
@@ -701,10 +706,13 @@ xavp_c_data_t *pvh_set_parsed(
 	return c_data;
 
 err:
-	// how can I call?? pvh_xavp_free_data(c_data, shm_free);
+	// how can I call?? pvh_xavi_free_data(c_data, shm_free);
 	return NULL;
 }
 
+/**
+ *
+ */
 int pvh_get_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	sr_xval_t *xval = NULL;
@@ -723,17 +731,17 @@ int pvh_get_uri(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 	else if(p_no >= 6 && p_no <= 10)
 		pvh_str_copy(&hname, &_hdr_to, header_name_size);
 
-	xval = pvh_xavp_get_value(msg, &xavp_name, &hname, 0);
+	xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0);
 	if(xval == NULL || !xval->v.s.s) {
-		/*	LM_DBG("xavp:%.*s hname:%.*s is null\n", xavp_name.len, xavp_name.s,
+		/*	LM_DBG("xavi:%.*s hname:%.*s is null\n", xavi_name.len, xavi_name.s,
 				hname.len, hname.s); */
 		goto err;
 	}
 
-	xval_pd = pvh_xavp_get_value(msg, &xavp_parsed_xname, &hname, 0);
+	xval_pd = pvh_xavi_get_value(msg, &xavi_parsed_xname, &hname, 0);
 
 	if(xval_pd) {
-		/*	LM_DBG("p_no:%d c_data from xavp_parsed_xname hname:%.*s\n", p_no,
+		/*	LM_DBG("p_no:%d c_data from xavi_parsed_xname hname:%.*s\n", p_no,
 				hname.len, hname.s); */
 		c_data = (xavp_c_data_t *)xval_pd->v.data->p;
 	}
@@ -782,6 +790,9 @@ err:
 	return pv_get_null(msg, param, res);
 }
 
+/**
+ *
+ */
 int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 {
 	sr_xval_t *xval = NULL;
@@ -836,7 +847,7 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 		goto err;
 	}
 
-	xval = pvh_xavp_get_value(msg, &xavp_name, &hname, 0);
+	xval = pvh_xavi_get_value(msg, &xavi_name, &hname, 0);
 	if(xval == NULL || !xval->v.s.s)
 		goto err;
 
@@ -848,14 +859,14 @@ int pvh_set_uri(struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 	memset(c_data, 0, sizeof(xavp_c_data_t));
 	if(pvh_merge_uri(msg, a_type, &xval->v.s, &fval, c_data) < 0)
 		goto err;
-	/*	LM_DBG("xavp:%.*s hname:%.*s value:%.*s\n", xavp_name.len, xavp_name.s,
+	/*	LM_DBG("xavi:%.*s hname:%.*s value:%.*s\n", xavi_name.len, xavi_name.s,
 			hname.len, hname.s, c_data->value.len, c_data->value.s); */
-	if(pvh_set_xavp(msg, &xavp_name, &hname, &c_data->value, SR_XTYPE_STR, 0, 0)
+	if(pvh_set_xavi(msg, &xavi_name, &hname, &c_data->value, SR_XTYPE_STR, 0, 0)
 			< 0)
 		goto err;
 
-	if(pvh_set_xavp(
-			   msg, &xavp_parsed_xname, &hname, c_data, SR_XTYPE_DATA, 0, 0)
+	if(pvh_set_xavi(
+			   msg, &xavi_parsed_xname, &hname, c_data, SR_XTYPE_DATA, 0, 0)
 			< 0)
 		goto err;
 
@@ -869,6 +880,9 @@ err:
 	return -1;
 }
 
+/**
+ *
+ */
 int pvh_merge_uri(struct sip_msg *msg, enum action_type type, str *cur,
 		str *new, xavp_c_data_t *c_data)
 {
@@ -1025,6 +1039,9 @@ err:
 	return -1;
 }
 
+/**
+ *
+ */
 int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	sr_xval_t *xval = NULL;
@@ -1042,7 +1059,7 @@ int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 					&msg->first_line.u.reply.status);
 			break;
 		case 2: // reason
-			xval = pvh_xavp_get_value(msg, &xavp_name, &_hdr_reply_reason, 0);
+			xval = pvh_xavi_get_value(msg, &xavi_name, &_hdr_reply_reason, 0);
 			return pv_get_strval(msg, param, res,
 					xval && xval->v.s.s ? &xval->v.s
 										: &msg->first_line.u.reply.reason);
@@ -1054,6 +1071,9 @@ int pvh_get_reply_sr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 	return pv_get_null(msg, param, res);
 }
 
+/**
+ *
+ */
 int pvh_set_reply_sr(
 		struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 {
@@ -1110,7 +1130,7 @@ int pvh_set_reply_sr(
 			msg->first_line.u.reply.status.s[0] = code + '0';
 			break;
 		case 2: // reason
-			if(pvh_set_xavp(msg, &xavp_name, &_hdr_reply_reason, &fval,
+			if(pvh_set_xavi(msg, &xavi_name, &_hdr_reply_reason, &fval,
 					   SR_XTYPE_STR, 0, 0)
 					< 0) {
 				LM_ERR("set reply: cannot set reply reason\n");

+ 5 - 9
src/modules/pv_headers/pvh_xavp.h

@@ -33,18 +33,14 @@
 
 int pvh_reply_append(sr_xavp_t **start);
 
-int pvh_set_xavp(struct sip_msg *msg, str *xname, str *name, void *data,
+int pvh_set_xavi(struct sip_msg *msg, str *xname, str *name, void *data,
 		sr_xtype_t type, int idx, int append);
-int pvh_free_xavp(str *xname);
-int pvh_xavp_is_null(sr_xavp_t *avp);
-int pvh_xavp_keys_count(sr_xavp_t **start);
-sr_xval_t *pvh_xavp_get_value(
-		struct sip_msg *msg, str *xname, str *name, int idx);
-sr_xavp_t *pvh_xavp_get_child(struct sip_msg *msg, str *xname, str *name);
+int pvh_xavi_keys_count(sr_xavp_t **start);
+sr_xavp_t *pvh_xavi_get_child(struct sip_msg *msg, str *xname, str *name);
+int pvh_avp_is_null(sr_xavp_t *avp);
 
-int pvh_get_branch_index(struct sip_msg *msg, int *br_idx);
 int pvh_get_branch_xname(struct sip_msg *msg, str *xname, str *dst);
-int pvh_clone_branch_xavp(struct sip_msg *msg, str *xname);
+int pvh_clone_branch_xavi(struct sip_msg *msg, str *xname);
 
 int pvh_parse_header_name(pv_spec_p sp, str *hname);
 int pvh_get_header(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);