From 32cd807f617004ffe450b0ef71b1b852422a11a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Mon, 15 Sep 2014 11:02:12 +0200 Subject: [PATCH] Change the implementation of sal_enable_tunnel and sal_disable_tunnel --- coreapi/bellesip_sal/sal_impl.c | 42 +++++++++++++++++++++++---------- coreapi/bellesip_sal/sal_impl.h | 2 ++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index a640f4814..e18ae51af 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -645,28 +645,44 @@ void sal_set_keepalive_period(Sal *ctx,unsigned int value){ belle_sip_listening_point_set_keep_alive(lp,ctx->keep_alive); } } - return ; } int sal_enable_tunnel(Sal *ctx, void *tunnelclient) { #ifdef TUNNEL_ENABLED - belle_sip_listening_point_t *lp; - int result; - - sal_unlisten_ports(ctx); - 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; + belle_sip_listening_point_t *lpUDP = NULL; + if(ctx->lpTunnel != NULL) { + ortp_error("sal_enable_tunnel(): tunnel is already enabled"); + return -1; + } + while((lpUDP = belle_sip_provider_get_listening_point(ctx->prov, "udp")) != NULL) { + belle_sip_object_ref(lpUDP); + belle_sip_provider_remove_listening_point(ctx->prov, lpUDP); + ctx->UDPListeningPoints = ms_list_append(ctx->UDPListeningPoints, lpUDP); + } + ctx->lpTunnel = belle_sip_tunnel_listening_point_new(ctx->stack, tunnelclient); + if(ctx->lpTunnel == NULL) return -1; + belle_sip_listening_point_set_keep_alive(ctx->lpTunnel, ctx->keep_alive); + belle_sip_provider_add_listening_point(ctx->prov, ctx->lpTunnel); + belle_sip_object_ref(ctx->lpTunnel); + return 0; #else return 0; #endif } void sal_disable_tunnel(Sal *ctx) { #ifdef TUNNEL_ENABLED - sal_unlisten_ports(ctx); + MSList *it; + if(ctx->lpTunnel == NULL) { + ortp_warning("sal_disable_tunnel(): no tunnel to disable"); + } else { + belle_sip_provider_remove_listening_point(ctx->prov, ctx->lpTunnel); + belle_sip_object_unref(ctx->lpTunnel); + ctx->lpTunnel = NULL; + for(it=ctx->UDPListeningPoints; it!=NULL; it=it->next) { + belle_sip_provider_add_listening_point(ctx->prov, (belle_sip_listening_point_t *)it->data); + } + ms_list_free_with_data(ctx->UDPListeningPoints, belle_sip_object_unref); + ctx->UDPListeningPoints = NULL; + } #endif } /** diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index 097bbb882..143e9e924 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -33,6 +33,8 @@ struct Sal{ belle_sip_provider_t *prov; belle_sip_header_user_agent_t* user_agent; belle_sip_listener_t *listener; + belle_sip_listening_point_t *lpTunnel; + MSList *UDPListeningPoints; void *up; /*user pointer*/ int session_expires; unsigned int keep_alive;