Commit 2af20c28 authored by Simon Morlat's avatar Simon Morlat

clean compatibility code (in the hope of fixing a memory leak)

parent 884cc808
......@@ -761,16 +761,17 @@ static void net_config_read (LinphoneCore *lc)
if (nat_policy_ref != NULL) {
lc->nat_policy = linphone_core_create_nat_policy_from_config(lc, nat_policy_ref);
}
if (lc->nat_policy == NULL){
/*this will create a default nat policy according to deprecated config keys, or an empty nat policy otherwise*/
linphone_core_set_firewall_policy(lc, linphone_core_get_firewall_policy(lc));
}
lc->net_conf.nat_address_ip = NULL;
tmp=lp_config_get_int(config,"net","download_bw",0);
linphone_core_set_download_bandwidth(lc,tmp);
tmp=lp_config_get_int(config,"net","upload_bw",0);
linphone_core_set_upload_bandwidth(lc,tmp);
if (lc->nat_policy == NULL) /* For compatibility, now the STUN server is stored in the NAT policy. */
linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
else
linphone_core_set_stun_server(lc, linphone_nat_policy_get_stun_server(lc->nat_policy));
tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
linphone_core_set_nat_address(lc,tmpstr);
......@@ -787,10 +788,6 @@ static void net_config_read (LinphoneCore *lc)
linphone_core_enable_dns_srv(lc, tmp);
tmp = lp_config_get_int(lc->config, "net", "dns_search_enabled", 1);
linphone_core_enable_dns_search(lc, tmp);
/* This is to filter out unsupported firewall policies */
if (nat_policy_ref == NULL)
linphone_core_set_firewall_policy(lc, linphone_core_get_firewall_policy(lc));
}
static void build_sound_devices_table(LinphoneCore *lc){
......@@ -6727,6 +6724,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
#endif
lc->msevq=NULL;
/* save all config */
friends_config_uninit(lc);
sip_config_uninit(lc);
......
......@@ -569,67 +569,22 @@ void linphone_core_adapt_to_network(LinphoneCore *lc, int ping_time_ms, Linphone
}
}
static void stun_server_resolved(LinphoneCore *lc, const char *name, struct addrinfo *addrinfo){
if (lc->net_conf.stun_addrinfo){
bctbx_freeaddrinfo(lc->net_conf.stun_addrinfo);
lc->net_conf.stun_addrinfo=NULL;
}
if (addrinfo){
ms_message("Stun server resolution successful.");
}else{
ms_warning("Stun server resolution failed.");
}
lc->net_conf.stun_addrinfo=addrinfo;
lc->net_conf.stun_res=NULL;
}
void linphone_core_resolve_stun_server(LinphoneCore *lc){
if (lc->nat_policy != NULL) {
linphone_nat_policy_resolve_stun_server(lc->nat_policy);
} else {
const char *server=linphone_core_get_stun_server(lc);
LinphoneFirewallPolicy firewall_policy = linphone_core_get_firewall_policy(lc);
if (lc->sal && server && !lc->net_conf.stun_res
&& ((firewall_policy == LinphonePolicyUseStun) || (firewall_policy == LinphonePolicyUseIce))) {
char host[NI_MAXHOST];
const char *service = "stun";
int port=3478;
int family = AF_INET;
linphone_parse_host_port(server,host,sizeof(host),&port);
if (linphone_core_ipv6_enabled(lc) == TRUE) family = AF_INET6;
lc->net_conf.stun_res = sal_resolve(lc->sal, service, "udp", host, port, family, (SalResolverCallback)stun_server_resolved, lc);
}
ms_error("linphone_core_resolve_stun_server(): called without nat_policy, this should not happen.");
}
}
/*
* This function returns the addrinfo representation of the stun server address.
* It is critical not to block for a long time if it can't be resolved, otherwise this stucks the main thread when making a call.
* On the contrary, a fully asynchronous call initiation is complex to develop.
* The compromise is then:
* - have a cache of the stun server addrinfo
* - this cached value is returned when it is non-null
* - an asynchronous resolution is asked each time this function is called to ensure frequent refreshes of the cached value.
* - if no cached value exists, block for a short time; this case must be unprobable because the resolution will be asked each time the stun server value is
* changed.
**/
const struct addrinfo *linphone_core_get_stun_server_addrinfo(LinphoneCore *lc){
if (lc->nat_policy != NULL) {
return linphone_nat_policy_get_stun_server_addrinfo(lc->nat_policy);
} else {
const char *server=linphone_core_get_stun_server(lc);
if (server){
int wait_ms=0;
int wait_limit=1000;
linphone_core_resolve_stun_server(lc);
while (!lc->net_conf.stun_addrinfo && lc->net_conf.stun_res!=NULL && wait_ms<wait_limit){
sal_iterate(lc->sal);
ms_usleep(50000);
wait_ms+=50;
}
}
return lc->net_conf.stun_addrinfo;
ms_error("linphone_core_get_stun_server_addrinfo(): called without nat_policy, this should not happen.");
}
return NULL;
}
void linphone_core_enable_forced_ice_relay(LinphoneCore *lc, bool_t enable) {
......
......@@ -838,7 +838,6 @@ typedef struct net_config
char *nat_address; /* may be IP or host name */
char *nat_address_ip; /* ip translated from nat_address */
struct addrinfo *stun_addrinfo;
SalResolverContext * stun_res;
int download_bw;
int upload_bw;
int mtu;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment