Browse code

core: add path route headers after local via

- minor header order fix: route header generated from recorded
path are added after the local via if no other route headers are
present in the message (they were added in front of the local
via until now).

Andrei Pelinescu-Onciul authored on 14/09/2009 11:32:08
Showing 1 changed files
... ...
@@ -1563,6 +1563,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1563 1563
 	new_buf=0;
1564 1564
 	received_buf=0;
1565 1565
 	rport_buf=0;
1566
+	via_anchor=0;
1566 1567
 	line_buf=0;
1567 1568
 	via_len=0;
1568 1569
 	path_buf.s=0;
... ...
@@ -1584,8 +1585,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1584 1585
 	branch.s=msg->add_to_branch_s;
1585 1586
 	branch.len=msg->add_to_branch_len;
1586 1587
 
1588
+	via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T);
1589
+	if (unlikely(via_anchor==0)) goto error00;
1587 1590
 	line_buf = create_via_hf( &via_len, msg, send_info, &branch);
1588
-	if (!line_buf){
1591
+	if (unlikely(!line_buf)){
1589 1592
 		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: "
1590 1593
 					"memory allocation failure\n");
1591 1594
 		goto error00;
... ...
@@ -1684,10 +1687,13 @@ after_update_via1:
1684 1687
 		memcpy(path_buf.s+ROUTE_PREFIX_LEN+msg->path_vec.len, CRLF, CRLF_LEN);
1685 1688
 		path_buf.s[path_buf.len]=0;
1686 1689
 		/* insert Route header either before the other routes
1687
-		   (if present & parsed) or after the local via */
1690
+		   (if present & parsed), after the local via or after in front of
1691
+		    the first via if we don't add a local via*/
1688 1692
 		if (msg->route){
1689 1693
 			path_anchor=anchor_lump(msg, msg->route->name.s-buf, 0, 
1690 1694
 									HDR_ROUTE_T);
1695
+		}else if (likely(via_anchor)){
1696
+			path_anchor=via_anchor;
1691 1697
 		}else if (likely(msg->via1)){
1692 1698
 			path_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, 
1693 1699
 									HDR_ROUTE_T);
... ...
@@ -1755,8 +1761,6 @@ after_update_via1:
1755 1761
 	/* try to add it before msg. 1st via */
1756 1762
 	/* add first via, as an anchor for second via*/
1757 1763
 	if(likely(line_buf)) {
1758
-		via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T);
1759
-		if (via_anchor==0) goto error04;
1760 1764
 		if ((via_lump=insert_new_lump_before(via_anchor, line_buf, via_len,
1761 1765
 											HDR_VIA_T))==0)
1762 1766
 			goto error04;