Browse code

- rport is added also in build_res_buf_from_sip_req

Andrei Pelinescu-Onciul authored on 23/01/2003 19:53:41
Showing 1 changed files
... ...
@@ -29,6 +29,9 @@
29 29
  * History:
30 30
  * --------
31 31
  * 2003-01-20 bug_fix: use of return value of snprintf aligned to C99 (jiri)
32
+ * 2003-01-23 added rport patches, contributed by 
33
+ *             Maxim Sobolev <sobomax@FreeBSD.org> and heavily modified by me
34
+ *             (andrei)
32 35
  *
33 36
  */
34 37
 
... ...
@@ -457,14 +460,20 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
457 460
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
458 461
 	msg->via1->host.s[msg->via1->host.len] = backup;
459 462
 	if (r!=0){
460
-		if ((received_buf=received_builder(msg,&received_len))==0)
463
+		if ((received_buf=received_builder(msg,&received_len))==0){
464
+			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
465
+							" received_builder failed\n");
461 466
 			goto error01;  /* free also line_buf */
467
+		}
462 468
 	}
463 469
 	
464 470
 	/* check if rport needs to be updated */
465 471
 	if (msg->via1->rport && msg->via1->rport->value.s==0){
466
-		if ((rport_buf=rport_builder(msg, &rport_len))==0)
472
+		if ((rport_buf=rport_builder(msg, &rport_len))==0){
473
+			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
474
+							" rport_builder failed\n");
467 475
 			goto error01; /* free everything */
476
+		}
468 477
 	}
469 478
 
470 479
 	/* add via header to the list */
... ...
@@ -497,7 +506,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
497 506
 	}
498 507
 	/* if rport needs to be updated, delete it and add it's value */
499 508
 	if (rport_len){
500
-		anchor=del_lump(&(msg->add_rm), msg->via1->rport->name.s-buf,
509
+		anchor=del_lump(&(msg->add_rm), msg->via1->rport->name.s-buf-1, /*';'*/
501 510
 							msg->via1->rport->name.len, HDR_VIA);
502 511
 		if (anchor==0) goto error03; /* free rport_buf*/
503 512
 		if (insert_new_lump_after(anchor, rport_buf, rport_len, HDR_VIA)==0)
... ...
@@ -633,7 +642,9 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
633 642
 	int               i;
634 643
 	char              backup;
635 644
 	char              *received_buf;
645
+	char              *rport_buf;
636 646
 	unsigned int               received_len;
647
+	unsigned int               rport_len;
637 648
 	char              *warning;
638 649
 	unsigned int      warning_len;
639 650
 	int r;
... ...
@@ -641,6 +652,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
641 652
 
642 653
 	received_buf=0;
643 654
 	received_len=0;
655
+	rport_buf=0;
656
+	rport_len=0;
644 657
 	buf=0;
645 658
 	/* make -Wall happy */
646 659
 	warning=0;
... ...
@@ -667,6 +680,14 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
667 680
 			goto error00;
668 681
 		}
669 682
 	}
683
+	/* check if rport needs to be updated */
684
+	if (msg->via1->rport && msg->via1->rport->value.s==0){
685
+		if ((rport_buf=rport_builder(msg, &rport_len))==0){
686
+			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req:"
687
+							" rport_builder failed\n");
688
+			goto error01; /* free everything */
689
+		}
690
+	}
670 691
 
671 692
 	/*computes the lenght of the new response buffer*/
672 693
 	len = 0;
... ...
@@ -685,7 +706,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
685 706
 					len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/;
686 707
 			}
687 708
 		} else if (hdr->type==HDR_VIA) {
688
-				if (hdr==msg->h_via1) len += received_len;
709
+				if (hdr==msg->h_via1) len += received_len+rport_len-RPORT_LEN;
689 710
 		} else if (hdr->type==HDR_RECORDROUTE) {
690 711
 				/* RR only for 1xx and 2xx replies */
691 712
 				if (code<180 || code>=300) continue;
... ...
@@ -761,10 +782,31 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
761 782
 					break;
762 783
 				}
763 784
 			case HDR_VIA:
764
-				append_str_trans( p, hdr->name.s ,
765
-					((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
766
-				if (hdr==msg->h_via1 && received_buf)
767
-					append_str( p, received_buf, received_len, msg);
785
+				if (hdr==msg->h_via1){
786
+					if (rport_buf){
787
+						/* copy until rport */
788
+						append_str_trans( p, hdr->name.s ,
789
+							msg->via1->rport->name.s-hdr->name.s-1,msg);
790
+						/* copy new rport */
791
+						append_str(p, rport_buf, rport_len, msg);
792
+						/* copy the rest of the via */
793
+						append_str_trans(p, msg->via1->rport->name.s+
794
+											msg->via1->rport->size, 
795
+											hdr->body.s+hdr->body.len-
796
+											msg->via1->rport->name.s-
797
+											msg->via1->rport->size, msg);
798
+					}else{
799
+						/* normal whole via copy */
800
+						append_str_trans( p, hdr->name.s ,
801
+							((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
802
+					}
803
+					if (received_buf)
804
+						append_str( p, received_buf, received_len, msg);
805
+				}else{
806
+					/* normal whole via copy */
807
+					append_str_trans( p, hdr->name.s ,
808
+						((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
809
+				}
768 810
 				append_str( p, CRLF,CRLF_LEN,msg);
769 811
 				break;
770 812
 			case HDR_RECORDROUTE:
... ...
@@ -810,10 +852,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
810 852
 	   needs to be deleted here
811 853
 	*/
812 854
 	if (received_buf) pkg_free(received_buf);
855
+	if (rport_buf) pkg_free(rport_buf);
813 856
 	return buf;
814 857
 
815 858
 error01:
816 859
 	if (received_buf) pkg_free(received_buf);
860
+	if (rport_buf) pkg_free(rport_buf);
817 861
 error00:
818 862
 	*returned_len=0;
819 863
 	return 0;