Explorar el Código

modules/tmx: replaced $T_reply_flags with $T_branch(flags)

Juha Heinanen hace 11 años
padre
commit
9708bcfbb4
Se han modificado 5 ficheros con 65 adiciones y 6 borrados
  1. 1 0
      modules/tmx/README
  2. 3 0
      modules/tmx/doc/tmx_admin.xml
  3. 57 1
      modules/tmx/t_var.c
  4. 2 2
      modules/tmx/t_var.h
  5. 2 3
      modules/tmx/tmx_mod.c

+ 1 - 0
modules/tmx/README

@@ -353,6 +353,7 @@ event_route [tm:branch-failure:contact] {
      * $T_req(pv)
      * $T_rpl(pv)
      * $T_reply_ruid
+     * $T_branch(pv)
 
    Exported pseudo-variables are documented at
    http://www.kamailio.org/wiki/.

+ 3 - 0
modules/tmx/doc/tmx_admin.xml

@@ -388,6 +388,9 @@ event_route [tm:branch-failure:contact] {
 			<listitem><para>
 				<emphasis>$T_reply_ruid</emphasis>
 			</para></listitem>
+			<listitem><para>
+				<emphasis>$T_branch(pv)</emphasis>
+			</para></listitem>
 		</itemizedlist>
 		<para>
 		Exported pseudo-variables are documented at &kamwikilink;.

+ 57 - 1
modules/tmx/t_var.c

@@ -322,6 +322,20 @@ int pv_get_t_var_rpl(struct sip_msg *msg,  pv_param_t *param,
 	return pv_get_spec_value(&_pv_trpl.msg, pv, res);
 }
 
+int pv_get_t_var_branch(struct sip_msg *msg,  pv_param_t *param,
+		pv_value_t *res)
+{
+	pv_spec_t *pv=NULL;
+
+	if(pv_t_update_rpl(msg))
+		return pv_get_null(msg, param, res);
+
+	pv = (pv_spec_t*)param->pvn.u.dname;
+	if(pv==NULL || pv_alter_context(pv))
+		return pv_get_null(msg, param, res);
+
+	return pv_get_spec_value(&_pv_trpl.msg, pv, res);
+}
 
 int pv_get_t_var_inv(struct sip_msg *msg,  pv_param_t *param,
 		pv_value_t *res)
@@ -616,6 +630,11 @@ int pv_parse_t_name(pv_spec_p sp, str *in)
 
 	switch(in->len)
 	{
+		case 5:
+			if(strncmp(in->s, "flags", 5) == 0)
+				sp->pvp.pvn.u.isname.name.n = 5;
+			else goto error;
+		break;
 		case 8:
 			if(strncmp(in->s, "id_label", 8)==0)
 				sp->pvp.pvn.u.isname.name.n = 0;
@@ -644,7 +663,7 @@ int pv_parse_t_name(pv_spec_p sp, str *in)
 	return 0;
 
 error:
-	LM_ERR("unknown PV time name %.*s\n", in->len, in->s);
+	LM_ERR("unknown PV name %.*s\n", in->len, in->s);
 	return -1;
 
 }
@@ -687,3 +706,40 @@ int pv_get_t(struct sip_msg *msg,  pv_param_t *param,
 			return pv_get_uintval(msg, param, res, t->label);
 	}
 }
+
+int pv_get_t_branch(struct sip_msg *msg,  pv_param_t *param,
+		    pv_value_t *res)
+{
+    tm_cell_t *t;
+    int branch;
+
+    if ((msg == NULL) || (param == NULL)) return -1;
+
+    t = _tmx_tmb.t_gett();
+    if ((t == NULL) || (t == T_UNDEFINED)) {
+	/* no T */
+	return pv_get_null(msg, param, res);
+    }
+
+    switch(param->pvn.u.isname.name.n) {
+    case 5:
+	switch (get_route_type()) {
+	case FAILURE_ROUTE:
+	case BRANCH_FAILURE_ROUTE:
+	    /* use the reason of the winning reply */
+	    if ((branch=_tmx_tmb.t_get_picked_branch()) < 0) {
+		LM_CRIT("no picked branch (%d) for a final response"
+			" in MODE_ONFAILURE\n", branch);
+		return -1;
+	    }
+	    res->ri = t->uac[branch].branch_flags;
+	    res->flags = PV_VAL_INT;
+	    LM_INFO("branch flags is [%u]\n", res->ri);
+	    break;
+	default:
+	    LM_ERR("unsupported route_type %d\n", get_route_type());
+	    return -1;
+	}
+    }
+    return 0;
+}

+ 2 - 2
modules/tmx/t_var.h

@@ -40,8 +40,8 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
-int pv_get_tm_reply_flags(struct sip_msg *msg, pv_param_t *param,
-		pv_value_t *res);
+int pv_get_t_branch(struct sip_msg *msg,  pv_param_t *param,
+		    pv_value_t *res);
 int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param,

+ 2 - 3
modules/tmx/tmx_mod.c

@@ -124,9 +124,6 @@ static pv_export_t mod_pvs[] = {
 	{ {"T_reply_ruid", sizeof("T_reply_ruid")-1}, PVT_OTHER,
 		pv_get_tm_reply_ruid, 0,
 		 0, 0, 0, 0 },
-	{ {"T_reply_flags", sizeof("T_reply_flags")-1}, PVT_OTHER,
-		pv_get_tm_reply_flags, 0,
-		 0, 0, 0, 0 },
 	{ {"T_reply_code", sizeof("T_reply_code")-1}, PVT_OTHER,
 		pv_get_tm_reply_code, 0,
 		 0, 0, 0, 0 },
@@ -144,6 +141,8 @@ static pv_export_t mod_pvs[] = {
 		pv_parse_t_var_name, 0, 0, 0 },
 	{ {"T", sizeof("T")-1}, PVT_OTHER, pv_get_t, 0,
 		pv_parse_t_name, 0, 0, 0 },
+	{ {"T_branch", sizeof("T_branch")-1}, PVT_OTHER, pv_get_t_branch, 0,
+		pv_parse_t_name, 0, 0, 0 },
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };