[sr-dev] git:hpw/branch_failure_route: modules/tm: Create branch-failure event route

Hugh Waite hugh.waite at crocodile-rcs.com
Tue Mar 26 15:02:56 CET 2013


Module: sip-router
Branch: hpw/branch_failure_route
Commit: 54a98bc741daba4d0c14c587d22dddf3c01a2e30
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=54a98bc741daba4d0c14c587d22dddf3c01a2e30

Author: Hugh Waite <hugh.waite at crocodile-rcs.com>
Committer: Hugh Waite <hugh.waite at crocodile-rcs.com>
Date:   Tue Mar 26 11:40:38 2013 +0000

modules/tm: Create branch-failure event route

---

 modules/tm/t_reply.c |   41 +++++++++++++----------------------------
 modules/tm/t_reply.h |    1 +
 modules/tm/tm.c      |   37 ++++++++-----------------------------
 3 files changed, 22 insertions(+), 57 deletions(-)

diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index 7314a21..7bf3a8f 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -173,7 +173,7 @@ char *tm_tag_suffix;
 /* where to go if there is no positive reply (>=300) */
 static int goto_on_failure=0;
 /* where to go if a failure is returned on a branch */
-static int goto_on_branch_failure=0;
+int goto_on_branch_failure=0;
 /* where to go on receipt of reply */
 static int goto_on_reply=0;
 /* where to go on receipt of reply without transaction context */
@@ -264,20 +264,6 @@ void t_on_failure( unsigned int go_to )
 }
 
 
-void t_on_branch_failure( unsigned int go_to )
-{
-	struct cell *t = get_t();
-
-	/* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction;
-	 * in REQUEST_ROUTE T will be set only if the transaction was already
-	 * created; if not -> use the static variable */
-	if (!t || t==T_UNDEFINED )
-		goto_on_branch_failure=go_to;
-	else
-		t->on_branch_failure = go_to;
-}
-
-
 void t_on_reply( unsigned int go_to )
 {
 	struct cell *t = get_t();
@@ -1067,20 +1053,18 @@ int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl,
 	struct sip_msg *shmem_msg = t->uas.request;
 	int on_branch_failure;
 
-	on_branch_failure = t->uac[picked_branch].on_branch_failure;
-
 	/* failure_route for a local UAC? */
 	if (!shmem_msg) {
 		LOG(L_WARN,"Warning: run_branch_failure_handlers: no UAC support (%d, %d) \n",
-			on_branch_failure, t->tmcb_hl.reg_types);
+			goto_on_branch_failure, t->tmcb_hl.reg_types);
 		return 0;
 	}
 
 	/* don't start faking anything if we don't have to */
-	if (unlikely(!on_branch_failure && !has_tran_tmcbs( t, TMCB_ON_BRANCH_FAILURE))) {
+	if (unlikely(!goto_on_branch_failure && !has_tran_tmcbs( t, TMCB_ON_BRANCH_FAILURE))) {
 		LOG(L_WARN,
 			"Warning: run_failure_handlers: no branch_failure handler (%d, %d)\n",
-			on_branch_failure, t->tmcb_hl.reg_types);
+			goto_on_branch_failure, t->tmcb_hl.reg_types);
 		return 1;
 	}
 
@@ -1090,19 +1074,17 @@ int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl,
 	}
 	/* fake also the env. conforming to the fake msg */
 	faked_env( t, &faked_req);
+	set_route_type(BRANCH_FAILURE_ROUTE);
+	set_t(t, picked_branch);
 	/* DONE with faking ;-) -> run the branch_failure handlers */
 
 	if (unlikely(has_tran_tmcbs( t, TMCB_ON_BRANCH_FAILURE)) ) {
 		run_trans_callbacks( TMCB_ON_BRANCH_FAILURE, t, &faked_req, rpl, code);
 	}
