Browse Source

modules/tm: Set branch_index to T_BR_UNDEFINED when outside BRANCH_ROUTE or TM_ONREPLY_ROUTE.

The inconsistent value of $T_branch_idx between BRANCH_ROUTE and
TM_ON_REPLY_ROUTE was fixed in an earlier commit, but now the value 0 has a
double meaning (branch 0 or invalid branch). This patch makes the invalid
branch distinguishable by setting it to -1.

Now $T_branch_idx will return the branch number (0-based) in BRANCH_ROUTE
and TM_ON_REPLY_ROUTE and -1 in other route types or if the message is not
part of a transaction.
Alex Hermann 13 years ago
parent
commit
397ef369d7
5 changed files with 9 additions and 4 deletions
  1. 2 2
      modules/tm/t_fwd.c
  2. 1 0
      modules/tm/t_lookup.c
  3. 1 1
      modules/tm/t_reply.c
  4. 4 0
      modules/tm/tm.c
  5. 1 1
      modules_k/tmx/t_var.c

+ 2 - 2
modules/tm/t_fwd.c

@@ -351,14 +351,14 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 				/* if DROP was called in cfg, don't forward, jump to end */
 				/* if DROP was called in cfg, don't forward, jump to end */
 				if (unlikely(ctx.run_flags&DROP_R_F))
 				if (unlikely(ctx.run_flags&DROP_R_F))
 				{
 				{
-					tm_ctx_set_branch_index(0);
+					tm_ctx_set_branch_index(T_BR_UNDEFINED);
 					set_route_type(backup_route_type);
 					set_route_type(backup_route_type);
 					/* triggered by drop in CFG */
 					/* triggered by drop in CFG */
 					ret=E_CFG;
 					ret=E_CFG;
 					goto error03;
 					goto error03;
 				}
 				}
 			}
 			}
-			tm_ctx_set_branch_index(0);
+			tm_ctx_set_branch_index(T_BR_UNDEFINED);
 			set_route_type(backup_route_type);
 			set_route_type(backup_route_type);
 		}
 		}
 
 

+ 1 - 0
modules/tm/t_lookup.c

@@ -1954,6 +1954,7 @@ tm_ctx_t* tm_ctx_get(void)
 void tm_ctx_init(void)
 void tm_ctx_init(void)
 {
 {
 	memset(&_tm_ctx, 0, sizeof(tm_ctx_t));
 	memset(&_tm_ctx, 0, sizeof(tm_ctx_t));
+	_tm_ctx.branch_index = T_BR_UNDEFINED;
 }
 }
 
 
 void tm_ctx_set_branch_index(int v)
 void tm_ctx_set_branch_index(int v)

+ 1 - 1
modules/tm/t_reply.c

@@ -2403,7 +2403,7 @@ int reply_received( struct sip_msg  *p_msg )
 	} /* provisional replies */
 	} /* provisional replies */
 
 
 done:
 done:
-	tm_ctx_set_branch_index(0);
+	tm_ctx_set_branch_index(T_BR_UNDEFINED);
 	/* we are done with the transaction, so unref it - the reference
 	/* we are done with the transaction, so unref it - the reference
 	 * was incremented by t_check() function -bogdan*/
 	 * was incremented by t_check() function -bogdan*/
 	t_unref(p_msg);
 	t_unref(p_msg);

+ 4 - 0
modules/tm/tm.c

@@ -863,6 +863,10 @@ static int mod_init(void)
 #endif /* WITH_EVENT_LOCAL_REQUEST */
 #endif /* WITH_EVENT_LOCAL_REQUEST */
 	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)
 	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)
 		WARN("empty/non existing on_sl_reply route\n");
 		WARN("empty/non existing on_sl_reply route\n");
+
+#ifdef WITH_TM_CTX
+	tm_ctx_init();
+#endif
 	tm_init = 1;
 	tm_init = 1;
 	return 0;
 	return 0;
 }
 }

+ 1 - 1
modules_k/tmx/t_var.c

@@ -377,7 +377,7 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 	if(tcx != NULL)
 	if(tcx != NULL)
 		idx = tcx->branch_index;
 		idx = tcx->branch_index;
 	
 	
-	ch = int2str(idx, &l);
+	ch = sint2str(idx, &l);
 
 
 	res->rs.s = ch;
 	res->rs.s = ch;
 	res->rs.len = l;
 	res->rs.len = l;