From e407f70c14871d4ca5f1bc7b90a0d4c45cd7ddc3 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 6 Nov 2013 16:36:43 +0100 Subject: [PATCH] Fix: in tunnel mode, linphone wasn't unregistering at exit. --- coreapi/TunnelManager.cc | 20 +++----------------- coreapi/linphonecall.c | 15 ++++++++------- coreapi/linphonecore.c | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/coreapi/TunnelManager.cc b/coreapi/TunnelManager.cc index e6063878a..efac8fbb0 100644 --- a/coreapi/TunnelManager.cc +++ b/coreapi/TunnelManager.cc @@ -274,20 +274,9 @@ void TunnelManager::processTunnelEvent(const Event &ev){ ms_message("Tunnel is up, registering now"); linphone_core_set_firewall_policy(mCore,LinphonePolicyNoFirewall); linphone_core_set_rtp_transport_factories(mCore,&mTransportFactories); -#ifdef USE_BELLESIP + sal_enable_tunnel(mCore->sal, mTunnelClient); -#else - eXosip_transport_hook_register(&mExosipTransport); - //force transport to udp - LCSipTransports lTransport; - - lTransport.udp_port=(0xDFFF&random())+1024; - lTransport.tcp_port=0; - lTransport.tls_port=0; - lTransport.dtls_port=0; - - linphone_core_set_sip_transports(mCore, &lTransport); -#endif + //register if (lProxy) { linphone_proxy_config_done(lProxy); @@ -343,7 +332,6 @@ void TunnelManager::enable(bool isEnable) { mReady=false; linphone_core_set_rtp_transport_factories(mCore,NULL); -#ifdef USE_BELLESIP sal_disable_tunnel(mCore->sal); // Set empty transports to force the setting of regular transport, otherwise it is not applied LCSipTransports lTransport; @@ -352,9 +340,7 @@ void TunnelManager::enable(bool isEnable) { lTransport.tls_port = 0; lTransport.dtls_port = 0; linphone_core_set_sip_transports(mCore, &lTransport); -#else - eXosip_transport_hook_register(NULL); -#endif + //Restore transport and firewall policy linphone_core_set_sip_transports(mCore, &mRegularTransport); linphone_core_set_firewall_policy(mCore, mPreviousFirewallPolicy); diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 695050ea4..7c24bbbd4 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -413,7 +413,6 @@ static int select_random_port(LinphoneCore *lc, SalStreamType type) { } static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){ - LinphonePresenceModel *model; int port_offset; int min_port, max_port; @@ -425,12 +424,7 @@ static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, call->media_start_time=0; call->log=linphone_call_log_new(call, from, to); call->owns_call_log=TRUE; - if (call->core->calls==NULL){ - /*there were no call, and now there is a call, send an on-the-phone presence notification automatically*/ - model = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL); - linphone_core_send_presence(call->core,model); - linphone_presence_model_unref(model); - } + linphone_core_get_audio_port_range(call->core, &min_port, &max_port); if (min_port == max_port) { /* Used fixed RTP audio port. */ @@ -731,6 +725,13 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const linphone_call_set_terminated(call); } if (cstate == LinphoneCallConnected) { + if (ms_list_size(lc->calls)==1){ + LinphonePresenceModel *model; + /*there were no call, and now there is a call, send an on-the-phone presence notification automatically*/ + model = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL); + linphone_core_send_presence(call->core,model); + linphone_presence_model_unref(model); + } call->log->status=LinphoneCallSuccess; call->media_start_time=time(NULL); } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 9ac7e8220..556154422 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -5423,12 +5423,13 @@ void sip_config_uninit(LinphoneCore *lc) lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up); lp_config_set_int(lc->config,"sip","register_only_when_upnp_is_ok",config->register_only_when_upnp_is_ok); - for(elem=config->proxies;elem!=NULL;elem=ms_list_next(elem)){ LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data); linphone_proxy_config_edit(cfg); /* to unregister */ } + + ms_message("Unregistration started."); for (i=0;i<20&&still_registered;i++){ still_registered=FALSE; @@ -5450,6 +5451,15 @@ void sip_config_uninit(LinphoneCore *lc) ms_list_free(lc->auth_info); lc->auth_info=NULL; + /*now that we are unregisted, we no longer need the tunnel.*/ +#ifdef TUNNEL_ENABLED + if (lc->tunnel) { + linphone_tunnel_destroy(lc->tunnel); + lc->tunnel=NULL; + ms_message("Tunnel destroyed."); + } +#endif + sal_reset_transports(lc->sal); sal_unlisten_ports(lc->sal); /*to make sure no new messages are received*/ sal_iterate(lc->sal); /*make sure event are purged*/ @@ -5550,6 +5560,7 @@ static void codecs_config_uninit(LinphoneCore *lc) void ui_config_uninit(LinphoneCore* lc) { + ms_message("Destroying friends."); if (lc->friends){ ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy); ms_list_free(lc->friends); @@ -5559,6 +5570,7 @@ void ui_config_uninit(LinphoneCore* lc) linphone_presence_model_unref(lc->presence_model); lc->presence_model = NULL; } + ms_message("Destroying friends done."); } /** @@ -5590,8 +5602,6 @@ static void linphone_core_uninit(LinphoneCore *lc) ms_usleep(50000); } - - if (lc->friends) /* FIXME we should wait until subscription to complete*/ ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions); linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down"); @@ -5601,9 +5611,7 @@ static void linphone_core_uninit(LinphoneCore *lc) lc->previewstream=NULL; } #endif -#ifdef TUNNEL_ENABLED - if (lc->tunnel) linphone_tunnel_destroy(lc->tunnel); -#endif + ms_event_queue_destroy(lc->msevq); lc->msevq=NULL; /* save all config */