-	if (on_branch_failure) {
-		/* avoid recursion -- if branch_failure_route forwards, and does not
-		 * set next branch failure route, branch_failure_route will not be reentered
-		 * on branch failure */
-		t->on_branch_failure=0;
+	if (goto_on_branch_failure) {
 		if (exec_pre_script_cb(&faked_req, BRANCH_FAILURE_CB_TYPE)>0) {
 			/* run a branch_failure_route action if some was marked */
-			if (run_top_route(branch_failure_rt.rlist[on_branch_failure], &faked_req, 0)<0)
+			if (run_top_route(event_rt.rlist[goto_on_branch_failure], &faked_req, 0)<0)
 				LOG(L_ERR, "ERROR: run_branch_failure_handlers: Error in run_top_route\n");
 			exec_post_script_cb(&faked_req, BRANCH_FAILURE_CB_TYPE);
 		}
@@ -1334,8 +1316,11 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
 		Trans->uac[branch].last_received=new_code;
 
 /* New branch failure route code */
-		if (unlikely(has_tran_tmcbs( Trans, TMCB_ON_BRANCH_FAILURE_RO|TMCB_ON_BRANCH_FAILURE)
-						|| Trans->uac[branch].on_branch_failure )) {
+		/* also append the current reply to the transaction to
+		 * make it available in failure routes - a kind of "fake"
+		 * save of the final reply per branch */
+		Trans->uac[branch].reply = reply;
+		if (unlikely(Trans->uac[branch].on_branch_failure )) {
 			extra_flags=
 				((Trans->uac[branch].request.flags & F_RB_TIMEOUT)?
 							FL_TIMEOUT:0) | 
diff --git a/modules/tm/t_reply.h b/modules/tm/t_reply.h
index 5717a8f..a3a3c68 100644
--- a/modules/tm/t_reply.h
+++ b/modules/tm/t_reply.h
@@ -61,6 +61,7 @@ enum rps {
 extern char tm_tags[TOTAG_VALUE_LEN];
 extern char *tm_tag_suffix;
 
+extern int goto_on_branch_failure;
 extern int goto_on_sl_reply;
 
 extern int failure_reply_mode;
diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index 22d4156..e2790b3 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -190,7 +190,6 @@ MODULE_VERSION
 static int fixup_hostport2proxy(void** param, int param_no);
 static int fixup_proto_hostport2proxy(void** param, int param_no);
 static int fixup_on_failure(void** param, int param_no);
-static int fixup_on_branch_failure(void** param, int param_no);
 static int fixup_on_reply(void** param, int param_no);
 static int fixup_on_branch(void** param, int param_no);
 static int fixup_t_reply(void** param, int param_no);
@@ -273,7 +272,6 @@ inline static int w_t_forward_nonack_sctp(struct sip_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_on_failure(struct sip_msg* msg, char *go_to, char *foo);
-inline static int w_t_on_branch_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_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int t_check_status(struct sip_msg* msg, char *match, char *foo);
@@ -411,14 +409,12 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE},
 	{"t_on_failure",       w_t_on_failure,         1, fixup_on_failure,
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
-	{"t_on_branch_failure",w_t_on_branch_failure,         1, fixup_on_branch_failure,
-			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
 	{"t_on_reply",         w_t_on_reply,            1, fixup_on_reply,
 			REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE },
 	{"t_on_branch",       w_t_on_branch,         1, fixup_on_branch,
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"t_check_status",     t_check_status,          1, fixup_t_check_status,
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
+			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_FAILURE_ROUTE},
 	{"t_write_req",       t_write_req,              2, fixup_t_write,
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"t_write_unix",      t_write_unix,             2, fixup_t_write,
@@ -605,21 +601,6 @@ static int fixup_on_failure(void** param, int param_no)
 }
 
 
-static int fixup_on_branch_failure(void** param, int param_no)
-{
-	if (param_no==1){
-		if(strlen((char*)*param)<=1
-				&& (*(char*)(*param)==0 || *(char*)(*param)=='0')) {
-			*param = (void*)0;
-			return 0;
-		}
-		return fixup_routes("t_on_branch_failure", &branch_failure_rt, param);
-	}
-	return 0;
-}
-
-
-
 static int fixup_on_reply(void** param, int param_no)
 {
 	if (param_no==1){
@@ -751,7 +732,6 @@ static int script_init( struct sip_msg *foo, unsigned int flags, void *bar)
 		message's t_on_failure value
 	*/
 	t_on_failure( 0 );
-	t_on_branch_failure(0);
 	t_on_reply(0);
 	t_on_branch(0);
 	/* reset the kr status */
@@ -874,6 +854,9 @@ static int mod_init(void)
 	    return -1;
 	}
 
+	goto_on_branch_failure = route_lookup(&event_rt, "tm:branch-failure");
+	if (goto_on_branch_failure >= 0 && event_rt.rlist[goto_on_branch_failure]==0)
+		goto_on_branch_failure = -1; /* disable */
 #ifdef WITH_EVENT_LOCAL_REQUEST
 	goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
 	if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
@@ -998,7 +981,10 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
 		}
 		status = int2str( lowest_status , 0);
 		break;
-
+	case BRANCH_FAILURE_ROUTE:
+#warning add the status for branch failure route
+		status = int2str(t->uac[get_t_branch()].last_received, 0);
+		break;
 	default:
 		LOG(L_ERR,"ERROR:t_check_status: unsupported route type %d\n",
 				get_route_type());
@@ -1387,11 +1373,6 @@ inline static int w_t_on_failure( struct sip_msg* msg, char *go_to, char *foo)
 	return 1;
 }
 
-inline static int w_t_on_branch_failure( struct sip_msg* msg, char *go_to, char *foo)
-{
-	t_on_branch_failure( (unsigned int )(long) go_to );
-	return 1;
-}
 
 inline static int w_t_on_branch( struct sip_msg* msg, char *go_to, char *foo)
 {
@@ -1435,7 +1416,6 @@ static int w_t_is_set(struct sip_msg* msg, char *target, char *foo )
 			else
 				r = t->on_reply;
 			break;
-#warning need to add branch_failure_route
 	}
 	if(r) return 1;
 	return -1;
@@ -1449,7 +1429,6 @@ static int fixup_t_is_set(void** param, int param_no)
 		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)) {
-#warning need to add branch_failure_route
 			return 0;
 		}
 




More information about the sr-dev mailing list