提交 978486d1 authored 作者: Anthony Minessale's avatar Anthony Minessale

deal with some sips: contacts

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8861 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 0ca1319e
...@@ -439,6 +439,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -439,6 +439,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
const char *contact_host = contact->m_url->url_host; const char *contact_host = contact->m_url->url_host;
char *path_encoded = NULL; char *path_encoded = NULL;
int path_encoded_len = 0; int path_encoded_len = 0;
const char *proto = "sip";
if (sip->sip_contact->m_url->url_type == url_sips) {
proto = "sips";
}
display = contact->m_display; display = contact->m_display;
...@@ -475,11 +480,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -475,11 +480,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
} }
if (contact->m_url->url_params) { if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s%s%s%s>", switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s%s;%s%s%s%s>",
display, contact->m_url->url_user, contact_host, new_port, display, proto, contact->m_url->url_user, contact_host, new_port,
contact->m_url->url_params, received_data, is_nat ? ";fs_nat=yes" : "", path_encoded ? path_encoded : ""); contact->m_url->url_params, received_data, is_nat ? ";fs_nat=yes" : "", path_encoded ? path_encoded : "");
} else { } else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s%s%s%s>", display, contact->m_url->url_user, contact_host, new_port, switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s%s%s%s%s>", display, proto, contact->m_url->url_user, contact_host, new_port,
received_data, is_nat ? ";fs_nat=yes" : "", path_encoded ? path_encoded : ""); received_data, is_nat ? ";fs_nat=yes" : "", path_encoded ? path_encoded : "");
} }
...@@ -730,6 +735,7 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h ...@@ -730,6 +735,7 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h
sofia_regtype_t type = REG_REGISTER; sofia_regtype_t type = REG_REGISTER;
int network_port = 0; int network_port = 0;
char *is_nat = NULL; char *is_nat = NULL;
int is_tls = 0, is_tcp = 0;
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr); get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
...@@ -746,45 +752,59 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h ...@@ -746,45 +752,59 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h
goto end; goto end;
} }
if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) { if (switch_stristr("transport=tls", sip->sip_contact->m_url->url_params)) {
if (sip && sip->sip_via) { is_tls += 1;
const char *port = sip->sip_via->v_port; }
const char *host = sip->sip_via->v_host;
if (host && sip->sip_via->v_received) { if (sip->sip_contact->m_url->url_type == url_sips) {
is_nat = "via received"; is_tls += 2;
} else if (host && strcmp(network_ip, host)) {
is_nat = "via host";
} else if (port && atoi(port) != network_port) {
is_nat = "via port";
}
}
} }
if (!is_nat && profile->nat_acl_count) { if (switch_stristr("transport=tcp", sip->sip_contact->m_url->url_params)) {
uint32_t x = 0; is_tcp = 1;
int ok = 1; }
char *last_acl = NULL;
const char *contact_host = NULL;
if (sip && sip->sip_contact && sip->sip_contact->m_url) { if (!is_tls && !is_tcp) {
contact_host = sip->sip_contact->m_url->url_host; if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) {
if (sip && sip->sip_via) {
const char *port = sip->sip_via->v_port;
const char *host = sip->sip_via->v_host;
if (host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (host && strcmp(network_ip, host)) {
is_nat = "via host";
} else if (port && atoi(port) != network_port) {
is_nat = "via port";
}
}
} }
if (!switch_strlen_zero(contact_host)) { if (!is_nat && profile->nat_acl_count) {
for (x = 0; x < profile->nat_acl_count; x++) { uint32_t x = 0;
last_acl = profile->nat_acl[x]; int ok = 1;
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) { char *last_acl = NULL;
break; const char *contact_host = NULL;
}
if (sip && sip->sip_contact && sip->sip_contact->m_url) {
contact_host = sip->sip_contact->m_url->url_host;
} }
if (ok) { if (!switch_strlen_zero(contact_host)) {
is_nat = last_acl; for (x = 0; x < profile->nat_acl_count; x++) {
last_acl = profile->nat_acl[x];
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
break;
}
}
if (ok) {
is_nat = last_acl;
}
} }
} }
} }
if (profile->reg_acl_count) { if (profile->reg_acl_count) {
uint32_t x = 0; uint32_t x = 0;
int ok = 1; int ok = 1;
...@@ -813,7 +833,7 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h ...@@ -813,7 +833,7 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h
} }
sofia_reg_handle_register(nua, profile, nh, sip, type, key, sizeof(key), &v_event, is_nat); sofia_reg_handle_register(nua, profile, nh, sip, type, key, sizeof(key), &v_event, is_nat);
if (v_event) { if (v_event) {
switch_event_fire(&v_event); switch_event_fire(&v_event);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论