From 82c498a7119d8106cdd1c7354652be53ade3579b Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 18 Apr 2013 10:28:50 +0200 Subject: [PATCH] Port tunnel to belle-sip. --- coreapi/Makefile.am | 3 +++ coreapi/TunnelManager.cc | 24 +++++++++++++++++++++++- coreapi/TunnelManager.hh | 5 +++++ coreapi/bellesip_sal/sal_impl.c | 15 +++++++++++++++ coreapi/linphonecore.c | 6 +++--- include/sal/sal.h | 2 ++ 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index 8a42e8733..3dd43c0db 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -126,6 +126,9 @@ AM_CFLAGS=\ if BUILD_WIZARD AM_CFLAGS+= -DBUILD_WIZARD endif +if USE_BELLESIP +AM_CFLAGS+= -DUSE_BELLESIP +endif AM_CXXFLAGS=$(AM_CFLAGS) diff --git a/coreapi/TunnelManager.cc b/coreapi/TunnelManager.cc index d1020b1b2..baf1454e3 100644 --- a/coreapi/TunnelManager.cc +++ b/coreapi/TunnelManager.cc @@ -18,6 +18,7 @@ #include "linphonecore_utils.h" #include "eXosip2/eXosip_transport_hook.h" #include "tunnel/udp_mirror.hh" +#include "private.h" #ifdef ANDROID #include @@ -27,6 +28,8 @@ using namespace belledonnecomm; using namespace ::std; +#ifndef USE_BELLESIP + Mutex TunnelManager::sMutex; int TunnelManager::eXosipSendto(int fd,const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen,void* userdata){ @@ -99,6 +102,7 @@ int TunnelManager::eXosipSelect(int max_fds, fd_set *s1, fd_set *s2, fd_set *s3, return select(max_fds,s1,s2,s3,tv); } } +#endif void TunnelManager::addServer(const char *ip, int port,unsigned int udpMirrorPort,unsigned int delay) { @@ -181,7 +185,9 @@ void TunnelManager::start() { } mTunnelClient->start(); +#ifndef USE_BELLESIP if (mSipSocket == NULL) mSipSocket =mTunnelClient->createSocket(5060); +#endif } bool TunnelManager::isStarted() { @@ -209,17 +215,21 @@ int TunnelManager::customRecvfrom(struct _RtpTransport *t, mblk_t *msg, int flag TunnelManager::TunnelManager(LinphoneCore* lc) :TunnelClientController() ,mCore(lc) +#ifndef USE_BELLESIP ,mSipSocket(NULL) +#endif ,mCallback(NULL) ,mEnabled(false) ,mTunnelClient(NULL) ,mAutoDetectStarted(false) ,mHttpProxyPort(0){ +#ifndef USE_BELLESIP mExosipTransport.data=this; mExosipTransport.recvfrom=eXosipRecvfrom; mExosipTransport.sendto=eXosipSendto; mExosipTransport.select=eXosipSelect; +#endif linphone_core_add_iterate_hook(mCore,(LinphoneCoreIterateHook)sOnIterate,this); mTransportFactories.audio_rtcp_func=sCreateRtpTransport; mTransportFactories.audio_rtcp_func_data=this; @@ -236,6 +246,9 @@ TunnelManager::~TunnelManager(){ } void TunnelManager::stopClient(){ +#ifdef USE_BELLESIP + sal_disable_tunnel(mCore->sal); +#else eXosip_transport_hook_register(NULL); if (mSipSocket != NULL){ sMutex.lock(); @@ -243,6 +256,7 @@ void TunnelManager::stopClient(){ mSipSocket = NULL; sMutex.unlock(); } +#endif if (mTunnelClient){ delete mTunnelClient; mTunnelClient=NULL; @@ -257,6 +271,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; @@ -267,6 +284,7 @@ void TunnelManager::processTunnelEvent(const Event &ev){ lTransport.dtls_port=0; linphone_core_set_sip_transports(mCore, &lTransport); +#endif //register if (lProxy) { linphone_proxy_config_done(lProxy); @@ -320,7 +338,11 @@ void TunnelManager::enable(bool isEnable) { linphone_core_set_rtp_transport_factories(mCore,NULL); +#ifdef USE_BELLESIP + sal_disable_tunnel(mCore->sal); +#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); @@ -387,7 +409,7 @@ void TunnelManager::enableLogs(bool isEnabled,LogHandler logHandler) { #ifdef ANDROID else SetLogHandler(linphone_android_tunnel_log_handler); #else - else SetLogHandler(default_log_handler); + else SetLogHandler(tunnel_default_log_handler); #endif if (isEnabled) { diff --git a/coreapi/TunnelManager.hh b/coreapi/TunnelManager.hh index d4c1458fc..0e8ae3745 100644 --- a/coreapi/TunnelManager.hh +++ b/coreapi/TunnelManager.hh @@ -15,9 +15,12 @@ #include "tunnel/client.hh" #include "linphonecore.h" +#ifndef USE_BELLESIP extern "C" { #include "eXosip2/eXosip_transport_hook.h" } +#endif + namespace belledonnecomm { class TunnelClient; class UdpMirrorClient; @@ -159,8 +162,10 @@ class UdpMirrorClient; void postEvent(const Event &ev); LinphoneCore* mCore; LCSipTransports mRegularTransport; +#ifndef USE_BELLESIP TunnelSocket *mSipSocket; eXosip_transport_hooks_t mExosipTransport; +#endif StateCallback mCallback; void * mCallbackData; bool mEnabled; diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index a4f4aac96..ab41a46b3 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -515,6 +515,21 @@ void sal_set_keepalive_period(Sal *ctx,unsigned int value){ } return ; } +int sal_enable_tunnel(Sal *ctx, void *tunnelclient) { + int result; + + sal_unlisten_ports(ctx); + belle_sip_listening_point_t* lp = belle_sip_tunnel_listening_point_new(ctx->stack, tunnelclient); + if (lp == NULL) return -1; + + belle_sip_listening_point_set_keep_alive(lp, ctx->keep_alive); + result = belle_sip_provider_add_listening_point(ctx->prov, lp); + set_tls_properties(ctx); + return result; +} +void sal_disable_tunnel(Sal *ctx) { + sal_unlisten_ports(ctx); +} /** * returns keepalive period in ms * 0 desactiaved diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index e8a5fc3dc..55f64905f 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -5366,6 +5366,9 @@ static void linphone_core_uninit(LinphoneCore *lc) video_preview_stop(lc->previewstream); 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; @@ -5414,9 +5417,6 @@ static void linphone_core_uninit(LinphoneCore *lc) linphone_core_message_storage_close(lc); ortp_exit(); linphone_core_set_state(lc,LinphoneGlobalOff,"Off"); -#ifdef TUNNEL_ENABLED - if (lc->tunnel) linphone_tunnel_destroy(lc->tunnel); -#endif } static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){ diff --git a/include/sal/sal.h b/include/sal/sal.h index 37068c4cd..aa4099825 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -383,6 +383,8 @@ void sal_set_user_agent(Sal *ctx, const char *user_agent); /*keepalive period in ms*/ void sal_set_keepalive_period(Sal *ctx,unsigned int value); void sal_use_tcp_tls_keepalive(Sal *ctx, bool_t enabled); +int sal_enable_tunnel(Sal *ctx, void *tunnelclient); +void sal_disable_tunnel(Sal *ctx); /** * returns keepalive period in ms * 0 desactiaved