Browse code

- more simple way of setting on_reply and failure routes; - bug in setting these routes from failure_route

Bogdan-Andrei Iancu authored on 05/02/2004 17:23:19
Showing 3 changed files
... ...
@@ -465,12 +465,6 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
465 465
 		return lowest_ret;
466 466
 	}
467 467
 
468
-	/* store script processing value of failure route to transactional
469
-	   context; if currently 0, this forwarding attempt will no longer 
470
-	   result in failure_route on error
471
-	*/
472
-	t->on_negative=get_on_negative();
473
-
474 468
 	/* send them out now */
475 469
 	success_branch=0;
476 470
 	for (i=first_branch; i<t->nr_of_outgoings; i++) {
... ...
@@ -113,16 +113,33 @@ static int goto_on_reply=0;
113 113
    *inside*  t_relay using hints stored in private memory
114 114
    before t_reay is called
115 115
 */
116
-  
117
-  
116
+
117
+
118 118
 void t_on_negative( unsigned int go_to )
119 119
 {
120
-	goto_on_negative=go_to;
120
+	struct cell *t = get_t();
121
+
122
+	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
123
+	 * in MODE_REQUEST T will be set only if the transaction was already 
124
+	 * created; if not -> use the static variable */
125
+	if (!t || t==T_UNDEFINED )
126
+		goto_on_negative=go_to;
127
+	else
128
+		get_t()->on_negative = go_to;
121 129
 }
122 130
 
131
+
123 132
 void t_on_reply( unsigned int go_to )
124 133
 {
125
-	goto_on_reply=go_to;
134
+	struct cell *t = get_t();
135
+
136
+	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
137
+	 * in MODE_REQUEST T will be set only if the transaction was already 
138
+	 * created; if not -> use the static variable */
139
+	if (!t || t==T_UNDEFINED )
140
+		goto_on_reply=go_to;
141
+	else
142
+		get_t()->on_reply = go_to;
126 143
 }
127 144
 
128 145
 
... ...
@@ -428,6 +445,7 @@ static inline int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
428 445
 {
429 446
 	static struct sip_msg fake_req;
430 447
 	struct sip_msg *shmem_msg = t->uas.request;
448
+	int on_failure;
431 449
 
432 450
 	/* failure_route for a local UAC? */
433 451
 	if (!shmem_msg) {
... ...
@@ -497,9 +515,11 @@ static inline int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
497 515
 		/* avoid recursion -- if failure_route forwards, and does not 
498 516
 		 * set next failure route, failure_route will not be rentered
499 517
 		 * on failure */
500
-		t_on_negative(0);
518
+		//goto_on_negative = 0;
519
+		on_failure = t->on_negative;
520
+		t->on_negative=0;
501 521
 		/* run a reply_route action if some was marked */
502
-		if (run_actions(failure_rlist[t->on_negative], &fake_req)<0)
522
+		if (run_actions(failure_rlist[on_failure], &fake_req)<0)
503 523
 			LOG(L_ERR, "ERROR: run_failure_handlers: Error in do_action\n");
504 524
 	}
505 525
 
... ...
@@ -728,58 +728,22 @@ inline static int w_t_retransmit_reply( struct sip_msg* p_msg, char* foo, char*
728 728
 inline static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar ) 
729 729
 {
730 730
 	/* t_newtran returns 0 on error (negative value means
731
-	   'transaction exists'
732
-	*/
731
+	   'transaction exists' */
733 732
 	return t_newtran( p_msg );
734 733
 }
735 734
 
736 735
 
737
-inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo )
736
+inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo)
738 737
 {
739
-	struct cell *t;
740
-
741
-	if (rmode==MODE_REQUEST || rmode==MODE_ONFAILURE) {
742
-		t_on_negative( (unsigned int )(long) go_to );
743
-		return 1;
744
-	}
745
-	if (rmode==MODE_ONREPLY ) {
746
-		/* transaction state is established */
747
-		t=get_t();
748
-		if (!t || t==T_UNDEFINED) {
749
-			LOG(L_CRIT, "BUG: w_t_on_negative entered without t\n");
750
-			return -1;
751
-		}
752
-		t->on_negative=(unsigned int)(long)go_to;
753
-		return 1;
754
-	}
755
-	LOG(L_CRIT, "BUG: w_t_on_negative entered in unsupported mode\n");
756
-	return -1;
738
+	t_on_negative( (unsigned int )(long) go_to );
739
+	return 1;
757 740
 }
758 741
 
759 742
 
760 743
 inline static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo )
761 744
 {
762
-	struct cell *t;
763
-
764
-	if (rmode==MODE_REQUEST) {
765
-		/* it's still in initial request processing stage, transaction
766
-		 * state is not estabslihed yet, store it in private memory ...
767
-		 * it will be copied to transaction state when it is set up */
768
-		t_on_reply( (unsigned int )(long) go_to );
769
-		return 1;
770
-	}
771
-	if (rmode==MODE_ONREPLY || rmode==MODE_ONFAILURE) {
772
-		/* transaction state is established */
773
-		t=get_t();
774
-		if (!t || t==T_UNDEFINED) {
775
-			LOG(L_CRIT, "BUG: w_t_on_reply entered without t\n");
776
-			return -1;
777
-		}
778
-		t->on_reply=(unsigned int) (long)go_to;
779
-		return 1;
780
-	}
781
-	LOG(L_CRIT, "BUG: w_t_on_reply entered in unsupported mode\n");
782
-	return -1;
745
+	t_on_reply( (unsigned int )(long) go_to );
746
+	return 1;
783 747
 }
784 748
 
785 749