소스 검색

tm: added t_is_set("target") function

- returns true if the attribute specified by the target parameter is set
  for current transaction (e.g., failure_route, branch_route,
  onreply_route)
- on_negative was replaced with on_failure internally to be consistent
  with config file naming
Daniel-Constantin Mierla 13 년 전
부모
커밋
6da3e961d7
10개의 변경된 파일139개의 추가작업 그리고 31개의 파일을 삭제
  1. 20 0
      modules/tm/README
  2. 35 0
      modules/tm/doc/functions.xml
  3. 1 1
      modules/tm/h_table.h
  4. 1 1
      modules/tm/t_fwd.c
  5. 2 2
      modules/tm/t_lookup.c
  6. 16 16
      modules/tm/t_reply.c
  7. 3 3
      modules/tm/t_reply.h
  8. 1 1
      modules/tm/timer.c
  9. 59 6
      modules/tm/tm.c
  10. 1 1
      modules/tm/tm_load.c

+ 20 - 0
modules/tm/README

@@ -106,6 +106,7 @@ Juha Heinanen
         1.5.43. t_replicate(params)
         1.5.43. t_replicate(params)
         1.5.44. t_relay_to(proxy, flags)
         1.5.44. t_relay_to(proxy, flags)
         1.5.45. t_set_no_e2e_cancel_reason(0|1)
         1.5.45. t_set_no_e2e_cancel_reason(0|1)
+        1.5.46. t_is_set(target)
 
 
    1.6. TM Module API
    1.6. TM Module API
 
 
@@ -2146,6 +2147,25 @@ opying
 ...
 ...
 }
 }
 
 
+1.5.46. t_is_set(target)
+
+   Return true if the attribute specified by 'target' is set for
+   transaction.
+
+   The target parameter can be:
+     * branch_route - the function returns true if a branch route is set
+       to be executed.
+     * failure_route - the function returns true if a failure route is set
+       to be executed.
+     * onreply_route - the function returns true if an onreply route is
+       set to be executed.
+
+   Example 79. t_replicate usage
+...
+if(!t_is_set("failure_route"))
+    LM_DBG("no failure route will be executed for current transaction\n");
+...
+
 1.6. TM Module API
 1.6. TM Module API
 
 
    There are applications which would like to generate SIP transactions
    There are applications which would like to generate SIP transactions

+ 35 - 0
modules/tm/doc/functions.xml

@@ -1535,5 +1535,40 @@ route {
 	</example>
 	</example>
 	</section>
 	</section>
 
 
+	<section id="t_is_set">
+	<title>
+	    <function>t_is_set(target)</function>
+	</title>
+	<para>
+		Return true if the attribute specified by 'target' is set for transaction.
+	</para>
+	<para>The target parameter can be:</para>
+	<itemizedlist>
+	    <listitem>
+		<para><emphasis>branch_route</emphasis> - the function returns true if a
+			branch route is set to be executed.
+		</para>
+	    </listitem>
+	    <listitem>
+		<para><emphasis>failure_route</emphasis> - the function returns true if a
+			failure route is set to be executed.
+		</para>
+	    </listitem>
+	    <listitem>
+		<para><emphasis>onreply_route</emphasis> - the function returns true if an
+			onreply route is set to be executed.
+		</para>
+	    </listitem>
+	</itemizedlist>
+	<example>
+	    <title><function>t_replicate</function> usage</title>
+	    <programlisting>
+...
+if(!t_is_set("failure_route"))
+    LM_DBG("no failure route will be executed for current transaction\n");
+...
+	    </programlisting>
+	</example>
+    </section>
 
 
 </section>
 </section>

+ 1 - 1
modules/tm/h_table.h

@@ -432,7 +432,7 @@ typedef struct cell
 	short relayed_reply_branch;
 	short relayed_reply_branch;
 
 
 	/* the route to take if no final positive reply arrived */
 	/* the route to take if no final positive reply arrived */
-	unsigned short on_negative;
+	unsigned short on_failure;
 	/* the onreply_route to be processed if registered to do so */
 	/* the onreply_route to be processed if registered to do so */
 	unsigned short on_reply;
 	unsigned short on_reply;
 	 /* The route to take for each downstream branch separately */
 	 /* The route to take for each downstream branch separately */

+ 1 - 1
modules/tm/t_fwd.c

@@ -138,7 +138,7 @@ void t_on_branch( unsigned int go_to )
 	if (!t || t==T_UNDEFINED ) {
 	if (!t || t==T_UNDEFINED ) {
 		goto_on_branch=go_to;
 		goto_on_branch=go_to;
 	} else {
 	} else {
-		get_t()->on_branch = go_to;
+		t->on_branch = go_to;
 	}
 	}
 }
 }
 
 

