Browse code

*** empty log message ***

Bogdan-Andrei Iancu authored on 03/12/2001 19:34:45
Showing 2 changed files
... ...
@@ -589,10 +589,6 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
589 589
       T->outbound_response->tl[RETRASMISSIONS_LIST].payload = T->outbound_response;
590 590
       T->outbound_response->tl[FR_TIMER_LIST].payload = T->outbound_response;
591 591
       T->outbound_response->my_T = T;
592
-      T->status = code;
593
-
594
-
595
-
596 592
    }
597 593
 
598 594
    buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );
... ...
@@ -612,6 +608,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
612 612
    }
613 613
    memcpy( T->outbound_response->retr_buffer , buf , len );
614 614
    free( buf ) ;
615
+   T->status = code;
615 616
 
616 617
    /* make sure that if we send something final upstream, everything else will be cancelled */
617 618
    if ( code>=300 &&  p_msg->first_line.u.request.method_value==METHOD_INVITE )
... ...
@@ -516,92 +516,65 @@ error:
516 516
 char * build_res_buf_from_sip_req(	unsigned int code ,
517 517
 	char *text , struct sip_msg* msg, unsigned int *returned_len)
518 518
 {
519
-	char                    *buf=0, *p;
519
+	char                    *buf, *p;
520 520
 	unsigned int       len,foo;
521 521
 	struct hdr_field  *hdr;
522
-	int first_via;
523
-	int str_len_text;
524
-	int i;
522
+	int                       i;
525 523
 
526
-	str_len_text=strlen(text);
524
+	/* force parsing all headers -- we want to return all
525
+	Via's in the reply and they may be scattered down to the
526
+	end of header (non-block Vias are a really poor property
527
+	of SIP :( ) */
528
+	parse_headers( msg, HDR_EOH );
527 529
 
528 530
 	/*computes the lenght of the new response buffer*/
529 531
 	len = 0;
530 532
 	/* first line */
531
-	len += 3/*code*/ + 1/*space*/ + str_len_text + CRLF_LEN/*new line*/;
532
-
533
-	/* force parsing all headers -- we want to return all
534
-           Via's in the reply and they may be scattered down to the
535
- 	   end of header (non-block Vias are a really poor property
536
-	   of SIP :( )
537
-        */
538
-	parse_headers( msg, HDR_EOH );
539
-	/* check if I have those HFs identifying a transaction here */
540
-	if (!check_transaction_quadruple( msg ))
541
-		goto error;
542
-
543
-	first_via = 1;
544
-	for ( hdr=msg->headers ; hdr ; hdr=hdr->next ) 
545
-		if (  hdr->type==HDR_FROM || 
546
-			(hdr->type==HDR_VIA ?  (first_via ? first_via=0, 0: 1 ) : 0) ||
547
-			hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
548
-			hdr->type==HDR_CSEQ )
549
-			len += hdr->body.len  + hdr->name.len  + MY_HF_SEP_LEN + CRLF_LEN;
533
+	len += 3/*code*/ + 1/*space*/ + strlen(text) + CRLF_LEN/*new line*/;
534
+	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
535
+	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
536
+		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
537
+				hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
538
+				hdr->type==HDR_CSEQ )
539
+			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) ;
550 540
 	/* end of message */
551 541
 	len += CRLF_LEN; /*new line*/
552 542
 
553 543
 	/*allocating mem*/
544
+	buf = 0;
554 545
 	buf = (char*) malloc( len+1 );
555
-	p=buf;
556 546
 	if (!buf)
557 547
 	{
558 548
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: out of memory\n");
559 549
 		goto error;
560 550
 	}
561
-	p=buf;
562 551
 
563 552
 	/* filling the buffer*/
553
+	p=buf;
564 554
 	/* first line */
565 555
 	for ( i=2 , foo = code  ;  i>=0  ;  i-- , foo=foo/10 )
566
-		*(p+i) = '0' + foo % 10;
556
+		*(p+i) = '0' + foo - ( foo/10 )*10;
567 557
 	p += 3;
568 558
 	*(p++) = ' ' ;
569
-	memcpy( p , text , str_len_text );
570
-	p += str_len_text;
559
+	memcpy( p , text , strlen(text) );
560
+	p += strlen(text);
571 561
 	memcpy( p, CRLF, CRLF_LEN );
572 562
 	p+=CRLF_LEN;
573
-	
574 563
 	/* headers*/
575
-	first_via=1;
576 564
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
577
-		if ( hdr->type==HDR_FROM ||
578
-			hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
579
-			(hdr->type==HDR_VIA || hdr->type==HDR_CSEQ )
565
+		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
566
+		hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
580 567
 		{
581
-			char *end; int plen;
582
-
583
-			end = hdr->name.s+hdr->name.len-1;
584
-			plen= (*end==0) ? hdr->name.len - 1 : hdr->name.len;
585
-			memcpy( p, hdr->name.s, plen );
586
-			p+=plen;
587
-
588
-			memcpy( p, MY_HF_SEP, MY_HF_SEP_LEN );
589
-			p+=MY_HF_SEP_LEN;
590
-
591
-			end = hdr->body.s+hdr->body.len-1;
592
-			plen= (*end==0) ? hdr->body.len - 1 : hdr->body.len;
593
-			memcpy( p, hdr->body.s, plen );
594
-			p+=plen;
595
-			memcpy( p, CRLF, CRLF_LEN );
596
-			p+=CRLF_LEN;
568
+			memcpy( p , msg->orig+(hdr->name.s-msg->buf) ,
569
+					((hdr->body.s+hdr->body.len ) -
570
+					hdr->name.s ) );
571
+			p += ((hdr->body.s+hdr->body.len ) - hdr->name.s );
597 572
 		}
573
+
598 574
 	memcpy( p, CRLF, CRLF_LEN );
599 575
 	p+=CRLF_LEN;
600 576
 	*(p++) = 0;
601
-
602
-
603
-	/* returned_len=len; */
604
-	*returned_len=p-buf;
577
+	*returned_len=len;
605 578
 	return buf;
606 579
 error:
607 580
 	if (buf) free(buf);