Browse code

t_unsafe_reply deprecated

Jiri Kuthan authored on 06/01/2003 03:55:41
Showing 5 changed files
... ...
@@ -75,4 +75,6 @@ XXX
75 75
 
76 76
 tm module:
77 77
 ----------
78
-XXX t_uac/FIFO
78
+- t_reply_unsafe, used in former versions within reply_routes,
79
+  is deprecated; now t_reply is used from any places in script
80
+- XXX t_uac/FIFO
... ...
@@ -142,7 +142,7 @@ Desc:	sets reply routing block, to which control is passed after
142 142
 		upstream "202 I will take care of it"); Note that the
143 143
 		set of command which are useable within reply_routes is
144 144
 		strictly limited to rewriting URI, initiating new branches,
145
-		logging, and sending 'unsafe' replies (t_reply_unsafe). Any 
145
+		logging, and sending stateful replies (t_reply). Any 
146 146
 		other commands may result in unpredictable behaviour and 
147 147
 		possible server failure.
148 148
 		Note that whenever reply_route is entered, uri is reset to
... ...
@@ -189,8 +189,7 @@ Example: see test/uas.cfg:
189 189
 Name:	t_reply
190 190
 Params:	code, reason phrase
191 191
 Desc: 	sends a stateful reply after a transaction has been
192
-		established; see t_newtran for usage; note: never use
193
-	    t_reply from within reply_route ... always use t_reply_unsafe
192
+		established; see t_newtran for usage; 
194 193
 
195 194
 ----- only --- advanced --- commands --- from --- here --- on -----
196 195
 
... ...
@@ -226,13 +225,6 @@ Params:	*import_structure
226 226
 Desc:	for programmatic use only -- import exported TM functions;
227 227
 		see the acc module for an example of use
228 228
 
229
-Name:	t_reply_unsafe
230
-Params:	code, reason phrase
231
-Desc: 	sends a stateful reply after a transaction has been
232
-		established; it can only be used from reply processing;
233
-	    using it from regular processing will introduce erroneous
234
-	    conditions; using t_reply from reply_processing will
235
-	    introduce a deadlock
236 229
 
237 230
 External Usage of TM
238 231
 ---------------------
... ...
@@ -50,6 +50,9 @@
50 50
 #include "fix_lumps.h"
51 51
 #include "t_stats.h"
52 52
 
53
+/* are we processing original or shmemed request ? */
54
+enum route_mode rmode=MODE_REQUEST;
55
+
53 56
 /* private place where we create to-tags for replies */
54 57
 static char tm_tags[TOTAG_LEN];
55 58
 static char *tm_tag_suffix;
