Module: sip-router Branch: master Commit: 9708bcfbb49586661aa96b34bd8c317a5dbd2006 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9708bcfb...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Mon Apr 21 18:31:30 2014 +0300
modules/tmx: replaced $T_reply_flags with $T_branch(flags)
---
modules/tmx/README | 1 + modules/tmx/doc/tmx_admin.xml | 3 ++ modules/tmx/t_var.c | 58 ++++++++++++++++++++++++++++++++++++++++- modules/tmx/t_var.h | 4 +- modules/tmx/tmx_mod.c | 5 +-- 5 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/modules/tmx/README b/modules/tmx/README index c317ff5..f78516b 100644 --- a/modules/tmx/README +++ b/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/. diff --git a/modules/tmx/doc/tmx_admin.xml b/modules/tmx/doc/tmx_admin.xml index 2496e64..8bae5ea 100644 --- a/modules/tmx/doc/tmx_admin.xml +++ b/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;. diff --git a/modules/tmx/t_var.c b/modules/tmx/t_var.c index 4d38d6b..6f7d346 100644 --- a/modules/tmx/t_var.c +++ b/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; +} diff --git a/modules/tmx/t_var.h b/modules/tmx/t_var.h index 3fedb60..d2d8678 100644 --- a/modules/tmx/t_var.h +++ b/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, diff --git a/modules/tmx/tmx_mod.c b/modules/tmx/tmx_mod.c index affc53c..dc8b42c 100644 --- a/modules/tmx/tmx_mod.c +++ b/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 } };