Browse code

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

- Feature added by Hugh Waite @ Crocodile RCS

Peter Dunkley authored on 02/04/2012 17:01:24
Showing 5 changed files
... ...
@@ -573,6 +573,39 @@ static int lua_sr_tm_t_release(lua_State *L)
573 573
 /**
574 574
  *
575 575
  */
576
+static int lua_sr_tm_t_replicate(lua_State *L)
577
+{
578
+	int ret;
579
+	sr_lua_env_t *env_L;
580
+	str suri;
581
+
582
+	env_L = sr_lua_env_get();
583
+
584
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_TM))
585
+	{
586
+		LM_WARN("weird: tm function executed but module not registered\n");
587
+		return app_lua_return_error(L);
588
+	}
589
+	if(env_L->msg==NULL)
590
+	{
591
+		LM_WARN("invalid parameters from Lua env\n");
592
+		return app_lua_return_error(L);
593
+	}
594
+	suri.s = (char*)lua_tostring(L, -1);
595
+	if(suri.s == NULL)
596
+	{
597
+		LM_WARN("invalid parameters from Lua\n");
598
+		return app_lua_return_error(L);
599
+	}
600
+	suri.len = strlen(suri.s);
601
+
602
+	ret = _lua_tmb.t_replicate(env_L->msg, &suri);
603
+	return app_lua_return_int(L, ret);
604
+}
605
+
606
+/**
607
+ *
608
+ */
576 609
 static const luaL_reg _sr_tm_Map [] = {
577 610
 	{"t_reply",        lua_sr_tm_t_reply},
578 611
 	{"t_relay",        lua_sr_tm_t_relay},
... ...
@@ -583,6 +616,7 @@ static const luaL_reg _sr_tm_Map [] = {
583 583
 	{"t_is_canceled",  lua_sr_tm_t_is_canceled},
584 584
 	{"t_newtran",      lua_sr_tm_t_newtran},
585 585
 	{"t_release",      lua_sr_tm_t_release},
586
+	{"t_replicate",    lua_sr_tm_t_replicate},
586 587
 	{NULL, NULL}
587 588
 };
588 589
 
... ...
@@ -49,9 +49,11 @@ enum unmatched_cancel_t { UM_CANCEL_STATEFULL=0, UM_CANCEL_STATELESS,
49 49
 
50 50
 typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
51 51
 typedef int (*taddblind_f)( /*struct cell *t */ );
52
+typedef int (*treplicate_uri_f)(struct sip_msg* p_msg , str *suri );
52 53
 
53 54
 void t_on_branch(unsigned int go_to);
54 55
 unsigned int get_on_branch();
56
+int t_replicate_uri(struct sip_msg *p_msg, str *suri);
55 57
 int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
56 58
 /*  -- not use outside t_fwd.c for noe
57 59
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
... ...
@@ -1472,22 +1472,14 @@ inline static int w_t_relay_to_avp( struct sip_msg  *p_msg ,
1472 1472
 	return r;
1473 1473
 }
1474 1474
 
1475
-inline static int w_t_replicate_uri(struct sip_msg  *msg ,
1476
-				char *uri,       /* sip uri as string or variable */
1477
-				char *_foo       /* nothing expected */ )
1475
+int t_replicate_uri(struct sip_msg *msg, str *suri)
1478 1476
 {
1479 1477
 	struct proxy_l *proxy;
1480 1478
 	struct sip_uri turi;
1481
-	str suri;
1482 1479
 	int r = -1;
1483 1480
 
1484 1481
 	memset(&turi, 0, sizeof(struct sip_uri));
1485
-	if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
1486
-	{
1487
-		LM_ERR("invalid replicate uri parameter");
1488
-		return -1;
1489
-	}
1490
-	if(parse_uri(suri.s, suri.len, &turi)!=0)
1482
+	if(parse_uri(suri->s, suri->len, &turi)!=0)
1491 1483
 	{
1492 1484
 		LM_ERR("bad replicate SIP address!\n");
1493 1485
 		return -1;
... ...
@@ -1496,7 +1488,7 @@ inline static int w_t_replicate_uri(struct sip_msg  *msg ,
1496 1496
 	proxy=mk_proxy(&turi.host, turi.port_no, turi.proto);
1497 1497
 	if (proxy==0) {
1498 1498
 		LM_ERR("cannot create proxy from URI <%.*s>\n",
1499
-			suri.len, suri.s );
1499
+			suri->len, suri->s );
1500 1500
 		return -1;
1501 1501
 	}
1502 1502
 
... ...
@@ -1504,7 +1496,20 @@ inline static int w_t_replicate_uri(struct sip_msg  *msg ,
1504 1504
 	free_proxy(proxy);
1505 1505
 	pkg_free(proxy);
1506 1506
 	return r;
1507
+}
1507 1508
 
1509
+inline static int w_t_replicate_uri(struct sip_msg  *msg ,
1510
+				char *uri,       /* sip uri as string or variable */
1511
+				char *_foo       /* nothing expected */ )
1512
+{
1513
+	str suri;
1514
+
1515
+	if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
1516
+	{
1517
+		LM_ERR("invalid replicate uri parameter");
1518
+		return -1;
1519
+	}
1520
+	return t_replicate_uri(msg, &suri);
1508 1521
 }
1509 1522
 
1510 1523
 inline static int w_t_replicate( struct sip_msg  *p_msg ,
... ...
@@ -84,6 +84,7 @@ int load_tm( struct tm_binds *tmb)
84 84
 	}*/
85 85
 
86 86
 	/* non-cfg API */
87
+	tmb->t_replicate = t_replicate_uri;
87 88
 	tmb->register_tmcb =register_tmcb;
88 89
 	tmb->t_reply = w_t_reply_wrp;
89 90
 	tmb->t_reply_with_body = t_reply_with_body;
... ...
@@ -59,6 +59,7 @@ struct tm_binds {
59 59
 	cmd_function     t_relay_to_udp; /* WARNING: failure_route unsafe */
60 60
 	cmd_function     t_relay_to_tcp; /* WARNING: failure_route unsafe */ 
61 61
 	cmd_function     t_relay;        /* WARNING: failure_route unsafe */
62
+	treplicate_uri_f t_replicate;    /* WARNING: failure_route unsafe */
62 63
 	tnewtran_f       t_newtran;
63 64
 	treply_f         t_reply;
64 65
 	treply_wb_f      t_reply_with_body;