[sr-dev] git:master: tmx: new pseudo-variable class $T(name)

Daniel-Constantin Mierla miconda at gmail.com
Thu Jun 30 16:02:24 CEST 2011


Module: sip-router
Branch: master
Commit: 793a3d362a31aeba402b481896176368e6d13ee7
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=793a3d362a31aeba402b481896176368e6d13ee7

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Jun 30 15:55:49 2011 +0200

tmx: new pseudo-variable class $T(name)

- retrieve transaction related attributes
- name can be:
	- id_label - internal transaction label
	- id_index - internal transaction index
	- branch_index - return the current branch index in transaction
	  (alias to $T_branch_idx)
	- reply_code - the winning reply code currently set for transaction
	  (alias to $T_reply_code)

---

 modules_k/tmx/t_var.c   |   68 +++++++++++++++++++++++++++++++++++++++++++++++
 modules_k/tmx/t_var.h   |    3 ++
 modules_k/tmx/tmx_mod.c |    2 +
 3 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/modules_k/tmx/t_var.c b/modules_k/tmx/t_var.c
index 7f537ff..ff78f45 100644
--- a/modules_k/tmx/t_var.c
+++ b/modules_k/tmx/t_var.c
@@ -444,3 +444,71 @@ int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 	return 0;
 }
 
+int pv_parse_t_name(pv_spec_p sp, str *in)
+{
+	if(sp==NULL || in==NULL || in->len<=0)
+		return -1;
+
+	switch(in->len)
+	{
+		case 8:
+			if(strncmp(in->s, "id_label", 8)==0)
+				sp->pvp.pvn.u.isname.name.n = 0;
+			else if(strncmp(in->s, "id_index", 8)==0)
+				sp->pvp.pvn.u.isname.name.n = 1;
+			else goto error;
+		break;
+		case 10:
+			if(strncmp(in->s, "reply_code", 10)==0)
+				sp->pvp.pvn.u.isname.name.n = 2;
+			else goto error;
+		break;
+		case 12:
+			if(strncmp(in->s, "branch_index", 12)==0)
+				sp->pvp.pvn.u.isname.name.n = 3;
+			else goto error;
+		break;
+		default:
+			goto error;
+	}
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
+	sp->pvp.pvn.u.isname.type = 0;
+
+	return 0;
+
+error:
+	LM_ERR("unknown PV time name %.*s\n", in->len, in->s);
+	return -1;
+
+}
+
+int pv_get_t(struct sip_msg *msg,  pv_param_t *param,
+		pv_value_t *res)
+{
+	tm_cell_t *t;
+
+	if(msg==NULL || param==NULL)
+		return -1;
+
+	/* aliases to old TM pvs */
+	switch(param->pvn.u.isname.name.n)
+	{
+		case 2:
+			return pv_get_tm_reply_code(msg, param, res);
+		case 3:
+			return pv_get_tm_branch_idx(msg, param, res);
+	}
+
+	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 1:
+			return pv_get_uintval(msg, param, res, t->label);
+		default:
+			return pv_get_uintval(msg, param, res, t->hash_index);
+	}
+}
diff --git a/modules_k/tmx/t_var.h b/modules_k/tmx/t_var.h
index 414bfb2..0d2e431 100644
--- a/modules_k/tmx/t_var.h
+++ b/modules_k/tmx/t_var.h
@@ -41,4 +41,7 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 int pv_get_tm_reply_code(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);
+int pv_parse_t_name(pv_spec_p sp, str *in);
 #endif
diff --git a/modules_k/tmx/tmx_mod.c b/modules_k/tmx/tmx_mod.c
index 8a36352..9bbd98c 100644
--- a/modules_k/tmx/tmx_mod.c
+++ b/modules_k/tmx/tmx_mod.c
@@ -121,6 +121,8 @@ static pv_export_t mod_pvs[] = {
 		pv_parse_t_var_name, 0, 0, 0 },
 	{ {"T_rpl", sizeof("T_rpl")-1}, PVT_OTHER, pv_get_t_var_rpl, 0,
 		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 },
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
 




More information about the sr-dev mailing list