Преглед на файлове

- @next_hop.src_ip: source ip of outgoing message

Tomas Mandys преди 16 години
родител
ревизия
3d55e46498
променени са 2 файла, в които са добавени 53 реда и са изтрити 0 реда
  1. 51 0
      select_core.c
  2. 2 0
      select_core.h

+ 51 - 0
select_core.c

@@ -61,6 +61,8 @@
 #include "parser/parse_body.h"
 #include "dset.h"
 #include "sr_module.h"
+#include "resolve.h"
+#include "forward.h"
 
 #define RETURN0_res(x) {*res=(x);return 0;}
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
@@ -103,6 +105,55 @@ int select_next_hop(str* res, select_t* s, struct sip_msg* msg)
 	return -1;
 }
 
+int select_next_hop_src_ip(str* res, select_t* s, struct sip_msg* msg) {
+	struct socket_info* socket_info;
+	union sockaddr_union to;
+	char proto;
+	struct sip_uri *u, next_hop;
+	str *dst_host;
+
+	if (msg->first_line.type!=SIP_REQUEST) 
+		return -1;
+
+	if (msg->force_send_socket) {
+		*res = msg->force_send_socket->address_str;
+		return 0;
+	}
+
+	if (msg->dst_uri.len) {
+		if (parse_uri(msg->dst_uri.s, msg->dst_uri.len, &next_hop) < 0)
+			return -1;
+		u = &next_hop;
+	}
+	else {
+		if (parse_sip_msg_uri(msg) < 0)
+			return -1;
+		u = &msg->parsed_uri;
+	}
+#ifdef USE_TLS
+	if (u->type==SIPS_URI_T)
+		proto = PROTO_TLS;
+	else
+#endif
+		proto = u->proto;
+
+#ifdef HONOR_MADDR
+	if (u->maddr_val.s && u->maddr_val.len)
+		dst_host = &u->maddr_val;
+	else
+#endif
+		dst_host = &u->host;
+
+	if (sip_hostport2su(&to, dst_host, u->port_no, &proto) < 0)
+		return -1;
+	socket_info = get_send_socket(msg, &to, proto);
+	if (!socket_info)
+		return -1;
+
+	*res = socket_info->address_str;
+	return 0;
+}
+
 #define SELECT_uri_header(_name_) \
 int select_##_name_(str* res, select_t* s, struct sip_msg* msg) \
 { \

+ 2 - 0
select_core.h

@@ -86,6 +86,7 @@ enum {
 SELECT_F(select_ruri)
 SELECT_F(select_dst_uri)
 SELECT_F(select_next_hop)
+SELECT_F(select_next_hop_src_ip)
 SELECT_F(select_from)
 SELECT_F(select_from_uri)
 SELECT_F(select_from_tag)
@@ -221,6 +222,7 @@ static select_row_t select_core[] = {
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("dst_uri"), select_dst_uri, 0},
 	{ select_dst_uri, SEL_PARAM_STR, STR_NULL, select_any_uri, NESTED},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("next_hop"), select_next_hop, 0},
+	{ select_next_hop, SEL_PARAM_STR, STR_STATIC_INIT("src_ip"), select_next_hop_src_ip, 0},
 	{ select_next_hop, SEL_PARAM_STR, STR_NULL, select_any_uri, NESTED},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("from"), select_from, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("f"), select_from, 0},