浏览代码

modules/tm, modules/app_lua: Exported t_replicate() to app_lua

- Feature added by Hugh Waite @ Crocodile RCS
Peter Dunkley 13 年之前
父节点
当前提交
412fc6621e
共有 5 个文件被更改,包括 54 次插入11 次删除
  1. 34 0
      modules/app_lua/app_lua_exp.c
  2. 2 0
      modules/tm/t_fwd.h
  3. 16 11
      modules/tm/tm.c
  4. 1 0
      modules/tm/tm_load.c
  5. 1 0
      modules/tm/tm_load.h

+ 34 - 0
modules/app_lua/app_lua_exp.c

@@ -570,6 +570,39 @@ static int lua_sr_tm_t_release(lua_State *L)
 	return app_lua_return_int(L, ret);
 }
 
+/**
+ *
+ */
+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);
+}
+
 /**
  *
  */
@@ -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}
 };
 

+ 2 - 0
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,

+ 16 - 11
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 ,

+ 1 - 0
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;

+ 1 - 0
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;