Browse Source

modules/tmx: set $T_branch_idx to sane values for more route types

$T_branch_idx will now return a branch number (0-based) in more route types.

BRANCH_ROUTE and TM_ON_REPLY_ROUTE: currently handled branch number
REQUEST_ROUTE and FAILURE_ROUTE: next branch number, will be increased by
    every append_branch

In FAILURE_ROUTE, the branch number of the winning reply can be retreived
with $T_rpl($T_branch_idx)

All other route types will result in (the invalid) branch number -1.
Alex Hermann 12 years ago
parent
commit
14ef60cf93
2 changed files with 33 additions and 5 deletions
  1. 1 0
      modules/tm/t_reply.c
  2. 32 5
      modules_k/tmx/t_var.c

+ 1 - 0
modules/tm/t_reply.c

@@ -1296,6 +1296,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
 							FL_TIMEOUT:0) | 
 				((Trans->uac[picked_branch].request.flags & F_RB_REPLIED)?
 						 	FL_REPLIED:0);
+			tm_ctx_set_branch_index(picked_branch);
 			run_failure_handlers( Trans, Trans->uac[picked_branch].reply,
 									picked_code, extra_flags);
 			if (unlikely((drop_replies==3 && branch_cnt<Trans->nr_of_outgoings) ||

+ 32 - 5
modules_k/tmx/t_var.c

@@ -21,6 +21,7 @@
  */
 
 #include "../../mem/mem.h"
+#include "../../dset.h"
 
 #include "tmx_mod.h"
 #include "t_var.h"
@@ -367,16 +368,42 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 {
 	int l = 0;
 	char *ch = NULL;
+	struct cell *t;
 	tm_ctx_t *tcx = 0;
-	int idx = 0;
+	int idx = T_BR_UNDEFINED;
 
 	if(msg==NULL || res==NULL)
 		return -1;
 
-	tcx = _tmx_tmb.tm_ctx_get();
-	if(tcx != NULL)
-		idx = tcx->branch_index;
-	
+	/* statefull replies have the branch_index set */
+	if(msg->first_line.type == SIP_REPLY && route_type != CORE_ONREPLY_ROUTE) {
+		tcx = _tmx_tmb.tm_ctx_get();
+		if(tcx != NULL)
+			idx = tcx->branch_index;
+	} else switch(route_type) {
+		case BRANCH_ROUTE:
+			/* branches have their index set */
+			tcx = _tmx_tmb.tm_ctx_get();
+			if(tcx != NULL)
+				idx = tcx->branch_index;
+			break;
+		case REQUEST_ROUTE:
+			/* take the branch number from the number of added branches */
+			idx = nr_branches;
+			break;
+		case FAILURE_ROUTE:
+			/* first get the transaction */
+			t = _tmx_tmb.t_gett();
+			if ( t == NULL && t == T_UNDEFINED ) {
+				return -1;
+			}
+			/* add the currently added branches to the number of
+			 * completed branches in the transaction
+			 */
+			idx = t->nr_of_outgoings + nr_branches;
+			break;
+	}
+
 	ch = sint2str(idx, &l);
 
 	res->rs.s = ch;