Browse code

Update tm module to use and set the global route_type variable.

This patch removes the rmode variable from tm module and replaces it
with the global variable route_type defined in route.h. In addition to
that we replaced MODE_* constants with *_ROUTE (also defined in
route.h).

A variable that was once defined in the tm module is now better moved
to the core, because just the core itself without the tm module loaded
can execute two types of routes, the request route and the global
onreply route (if used).

Jan Janak authored on 07/03/2009 00:51:19
Showing 9 changed files
... ...
@@ -97,6 +97,7 @@
97 97
 #include "../../data_lump.h"
98 98
 #include "../../onsend.h"
99 99
 #include "../../compiler_opt.h"
100
+#include "../../route.h"
100 101
 #include "t_funcs.h"
101 102
 #include "t_hooks.h"
102 103
 #include "t_msgbuilder.h"
... ...
@@ -126,8 +127,8 @@ void t_on_branch( unsigned int go_to )
126 127
 {
127 128
 	struct cell *t = get_t();
128 129
 
129
-       /* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
130
-        * in MODE_REQUEST T will be set only if the transaction was already
130
+       /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
131
+        * in REQUEST_ROUTE T will be set only if the transaction was already
131 132
         * created; if not -> use the static variable */
132 133
 	if (!t || t==T_UNDEFINED ) {
133 134
 		goto_on_branch=go_to;
... ...
@@ -191,6 +192,7 @@ static char *print_uac_request( struct cell *t, struct sip_msg *i_req,
191 192
 	if (unlikely(branch_route)) {
192 193
 		reset_static_buffer();
193 194
 		     /* run branch_route actions if provided */
195
+		set_route_type(BRANCH_ROUTE);
194 196
 		init_run_actions_ctx(&ra_ctx);
195 197
 		if (run_actions(&ra_ctx, branch_rt.rlist[branch_route], i_req) < 0) {
196 198
 			LOG(L_ERR, "ERROR: print_uac_request: Error in run_actions\n");
... ...
@@ -812,7 +814,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
812 814
 		 * is called (we are already holding the reply mutex for the cancel
813 815
 		 * transaction).
814 816
 		 */
815
-		if ((rmode==MODE_ONFAILURE) && (t_cancel==get_t()))
817
+		if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t()))
816 818
 			t_reply_unsafe( t_cancel, cancel_msg, 500, "cancel error");
817 819
 		else
818 820
 			t_reply( t_cancel, cancel_msg, 500, "cancel error");
... ...
@@ -825,7 +827,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
825 827
 		 * is called (we are already hold the reply mutex for the cancel
826 828
 		 * transaction).
827 829
 		 */
828
-		if ((rmode==MODE_ONFAILURE) && (t_cancel==get_t()))
830
+		if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t()))
829 831
 			t_reply_unsafe( t_cancel, cancel_msg, 200, CANCELING );
830 832
 		else
831 833
 			t_reply( t_cancel, cancel_msg, 200, CANCELING );
... ...
@@ -838,7 +840,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
838 840
 		 * is called (we are already hold the reply mutex for the cancel
839 841
 		 * transaction).
840 842
 		 */
841
-		if ((rmode==MODE_ONFAILURE) && (t_cancel==get_t()))
843
+		if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t()))
842 844
 			t_reply_unsafe( t_cancel, cancel_msg, 200, CANCEL_DONE );
843 845
 		else
844 846
 			t_reply( t_cancel, cancel_msg, 200, CANCEL_DONE );
