Browse code

tm: KEMI expose t_relay_to_<proto>(host, port) functions

Anthony Alba authored on 27/11/2020 03:02:34
Showing 1 changed files
... ...
@@ -2920,6 +2920,36 @@ static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto)
2920 2920
 	return _w_t_relay_to(msg, (struct proxy_l *)0, proto);
2921 2921
 }
2922 2922
 
2923
+/**
2924
+ *
2925
+ */
2926
+static int ki_t_relay_to_proto2(sip_msg_t *msg, str *sproto, str *host, unsigned int port)
2927
+{
2928
+
2929
+	int proto = PROTO_NONE;
2930
+	struct proxy_l *proxy;
2931
+
2932
+	if (sproto != NULL && sproto->s != NULL && sproto->len == 3) {
2933
+		if (strncasecmp(sproto->s, "UDP", 3) == 0) {
2934
+			proto = PROTO_UDP;
2935
+		} else if (strncasecmp(sproto->s, "TCP", 3) == 0) {
2936
+			proto = PROTO_TCP;
2937
+		} else if (strncasecmp(sproto->s, "TLS", 3)) {
2938
+			proto = PROTO_TLS;
2939
+		} else {
2940
+			LM_ERR("t_relay_to_proto2 failed, bad protocol specified <%s>\n", sproto->s);
2941
+			return E_UNSPEC;
2942
+		}
2943
+	}
2944
+	proxy = mk_proxy(host, port, 0);
2945
+	if (proxy == 0) {
2946
+		LM_ERR("bad host, port provided <%s,%d>\n",
2947
+		       host->s, port );
2948
+		return E_BAD_ADDRESS;
2949
+	}
2950
+	return _w_t_relay_to(msg, proxy, proto);
2951
+}
2952
+
2923 2953
 /**
2924 2954
  *
2925 2955
  */
... ...
@@ -3254,6 +3284,11 @@ static sr_kemi_t tm_kemi_exports[] = {
3254 3284
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3255 3285
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3256 3286
 	},
3287
+	{ str_init("tm"), str_init("t_relay_to_proto2"),
3288
+		SR_KEMIP_INT, ki_t_relay_to_proto2,
3289
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
3290
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3291
+	},
3257 3292
 	{ str_init("tm"), str_init("t_get_status_code"),
3258 3293
 		SR_KEMIP_INT, ki_t_get_status_code,
3259 3294
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,