mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-05 18:13:27 +00:00
support allowing pidf-ful presence clients to share the same account and 'appear offline' without influencing each other =/ also refactor the contact generation string based on nat into a helper function
This commit is contained in:
parent
c4e350ab0c
commit
97a68c50d9
src/mod/endpoints/mod_sofia
@ -745,6 +745,14 @@ typedef struct {
|
|||||||
char *route_uri;
|
char *route_uri;
|
||||||
} sofia_destination_t;
|
} sofia_destination_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char network_ip[80];
|
||||||
|
int network_port;
|
||||||
|
const char *is_nat;
|
||||||
|
int is_auto_nat;
|
||||||
|
} sofia_nat_parse_t;
|
||||||
|
|
||||||
|
|
||||||
#define sofia_test_pflag(obj, flag) ((obj)->pflags[flag] ? 1 : 0)
|
#define sofia_test_pflag(obj, flag) ((obj)->pflags[flag] ? 1 : 0)
|
||||||
#define sofia_set_pflag(obj, flag) (obj)->pflags[flag] = 1
|
#define sofia_set_pflag(obj, flag) (obj)->pflags[flag] = 1
|
||||||
#define sofia_set_pflag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
|
#define sofia_set_pflag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
|
||||||
@ -1040,3 +1048,4 @@ switch_status_t sofia_glue_sdp_map(const char *r_sdp, switch_event_t **fmtp, swi
|
|||||||
void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl);
|
void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl);
|
||||||
void sofia_glue_check_dtmf_type(private_object_t *tech_pvt);
|
void sofia_glue_check_dtmf_type(private_object_t *tech_pvt);
|
||||||
void sofia_glue_parse_rtp_bugs(uint32_t *flag_pole, const char *str);
|
void sofia_glue_parse_rtp_bugs(uint32_t *flag_pole, const char *str);
|
||||||
|
char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, sofia_nat_parse_t *np);
|
||||||
|
@ -6136,6 +6136,129 @@ void sofia_glue_parse_rtp_bugs(uint32_t *flag_pole, const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, sofia_nat_parse_t *np)
|
||||||
|
{
|
||||||
|
char *contact_str = NULL;
|
||||||
|
const char *contact_host, *contact_user;
|
||||||
|
sip_contact_t const *contact;
|
||||||
|
char *port;
|
||||||
|
const char *display = "\"user\"";
|
||||||
|
char new_port[25] = "";
|
||||||
|
sofia_nat_parse_t lnp = { { 0 } };
|
||||||
|
const char *ipv6;
|
||||||
|
sip_from_t const *from;
|
||||||
|
|
||||||
|
if (!sip || !sip->sip_contact || !sip->sip_contact->m_url) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
from = sip->sip_from;
|
||||||
|
contact = sip->sip_contact;
|
||||||
|
|
||||||
|
if (!np) {
|
||||||
|
np = &lnp;
|
||||||
|
}
|
||||||
|
|
||||||
|
sofia_glue_get_addr(nua_current_request(profile->nua), np->network_ip, sizeof(np->network_ip), &np->network_port);
|
||||||
|
|
||||||
|
if (sofia_glue_check_nat(profile, np->network_ip)) {
|
||||||
|
np->is_auto_nat = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
port = (char *) contact->m_url->url_port;
|
||||||
|
contact_host = sip->sip_contact->m_url->url_host;
|
||||||
|
contact_user = sip->sip_contact->m_url->url_user;
|
||||||
|
|
||||||
|
display = contact->m_display;
|
||||||
|
|
||||||
|
|
||||||
|
if (zstr(display)) {
|
||||||
|
if (from) {
|
||||||
|
display = from->a_display;
|
||||||
|
if (zstr(display)) {
|
||||||
|
display = "\"user\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
display = "\"user\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)) {
|
||||||
|
if (sip->sip_via) {
|
||||||
|
const char *v_port = sip->sip_via->v_port;
|
||||||
|
const char *v_host = sip->sip_via->v_host;
|
||||||
|
|
||||||
|
if (v_host && sip->sip_via->v_received) {
|
||||||
|
np->is_nat = "via received";
|
||||||
|
} else if (v_host && strcmp(np->network_ip, v_host)) {
|
||||||
|
np->is_nat = "via host";
|
||||||
|
} else if (v_port && atoi(v_port) != np->network_port) {
|
||||||
|
np->is_nat = "via port";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!np->is_nat && sip && sip->sip_via && sip->sip_via->v_port &&
|
||||||
|
atoi(sip->sip_via->v_port) == 5060 && np->network_port != 5060 ) {
|
||||||
|
np->is_nat = "via port";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!np->is_nat && profile->nat_acl_count) {
|
||||||
|
uint32_t x = 0;
|
||||||
|
int ok = 1;
|
||||||
|
char *last_acl = NULL;
|
||||||
|
|
||||||
|
if (!zstr(contact_host)) {
|
||||||
|
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) {
|
||||||
|
np->is_nat = last_acl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (np->is_nat && profile->local_network && switch_check_network_list_ip(np->network_ip, profile->local_network)) {
|
||||||
|
if (profile->debug) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s is on local network, not seting NAT mode.\n", np->network_ip);
|
||||||
|
}
|
||||||
|
np->is_nat = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zstr(contact_host)) {
|
||||||
|
np->is_nat = "No contact host";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (np->is_nat) {
|
||||||
|
contact_host = np->network_ip;
|
||||||
|
switch_snprintf(new_port, sizeof(new_port), ":%d", np->network_port);
|
||||||
|
port = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
switch_snprintf(new_port, sizeof(new_port), ":%s", port);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipv6 = strchr(contact_host, ':');
|
||||||
|
if (contact->m_url->url_params) {
|
||||||
|
contact_str = switch_mprintf("%s <sip:%s@%s%s%s%s;%s>%s",
|
||||||
|
display, contact->m_url->url_user,
|
||||||
|
ipv6 ? "[" : "",
|
||||||
|
contact_host, ipv6 ? "]" : "", new_port, contact->m_url->url_params, np->is_nat ? ";fs_nat=yes" : "");
|
||||||
|
} else {
|
||||||
|
contact_str = switch_mprintf("%s <sip:%s@%s%s%s%s>%s",
|
||||||
|
display,
|
||||||
|
contact->m_url->url_user, ipv6 ? "[" : "", contact_host, ipv6 ? "]" : "", new_port, np->is_nat ? ";fs_nat=yes" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return contact_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user