Browse code

core: kemi - added KSR.to_UDP() - return true if target is over UDP

- uses the R-URI/D-URI for requests (no DNS query done if transport is missing)
and 2nd Via for replies

Daniel-Constantin Mierla authored on 14/06/2021 11:22:35
Showing 1 changed files
... ...
@@ -1536,6 +1536,57 @@ static int sr_kemi_core_route(sip_msg_t *msg, str *route)
1536 1536
 	return ret;
1537 1537
 }
1538 1538
 
1539
+/**
1540
+ *
1541
+ */
1542
+static int sr_kemi_core_to_proto_helper(sip_msg_t *msg)
1543
+{
1544
+	sip_uri_t parsed_uri;
1545
+	str uri;
1546
+
1547
+	if(msg==NULL) {
1548
+		return -1;
1549
+	}
1550
+	if(msg->first_line.type == SIP_REPLY) {
1551
+		/* REPLY doesnt have r/d-uri - use second Via */
1552
+		if(parse_headers( msg, HDR_VIA2_F, 0)==-1) {
1553
+			LM_DBG("no 2nd via parsed\n");
1554
+			return -1;
1555
+		}
1556
+		if((msg->via2==0) || (msg->via2->error!=PARSE_OK)) {
1557
+			return -1;
1558
+		}
1559
+		return (int)msg->via2->proto;
1560
+	}
1561
+	if (msg->dst_uri.s != NULL && msg->dst_uri.len>0) {
1562
+		uri = msg->dst_uri;
1563
+	} else {
1564
+		if (msg->new_uri.s!=NULL && msg->new_uri.len>0)
1565
+		{
1566
+			uri = msg->new_uri;
1567
+		} else {
1568
+			uri = msg->first_line.u.request.uri;
1569
+		}
1570
+	}
1571
+	if(parse_uri(uri.s, uri.len, &parsed_uri)!=0) {
1572
+		LM_ERR("failed to parse nh uri [%.*s]\n", uri.len, uri.s);
1573
+		return -1;
1574
+	}
1575
+	return (int)parsed_uri.proto;
1576
+}
1577
+
1578
+/**
1579
+ *
1580
+ */
1581
+static int sr_kemi_core_to_proto_udp(sip_msg_t *msg)
1582
+{
1583
+	int proto;
1584
+
1585
+	proto = sr_kemi_core_to_proto_helper(msg);
1586
+	return (proto == PROTO_UDP)?SR_KEMI_TRUE:SR_KEMI_FALSE;
1587
+}
1588
+
1589
+
1539 1590
 /**
1540 1591
  *
1541 1592
  */
... ...
@@ -1925,6 +1976,11 @@ static sr_kemi_t _sr_kemi_core[] = {
1925 1976
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1926 1977
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1927 1978
 	},
1979
+	{ str_init(""), str_init("to_UDP"),
1980
+		SR_KEMIP_BOOL, sr_kemi_core_to_proto_udp,
1981
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1982
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1983
+	},
1928 1984
 	{ str_init(""), str_init("is_src_port"),
1929 1985
 		SR_KEMIP_BOOL, sr_kemi_core_is_src_port,
1930 1986
 		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,