... ...
@@ -1046,7 +1048,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
1046 1048
 	if (first_branch==0) {
1047 1049
 #ifdef POSTPONE_MSG_CLONING
1048 1050
 		/* update the shmem-ized msg with the lumps */
1049
-		if ((rmode == MODE_REQUEST) &&
1051
+		if ((is_route_type(REQUEST_ROUTE)) &&
1050 1052
 			save_msg_lumps(t->uas.request, p_msg)) {
1051 1053
 				LOG(L_ERR, "ERROR: t_forward_nonack: "
1052 1054
 					"failed to save the message lumps\n");
... ...
@@ -1102,7 +1104,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
1102 1104
 	ser_error=0; /* clear branch adding errors */
1103 1105
 	/* send them out now */
1104 1106
 	success_branch=0;
1105
-	lock_replies= ! ((rmode==MODE_ONFAILURE) && (t==get_t()));
1107
+	lock_replies= ! ((is_route_type(FAILURE_ROUTE)) && (t==get_t()));
1106 1108
 	for (i=first_branch; i<t->nr_of_outgoings; i++) {
1107 1109
 		if (added_branches & (1<<i)) {
1108 1110
 			
... ...
@@ -1454,7 +1454,7 @@ int t_unref( struct sip_msg* p_msg  )
1454 1454
 		kr=get_kr();
1455 1455
 		if (unlikely(kr == REQ_ERR_DELAYED)){
1456 1456
 			DBG("t_unref: delayed error reply generation(%d)\n", tm_error);
1457
-			if (unlikely(rmode==MODE_ONFAILURE)){
1457
+			if (unlikely(is_route_type(FAILURE_ROUTE))){
1458 1458
 				BUG("tm: t_unref: called w/ kr=REQ_ERR_DELAYED in failure"
1459 1459
 						" route for %p\n", T);
1460 1460
 			}else if (unlikely( kill_transaction(T, tm_error)<=0 )){
... ...
@@ -1675,8 +1675,8 @@ int t_set_fr(struct sip_msg* msg, unsigned int fr_inv_to, unsigned int fr_to)
1675 1675
 	}
1676 1676
 	
1677 1677
 	t=get_t();
1678
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1679
-	 * in MODE_REQUEST T will be set only if the transaction was already
1678
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1679
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1680 1680
 	 * created; if not -> use the static variables */
1681 1681
 	if (!t || t==T_UNDEFINED ){
1682 1682
 		set_msgid_val(user_fr_inv_timeout, msg->id, int, (int)fr_inv);
... ...
@@ -1693,8 +1693,8 @@ int t_reset_fr()
1693 1693
 	struct cell *t;
1694 1694
 
1695 1695
 	t=get_t();
1696
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1697
-	 * in MODE_REQUEST T will be set only if the transaction was already
1696
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1697
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1698 1698
 	 * created; if not -> use the static variables */
1699 1699
 	if (!t || t==T_UNDEFINED ){
1700 1700
 		memset(&user_fr_inv_timeout, 0, sizeof(user_fr_inv_timeout));
... ...
@@ -1739,8 +1739,8 @@ int t_set_retr(struct sip_msg* msg, unsigned int t1_to, unsigned int t2_to)
1739 1739
 	} 
1740 1740
 	
1741 1741
 	t=get_t();
1742
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1743
-	 * in MODE_REQUEST T will be set only if the transaction was already
1742
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1743
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1744 1744
 	 * created; if not -> use the static variables */
1745 1745
 	if (!t || t==T_UNDEFINED ){
1746 1746
 		set_msgid_val(user_rt_t1_timeout, msg->id, int, (int)retr_t1);
... ...
@@ -1757,8 +1757,8 @@ int t_reset_retr()
1757 1757
 	struct cell *t;
1758 1758
 
1759 1759
 	t=get_t();
1760
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1761
-	 * in MODE_REQUEST T will be set only if the transaction was already
1760
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1761
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1762 1762
 	 * created; if not -> use the static variables */
1763 1763
 	if (!t || t==T_UNDEFINED ){
1764 1764
 		memset(&user_rt_t1_timeout, 0, sizeof(user_rt_t1_timeout));
... ...
@@ -1799,8 +1799,8 @@ int t_set_max_lifetime(struct sip_msg* msg,
1799 1799
 	}
1800 1800
 	
1801 1801
 	t=get_t();
1802
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1803
-	 * in MODE_REQUEST T will be set only if the transaction was already
1802
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1803
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1804 1804
 	 * created; if not -> use the static variables */
1805 1805
 	if (!t || t==T_UNDEFINED ){
1806 1806
 		set_msgid_val(user_noninv_max_lifetime, msg->id, int,
... ...
@@ -1820,8 +1820,8 @@ int t_reset_max_lifetime()
1820 1820
 	struct cell *t;
1821 1821
 
1822 1822
 	t=get_t();
1823
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1824
-	 * in MODE_REQUEST T will be set only if the transaction was already
1823
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1824
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1825 1825
 	 * created; if not -> use the static variables */
1826 1826
 	if (!t || t==T_UNDEFINED ){
1827 1827
 		memset(&user_inv_max_lifetime, 0, sizeof(user_inv_max_lifetime));
... ...
@@ -108,6 +108,7 @@
108 108
 #include "../../action.h"
109 109
 #include "../../dset.h"
110 110
 #include "../../tags.h"
111
+#include "../../route.h"
111 112
 #include "../../data_lump.h"
112 113
 #include "../../data_lump_rpl.h"
113 114
 #include "../../usr_avp.h"
... ...
@@ -137,9 +138,6 @@
137 138
 #include "uac.h"
138 139
 
139 140
 
140
-/* are we processing original or shmemed request ? */
141
-enum route_mode rmode=MODE_REQUEST;
142
-
143 141
 /* private place where we create to-tags for replies */
144 142
 /* janakj: made public, I need to access this value to store it in dialogs */
145 143
 char tm_tags[TOTAG_VALUE_LEN];
... ...
@@ -187,8 +185,8 @@ void t_on_negative( unsigned int go_to )
187 185
 {
188 186
 	struct cell *t = get_t();
189 187
 
190
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
191
-	 * in MODE_REQUEST T will be set only if the transaction was already
188
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
189
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
192 190
 	 * created; if not -> use the static variable */
193 191
 	if (!t || t==T_UNDEFINED )
194 192
 		goto_on_negative=go_to;
... ...
@@ -201,8 +199,8 @@ void t_on_reply( unsigned int go_to )
201 199
 {
202 200
 	struct cell *t = get_t();
203 201
 
204
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
205
-	 * in MODE_REQUEST T will be set only if the transaction was already
202
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
203
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
206 204
 	 * created; if not -> use the static variable */
207 205
 	if (!t || t==T_UNDEFINED )
208 206
 		goto_on_reply=go_to;
... ...
@@ -659,7 +657,7 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
659 657
  * the env. will be restore to original */
660 658
 void faked_env( struct cell *t,struct sip_msg *msg)
661 659
 {
662
-	static enum route_mode backup_mode;
660
+	static int backup_route_type;
663 661
 	static struct cell *backup_t;
664 662
 	static unsigned int backup_msgid;
665 663
 	static avp_list_t* backup_user_from, *backup_user_to;
... ...
@@ -669,11 +667,11 @@ void faked_env( struct cell *t,struct sip_msg *msg)
669 667
 
670 668
 	if (msg) {
671 669
 		/* remember we are back in request processing, but process
672
-		 * a shmem-ed replica of the request; advertise it in rmode;
670
+		 * a shmem-ed replica of the request; advertise it in route type;
673 671
 		 * for example t_reply needs to know that
674 672
 		 */
675
-		backup_mode=rmode;
676
-		rmode=MODE_ONFAILURE;
673
+		backup_route_type=route_type;
674
+		set_route_type(FAILURE_ROUTE);
677 675
 		/* also, tm actions look in beginning whether transaction is
678 676
 		 * set -- whether we are called from a reply-processing
679 677
 		 * or a timer process, we need to set current transaction;
... ...
@@ -701,7 +699,7 @@ void faked_env( struct cell *t,struct sip_msg *msg)
701 699
 		/* restore original environment */
702 700
 		set_t(backup_t);
703 701
 		global_msg_id=backup_msgid;
704
-		rmode=backup_mode;
702
+		set_route_type(backup_route_type);
705 703
 		/* restore original avp list */
706 704
 		set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, backup_user_from );
707 705
 		set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, backup_user_to );
... ...
@@ -1932,7 +1930,7 @@ int reply_received( struct sip_msg  *p_msg )
1932 1930
 	}
1933 1931
 	/* processing of on_reply block */
1934 1932
 	if (t->on_reply) {
1935
-		rmode=MODE_ONREPLY;
1933
+		set_route_type(ONREPLY_ROUTE);
1936 1934
 		/* transfer transaction flag to message context */
1937 1935
 		if (t->uas.request) p_msg->flags=t->uas.request->flags;
1938 1936
 		/* set the as avp_list the one from transaction */
... ...
@@ -58,9 +58,6 @@ extern char *tm_tag_suffix;
58 58
 
59 59
 extern int goto_on_sl_reply;
60 60
 
61
-enum route_mode { MODE_REQUEST=1, MODE_ONREPLY, MODE_ONFAILURE };
62
-extern enum route_mode rmode;
63
-
64 61
 /* has this to-tag been never seen in previous 200/INVs? */
65 62
 int unmatched_totag(struct cell *t, struct sip_msg *ack);
66 63
 
... ...
@@ -642,7 +642,7 @@ static int script_init( struct sip_msg *foo, void *bar)
642 642
 	reset_kr(0);
643 643
 	/* set request mode so that multiple-mode actions know
644 644
 	 * how to behave */
645
-	rmode=MODE_REQUEST;
645
+	set_route_type(REQUEST_ROUTE);
646 646
 
647 647
 #ifdef POSTPONE_MSG_CLONING
648 648
 	lumps_are_cloned = 0;
... ...
@@ -835,20 +835,20 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
835 835
 		break;
836 836
 	}
837 837
 	
838
-	switch(rmode) {
839
-	case MODE_REQUEST:
838
+	switch(route_type) {
839
+	case REQUEST_ROUTE:
840 840
 		/* use the status of the last sent reply */
841 841
 		status = int2str( t->uas.status, 0);
842 842
 		break;
843 843
 		
844
-	case MODE_ONREPLY:
844
+	case ONREPLY_ROUTE:
845 845
 		/* use the status of the current reply */
846 846
 		status = msg->first_line.u.reply.status.s;
847 847
 		backup = status[msg->first_line.u.reply.status.len];
848 848
 		status[msg->first_line.u.reply.status.len] = 0;
849 849
 		break;
850 850
 
851
-	case MODE_ONFAILURE:
851
+	case FAILURE_ROUTE:
852 852
 		/* use the status of the winning reply */
853 853
 		ret = t_pick_branch( -1, 0, t, &lowest_status);
854 854
 		if (ret == -1) {
... ...
@@ -861,14 +861,14 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
861 861
 		}
862 862
 		if (ret < 0) {
863 863
 			LOG(L_CRIT,"BUG:t_check_status: t_pick_branch failed to get "
864
-				" a final response in MODE_ONFAILURE\n");
864
+				" a final response in FAILURE_ROUTE\n");
865 865
 			goto error;
866 866
 		}
867 867
 		status = int2str( lowest_status , 0);
868 868
 		break;
869 869
 
870 870
 	default:
871
-		LOG(L_ERR,"ERROR:t_check_status: unsupported mode %d\n",rmode);
871
+		LOG(L_ERR,"ERROR:t_check_status: unsupported route type %d\n",route_type);
872 872
 		goto error;
873 873
 	}
874 874
 
... ...
@@ -1143,10 +1143,10 @@ inline static int w_t_reply(struct sip_msg* msg, char* p1, char* p2)
1143 1143
 	 * the safe version would lead to a deadlock
1144 1144
 	 */
1145 1145
 	 
1146
-	if (rmode==MODE_ONFAILURE) {
1146
+	if (is_route_type(FAILURE_ROUTE)) {
1147 1147
 		DBG("DEBUG: t_reply_unsafe called from w_t_reply\n");
1148 1148
 		ret = t_reply_unsafe(t, msg, code, r);
1149
-	} else if (rmode==MODE_REQUEST) {
1149
+	} else if (is_route_type(REQUEST_ROUTE)) {
1150 1150
 		ret = t_reply( t, msg, code, r);
1151 1151
 	} else {
1152 1152
 		LOG(L_CRIT, "BUG: w_t_reply entered in unsupported mode\n");
... ...
@@ -1233,7 +1233,7 @@ inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
1233 1233
 {
1234 1234
 	struct cell *t;
1235 1235
 
1236
-	if (rmode==MODE_ONFAILURE) {
1236
+	if (is_route_type(FAILURE_ROUTE)) {
1237 1237
 		t=get_t();
1238 1238
 		if (!t || t==T_UNDEFINED) {
1239 1239
 			LOG(L_CRIT, "BUG: w_t_relay_to: undefined T\n");
... ...
@@ -1248,10 +1248,10 @@ inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
1248 1248
 		}
1249 1249
 		return 1;
1250 1250
 	}
1251
-	if (rmode==MODE_REQUEST)
1251
+	if (is_route_type(REQUEST_ROUTE))
1252 1252
 		return t_relay_to( p_msg, proxy, force_proto,
1253 1253
 			0 /* no replication */ );
1254
-	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported mode: %d\n", rmode);
1254
+	LOG(L_CRIT, "ERROR: w_t_relay_to: unsupported route type: %d\n", route_type);
1255 1255
 	return 0;
1256 1256
 }
1257 1257
 
... ...
@@ -1517,8 +1517,8 @@ static int t_set_auto_inv_100(struct sip_msg* msg, char* p1, char* p2)
1517 1517
 	
1518 1518
 	if (get_int_fparam(&state, msg, (fparam_t*)p1) < 0) return -1;
1519 1519
 	t=get_t();
1520
-	/* in MODE_REPLY and MODE_ONFAILURE T will be set to current transaction;
1521
-	 * in MODE_REQUEST T will be set only if the transaction was already
1520
+	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
1521
+	 * in REQUEST_ROUTE T will be set only if the transaction was already
1522 1522
 	 * created; if not -> use the static variables */
1523 1523
 	if (!t || t==T_UNDEFINED ){
1524 1524
 		if (state)
... ...
@@ -199,7 +199,6 @@ int load_tm( struct tm_binds *tmb)
199 199
 	tmb->prepare_request_within = prepare_req_within;
200 200
 	tmb->send_prepared_request = send_prepared_request;
201 201
 	
202
-	tmb->route_mode = &rmode;
203 202
 #ifdef DIALOG_CALLBACKS
204 203
 	tmb->register_new_dlg_cb=register_new_dlg_cb;
205 204
 	tmb->register_dlg_tmcb=register_dlg_tmcb;
... ...
@@ -68,6 +68,7 @@ static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
68 68
 		onsnd_info.buf=buf;
69 69
 		onsnd_info.len=len;
70 70
 		p_onsend=&onsnd_info;
71
+		set_route_type(ONSEND_ROUTE);
71 72
 		init_run_actions_ctx(&ra_ctx);
72 73
 		ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
73 74
 		p_onsend=0; /* reset it */
... ...
@@ -169,6 +169,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
169 169
 		if (exec_pre_req_cb(msg)==0 )
170 170
 			goto end; /* drop the request */
171 171
 
172
+		set_route_type(REQUEST_ROUTE);
172 173
 		/* exec the routing script */
173 174
 		init_run_actions_ctx(&ra_ctx);
174 175
 		if (run_actions(&ra_ctx, main_rt.rlist[DEFAULT_RT], msg)<0){
... ...
@@ -210,8 +211,10 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
210 211
 		*/
211 212
 		if (exec_pre_rpl_cb(msg)==0 )
212 213
 			goto end; /* drop the request */
214
+
213 215
 		/* exec the onreply routing script */
214 216
 		if (onreply_rt.rlist[DEFAULT_RT]){
217
+			set_route_type(ONREPLY_ROUTE);
215 218
 			init_run_actions_ctx(&ra_ctx);
216 219
 			ret=run_actions(&ra_ctx, onreply_rt.rlist[DEFAULT_RT], msg);
217 220
 			if (ret<0){
... ...
@@ -93,6 +93,7 @@ struct route_list failure_rt;
93 93
 struct route_list branch_rt;
94 94
 struct route_list onsend_rt;
95 95
 
96
+int route_type = REQUEST_ROUTE;
96 97
 
97 98
 /** script optimization level, useful for debugging.
98 99
  *  0 - no optimization