Module: kamailio Branch: master Commit: 93b2c03eca373831d895f392b790b28973c8e30e URL: https://github.com/kamailio/kamailio/commit/93b2c03eca373831d895f392b790b289...
Author: Anthony Alba ascanio.alba7@gmail.com Committer: Anthony Alba ascanio.alba7@gmail.com Date: 2020-11-27T11:05:55+08:00
tm: KEMI expose t_relay_to_<proto>(host, port) functions
---
Modified: src/modules/tm/tm.c
---
Diff: https://github.com/kamailio/kamailio/commit/93b2c03eca373831d895f392b790b289... Patch: https://github.com/kamailio/kamailio/commit/93b2c03eca373831d895f392b790b289...
---
diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c index d6bb017287..e46c3fb057 100644 --- a/src/modules/tm/tm.c +++ b/src/modules/tm/tm.c @@ -2920,6 +2920,36 @@ static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto) return _w_t_relay_to(msg, (struct proxy_l *)0, proto); }
+/** + * + */ +static int ki_t_relay_to_proto2(sip_msg_t *msg, str *sproto, str *host, unsigned int port) +{ + + int proto = PROTO_NONE; + struct proxy_l *proxy; + + if (sproto != NULL && sproto->s != NULL && sproto->len == 3) { + if (strncasecmp(sproto->s, "UDP", 3) == 0) { + proto = PROTO_UDP; + } else if (strncasecmp(sproto->s, "TCP", 3) == 0) { + proto = PROTO_TCP; + } else if (strncasecmp(sproto->s, "TLS", 3)) { + proto = PROTO_TLS; + } else { + LM_ERR("t_relay_to_proto2 failed, bad protocol specified <%s>\n", sproto->s); + return E_UNSPEC; + } + } + proxy = mk_proxy(host, port, 0); + if (proxy == 0) { + LM_ERR("bad host, port provided <%s,%d>\n", + host->s, port ); + return E_BAD_ADDRESS; + } + return _w_t_relay_to(msg, proxy, proto); +} + /** * */ @@ -3254,6 +3284,11 @@ static sr_kemi_t tm_kemi_exports[] = { { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("tm"), str_init("t_relay_to_proto2"), + SR_KEMIP_INT, ki_t_relay_to_proto2, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { str_init("tm"), str_init("t_get_status_code"), SR_KEMIP_INT, ki_t_get_status_code, { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,