Browse code

lost: change in the method for parsing the From header in lost_get_from_header() related to #2723

(cherry picked from commit fe6923cd8e995c400fc1838304c95142cc00273e)

Wolfgang Kampichler authored on 04/05/2021 21:24:53
Showing 1 changed files
... ...
@@ -442,9 +442,10 @@ p_lost_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
442 442
 	str hdr = STR_NULL;
443 443
 	p_lost_geolist_t list = NULL;
444 444
 
445
+	*items = 0;
446
+
445 447
 	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
446 448
 		LM_ERR("failed to parse SIP headers\n");
447
-		*items = 0;
448 449
 		return list;
449 450
 	}
450 451
 
... ...
@@ -481,8 +482,8 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
481 482
 
482 483
 	*lgth = 0;
483 484
 
484
-	if(parse_headers(msg, HDR_PAI_F, 0) == -1) {
485
-		LM_ERR("could not parse P-A-I header\n");
485
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
486
+		LM_ERR("failed to parse SIP headers\n");
486 487
 		return res;
487 488
 	}
488 489
 
... ...
@@ -640,34 +641,53 @@ int lost_get_nameinfo(char *ip, str *name, int flag)
640 641
  */
641 642
 char *lost_get_from_header(struct sip_msg *msg, int *lgth)
642 643
 {
643
-	to_body_t *f_body;
644
+	struct hdr_field *hf;
645
+	to_body_t *from_body;
644 646
 	char *res = NULL;
645 647
 
646 648
 	*lgth = 0;
647 649
 
648
-	if(parse_headers(msg, HDR_FROM_F, 0) == -1) {
649
-		LM_ERR("failed to parse From header\n");
650
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
651
+		LM_ERR("failed to parse SIP headers\n");
650 652
 		return res;
651 653
 	}
652 654
 
653
-	if(msg->from == NULL || get_from(msg) == NULL) {
654
-		LM_ERR("From header not found\n");
655
-		return res;
656
-	}
657
-	f_body = get_from(msg);
655
+	for(hf = msg->headers; hf; hf = hf->next) {
656
+		if(hf->type == HDR_FROM_T) {
658 657
 
659
-	LM_DBG("From body:  [%.*s]\n", f_body->body.len, f_body->body.s);
658
+			LM_DBG("From body:  [%.*s]\n", hf->body.len, hf->body.s);
660 659
 
661
-	res = (char *)pkg_malloc((f_body->uri.len + 1) * sizeof(char));
662
-	if(res == NULL) {
663
-		PKG_MEM_ERROR;
664
-		return res;
665
-	} else {
666
-		memset(res, 0, f_body->uri.len + 1);
667
-		memcpy(res, f_body->uri.s, f_body->uri.len + 1);
668
-		res[f_body->uri.len] = '\0';
660
+			/* first, get some memory */
661
+			from_body = pkg_malloc(sizeof(to_body_t));
662
+			if(from_body == NULL) {
663
+				PKG_MEM_ERROR;
664
+				return res;
665
+			}
666
+			/* parse From body */
667
+			memset(from_body, 0, sizeof(to_body_t));
668
+			parse_to(hf->body.s, hf->body.s + hf->body.len + 1, from_body);
669
+			if(from_body->error == PARSE_ERROR) {
670
+				LM_ERR("bad From header\n");
671
+				pkg_free(from_body);
672
+				return res;
673
+			}
674
+			if(from_body->error == PARSE_OK) {
675
+				res = (char *)pkg_malloc(
676
+						(from_body->uri.len + 1) * sizeof(char));
677
+				if(res == NULL) {
678
+					PKG_MEM_ERROR;
679
+					pkg_free(from_body);
680
+					return res;
681
+				} else {
682
+					memset(res, 0, from_body->uri.len + 1);
683
+					memcpy(res, from_body->uri.s, from_body->uri.len + 1);
684
+					res[from_body->uri.len] = '\0';
685
+					pkg_free(from_body);
669 686
 
670
-		*lgth = strlen(res);
687
+					*lgth = strlen(res);
688
+				}
689
+			}
690
+		}
671 691
 	}
672 692
 
673 693
 	return res;