فهرست منبع

- 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 17 سال پیش
والد
کامیت
f90ef68342
4فایلهای تغییر یافته به همراه50 افزوده شده و 0 حذف شده
  1. 23 0
      parser/parse_uri.c
  2. 1 0
      parser/parse_uri.h
  3. 24 0
      select_core.c
  4. 2 0
      select_core.h

+ 23 - 0
parser/parse_uri.c

@@ -1456,3 +1456,26 @@ inline void uri_type_to_str(uri_type type, str *s) {
 	}
 }
 
+static str	s_udp  = STR_STATIC_INIT("udp");
+static str	s_tcp  = STR_STATIC_INIT("tcp");
+static str	s_tls  = STR_STATIC_INIT("tls");
+static str	s_sctp = STR_STATIC_INIT("sctp");
+
+inline void proto_type_to_str(unsigned short type, str *s) {
+	switch (type) {
+	case PROTO_UDP:
+		*s = s_udp;
+		break;
+	case PROTO_TCP:
+		*s = s_tcp;
+		break;
+	case PROTO_TLS:
+		*s = s_tls;
+		break;
+	case PROTO_SCTP:
+		*s = s_sctp;
+		break;
+	default:
+		*s = s_null;
+	}
+}

+ 1 - 0
parser/parse_uri.h

@@ -48,5 +48,6 @@ int parse_sip_msg_uri(struct sip_msg* msg);
 int parse_orig_ruri(struct sip_msg* msg);
 int normalize_tel_user(char* res, str* src);
 void uri_type_to_str(uri_type type, str *s);
+void proto_type_to_str(unsigned short type, str *s);
 
 #endif /* PARSE_URI_H */

+ 24 - 0
select_core.c

@@ -689,6 +689,30 @@ int select_uri_hostport(str* res, select_t* s, struct sip_msg* msg)
 	return 0;
 }
 
+int select_uri_proto(str* res, select_t* s, struct sip_msg* msg)
+{
+	if (parse_uri(res->s, res->len, &uri)<0)
+		return -1;
+
+	if (uri.proto != PROTO_NONE) {
+		proto_type_to_str(uri.proto, res);
+	} else {
+		switch (uri.type) {
+			case SIPS_URI_T:
+			case TELS_URI_T:
+				proto_type_to_str(PROTO_TLS, res);
+				break;
+			case SIP_URI_T:
+			case TEL_URI_T:
+				proto_type_to_str(PROTO_UDP, res);
+				break;
+			case ERROR_URI_T:
+				return -1;
+		}
+	}
+	return 0;
+}
+
 int select_uri_params(str* res, select_t* s, struct sip_msg* msg)
 {
 	if (!msg || !res) {

+ 2 - 0
select_core.h

@@ -156,6 +156,7 @@ SELECT_F(select_uri_host)
 SELECT_F(select_uri_port)
 SELECT_F(select_uri_hostport)
 SELECT_F(select_uri_params)
+SELECT_F(select_uri_proto)
 
 SELECT_F(select_event)
 
@@ -279,6 +280,7 @@ static select_row_t select_core[] = {
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("port"), select_uri_port, 0},
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("params"), select_uri_params, CONSUME_NEXT_STR | OPTIONAL | FIXUP_CALL },
 	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("hostport"), select_uri_hostport, 0},
+	{ select_any_uri, SEL_PARAM_STR, STR_STATIC_INIT("transport"), select_uri_proto, 0},
 
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("event"), select_event, 0},