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 1584
 	branch.s=msg->add_to_branch_s;
1585 1585
 	branch.len=msg->add_to_branch_len;
1586 1586
 
1587
+	via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T);
1588
+	if (unlikely(via_anchor==0)) goto error00;
1587 1589
 	line_buf = create_via_hf( &via_len, msg, send_info, &branch);
1588
-	if (!line_buf){
1590
+	if (unlikely(!line_buf)){
1589 1591
 		LOG(L_ERR,"ERROR: build_req_buf_from_sip_req: "
1590 1592
 					"memory allocation failure\n");
1591 1593
 		goto error00;
... ...
@@ -1684,10 +1687,13 @@ after_update_via1:
1684 1684
 		memcpy(path_buf.s+ROUTE_PREFIX_LEN+msg->path_vec.len, CRLF, CRLF_LEN);
1685 1685
 		path_buf.s[path_buf.len]=0;
1686 1686
 		/* insert Route header either before the other routes
1687
-		   (if present & parsed) or after the local via */
1687
+		   (if present & parsed), after the local via or after in front of
1688
+		    the first via if we don't add a local via*/
1688 1689
 		if (msg->route){
1689 1690
 			path_anchor=anchor_lump(msg, msg->route->name.s-buf, 0, 
1690 1691
 									HDR_ROUTE_T);
1692
+		}else if (likely(via_anchor)){
1693
+			path_anchor=via_anchor;
1691 1694
 		}else if (likely(msg->via1)){
1692 1695
 			path_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, 
1693 1696
 									HDR_ROUTE_T);
... ...
@@ -1755,8 +1761,6 @@ after_update_via1:
1755 1755
 	/* try to add it before msg. 1st via */
1756 1756
 	/* add first via, as an anchor for second via*/
1757 1757
 	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 1758
 		if ((via_lump=insert_new_lump_before(via_anchor, line_buf, via_len,
1761 1759
 											HDR_VIA_T))==0)
1762 1760
 			goto error04;