[sr-dev] git:master: async: added async_route(route, seconds)

Daniel-Constantin Mierla miconda at gmail.com
Sun Jun 26 11:52:40 CEST 2011


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Jun 26 11:27:53 2011 +0200

async: added async_route(route, seconds)

- executed route block asynchronously after seconds

---

 modules/async/async_mod.c |   59 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/modules/async/async_mod.c b/modules/async/async_mod.c
index 2d2e18f..fc974e2 100644
--- a/modules/async/async_mod.c
+++ b/modules/async/async_mod.c
@@ -47,12 +47,16 @@ static void mod_destroy(void);
 
 static int w_async_sleep(struct sip_msg* msg, char* sec, char* str2);
 static int fixup_async_sleep(void** param, int param_no);
+static int w_async_route(struct sip_msg* msg, char* rt, char* sec);
+static int fixup_async_route(void** param, int param_no);
 
 /* tm */
 struct tm_binds tmb;
 
 
 static cmd_export_t cmds[]={
+	{"async_route", (cmd_function)w_async_route, 2, fixup_async_route,
+		0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
 	{"async_sleep", (cmd_function)w_async_sleep, 1, fixup_async_sleep,
 		0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
 	{0, 0, 0, 0, 0, 0}
@@ -169,3 +173,58 @@ static int fixup_async_sleep(void** param, int param_no)
 	*param = (void*)ap;
 	return 0;
 }
+
+static int w_async_route(struct sip_msg* msg, char* rt, char* sec)
+{
+	cfg_action_t *act;
+	int s;
+	str rn;
+	int ri;
+
+	if(msg==NULL)
+		return -1;
+
+	if(fixup_get_svalue(msg, (gparam_t*)rt, &rn)!=0)
+	{
+		LM_ERR("no async route block name\n");
+		return -1;
+	}
+
+	if(fixup_get_ivalue(msg, (gparam_t*)sec, &s)!=0)
+	{
+		LM_ERR("no async interval value\n");
+		return -1;
+	}
+
+	ri = route_get(&main_rt, rn.s);
+	if(ri<0)
+	{
+		LM_ERR("unable to find route block [%.*s]\n", rn.len, rn.s);
+		return -1;
+	}
+	act = main_rt.rlist[ri];
+	if(act==NULL)
+	{
+		LM_ERR("empty action lists in route block [%.*s]\n", rn.len, rn.s);
+		return -1;
+	}
+
+	if(async_sleep(msg, s, act)<0)
+		return -1;
+	/* force exit in config */
+	return 0;
+}
+
+static int fixup_async_route(void** param, int param_no)
+{
+	if(param_no==1)
+	{
+		if(fixup_spve_null(param, 1)<0)
+			return -1;
+		return 0;
+	} else if(param_no==2) {
+		if(fixup_igp_null(param, 1)<0)
+			return -1;
+	}
+	return 0;
+}




More information about the sr-dev mailing list