Module: kamailio
Branch: master
Commit: 6c18df166379dd635bb99375ae1269b1ef8d96b2
URL:
https://github.com/kamailio/kamailio/commit/6c18df166379dd635bb99375ae1269b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2020-11-30T09:02:33+01:00
Merge pull request #2563 from aalba6675/kemi-tm-proto
tm: KEMI expose t_relay_to_xxx protocol functions
---
Modified: src/modules/tm/tm.c
---
Diff:
https://github.com/kamailio/kamailio/commit/6c18df166379dd635bb99375ae1269b…
Patch:
https://github.com/kamailio/kamailio/commit/6c18df166379dd635bb99375ae1269b…
---
diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index 99c932b417..e46c3fb057 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -2897,6 +2897,59 @@ static int ki_t_relay(sip_msg_t *msg)
return _w_t_relay_to(msg, (struct proxy_l *)0, PROTO_NONE);
}
+/**
+ *
+ */
+static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto)
+{
+
+ int proto = PROTO_NONE;
+
+ 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_proto failed, bad protocol specified <%s>\n",
sproto->s);
+ return E_UNSPEC;
+ }
+ }
+ 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);
+}
+
/**
*
*/
@@ -3226,6 +3279,16 @@ static sr_kemi_t tm_kemi_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("tm"), str_init("t_relay_to_proto"),
+ SR_KEMIP_INT, ki_t_relay_to_proto,
+ { 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,