Преглед на файлове

t_unsafe_reply deprecated

Jiri Kuthan преди 23 години
родител
ревизия
eaf10d3693
променени са 5 файла, в които са добавени 41 реда и са изтрити 13 реда
  1. 3 1
      NEWS
  2. 2 10
      modules/tm/README
  3. 7 0
      modules/tm/t_reply.c
  4. 3 0
      modules/tm/t_reply.h
  5. 26 2
      modules/tm/tm.c

+ 3 - 1
NEWS

@@ -75,4 +75,6 @@ XXX
 
 tm module:
 ----------
-XXX t_uac/FIFO
+- t_reply_unsafe, used in former versions within reply_routes,
+  is deprecated; now t_reply is used from any places in script
+- XXX t_uac/FIFO

+ 2 - 10
modules/tm/README

@@ -142,7 +142,7 @@ Desc:	sets reply routing block, to which control is passed after
 		upstream "202 I will take care of it"); Note that the
 		set of command which are useable within reply_routes is
 		strictly limited to rewriting URI, initiating new branches,
-		logging, and sending 'unsafe' replies (t_reply_unsafe). Any 
+		logging, and sending stateful replies (t_reply). Any 
 		other commands may result in unpredictable behaviour and 
 		possible server failure.
 		Note that whenever reply_route is entered, uri is reset to
@@ -189,8 +189,7 @@ Example: see test/uas.cfg:
 Name:	t_reply
 Params:	code, reason phrase
 Desc: 	sends a stateful reply after a transaction has been
-		established; see t_newtran for usage; note: never use
-	    t_reply from within reply_route ... always use t_reply_unsafe
+		established; see t_newtran for usage; 
 
 ----- only --- advanced --- commands --- from --- here --- on -----
 
@@ -226,13 +225,6 @@ Params:	*import_structure
 Desc:	for programmatic use only -- import exported TM functions;
 		see the acc module for an example of use
 
-Name:	t_reply_unsafe
-Params:	code, reason phrase
-Desc: 	sends a stateful reply after a transaction has been
-		established; it can only be used from reply processing;
-	    using it from regular processing will introduce erroneous
-	    conditions; using t_reply from reply_processing will
-	    introduce a deadlock
 
 External Usage of TM
 ---------------------

+ 7 - 0
modules/tm/t_reply.c

@@ -50,6 +50,9 @@
 #include "fix_lumps.h"
 #include "t_stats.h"
 
+/* are we processing original or shmemed request ? */
+enum route_mode rmode=MODE_REQUEST;
+
 /* private place where we create to-tags for replies */
 static char tm_tags[TOTAG_LEN];
 static char *tm_tag_suffix;
@@ -858,6 +861,7 @@ void on_negative_reply( struct cell* t, struct sip_msg* msg,
 {
 	int act_ret;
 	struct sip_msg faked_msg;
+	enum route_mode backup_mode;
 
 	/* nobody cares about a negative transaction -- ok, return */
 	if (!t->on_negative) {
@@ -900,7 +904,10 @@ void on_negative_reply( struct cell* t, struct sip_msg* msg,
 	*/
 	faked_msg.id=t->uas.request->id-1;
 
+	backup_mode=rmode;
+	rmode=MODE_ONREPLY_REQUEST;
 	act_ret=run_actions(reply_rlist[t->on_negative], &faked_msg );
+	rmode=backup_mode;
 
 	if (act_ret<0) {
 		LOG(L_ERR, "on_negative_reply: Error in do_action\n");

+ 3 - 0
modules/tm/t_reply.h

@@ -48,6 +48,9 @@ enum rps {
 	RPS_PROVISIONAL
 };
 
+enum route_mode { MODE_REQUEST=1, MODE_ONREPLY_REQUEST };
+extern enum route_mode rmode;
+
 /* branch bitmap type */
 typedef unsigned int branch_bm_t;
 

+ 26 - 2
modules/tm/tm.c

@@ -80,7 +80,9 @@
 
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2);
 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2);
+#ifdef _OBSOLETED
 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2);
+#endif
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2);
 inline static int fixup_t_send_reply(void** param, int param_no);
 inline static int fixup_str2int( void** param, int param_no);
@@ -113,7 +115,9 @@ struct module_exports exports= {
 				"t_newtran",
 				"t_lookup_request",
 				T_REPLY,
+#ifdef _OBSO
 				T_REPLY_UNSAFE,
+#endif
 				"t_retransmit_reply",
 				"t_release",
 				T_RELAY_TO,
@@ -133,7 +137,9 @@ struct module_exports exports= {
 					w_t_newtran,
 					w_t_check,
 					w_t_reply,
+#ifdef _OBSO
 					w_t_reply_unsafe,
+#endif
 					w_t_retransmit_reply,
 					w_t_release,
 					w_t_relay_to,
@@ -151,7 +157,9 @@ struct module_exports exports= {
 				0, /* t_newtran */
 				0, /* t_lookup_request */
 				2, /* t_reply */
+#ifdef _OBSO
 				2, /* t_reply_unsafe */
+#endif
 				0, /* t_retransmit_reply */
 				0, /* t_release */
 				2, /* t_relay_to */
@@ -168,7 +176,9 @@ struct module_exports exports= {
 				0,						/* t_newtran */
 				0,						/* t_lookup_request */
 				fixup_t_send_reply,		/* t_reply */
+#ifdef _OBSO
 				fixup_t_send_reply,		/* t_reply_unsafe */
+#endif
 				0,						/* t_retransmit_reply */
 				0,						/* t_release */
 				fixup_hostport2proxy,	/* t_relay_to */
@@ -182,7 +192,11 @@ struct module_exports exports= {
 				0						/* t_newdlg */
 	
 		},
+#ifdef _OBSO
 	15,
+#else
+	14,
+#endif
 
 	/* ------------ exported variables ---------- */
 	(char *[]) { /* Module parameter names */
@@ -462,10 +476,19 @@ inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2)
 			"for which no T-state has been established\n");
 		return -1;
 	}
-	return t_reply( t, msg, (unsigned int) str, str2);
+	/* if called from reply_route, make sure that unsafe version
+	 * is called; we are already in a mutex and another mutex in
+	 * the safe version would lead to a deadlock
+	 */
+	if (rmode==MODE_ONREPLY_REQUEST) { 
+		DBG("DEBUG: t_reply_unsafe called from w_t_reply\n");
+		return t_reply_unsafe(t, msg, (unsigned int) str, str2);
+	} else {
+		return t_reply( t, msg, (unsigned int) str, str2);
+	}
 }
 
-
+#ifdef _OBSOLETED
 inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2)
 {
 	struct cell *t;
@@ -483,6 +506,7 @@ inline static int w_t_reply_unsafe(struct sip_msg* msg, char* str, char* str2)
 	}
 	return t_reply_unsafe(t, msg, (unsigned int) str, str2);
 }
+#endif
 
 
 inline static int w_t_release(struct sip_msg* msg, char* str, char* str2)