[sr-dev] git:5.4:9ed21cd1: pv_headers: don't try to replace header

Victor Seva linuxmaniac at torreviejawireless.org
Fri Oct 29 12:06:51 CEST 2021


Module: kamailio
Branch: 5.4
Commit: 9ed21cd119739bb2768518d15fef98b65f5eaa45
URL: https://github.com/kamailio/kamailio/commit/9ed21cd119739bb2768518d15fef98b65f5eaa45

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2021-10-29T12:06:13+02:00

pv_headers: don't try to replace header

Multiple headers where not removed if new value was just one header.

(cherry picked from commit 09981c41cb6685fa18f61b9e7d66339917c4f097)

---

Modified: src/modules/pv_headers/pvh_func.c
Modified: src/modules/pv_headers/pvh_hdr.c
Modified: src/modules/pv_headers/pvh_hdr.h

---

Diff:  https://github.com/kamailio/kamailio/commit/9ed21cd119739bb2768518d15fef98b65f5eaa45.diff
Patch: https://github.com/kamailio/kamailio/commit/9ed21cd119739bb2768518d15fef98b65f5eaa45.patch

---

diff --git a/src/modules/pv_headers/pvh_func.c b/src/modules/pv_headers/pvh_func.c
index 90feddeefde..fcc5b6a00b9 100644
--- a/src/modules/pv_headers/pvh_func.c
+++ b/src/modules/pv_headers/pvh_func.c
@@ -272,12 +272,6 @@ int pvh_apply_headers(struct sip_msg *msg)
 		}
 
 		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);
-				continue;
-			}
 			LM_DBG("remove header[%s]: %s\n", sub->name.s, sub->val.v.s.s);
 			pvh_real_hdr_del_by_name(msg, &sub->name);
 			pvh_str_hash_add_key(&rm_hdrs, &sub->name);
diff --git a/src/modules/pv_headers/pvh_hdr.c b/src/modules/pv_headers/pvh_hdr.c
index d83a646c0db..31c09b4b5da 100644
--- a/src/modules/pv_headers/pvh_hdr.c
+++ b/src/modules/pv_headers/pvh_hdr.c
@@ -131,80 +131,6 @@ int pvh_real_hdr_append(struct sip_msg *msg, str *hname, str *hvalue)
 	return 1;
 }
 
-int pvh_real_hdr_replace(struct sip_msg *msg, str *hname, str *hvalue)
-{
-	struct lump *anchor = NULL;
-	hdr_field_t *hf = NULL;
-	str new_h = STR_NULL;
-	int new = 1;
-
-	if(hname->s == NULL || hvalue->s == NULL) {
-		LM_ERR("header name/value cannot be empty");
-		return -1;
-	}
-
-	for(hf = msg->headers; hf; hf = hf->next) {
-		if(hf->name.len == hname->len
-				&& strncasecmp(hf->name.s, hname->s, hname->len) == 0) {
-			if(hf->body.len == hvalue->len
-					&& strncasecmp(hf->body.s, hvalue->s, hvalue->len) == 0) {
-				return 1;
-			}
-			new = 0;
-			break;
-		}
-		if(!hf->next)
-			break;
-	}
-
-	if(hf == NULL) {
-		LM_ERR("unable to find header lump\n");
-		return -1;
-	}
-
-	if(new == 0) {
-		if((anchor = del_lump(msg, hf->name.s - msg->buf, hf->len, 0)) == 0) {
-			LM_ERR("unable to delete header lump\n");
-			return -1;
-		}
-	} else {
-		anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
-	}
-
-	if(anchor == 0) {
-		LM_ERR("unable to find header lump\n");
-		return -1;
-	}
-
-	if(pvh_create_hdr_str(hname, hvalue, &new_h) <= 0)
-		return -1;
-
-	if(insert_new_lump_after(anchor, new_h.s, new_h.len, 0) == 0) {
-		LM_ERR("cannot insert header lump\n");
-		pkg_free(new_h.s);
-		return -1;
-	}
-
-	LM_DBG("%s header: %.*s\n", new ? "append" : "replace", new_h.len, new_h.s);
-
-	return 1;
-}
-
-int pvh_real_hdr_del_by_name(struct sip_msg *msg, str *hname)
-{
-	hdr_field_t *hf = NULL;
-
-	for(hf = msg->headers; hf; hf = hf->next) {
-		if(hf->name.len == hname->len
-				&& strncasecmp(hf->name.s, hname->s, hname->len) == 0) {
-			LM_DBG("remove header[%.*s]: %.*s\n", hf->name.len, hf->name.s,
-					hf->body.len, hf->body.s);
-			del_lump(msg, hf->name.s - msg->buf, hf->len, 0);
-		}
-	}
-	return 1;
-}
-
 int pvh_real_hdr_remove_display(struct sip_msg *msg, str *hname)
 {
 	hdr_field_t *hf = NULL;
diff --git a/src/modules/pv_headers/pvh_hdr.h b/src/modules/pv_headers/pvh_hdr.h
index 4f869538238..a5ad4157f9d 100644
--- a/src/modules/pv_headers/pvh_hdr.h
+++ b/src/modules/pv_headers/pvh_hdr.h
@@ -38,7 +38,6 @@ void pvh_hdrs_set_applied(struct sip_msg *msg);
 void pvh_hdrs_reset_flags(struct sip_msg *msg);
 
 int pvh_real_hdr_append(struct sip_msg *msg, str *hname, str *hvalue);
-int pvh_real_hdr_replace(struct sip_msg *msg, str *hname, str *hvalue);
 int pvh_real_hdr_del_by_name(struct sip_msg *msg, str *hname);
 int pvh_real_hdr_remove_display(struct sip_msg *msg, str *hname);
 int pvh_real_replace_reply_reason(struct sip_msg *msg, str *value);




More information about the sr-dev mailing list