Skip to content

Commit

Permalink
Merge pull request #2563 from aalba6675/kemi-tm-proto
Browse files Browse the repository at this point in the history
tm: KEMI expose t_relay_to_xxx protocol functions
  • Loading branch information
miconda committed Nov 30, 2020
2 parents 0f572ca + 93b2c03 commit 6c18df1
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/modules/tm/tm.c
Expand Up @@ -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);
}

/**
*
*/
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6c18df1

Please sign in to comment.