Browse code

Merge pull request #2526 from smititelu/master

textops: fix append_hf function

Daniel-Constantin Mierla authored on 23/10/2020 08:26:27 • GitHub committed on 23/10/2020 08:26:27
Showing 1 changed files
... ...
@@ -3361,7 +3361,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
3361 3361
 		gparam_p hfval, int mode, gparam_p hfanc)
3362 3362
 {
3363 3363
 	struct lump* anchor;
3364
-	struct hdr_field *hf;
3364
+	struct hdr_field *hf, *append_hf;
3365 3365
 	char *s;
3366 3366
 	int len;
3367 3367
 	str s0;
... ...
@@ -3372,6 +3372,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
3372 3372
 	}
3373 3373
 
3374 3374
 	hf = 0;
3375
+	append_hf = 0;
3375 3376
 	if(hfanc!=NULL) {
3376 3377
 		for (hf=msg->headers; hf; hf=hf->next) {
3377 3378
 			if(hfanc->type==GPARAM_TYPE_INT)
... ...
@@ -3384,20 +3385,25 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
3384 3385
 				if (cmp_hdrname_str(&hf->name,&hfanc->v.str)!=0)
3385 3386
 					continue;
3386 3387
 			}
3387
-			break;
3388
+			if (mode == 0) { /* append */
3389
+				append_hf = hf;
3390
+				continue;
3391
+			} else { /* insert */
3392
+				break;
3393
+			}
3388 3394
 		}
3389 3395
 	}
3390 3396
 
3391 3397
 	if(mode == 0) { /* append */
3392
-		if(hf==0) { /* after last header */
3398
+		if(append_hf==0) { /* after last header */
3393 3399
 			anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
3394
-		} else { /* after hf */
3395
-			anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);
3400
+		} else { /* after last hf */
3401
+			anchor = anchor_lump(msg, append_hf->name.s + append_hf->len - msg->buf, 0, 0);
3396 3402
 		}
3397 3403
 	} else { /* insert */
3398 3404
 		if(hf==0) { /* before first header */
3399 3405
 			anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);
3400
-		} else { /* before hf */
3406
+		} else { /* before first hf */
3401 3407
 			anchor = anchor_lump(msg, hf->name.s - msg->buf, 0, 0);
3402 3408
 		}
3403 3409
 	}