Browse code

- adding any_uri.transport select NOTE: if there is no transport parameter in the uri, it returns the default transport based on the uri type (sip/sips).

Michal Matyska authored on 15/02/2008 17:37:24
Showing 4 changed files
... ...
@@ -1456,3 +1456,26 @@ inline void uri_type_to_str(uri_type type, str *s) {
1456 1456
 	}
1457 1457
 }
1458 1458
 
1459
+static str	s_udp  = STR_STATIC_INIT("udp");
1460
+static str	s_tcp  = STR_STATIC_INIT("tcp");
1461
+static str	s_tls  = STR_STATIC_INIT("tls");
1462
+static str	s_sctp = STR_STATIC_INIT("sctp");
1463
+
1464
+inline void proto_type_to_str(unsigned short type, str *s) {
1465
+	switch (type) {
1466
+	case PROTO_UDP:
1467
+		*s = s_udp;
1468
+		break;
1469
+	case PROTO_TCP:
1470
+		*s = s_tcp;
1471
+		break;
1472
+	case PROTO_TLS:
1473
+		*s = s_tls;
1474
+		break;
1475
+	case PROTO_SCTP:
1476
+		*s = s_sctp;
1477
+		break;
1478
+	default:
1479
+		*s = s_null;
1480
+	}
1481
+}
... ...
@@ -48,5 +48,6 @@ int parse_sip_msg_uri(struct sip_msg* msg);
48 48
 int parse_orig_ruri(struct sip_msg* msg);
49 49
 int normalize_tel_user(char* res, str* src);
50 50
 void uri_type_to_str(uri_type type, str *s);
51
+void proto_type_to_str(unsigned short type, str *s);
51 52
 
52 53
 #endif /* PARSE_URI_H */
... ...
@@ -689,6 +689,30 @@ int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
689 689
 	return 0;
690 690
 }
691 691
 
692
+int select_uri_proto(str* res, select_t* s, struct sip_msg* msg)
693
+{
694
+	if (parse_uri(res->s, res->len, &uri)<0)
695
+		return -1;
696
+
697
+	if (uri.proto != PROTO_NONE) {
698
+		proto_type_to_str(uri.proto, res);
699
+	} else {
700
+		switch (uri.type) {
701
+			case SIPS_URI_T:
702
+			case TELS_URI_T:
703
+				proto_type_to_str(PROTO_TLS, res);
704
+				break;
705
+			case SIP_URI_T:
706
+			case TEL_URI_T:
707
+				proto_type_to_str(PROTO_UDP, res);
708
+				break;
709
+			case ERROR_URI_T:
710
+				return -1;
711
+		}
712
+	}
713
+	return 0;
714
+}
715
+
692 716
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
693 717
 {
694 718
 	if (!msg || !res) {
... ...
@@ -156,6 +156,7 @@ SELECT_F(select_uri_host)
156 156
 SELECT_F(select_uri_port)
157 157
 SELECT_F(select_uri_hostport)
158 158
 SELECT_F(select_uri_params)
159
+SELECT_F(select_uri_proto)
159 160
 
160 161
 SELECT_F(select_event)
161 162
 
... ...
@@ -279,6 +280,7 @@ static select_row_t select_core[] = {
279 279
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
280 280
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, CONSUME_NEXT_STR | OPTIONAL | FIXUP_CALL },
281 281
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
282
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("transport"), select_uri_proto, 0},
282 283
 
283 284
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},
284 285