From 2af20c28af88cd17ce64b9fc6e9934567c4fc90a Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 18 Oct 2016 15:48:15 +0200 Subject: [PATCH] clean compatibility code (in the hope of fixing a memory leak) --- coreapi/linphonecore.c | 14 +++++------- coreapi/misc.c | 51 +++--------------------------------------- coreapi/private.h | 1 - 3 files changed, 9 insertions(+), 57 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 057b3dde7..3966a7ffe 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -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); diff --git a/coreapi/misc.c b/coreapi/misc.c index 7613698ed..7f586108c 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -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_mssal); - 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) { diff --git a/coreapi/private.h b/coreapi/private.h index a56e47449..5573e6af2 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -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;