+ 2 - 2
modules/tm/t_lookup.c

@@ -67,7 +67,7 @@
  * 2003-03-30  set_kr for requests only (jiri)
  * 2003-03-30  set_kr for requests only (jiri)
  * 2003-04-04  bug_fix: RESPONSE_IN callback not called for local
  * 2003-04-04  bug_fix: RESPONSE_IN callback not called for local
  *             UAC transactions (jiri)
  *             UAC transactions (jiri)
- * 2003-04-07  new transactions inherit on_negative and on_relpy from script
+ * 2003-04-07  new transactions inherit on_failure and on_relpy from script
  *             variables on instantiation (jiri)
  *             variables on instantiation (jiri)
  * 2003-04-30  t_newtran clean up (jiri)
  * 2003-04-30  t_newtran clean up (jiri)
  * 2003-08-21  request lookups fixed to skip UAC transactions, 
  * 2003-08-21  request lookups fixed to skip UAC transactions, 
@@ -1269,7 +1269,7 @@ static inline void init_new_t(struct cell *new_cell, struct sip_msg *p_msg)
 		if (likely(lifetime==0))
 		if (likely(lifetime==0))
 			lifetime=cfg_get(tm, tm_cfg, tm_max_noninv_lifetime);
 			lifetime=cfg_get(tm, tm_cfg, tm_max_noninv_lifetime);
 	}
 	}
-	new_cell->on_negative=get_on_negative();
+	new_cell->on_failure=get_on_failure();
 	new_cell->on_reply=get_on_reply();
 	new_cell->on_reply=get_on_reply();
 	new_cell->end_of_life=get_ticks_raw()+lifetime;;
 	new_cell->end_of_life=get_ticks_raw()+lifetime;;
 	new_cell->fr_timeout=(ticks_t)get_msgid_val(user_fr_timeout,
 	new_cell->fr_timeout=(ticks_t)get_msgid_val(user_fr_timeout,

+ 16 - 16
modules/tm/t_reply.c

@@ -170,8 +170,8 @@ char tm_tags[TOTAG_VALUE_LEN];
 static str  tm_tag = {tm_tags,TOTAG_VALUE_LEN};
 static str  tm_tag = {tm_tags,TOTAG_VALUE_LEN};
 char *tm_tag_suffix;
 char *tm_tag_suffix;
 
 
-/* where to go if there is no positive reply */
-static int goto_on_negative=0;
+/* where to go if there is no positive reply (>=300) */
+static int goto_on_failure=0;
 /* where to go on receipt of reply */
 /* where to go on receipt of reply */
 static int goto_on_reply=0;
 static int goto_on_reply=0;
 /* where to go on receipt of reply without transaction context */
 /* where to go on receipt of reply without transaction context */
@@ -245,7 +245,7 @@ int t_get_picked_branch(void)
 */
 */
 
 
 
 
-void t_on_negative( unsigned int go_to )
+void t_on_failure( unsigned int go_to )
 {
 {
 	struct cell *t = get_t();
 	struct cell *t = get_t();
 
 
@@ -253,9 +253,9 @@ void t_on_negative( unsigned int go_to )
 	 * in REQUEST_ROUTE T will be set only if the transaction was already
 	 * in REQUEST_ROUTE T will be set only if the transaction was already
 	 * created; if not -> use the static variable */
 	 * created; if not -> use the static variable */
 	if (!t || t==T_UNDEFINED )
 	if (!t || t==T_UNDEFINED )
-		goto_on_negative=go_to;
+		goto_on_failure=go_to;
 	else
 	else
-		get_t()->on_negative = go_to;
+		t->on_failure = go_to;
 }
 }
 
 
 
 
@@ -269,13 +269,13 @@ void t_on_reply( unsigned int go_to )
 	if (!t || t==T_UNDEFINED )
 	if (!t || t==T_UNDEFINED )
 		goto_on_reply=go_to;
 		goto_on_reply=go_to;
 	else
 	else
-		get_t()->on_reply = go_to;
+		t->on_reply = go_to;
 }
 }
 
 
 
 
