[sr-dev] git:5.3:f641fe53: textops: fix append_hf function

Stefan Mititelu stefan-cristian.mititelu at 1and1.ro
Mon Oct 26 10:32:33 CET 2020


Module: kamailio
Branch: 5.3
Commit: f641fe53fdbbd54db8ef136ec2425d7624e50173
URL: https://github.com/kamailio/kamailio/commit/f641fe53fdbbd54db8ef136ec2425d7624e50173

Author: Stefan Mititelu <stefan-cristian.mititelu at 1and1.ro>
Committer: Stefan Mititelu <stefan-cristian.mititelu at 1and1.ro>
Date: 2020-10-26T11:32:01+02:00

textops: fix append_hf function

Before: append_hf adds header after first header occurance

After: append_hf adds header after last header occurance

(cherry-picked from commit 4adea97a4f8a9b35273d4d28b0518964abb7f0d8)

---

Modified: src/modules/textops/textops.c

---

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

---

diff --git a/src/modules/textops/textops.c b/src/modules/textops/textops.c
index 0b7fd9e16e..580c850e71 100644
--- a/src/modules/textops/textops.c
+++ b/src/modules/textops/textops.c
@@ -3229,7 +3229,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
 		gparam_p hfval, int mode, gparam_p hfanc)
 {
 	struct lump* anchor;
-	struct hdr_field *hf;
+	struct hdr_field *hf, *append_hf;
 	char *s;
 	int len;
 	str s0;
@@ -3240,6 +3240,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
 	}
 
 	hf = 0;
+	append_hf = 0;
 	if(hfanc!=NULL) {
 		for (hf=msg->headers; hf; hf=hf->next) {
 			if(hfanc->type==GPARAM_TYPE_INT)
@@ -3252,20 +3253,25 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
 				if (cmp_hdrname_str(&hf->name,&hfanc->v.str)!=0)
 					continue;
 			}
-			break;
+			if (mode == 0) { /* append */
+				append_hf = hf;
+				continue;
+			} else { /* insert */
+				break;
+			}
 		}
 	}
 
 	if(mode == 0) { /* append */
-		if(hf==0) { /* after last header */
+		if(append_hf==0) { /* after last header */
 			anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
-		} else { /* after hf */
-			anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
+		} else { /* after last hf */
+			anchor = anchor_lump(msg, append_hf->name.s + append_hf->len - msg->buf, 0, 0);
 		}
 	} else { /* insert */
 		if(hf==0) { /* before first header */
 			anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);
-		} else { /* before hf */
+		} else { /* before first hf */
 			anchor = anchor_lump(msg, hf->name.s - msg->buf, 0, 0);
 		}
 	}




More information about the sr-dev mailing list