From 3d512a019c964111d9e1d84562e52dfc86b8bf84 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 22 Aug 2014 14:47:45 +0200 Subject: [PATCH 1/2] Fix update of primary contact. --- coreapi/linphonecall.c | 20 +------------------- coreapi/linphonecore.c | 4 ++-- coreapi/misc.c | 20 ++++++++++++++++++++ coreapi/private.h | 1 + 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 3e584318d..d34d88f3b 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -679,25 +679,7 @@ static void linphone_call_get_local_ip(LinphoneCall *call, const LinphoneAddress return; } #endif //BUILD_UPNP - if (af==AF_UNSPEC){ - if (linphone_core_ipv6_enabled(call->core)){ - bool_t has_ipv6; - has_ipv6=linphone_core_get_local_ip_for(AF_INET6,dest,call->localip)==0; - if (strcmp(call->localip,"::1")!=0) - return; /*this machine has real ipv6 connectivity*/ - if (linphone_core_get_local_ip_for(AF_INET,dest,call->localip)==0 && strcmp(call->localip,"127.0.0.1")!=0) - return; /*this machine has only ipv4 connectivity*/ - if (has_ipv6){ - /*this machine has only local loopback for both ipv4 and ipv6, so prefer ipv6*/ - strncpy(call->localip,"::1",LINPHONE_IPADDR_SIZE); - return; - } - } - /*in all other cases use IPv4*/ - af=AF_INET; - } - if (linphone_core_get_local_ip_for(af,dest,call->localip)==0) - return; + linphone_core_get_local_ip(call->core, af, dest, call->localip); } static void linphone_call_destroy(LinphoneCall *obj); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index a3244e59d..165974e77 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1536,7 +1536,7 @@ static void update_primary_contact(LinphoneCore *lc){ ms_error("Could not parse identity contact !"); url=linphone_address_new("sip:unknown@unkwownhost"); } - linphone_core_get_local_ip_for(AF_UNSPEC, NULL, tmp); + linphone_core_get_local_ip(lc, AF_UNSPEC, NULL, tmp); if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){ ms_warning("Local loopback network only !"); lc->sip_conf.loopback_only=TRUE; @@ -2132,7 +2132,7 @@ static void monitor_network_state(LinphoneCore *lc, time_t curtime){ /* only do the network up checking every five seconds */ if (lc->network_last_check==0 || (curtime-lc->network_last_check)>=5){ - linphone_core_get_local_ip_for(AF_UNSPEC,NULL,newip); + linphone_core_get_local_ip(lc,AF_UNSPEC,NULL,newip); if (strcmp(newip,"::1")!=0 && strcmp(newip,"127.0.0.1")!=0){ new_status=TRUE; }else new_status=FALSE; /*no network*/ diff --git a/coreapi/misc.c b/coreapi/misc.c index 47495ebe4..98deff33d 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -1125,6 +1125,26 @@ int linphone_core_get_local_ip_for(int type, const char *dest, char *result){ return 0; } +void linphone_core_get_local_ip(LinphoneCore *lc, int af, const char *dest, char *result) { + if (af == AF_UNSPEC) { + if (linphone_core_ipv6_enabled(lc)) { + bool_t has_ipv6 = linphone_core_get_local_ip_for(AF_INET6, dest, result) == 0; + if (strcmp(result, "::1") != 0) + return; /*this machine has real ipv6 connectivity*/ + if ((linphone_core_get_local_ip_for(AF_INET, dest, result) == 0) && (strcmp(result, "127.0.0.1") != 0)) + return; /*this machine has only ipv4 connectivity*/ + if (has_ipv6) { + /*this machine has only local loopback for both ipv4 and ipv6, so prefer ipv6*/ + strncpy(result, "::1", LINPHONE_IPADDR_SIZE); + return; + } + } + /*in all other cases use IPv4*/ + af = AF_INET; + } + linphone_core_get_local_ip_for(af, dest, result); +} + SalReason linphone_reason_to_sal(LinphoneReason reason){ switch(reason){ case LinphoneReasonNone: diff --git a/coreapi/private.h b/coreapi/private.h index 1ada4a618..4f6967ef0 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -360,6 +360,7 @@ void linphone_proxy_config_get_contact(LinphoneProxyConfig *cfg, const char **ip LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri); const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAddress *to); int linphone_core_get_local_ip_for(int type, const char *dest, char *result); +void linphone_core_get_local_ip(LinphoneCore *lc, int af, const char *dest, char *result); LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LinphoneCore *lc, int index); void linphone_proxy_config_write_to_config_file(struct _LpConfig* config,LinphoneProxyConfig *obj, int index); From ec11864066e50e8f282bcce7e26aead5090037d7 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 22 Aug 2014 17:57:45 +0200 Subject: [PATCH 2/2] Remove duplicated user pointer. --- coreapi/linphonecall.c | 13 ++++++------- coreapi/private.h | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index d34d88f3b..c643a3e03 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -1179,27 +1179,26 @@ const LinphoneErrorInfo *linphone_call_get_error_info(const LinphoneCall *call){ } /** - * Get the user_pointer in the LinphoneCall + * Get the user pointer associated with the LinphoneCall * * @ingroup call_control - * - * return user_pointer an opaque user pointer that can be retrieved at any time + * @return an opaque user pointer that can be retrieved at any time **/ void *linphone_call_get_user_data(const LinphoneCall *call) { - return call->user_pointer; + return call->user_data; } /** - * Set the user_pointer in the LinphoneCall + * Set the user pointer associated with the LinphoneCall * * @ingroup call_control * - * the user_pointer is an opaque user pointer that can be retrieved at any time in the LinphoneCall + * the user pointer is an opaque user pointer that can be retrieved at any time in the LinphoneCall **/ void linphone_call_set_user_data(LinphoneCall *call, void *user_pointer) { - call->user_pointer = user_pointer; + call->user_data = user_pointer; } /** diff --git a/coreapi/private.h b/coreapi/private.h index 4f6967ef0..97ddf8b1b 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -201,7 +201,6 @@ struct _LinphoneCall LinphoneCallState prevstate; LinphoneCallState transfer_state; /*idle if no transfer*/ LinphoneProxyConfig *dest_proxy; - void * user_pointer; PortConfig media_ports[2]; MSMediaStreamSessions sessions[2]; /*the rtp, srtp, zrtp contexts for each stream*/ StunCandidate ac,vc; /*audio video ip/port discovered by STUN*/