-unsigned int get_on_negative()
+unsigned int get_on_failure()
 {
 {
-	return goto_on_negative;
+	return goto_on_failure;
 }
 }
 unsigned int get_on_reply()
 unsigned int get_on_reply()
 {
 {
@@ -875,7 +875,7 @@ void faked_env( struct cell *t, struct sip_msg *msg)
 int fake_req(struct sip_msg *faked_req,
 int fake_req(struct sip_msg *faked_req,
 		struct sip_msg *shmem_msg, int extra_flags, struct ua_client *uac)
 		struct sip_msg *shmem_msg, int extra_flags, struct ua_client *uac)
 {
 {
-	/* on_negative_reply faked msg now copied from shmem msg (as opposed
+	/* on_failure_reply faked msg now copied from shmem msg (as opposed
 	 * to zero-ing) -- more "read-only" actions (exec in particular) will
 	 * to zero-ing) -- more "read-only" actions (exec in particular) will
 	 * work from reply_route as they will see msg->from, etc.; caution,
 	 * work from reply_route as they will see msg->from, etc.; caution,
 	 * rw actions may append some pkg stuff to msg, which will possibly be
 	 * rw actions may append some pkg stuff to msg, which will possibly be
@@ -986,15 +986,15 @@ int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
 	/* failure_route for a local UAC? */
 	/* failure_route for a local UAC? */
 	if (!shmem_msg) {
 	if (!shmem_msg) {
 		LOG(L_WARN,"Warning: run_failure_handlers: no UAC support (%d, %d) \n",
 		LOG(L_WARN,"Warning: run_failure_handlers: no UAC support (%d, %d) \n",
-			t->on_negative, t->tmcb_hl.reg_types);
+			t->on_failure, t->tmcb_hl.reg_types);
 		return 0;
 		return 0;
 	}
 	}
 
 
 	/* don't start faking anything if we don't have to */
 	/* don't start faking anything if we don't have to */
-	if (unlikely(!t->on_negative && !has_tran_tmcbs( t, TMCB_ON_FAILURE))) {
+	if (unlikely(!t->on_failure && !has_tran_tmcbs( t, TMCB_ON_FAILURE))) {
 		LOG(L_WARN,
 		LOG(L_WARN,
 			"Warning: run_failure_handlers: no negative handler (%d, %d)\n",
 			"Warning: run_failure_handlers: no negative handler (%d, %d)\n",
-			t->on_negative,
+			t->on_failure,
 			t->tmcb_hl.reg_types);
 			t->tmcb_hl.reg_types);
 		return 1;
 		return 1;
 	}
 	}
@@ -1010,12 +1010,12 @@ int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
 	if (unlikely(has_tran_tmcbs( t, TMCB_ON_FAILURE)) ) {
 	if (unlikely(has_tran_tmcbs( t, TMCB_ON_FAILURE)) ) {
 		run_trans_callbacks( TMCB_ON_FAILURE, t, &faked_req, rpl, code);
 		run_trans_callbacks( TMCB_ON_FAILURE, t, &faked_req, rpl, code);
 	}
 	}
-	if (t->on_negative) {
+	if (t->on_failure) {
 		/* avoid recursion -- if failure_route forwards, and does not
 		/* avoid recursion -- if failure_route forwards, and does not
 		 * set next failure route, failure_route will not be reentered
 		 * set next failure route, failure_route will not be reentered
 		 * on failure */
 		 * on failure */
-		on_failure = t->on_negative;
-		t->on_negative=0;
+		on_failure = t->on_failure;
+		t->on_failure=0;
 		if (exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE)>0) {
 		if (exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE)>0) {
 			/* run a failure_route action if some was marked */
 			/* run a failure_route action if some was marked */
 			if (run_top_route(failure_rt.rlist[on_failure], &faked_req, 0)<0)
 			if (run_top_route(failure_rt.rlist[on_failure], &faked_req, 0)<0)
@@ -1287,7 +1287,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
 		replies_dropped = 0;
 		replies_dropped = 0;
 		/* run ON_FAILURE handlers ( route and callbacks) */
 		/* run ON_FAILURE handlers ( route and callbacks) */
 		if (unlikely(has_tran_tmcbs( Trans, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE)
 		if (unlikely(has_tran_tmcbs( Trans, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE)
-						|| Trans->on_negative )) {
+						|| Trans->on_failure )) {
 			extra_flags=
 			extra_flags=
 				((Trans->uac[picked_branch].request.flags & F_RB_TIMEOUT)?
 				((Trans->uac[picked_branch].request.flags & F_RB_TIMEOUT)?
 							FL_TIMEOUT:0) | 
 							FL_TIMEOUT:0) | 

+ 3 - 3
modules/tm/t_reply.h

@@ -201,14 +201,14 @@ void set_final_timer( /* struct s_table *h_table,*/ struct cell *t );
 
 
 void cleanup_uac_timers( struct cell *t );
 void cleanup_uac_timers( struct cell *t );
 
 
-void on_negative_reply( struct cell* t, struct sip_msg* msg,
+void on_failure_reply( struct cell* t, struct sip_msg* msg,
 	int code, void *param  );
 	int code, void *param  );
 
 
 /* set which 'reply' structure to take if only negative
 /* set which 'reply' structure to take if only negative
    replies arrive 
    replies arrive 
 */
 */
-void t_on_negative( unsigned int go_to );
-unsigned int get_on_negative(void);
+void t_on_failure( unsigned int go_to );
+unsigned int get_on_failure(void);
 void t_on_reply( unsigned int go_to );
 void t_on_reply( unsigned int go_to );
 unsigned int get_on_reply(void);
 unsigned int get_on_reply(void);
 
 

+ 1 - 1
modules/tm/timer.c

@@ -471,7 +471,7 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
 		&& t->nr_of_outgoings==1
 		&& t->nr_of_outgoings==1
 		/* on_negativ reply handler not installed -- serial forking 
 		/* on_negativ reply handler not installed -- serial forking 
 		 * could occur otherwise */
 		 * could occur otherwise */
-		&& t->on_negative==0
+		&& t->on_failure==0
 		/* the same for FAILURE callbacks */
 		/* the same for FAILURE callbacks */
 		&& !has_tran_tmcbs( t, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE) 
 		&& !has_tran_tmcbs( t, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE) 
 		/* something received -- we will not be silent on error */
 		/* something received -- we will not be silent on error */

+ 59 - 6
modules/tm/tm.c

@@ -195,6 +195,7 @@ static int fixup_on_branch(void** param, int param_no);
 static int fixup_t_reply(void** param, int param_no);
 static int fixup_t_reply(void** param, int param_no);
 static int fixup_on_sl_reply(modparam_t type, void* val);
 static int fixup_on_sl_reply(modparam_t type, void* val);
 static int fixup_t_relay_to(void** param, int param_no);
 static int fixup_t_relay_to(void** param, int param_no);
+static int fixup_t_is_set(void** param, int param_no);
 
 
 /* init functions */
 /* init functions */
 static int mod_init(void);
 static int mod_init(void);
@@ -270,7 +271,7 @@ inline static int w_t_forward_nonack_sctp(struct sip_msg*, char* str,char*);
 #endif
 #endif
 inline static int w_t_forward_nonack_to(struct sip_msg* msg, char* str,char*);
 inline static int w_t_forward_nonack_to(struct sip_msg* msg, char* str,char*);
 inline static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo, char *_bar);
 inline static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo, char *_bar);
-inline static int w_t_on_negative(struct sip_msg* msg, char *go_to, char *foo);
+inline static int w_t_on_failure(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_branch(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_branch(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int t_check_status(struct sip_msg* msg, char *match, char *foo);
 inline static int t_check_status(struct sip_msg* msg, char *match, char *foo);
@@ -298,6 +299,7 @@ static int t_grep_status(struct sip_msg* msg, char*, char*);
 static int w_t_drop_replies(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_drop_replies(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar);
+static int w_t_is_set(struct sip_msg* msg, char* target, char* bar);
 
 
 
 
 /* by default the fr timers avps are not set, so that the avps won't be
 /* by default the fr timers avps are not set, so that the avps won't be
@@ -401,7 +403,7 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE},
 			REQUEST_ROUTE},
 	{"t_relay_cancel",     w_t_relay_cancel,        0, 0,
 	{"t_relay_cancel",     w_t_relay_cancel,        0, 0,
 			REQUEST_ROUTE},
 			REQUEST_ROUTE},
-	{"t_on_failure",       w_t_on_negative,         1, fixup_on_failure,
+	{"t_on_failure",       w_t_on_failure,         1, fixup_on_failure,
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
 	{"t_on_reply",         w_t_on_reply,            1, fixup_on_reply,
 	{"t_on_reply",         w_t_on_reply,            1, fixup_on_reply,
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
@@ -462,6 +464,8 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE},
 			REQUEST_ROUTE},
 	{"t_check_trans",	  w_t_check_trans,			0, 0,
 	{"t_check_trans",	  w_t_check_trans,			0, 0,
 			REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE },
 			REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE },
+	{"t_is_set",	      w_t_is_set,				1, fixup_t_is_set,
+			ANY_ROUTE },
 
 
 	{"t_load_contacts", t_load_contacts,            0, 0,
 	{"t_load_contacts", t_load_contacts,            0, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE},
 			REQUEST_ROUTE | FAILURE_ROUTE},
@@ -717,9 +721,9 @@ static int script_init( struct sip_msg *foo, unsigned int flags, void *bar)
 	 * not be used again */
 	 * not be used again */
 
 
 	/* make sure the new message will not inherit previous
 	/* make sure the new message will not inherit previous
-		message's t_on_negative value
+		message's t_on_failure value
 	*/
 	*/
-	t_on_negative( 0 );
+	t_on_failure( 0 );
 	t_on_reply(0);
 	t_on_reply(0);
 	t_on_branch(0);
 	t_on_branch(0);
 	/* reset the kr status */
 	/* reset the kr status */
@@ -1336,9 +1340,9 @@ inline static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar )
 }
 }
 
 
 
 
-inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo)
+inline static int w_t_on_failure( struct sip_msg* msg, char *go_to, char *foo)
 {
 {
-	t_on_negative( (unsigned int )(long) go_to );
+	t_on_failure( (unsigned int )(long) go_to );
 	return 1;
 	return 1;
 }
 }
 
 
@@ -1356,6 +1360,55 @@ inline static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo )
 }
 }
 
 
 
 
+static int w_t_is_set(struct sip_msg* msg, char *target, char *foo )
+{
+	int r;
+	tm_cell_t *t = NULL;
+	
+	r = 0;
+	t = get_t();
+	if (t==T_UNDEFINED) t = NULL;
+
+	switch(target[0]) {
+		case 'b':
+			if(t==NULL)
+				r = get_on_branch();
+			else
+				r = t->on_branch;
+			break;
+		case 'f':
+			if(t==NULL)
+				r = get_on_failure();
+			else
+				r = t->on_failure;
+			break;
+		case 'o':
+			if(t==NULL)
+				r = get_on_reply();
+			else
+				r = t->on_reply;
+			break;
+	}
+	if(r) return 1;
+	return -1;
+}
+
+static int fixup_t_is_set(void** param, int param_no)
+{
+	int len;
+	if (param_no==1) {
+		len = strlen((char*)*param);
+		if((len==13 && strncmp((char*)*param, "failure_route", 13)==0)
+				|| (len==13 && strncmp((char*)*param, "onreply_route", 13)==0)
+				|| (len==12 && strncmp((char*)*param, "branch_route", 12)==0)) {
+			return 0;
+		}
+
+		LM_ERR("invalid parameter value: %s\n", (char*)*param);
+		return 1;
+	}
+	return 0;
+}
 
 
 inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
 inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
 									struct proxy_l *proxy, int force_proto)
 									struct proxy_l *proxy, int force_proto)

+ 1 - 1
modules/tm/tm_load.c

@@ -157,7 +157,7 @@ int load_xtm(tm_xapi_t *xapi)
 
 
 	memset(xapi, 0, sizeof(tm_xapi_t));
 	memset(xapi, 0, sizeof(tm_xapi_t));
 
 
-	xapi->t_on_failure    = t_on_negative;
+	xapi->t_on_failure    = t_on_failure;
 	xapi->t_on_branch     = t_on_branch;
 	xapi->t_on_branch     = t_on_branch;
 	xapi->t_on_reply      = t_on_reply;
 	xapi->t_on_reply      = t_on_reply;
 	xapi->t_check_trans   = t_check_trans;
 	xapi->t_check_trans   = t_check_trans;