Browse code

Merge 93b2c03eca373831d895f392b790b28973c8e30e into 85b2f1a18ad12a74bc80a4946d41510795e47e04

aalba6675 authored on 27/11/2020 03:06:05 • GitHub committed on 27/11/2020 03:06:05
Showing 1 changed files
... ...
@@ -2897,6 +2897,59 @@ static int ki_t_relay(sip_msg_t *msg)
2897 2897
 	return _w_t_relay_to(msg, (struct proxy_l *)0, PROTO_NONE);
2898 2898
 }
2899 2899
 
2900
+/**
2901
+ *
2902
+ */
2903
+static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto)
2904
+{
2905
+
2906
+	int proto = PROTO_NONE;
2907
+
2908
+	if (sproto != NULL && sproto->s != NULL && sproto->len == 3) {
2909
+		if (strncasecmp(sproto->s, "UDP", 3) == 0) {
2910
+			proto = PROTO_UDP;
2911
+		} else if (strncasecmp(sproto->s, "TCP", 3) == 0) {
2912
+			proto = PROTO_TCP;
2913
+		} else if (strncasecmp(sproto->s, "TLS", 3)) {
2914
+			proto = PROTO_TLS;
2915
+		} else {
2916
+			LM_ERR("t_relay_to_proto failed, bad protocol specified <%s>\n", sproto->s);
2917
+			return E_UNSPEC;
2918
+		}
2919
+	}
2920
+	return _w_t_relay_to(msg, (struct proxy_l *)0, proto);
2921
+}
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
+
2900 2953
 /**
2901 2954
  *
2902 2955
  */
... ...
@@ -3226,6 +3279,16 @@ static sr_kemi_t tm_kemi_exports[] = {
3226 3279
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
3227 3280
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3228 3281
 	},
3282
+	{ str_init("tm"), str_init("t_relay_to_proto"),
3283
+		SR_KEMIP_INT, ki_t_relay_to_proto,
3284
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3285
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
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
+	},
3229 3292
 	{ str_init("tm"), str_init("t_get_status_code"),
3230 3293
 		SR_KEMIP_INT, ki_t_get_status_code,
3231 3294
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,