Module: sip-router
Branch: alexh/for4.0
Commit: 3df0016594a6908c652766435894f8195355c6f5
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=3df0016…
Author: Alex Hermann <alex(a)speakup.nl>
Committer: Alex Hermann <alex(a)speakup.nl>
Date: Mon Oct 29 15:25:21 2012 +0100
modules_k/tmx: Add $T_reply_last, returning last reply code
Make the last/previous reply on a branch available to the script via
$T_reply_last. Only available in TM_ONREPLY_ROUTE.
---
modules_k/tmx/README | 1 +
modules_k/tmx/doc/tmx_admin.xml | 3 ++
modules_k/tmx/t_var.c | 43 +++++++++++++++++++++++++++++++++++++++
modules_k/tmx/t_var.h | 2 +
modules_k/tmx/tmx_mod.c | 3 ++
5 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/modules_k/tmx/README b/modules_k/tmx/README
index fb79293..e3d1662 100644
--- a/modules_k/tmx/README
+++ b/modules_k/tmx/README
@@ -315,6 +315,7 @@ tcontinue('123', '456', 'MYROUTE');
* $T_branch_idx
* $T_reply_code
* $T_reply_reason
+ * $T_reply_last
* $T_req(pv)
* $T_rpl(pv)
diff --git a/modules_k/tmx/doc/tmx_admin.xml b/modules_k/tmx/doc/tmx_admin.xml
index 84ccc19..a8b2e32 100644
--- a/modules_k/tmx/doc/tmx_admin.xml
+++ b/modules_k/tmx/doc/tmx_admin.xml
@@ -347,6 +347,9 @@ tcontinue('123', '456', 'MYROUTE');
<emphasis>$T_reply_reason</emphasis>
</para></listitem>
<listitem><para>
+ <emphasis>$T_reply_last</emphasis>
+ </para></listitem>
+ <listitem><para>
<emphasis>$T_req(pv)</emphasis>
</para></listitem>
<listitem><para>
diff --git a/modules_k/tmx/t_var.c b/modules_k/tmx/t_var.c
index 01b8494..11e3229 100644
--- a/modules_k/tmx/t_var.c
+++ b/modules_k/tmx/t_var.c
@@ -527,6 +527,49 @@ int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param,
return 0;
}
+int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param,
+ pv_value_t *res)
+{
+ struct cell *t;
+ tm_ctx_t *tcx = 0;
+ int code;
+
+ if(msg==NULL || res==NULL)
+ return -1;
+
+ /* Only for TM reply route */
+ if (get_route_type() != TM_ONREPLY_ROUTE) {
+ LM_ERR("unsupported route_type %d\n", get_route_type());
+ return -1;
+ }
+
+ /* first get the transaction */
+ if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
+ if ( (t=_tmx_tmb.t_gett())==0) {
+ /* no T */
+ LM_ERR("could not get transaction\n");
+ return -1;
+ }
+
+ /* get the current branch index */
+ tcx = _tmx_tmb.tm_ctx_get();
+ if(tcx == NULL) {
+ LM_ERR("could not get tm context\n");
+ return -1;
+ }
+
+ /* get the last received reply code */
+ code = t->uac[tcx->branch_index].last_received;
+
+ LM_DBG("reply code is <%d>\n",code);
+
+ res->rs.s = int2str( code, &res->rs.len);
+
+ res->ri = code;
+ res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
+ return 0;
+}
+
int pv_parse_t_name(pv_spec_p sp, str *in)
{
if(sp==NULL || in==NULL || in->len<=0)
diff --git a/modules_k/tmx/t_var.h b/modules_k/tmx/t_var.h
index 248a58e..dbfd559 100644
--- a/modules_k/tmx/t_var.h
+++ b/modules_k/tmx/t_var.h
@@ -42,6 +42,8 @@ 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,
pv_value_t *res);
+int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param,
+ pv_value_t *res);
int pv_get_t(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
diff --git a/modules_k/tmx/tmx_mod.c b/modules_k/tmx/tmx_mod.c
index 927feb1..c559f40 100644
--- a/modules_k/tmx/tmx_mod.c
+++ b/modules_k/tmx/tmx_mod.c
@@ -129,6 +129,9 @@ static pv_export_t mod_pvs[] = {
{ {"T_reply_reason", sizeof("T_reply_reason")-1}, PVT_OTHER,
pv_get_tm_reply_reason, 0,
0, 0, 0, 0 },
+ { {"T_reply_last", sizeof("T_reply_last")-1}, PVT_OTHER,
+ pv_get_tm_reply_last_received, 0,
+ 0, 0, 0, 0 },
{ {"T_inv", sizeof("T_inv")-1}, PVT_OTHER, pv_get_t_var_inv, 0,
pv_parse_t_var_name, 0, 0, 0 },
{ {"T_req", sizeof("T_req")-1}, PVT_OTHER, pv_get_t_var_req, 0,