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 457
 	r=check_address(&msg->rcv.src_ip, msg->via1->host.s, received_dns);
458 458
 	msg->via1->host.s[msg->via1->host.len] = backup;
459 459
 	if (r!=0){
460
-		if ((received_buf=received_builder(msg,&received_len))==0)
460
+		if ((received_buf=received_builder(msg,&received_len))==0){
461
+			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
462
+							" received_builder failed\n");
461 463
 			goto error01;  /* free also line_buf */
464
+		}
462 465
 	}
463 466
 	
464 467
 	/* check if rport needs to be updated */
465 468
 	if (msg->via1->rport && msg->via1->rport->value.s==0){
466
-		if ((rport_buf=rport_builder(msg, &rport_len))==0)
469
+		if ((rport_buf=rport_builder(msg, &rport_len))==0){
470
+			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req:"
471
+							" rport_builder failed\n");
467 472
 			goto error01; /* free everything */
473
+		}
468 474
 	}
469 475
 
470 476
 	/* add via header to the list */
... ...
@@ -497,7 +506,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
497 497
 	}
498 498
 	/* if rport needs to be updated, delete it and add it's value */
499 499
 	if (rport_len){
500
-		anchor=del_lump(&(msg->add_rm), msg->via1->rport->name.s-buf,
500
+		anchor=del_lump(&(msg->add_rm), msg->via1->rport->name.s-buf-1, /*';'*/
501 501
 							msg->via1->rport->name.len, HDR_VIA);
502 502
 		if (anchor==0) goto error03; /* free rport_buf*/
503 503
 		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 633
 	int               i;
634 634
 	char              backup;
635 635
 	char              *received_buf;
636
+	char              *rport_buf;
636 637
 	unsigned int               received_len;
638
+	unsigned int               rport_len;
637 639
 	char              *warning;
638 640
 	unsigned int      warning_len;
639 641
 	int r;
... ...
@@ -641,6 +652,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
641 641
 
642 642
 	received_buf=0;
643 643
 	received_len=0;
644
+	rport_buf=0;
645
+	rport_len=0;
644 646
 	buf=0;
645 647
 	/* make -Wall happy */
646 648
 	warning=0;
... ...
@@ -667,6 +680,14 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
667 667
 			goto error00;
668 668
 		}
669 669
 	}
670
+	/* check if rport needs to be updated */
671
+	if (msg->via1->rport && msg->via1->rport->value.s==0){
672
+		if ((rport_buf=rport_builder(msg, &rport_len))==0){
673
+			LOG(L_ERR, "ERROR: build_res_buf_from_sip_req:"
674
+							" rport_builder failed\n");
675
+			goto error01; /* free everything */
676
+		}
677
+	}
670 678
 
671 679
 	/*computes the lenght of the new response buffer*/
672 680
 	len = 0;
... ...
@@ -685,7 +706,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
685 685
 					len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/;
686 686
 			}
687 687
 		} else if (hdr->type==HDR_VIA) {
688
-				if (hdr==msg->h_via1) len += received_len;
688
+				if (hdr==msg->h_via1) len += received_len+rport_len-RPORT_LEN;
689 689
 		} else if (hdr->type==HDR_RECORDROUTE) {
690 690
 				/* RR only for 1xx and 2xx replies */
691 691
 				if (code<180 || code>=300) continue;
... ...
@@ -761,10 +782,31 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
761 761
 					break;
762 762
 				}
763 763
 			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);
764
+				if (hdr==msg->h_via1){
765
+					if (rport_buf){
766
+						/* copy until rport */
767
+						append_str_trans( p, hdr->name.s ,
768
+							msg->via1->rport->name.s-hdr->name.s-1,msg);
769
+						/* copy new rport */
770
+						append_str(p, rport_buf, rport_len, msg);
771
+						/* copy the rest of the via */
772
+						append_str_trans(p, msg->via1->rport->name.s+
773
+											msg->via1->rport->size, 
774
+											hdr->body.s+hdr->body.len-
775
+											msg->via1->rport->name.s-
776
+											msg->via1->rport->size, msg);
777
+					}else{
778
+						/* normal whole via copy */
779
+						append_str_trans( p, hdr->name.s ,
780
+							((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
781
+					}
782
+					if (received_buf)
783
+						append_str( p, received_buf, received_len, msg);
784
+				}else{
785
+					/* normal whole via copy */
786
+					append_str_trans( p, hdr->name.s ,
787
+						((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
788
+				}
768 789
 				append_str( p, CRLF,CRLF_LEN,msg);
769 790
 				break;
770 791
 			case HDR_RECORDROUTE:
... ...
@@ -810,10 +852,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
810 810
 	   needs to be deleted here
811 811
 	*/
812 812
 	if (received_buf) pkg_free(received_buf);
813
+	if (rport_buf) pkg_free(rport_buf);
813 814
 	return buf;
814 815
 
815 816
 error01:
816 817
 	if (received_buf) pkg_free(received_buf);
818
+	if (rport_buf) pkg_free(rport_buf);
817 819
 error00:
818 820
 	*returned_len=0;
819 821
 	return 0;