... ...
@@ -858,6 +861,7 @@ void on_negative_reply( struct cell* t, struct sip_msg* msg,
858 858
 {
859 859
 	int act_ret;
860 860
 	struct sip_msg faked_msg;
861
+	enum route_mode backup_mode;
861 862
 
862 863
 	/* nobody cares about a negative transaction -- ok, return */
863 864
 	if (!t->on_negative) {
... ...
@@ -900,7 +904,10 @@ void on_negative_reply( struct cell* t, struct sip_msg* msg,
900 900
 	*/
901 901
 	faked_msg.id=t->uas.request->id-1;
902 902
 
903
+	backup_mode=rmode;
904
+	rmode=MODE_ONREPLY_REQUEST;
903 905
 	act_ret=run_actions(reply_rlist[t->on_negative], &faked_msg );
906
+	rmode=backup_mode;
904 907
 
905 908
 	if (act_ret<0) {
906 909
 		LOG(L_ERR, "on_negative_reply: Error in do_action\n");
... ...
@@ -48,6 +48,9 @@ enum rps {
48 48
 	RPS_PROVISIONAL
49 49
 };
50 50
 
51
+enum route_mode { MODE_REQUEST=1, MODE_ONREPLY_REQUEST };
52
+extern enum route_mode rmode;
53
+
51 54
 /* branch bitmap type */
52 55
 typedef unsigned int branch_bm_t;
53 56
 
... ...
@@ -80,7 +80,9 @@
80 80
 
81 81
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
82 82
 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
83
+#ifdef _OBSOLETED
83 84
 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2);
85
+#endif
84 86
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
85 87
 inline static int fixup_t_send_reply(void** param, int param_no);
86 88
 inline static int fixup_str2int( void** param, int param_no);
... ...
@@ -113,7 +115,9 @@ struct module_exports exports= {
113 113
 				"t_newtran",
114 114
 				"t_lookup_request",
115 115
 				T_REPLY,
116
+#ifdef _OBSO
116 117
 				T_REPLY_UNSAFE,
118
+#endif
117 119
 				"t_retransmit_reply",
118 120
 				"t_release",
119 121
 				T_RELAY_TO,
... ...
@@ -133,7 +137,9 @@ struct module_exports exports= {
133 133
 					w_t_newtran,
134 134
 					w_t_check,
135 135
 					w_t_reply,
136
+#ifdef _OBSO
136 137
 					w_t_reply_unsafe,
138
+#endif
137 139
 					w_t_retransmit_reply,
138 140
 					w_t_release,
139 141
 					w_t_relay_to,
... ...
@@ -151,7 +157,9 @@ struct module_exports exports= {
151 151
 				0, /* t_newtran */
152 152
 				0, /* t_lookup_request */
153 153
 				2, /* t_reply */
154
+#ifdef _OBSO
154 155
 				2, /* t_reply_unsafe */
156
+#endif
155 157
 				0, /* t_retransmit_reply */
156 158
 				0, /* t_release */
157 159
 				2, /* t_relay_to */
... ...
@@ -168,7 +176,9 @@ struct module_exports exports= {
168 168
 				0,						/* t_newtran */
169 169
 				0,						/* t_lookup_request */
170 170
 				fixup_t_send_reply,		/* t_reply */
171
+#ifdef _OBSO
171 172
 				fixup_t_send_reply,		/* t_reply_unsafe */
173
+#endif
172 174
 				0,						/* t_retransmit_reply */
173 175
 				0,						/* t_release */
174 176
 				fixup_hostport2proxy,	/* t_relay_to */
... ...
@@ -182,7 +192,11 @@ struct module_exports exports= {
182 182
 				0						/* t_newdlg */
183 183
 	
184 184
 		},
185
+#ifdef _OBSO
185 186
 	15,
187
+#else
188
+	14,
189
+#endif
186 190
 
187 191
 	/* ------------ exported variables ---------- */
188 192
 	(char *[]) { /* Module parameter names */
... ...
@@ -462,10 +476,19 @@ inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2)
462 462
 			"for which no T-state has been established\n");
463 463
 		return -1;
464 464
 	}
465
-	return t_reply( t, msg, (unsigned int) str, str2);
465
+	/* if called from reply_route, make sure that unsafe version
466
+	 * is called; we are already in a mutex and another mutex in
467
+	 * the safe version would lead to a deadlock
468
+	 */
469
+	if (rmode==MODE_ONREPLY_REQUEST) { 
470
+		DBG("DEBUG: t_reply_unsafe called from w_t_reply\n");
471
+		return t_reply_unsafe(t, msg, (unsigned int) str, str2);
472
+	} else {
473
+		return t_reply( t, msg, (unsigned int) str, str2);
474
+	}
466 475
 }
467 476
 
468
-
477
+#ifdef _OBSOLETED
469 478
 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2)
470 479
 {
471 480
 	struct cell *t;
... ...
@@ -483,6 +506,7 @@ inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2)
483 483
 	}
484 484
 	return t_reply_unsafe(t, msg, (unsigned int) str, str2);
485 485
 }
486
+#endif
486 487
 
487 488
 
488 489
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2)