From 02e20501c98ec2392366cdc49b1cfae6492570f3 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 31 Jul 2017 17:37:42 +0200 Subject: [PATCH] Improve conditions about STUN being activated or not when gathering ICE candidates. --- coreapi/misc.c | 9 +++------ coreapi/nat_policy.c | 2 +- coreapi/private.h | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/coreapi/misc.c b/coreapi/misc.c index bb8541138..6d0f4819f 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -616,9 +616,6 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){ IceCheckList *video_cl; IceCheckList *text_cl; LinphoneNatPolicy *nat_policy = call->nat_policy; - const char *server = NULL; - - if (nat_policy != NULL) server = linphone_nat_policy_get_stun_server(nat_policy); if (call->ice_session == NULL) return -1; audio_cl = ice_session_check_list(call->ice_session, call->main_audio_stream_index); @@ -626,7 +623,7 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){ text_cl = ice_session_check_list(call->ice_session, call->main_text_stream_index); if ((audio_cl == NULL) && (video_cl == NULL) && (text_cl == NULL)) return -1; - if ((nat_policy != NULL) && (server != NULL) && (server[0] != '\0')) { + if ((nat_policy != NULL) && linphone_nat_policy_stun_server_activated(nat_policy)) { ai=linphone_nat_policy_get_stun_server_addrinfo(nat_policy); if (ai==NULL){ ms_warning("Fail to resolve STUN server for ICE gathering, continuing without stun."); @@ -658,9 +655,9 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){ } else { linphone_core_add_local_ice_candidates(call, AF_INET, local_addr, audio_cl, video_cl, text_cl); } - if ((ai != NULL) && (nat_policy != NULL) - && (linphone_nat_policy_stun_enabled(nat_policy) || linphone_nat_policy_turn_enabled(nat_policy))) { + if ((ai != NULL) && (nat_policy != NULL) && linphone_nat_policy_stun_server_activated(nat_policy)) { bool_t gathering_in_progress; + const char *server = linphone_nat_policy_get_stun_server(nat_policy); ms_message("ICE: gathering candidate from [%s] using %s", server, linphone_nat_policy_turn_enabled(nat_policy) ? "TURN" : "STUN"); /* Gather local srflx candidates. */ ice_session_enable_turn(call->ice_session, linphone_nat_policy_turn_enabled(nat_policy)); diff --git a/coreapi/nat_policy.c b/coreapi/nat_policy.c index acc34c34b..dcd0b2d75 100644 --- a/coreapi/nat_policy.c +++ b/coreapi/nat_policy.c @@ -45,7 +45,7 @@ static void linphone_nat_policy_destroy(LinphoneNatPolicy *policy) { } } -static bool_t linphone_nat_policy_stun_server_activated(LinphoneNatPolicy *policy) { +bool_t linphone_nat_policy_stun_server_activated(LinphoneNatPolicy *policy) { const char *server = linphone_nat_policy_get_stun_server(policy); return (server != NULL) && (server[0] != '\0') && ((linphone_nat_policy_stun_enabled(policy) == TRUE) || (linphone_nat_policy_turn_enabled(policy) == TRUE)); diff --git a/coreapi/private.h b/coreapi/private.h index b95916c60..bc2175efb 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1371,6 +1371,7 @@ struct _LinphoneNatPolicy { BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneNatPolicy); +bool_t linphone_nat_policy_stun_server_activated(LinphoneNatPolicy *policy); void linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy); struct _LinphoneImNotifPolicy {