Browse code

bug_fix: reply status processing changed to withstand final-provisional-final

Jiri Kuthan authored on 23/06/2003 00:07:44
Showing 1 changed files
... ...
@@ -551,6 +551,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
551 551
 	int branch_cnt;
552 552
 	int picked_branch;
553 553
 	int picked_code;
554
+	int inv_through;
554 555
 
555 556
 	/* note: this code never lets replies to CANCEL go through;
556 557
 	   we generate always a local 200 for CANCEL; 200s are
... ...
@@ -559,45 +560,37 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
559 560
 	   out
560 561
 	*/
561 562
 	DBG("->>>>>>>>> T_code=%d, new_code=%d\n",Trans->uas.status,new_code);
563
+	inv_through=new_code>=200 && new_code<300 && Trans->is_invite;
562 564
 	/* if final response sent out, allow only INVITE 2xx  */
563 565
 	if ( Trans->uas.status >= 200 ) {
564
-		if (new_code>=200 && new_code < 300  && 
565
-#ifdef _BUG_FIX /* t may be local, in which case there is no request */
566
-			Trans->uas.request->REQ_METHOD==METHOD_INVITE) {
567
-#endif
568
-			Trans->is_invite ) {
566
+		if (inv_through) {
569 567
 			DBG("DBG: t_should_relay: 200 INV after final sent\n");
570 568
 			*should_store=0;
571 569
 			Trans->uac[branch].last_received=new_code;
572 570
 			*should_relay=branch;
573 571
 			return RPS_PUSHED_AFTER_COMPLETION;
574
-		} else {
575
-			/* except the exception above, too late  messages will
576
-			   be discarded */
577
-			*should_store=0;
578
-			*should_relay=-1;
579
-			return RPS_DISCARDED;
580
-		}
572
+		} 
573
+		/* except the exception above, too late  messages will
574
+		   be discarded */
575
+		goto discard;
581 576
 	} 
582 577
 
578
+	/* if final response received at this branch, allow only INVITE 2xx */
579
+	if (Trans->uac[branch].last_received>=200
580
+			&& !(inv_through && Trans->uac[branch].last_received<300)) {
581
+		LOG(L_ERR, "ERROR: t_should_relay: status rewrite by UAS: "
582
+			"stored: %d, received: %d\n",
583
+			Trans->uac[branch].last_received, new_code );
584
+		goto discard;
585
+	}
586
+
587
+
583 588
 	/* no final response sent yet */
584 589
 	/* negative replies subject to fork picking */
585 590
 	if (new_code >=300 ) {
586
-		/* negative reply received after we have received
587
-		   a final reply previously -- discard , unless
588
-		   a recoverable error occured, in which case
589
-		   retry
590
-	    */
591
-		if (Trans->uac[branch].last_received>=200) {
592
-			/* then drop! */
593
-			*should_store=0;
594
-			*should_relay=-1;
595
-			return RPS_DISCARDED;
596
-		}
597 591
 
598 592
 		Trans->uac[branch].last_received=new_code;
599 593
 
600
-
601 594
 		/* if all_final return lowest */
602 595
 		picked_branch=pick_branch(branch,new_code, Trans, &picked_code);
603 596
 		if (picked_branch==-2) { /* branches open yet */
... ...
@@ -671,6 +664,7 @@ error:
671 664
 	/* reply_status didn't match -- it must be something weird */
672 665
 	LOG(L_CRIT, "ERROR: Oh my gooosh! We don't know whether to relay %d\n",
673 666
 		new_code);
667
+discard:
674 668
 	*should_store=0;
675 669
 	*should_relay=-1;
676 670
 	return RPS_DISCARDED;