Module: sip-router
Branch: master
Commit: 412fc6621e91fee014188ef0a20aaa09dc602a33
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=412fc66…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Mon Apr 2 18:01:24 2012 +0100
modules/tm, modules/app_lua: Exported t_replicate() to app_lua
- Feature added by Hugh Waite @ Crocodile RCS
---
modules/app_lua/app_lua_exp.c | 34 ++++++++++++++++++++++++++++++++++
modules/tm/t_fwd.h | 2 ++
modules/tm/tm.c | 27 ++++++++++++++++-----------
modules/tm/tm_load.c | 1 +
modules/tm/tm_load.h | 1 +
5 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c
index 587d8c0..beb4ccd 100644
--- a/modules/app_lua/app_lua_exp.c
+++ b/modules/app_lua/app_lua_exp.c
@@ -573,6 +573,39 @@ static int lua_sr_tm_t_release(lua_State *L)
/**
*
*/
+static int lua_sr_tm_t_replicate(lua_State *L)
+{
+ int ret;
+ sr_lua_env_t *env_L;
+ str suri;
+
+ env_L = sr_lua_env_get();
+
+ if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
+ {
+ LM_WARN("weird: tm function executed but module not registered\n");
+ return app_lua_return_error(L);
+ }
+ if(env_L->msg==NULL)
+ {
+ LM_WARN("invalid parameters from Lua env\n");
+ return app_lua_return_error(L);
+ }
+ suri.s = (char*)lua_tostring(L, -1);
+ if(suri.s == NULL)
+ {
+ LM_WARN("invalid parameters from Lua\n");
+ return app_lua_return_error(L);
+ }
+ suri.len = strlen(suri.s);
+
+ ret = _lua_tmb.t_replicate(env_L->msg, &suri);
+ return app_lua_return_int(L, ret);
+}
+
+/**
+ *
+ */
static const luaL_reg _sr_tm_Map [] = {
{"t_reply", lua_sr_tm_t_reply},
{"t_relay", lua_sr_tm_t_relay},
@@ -583,6 +616,7 @@ static const luaL_reg _sr_tm_Map [] = {
{"t_is_canceled", lua_sr_tm_t_is_canceled},
{"t_newtran", lua_sr_tm_t_newtran},
{"t_release", lua_sr_tm_t_release},
+ {"t_replicate", lua_sr_tm_t_replicate},
{NULL, NULL}
};
diff --git a/modules/tm/t_fwd.h b/modules/tm/t_fwd.h
index 109510f..0484c5d 100644
--- a/modules/tm/t_fwd.h
+++ b/modules/tm/t_fwd.h
@@ -49,9 +49,11 @@ enum unmatched_cancel_t { UM_CANCEL_STATEFULL=0, UM_CANCEL_STATELESS,
typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
typedef int (*taddblind_f)( /*struct cell *t */ );
+typedef int (*treplicate_uri_f)(struct sip_msg* p_msg , str *suri );
void t_on_branch(unsigned int go_to);
unsigned int get_on_branch();
+int t_replicate_uri(struct sip_msg *p_msg, str *suri);
int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
/* -- not use outside t_fwd.c for noe
char *print_uac_request( struct cell *t, struct sip_msg *i_req,
diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index 20167bb..3ca56ba 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -1472,22 +1472,14 @@ inline static int w_t_relay_to_avp( struct sip_msg *p_msg ,
return r;
}
-inline static int w_t_replicate_uri(struct sip_msg *msg ,
- char *uri, /* sip uri as string or variable */
- char *_foo /* nothing expected */ )
+int t_replicate_uri(struct sip_msg *msg, str *suri)
{
struct proxy_l *proxy;
struct sip_uri turi;
- str suri;
int r = -1;
memset(&turi, 0, sizeof(struct sip_uri));
- if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
- {
- LM_ERR("invalid replicate uri parameter");
- return -1;
- }
- if(parse_uri(suri.s, suri.len, &turi)!=0)
+ if(parse_uri(suri->s, suri->len, &turi)!=0)
{
LM_ERR("bad replicate SIP address!\n");
return -1;
@@ -1496,7 +1488,7 @@ inline static int w_t_replicate_uri(struct sip_msg *msg ,
proxy=mk_proxy(&turi.host, turi.port_no, turi.proto);
if (proxy==0) {
LM_ERR("cannot create proxy from URI <%.*s>\n",
- suri.len, suri.s );
+ suri->len, suri->s );
return -1;
}
@@ -1504,7 +1496,20 @@ inline static int w_t_replicate_uri(struct sip_msg *msg ,
free_proxy(proxy);
pkg_free(proxy);
return r;
+}
+inline static int w_t_replicate_uri(struct sip_msg *msg ,
+ char *uri, /* sip uri as string or variable */
+ char *_foo /* nothing expected */ )
+{
+ str suri;
+
+ if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
+ {
+ LM_ERR("invalid replicate uri parameter");
+ return -1;
+ }
+ return t_replicate_uri(msg, &suri);
}
inline static int w_t_replicate( struct sip_msg *p_msg ,
diff --git a/modules/tm/tm_load.c b/modules/tm/tm_load.c
index d57fd45..9cb6a4d 100644
--- a/modules/tm/tm_load.c
+++ b/modules/tm/tm_load.c
@@ -84,6 +84,7 @@ int load_tm( struct tm_binds *tmb)
}*/
/* non-cfg API */
+ tmb->t_replicate = t_replicate_uri;
tmb->register_tmcb =register_tmcb;
tmb->t_reply = w_t_reply_wrp;
tmb->t_reply_with_body = t_reply_with_body;
diff --git a/modules/tm/tm_load.h b/modules/tm/tm_load.h
index 370c2ef..1c43d41 100644
--- a/modules/tm/tm_load.h
+++ b/modules/tm/tm_load.h
@@ -59,6 +59,7 @@ struct tm_binds {
cmd_function t_relay_to_udp; /* WARNING: failure_route unsafe */
cmd_function t_relay_to_tcp; /* WARNING: failure_route unsafe */
cmd_function t_relay; /* WARNING: failure_route unsafe */
+ treplicate_uri_f t_replicate; /* WARNING: failure_route unsafe */
tnewtran_f t_newtran;
treply_f t_reply;
treply_wb_f t_reply_with_body;