[sr-dev] git:master: tmx: exported asynchronous functions to config

Daniel-Constantin Mierla miconda at gmail.com
Sun Jul 3 15:33:59 CEST 2011


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Jul  3 15:07:04 2011 +0200

tmx: exported asynchronous functions to config

- t_suspend() - suppend the execution of SIP request in a transaction -
  the transaction is created if it does not exist already. $T(id_index)
  and $T(id_label) can be used to get transaction's internal index and
  label identifiers
- t_continue(index, label, rtname) - continue the execution of a
  suspended transaction identified by (index, label) with the actions in
  route[rtname]

---

 modules_k/tmx/tmx_mod.c |  114 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/modules_k/tmx/tmx_mod.c b/modules_k/tmx/tmx_mod.c
index 9bbd98c..ba19538 100644
--- a/modules_k/tmx/tmx_mod.c
+++ b/modules_k/tmx/tmx_mod.c
@@ -48,7 +48,8 @@ static void destroy(void);
 
 static int t_cancel_branches(struct sip_msg* msg, char *k, char *s2);
 static int fixup_cancel_branches(void** param, int param_no);
-static int t_cancel_callid(struct sip_msg* msg, char *cid, char *cseq, char *flag);
+static int t_cancel_callid(struct sip_msg* msg, char *cid, char *cseq,
+				char *flag);
 static int fixup_cancel_callid(void** param, int param_no);
 static int t_reply_callid(struct sip_msg* msg, char *cid, char *cseq,
 				char *rc, char *rs);
@@ -58,6 +59,10 @@ static int t_flush_flags(struct sip_msg* msg, char*, char* );
 static int t_is_failure_route(struct sip_msg* msg, char*, char* );
 static int t_is_branch_route(struct sip_msg* msg, char*, char* );
 
+static int w_t_suspend(struct sip_msg* msg, char*, char*);
+static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn);
+static int fixup_t_continue(void** param, int param_no);
+
 /* statistic variables */
 stat_var *tm_rcv_rpls;
 stat_var *tm_rld_rpls;
@@ -141,7 +146,7 @@ static cmd_export_t cmds[]={
 		fixup_cancel_branches, 0, ONREPLY_ROUTE },
 	{"t_cancel_callid", (cmd_function)t_cancel_callid,  3,
 		fixup_cancel_callid, 0, ANY_ROUTE },
-	{"t_reply_callid", (cmd_function)t_reply_callid,  4,
+	{"t_reply_callid", (cmd_function)t_reply_callid,    4,
 		fixup_reply_callid, 0, ANY_ROUTE },
 	{"t_flush_flags",   (cmd_function)t_flush_flags,    0, 0,
 			0, ANY_ROUTE  },
@@ -149,6 +154,10 @@ static cmd_export_t cmds[]={
 			0, ANY_ROUTE  },
 	{"t_is_branch_route",    (cmd_function)t_is_branch_route,    0, 0,
 			0, ANY_ROUTE  },
+	{"t_suspend",    (cmd_function)w_t_suspend,    0, 0,
+			0, ANY_ROUTE  },
+	{"t_continue", (cmd_function)w_t_continue,     3,
+		fixup_t_continue, 0, ANY_ROUTE },
 	{0,0,0,0,0,0}
 };
 
@@ -449,6 +458,107 @@ static int t_is_branch_route(struct sip_msg* msg, char *foo, char *bar)
 	return -1;
 }
 
+/**
+ *
+ */
+static int w_t_suspend(struct sip_msg* msg, char *p1, char *p2)
+{
+	unsigned int tindex;
+	unsigned int tlabel;
+	tm_cell_t *t = 0;
+
+	t=_tmx_tmb.t_gett();
+	if (t==NULL || t==T_UNDEFINED)
+	{
+		if(_tmx_tmb.t_newtran(msg)<0)
+		{
+			LM_ERR("cannot create the transaction\n");
+			return -1;
+		}
+		t = _tmx_tmb.t_gett();
+		if (t==NULL || t==T_UNDEFINED)
+		{
+			LM_ERR("cannot lookup the transaction\n");
+			return -1;
+		}
+	}
+	if(_tmx_tmb.t_suspend(msg, &tindex, &tlabel)<0)
+	{
+		LM_ERR("failed to suppend the processing\n");
+		return -1;
+	}
+
+	LM_DBG("transaction suspended [%u:%u]\n", tindex, tlabel);
+	return 1;
+}
+
+/**
+ *
+ */
+static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn)
+{
+	unsigned int tindex;
+	unsigned int tlabel;
+	str rtname;
+	cfg_action_t *act;
+	int ri;
+
+	if(fixup_get_ivalue(msg, (gparam_p)idx, (int*)&tindex)<0)
+	{
+		LM_ERR("cannot get transaction index\n");
+		return -1;
+	}
+
+	if(fixup_get_ivalue(msg, (gparam_p)lbl, (int*)&tlabel)<0)
+	{
+		LM_ERR("cannot get transaction label\n");
+		return -1;
+	}
+
+	if(fixup_get_svalue(msg, (gparam_p)rtn, &rtname)<0)
+	{
+		LM_ERR("cannot get route block name\n");
+		return -1;
+	}
+
+	ri = route_get(&main_rt, rtname.s);
+	if(ri<0)
+	{
+		LM_ERR("unable to find route block [%.*s]\n", rtname.len, rtname.s);
+		return -1;
+	}
+	act = main_rt.rlist[ri];
+	if(act==NULL)
+	{
+		LM_ERR("empty action lists in route block [%.*s]\n",
+				rtname.len, rtname.s);
+		return -1;
+	}
+
+	if(_tmx_tmb.t_continue(tindex, tlabel, act)<0)
+	{
+		LM_ERR("resuming the processing of transaction [%u:%u] failed\n",
+				tindex, tlabel);
+		return -1;
+	}
+	return 1;
+}
+
+/**
+ *
+ */
+static int fixup_t_continue(void** param, int param_no)
+{
+	if (param_no==1 || param_no==2) {
+		return fixup_igp_null(param, 1);
+	}
+	if (param_no==3) {
+		return fixup_spve_null(param, 1);
+	}
+
+	return 0;
+}
+
 #ifdef STATISTICS
 
 /*** tm stats ***/




More information about the sr-dev mailing list