Commit 7375477e authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Add tunnel support.

parent 4f2fe6e5
......@@ -20,6 +20,7 @@ AM_SILENT_RULES(yes)
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
dnl AC_PROG_CC_C99
LT_INIT(disable-static win32-dll)
......@@ -166,6 +167,15 @@ AC_SUBST(TLS_CFLAGS)
AC_SUBST(TLS_LIBS)
AC_SUBST(TLS_PC)
AC_ARG_ENABLE(tunnel,
[AS_HELP_STRING([--enable-tunnel], [Enable tunnel support (default=no)])])
if test "$enable_tunnel" = "yes" ; then
PKG_CHECK_MODULES(TUNNEL, tunnel, [found_tunnel=yes], [found_tunnel=no])
if test "$found_tunnel" = "yes" ; then
AC_DEFINE(HAVE_TUNNEL, 1, [Defined when tunnel is enabled and available])
fi
fi
PKG_CHECK_MODULES(CUNIT, cunit, [found_cunit=yes],[found_cunit=no])
if test "$found_cunit" = "no" ; then
......
......@@ -33,10 +33,12 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_udp_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_stream_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_tls_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_tunnel_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_udp_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_stream_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_tls_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_tunnel_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_provider_t),
BELLE_SIP_TYPE_ID(belle_sip_main_loop_t),
BELLE_SIP_TYPE_ID(belle_sip_source_t),
......
......@@ -66,6 +66,8 @@ BELLESIP_EXPORT int belle_sip_tls_listening_point_set_root_ca(belle_sip_tls_list
BELLESIP_EXPORT int belle_sip_tls_listening_point_set_verify_exceptions(belle_sip_tls_listening_point_t *s, int flags);
BELLESIP_EXPORT belle_sip_listening_point_t * belle_sip_tunnel_listening_point_new(belle_sip_stack_t *s, void *tunnelclient);
#define BELLE_SIP_UDP_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_udp_listening_point_t)
#define BELLE_SIP_STREAM_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_stream_listening_point_t)
......
......@@ -14,6 +14,10 @@
/*inherite from belle_sip_parameters_t*/
typedef struct _belle_sip_uri belle_sip_uri_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
*
*/
......@@ -187,5 +191,10 @@ int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int of
* */
BELLESIP_EXPORT int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri_b);
#ifdef __cplusplus
}
#endif
#endif /*BELLE_SIP_URI_H_*/
......@@ -60,13 +60,15 @@ libbellesip_la_SOURCES= \
transports/stream_listeningpoint.c \
transports/tls_listeningpoint_polarssl.c \
transports/tls_channel_polarssl.c \
transports/tunnel_listeningpoint.cc \
transports/tunnel_channel.cc \
refresher.c refresher-helper.h \
dns.c dns.h
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS) $(TLS_CFLAGS) $(LIBBELLESIP_CFLAGS)
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS) $(TLS_CFLAGS) $(TUNNEL_CFLAGS) $(LIBBELLESIP_CFLAGS)
libbellesip_la_LIBADD=libbellesip_generated.la $(ANTLR_LIBS) $(TLS_LIBS)
libbellesip_la_LIBADD=libbellesip_generated.la $(ANTLR_LIBS) $(TLS_LIBS) $(TUNNEL_LIBS)
libbellesip_la_LDFLAGS=-no-undefined $(LDFLAGS)
......
......@@ -51,6 +51,10 @@ struct belle_sip_resolver_context{
uint8_t done;
};
#ifdef __cplusplus
extern "C" {
#endif
int belle_sip_addrinfo_to_ip(const struct addrinfo *ai, char *ip, size_t ip_size, int *port);
BELLESIP_INTERNAL_EXPORT struct addrinfo * belle_sip_ip_address_to_addrinfo(int family, const char *ipaddress, int port);
BELLESIP_INTERNAL_EXPORT unsigned long belle_sip_resolve(belle_sip_stack_t *stack, const char *name, int port, int family, belle_sip_resolver_callback_t cb , void *data, belle_sip_main_loop_t *ml);
......@@ -69,4 +73,9 @@ void belle_sip_get_src_addr_for(const struct sockaddr *dest, socklen_t destlen,
**/
void belle_sip_address_remove_v4_mapping(const struct sockaddr *v6, struct sockaddr *result, socklen_t *result_len);
#ifdef __cplusplus
}
#endif
#endif
......@@ -96,6 +96,10 @@ struct belle_sip_channel{
#define BELLE_SIP_CHANNEL(obj) BELLE_SIP_CAST(obj,belle_sip_channel_t)
#ifdef __cplusplus
extern "C" {
#endif
void belle_sip_channel_add_listener(belle_sip_channel_t *chan, belle_sip_channel_listener_t *l);
void belle_sip_channel_remove_listener(belle_sip_channel_t *obj, belle_sip_channel_listener_t *l);
......@@ -148,6 +152,11 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
/*this function is to be used only in belle_sip_listening_point_clean_channels()*/
void belle_sip_channel_force_close(belle_sip_channel_t *obj);
#ifdef __cplusplus
}
#endif
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_channel_t,belle_sip_source_t)
const char *transport;
int reliable;
......
......@@ -50,7 +50,13 @@ struct belle_sip_listening_point{
int ai_family; /*AF_INET or AF_INET6*/
};
#ifdef __cplusplus
extern "C" {
#endif
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port);
#ifdef __cplusplus
}
#endif
belle_sip_channel_t *_belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const belle_sip_hop_t *hop, const struct addrinfo *addr);
belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listening_point_t *ip, const belle_sip_hop_t *hop);
void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
......@@ -104,6 +110,15 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_listening_point_t * belle_sip_tls_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_tls_listening_point_t* lp, const char *bindip, int localport,const char *cname, const char *name, int port);
/*tunnel*/
#ifdef HAVE_TUNNEL
typedef struct belle_sip_tunnel_listening_point belle_sip_tunnel_listening_point_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tunnel_listening_point_t,belle_sip_listening_point_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_TUNNEL_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_tunnel_listening_point_t)
belle_sip_channel_t * belle_sip_channel_new_tunnel(belle_sip_stack_t *s, void *tunnelclient, const char *bindip, int localport, const char *name, int port);
#endif
#include "transports/stream_channel.h"
#endif /* LISTENINGPOINT_INTERNAL_H_ */
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010-2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define DNS_H /* do not include dns.h in a CPP file! */
#include "belle_sip_internal.h"
#include "channel.h"
#ifdef HAVE_TUNNEL
#include <tunnel/client.hh>
#define TUNNEL_POLLING_DURATION 20 /* in ms */
using namespace belledonnecomm;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tunnel_channel_t, belle_sip_channel_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
struct belle_sip_tunnel_channel {
belle_sip_channel_t base;
belle_sip_source_t *pollingtimer;
TunnelClient *tunnelclient;
TunnelSocket *tunnelsocket;
};
typedef struct belle_sip_tunnel_channel belle_sip_tunnel_channel_t;
static int tunnel_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
int err;
err = chan->tunnelsocket->sendto(buf, buflen, obj->peer->ai_addr, obj->peer->ai_addrlen);
return err;
}
static int tunnel_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
int err;
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
err = chan->tunnelsocket->recvfrom(buf, buflen, (struct sockaddr *)&addr, addrlen);
return err;
}
static int tunnel_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai) {
struct sockaddr_storage laddr;
socklen_t lslen = sizeof(laddr);
if (obj->local_ip == NULL) {
belle_sip_get_src_addr_for(ai->ai_addr, ai->ai_addrlen, (struct sockaddr *)&laddr, &lslen, obj->local_port);
belle_sip_address_remove_v4_mapping((struct sockaddr *)&laddr, (struct sockaddr *)&laddr, &lslen);
}
belle_sip_channel_set_ready(obj, (struct sockaddr *)&laddr, lslen);
return 0;
}
static void tunnel_channel_close(belle_sip_channel_t *obj) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
chan->tunnelclient->closeSocket(chan->tunnelsocket);
chan->tunnelsocket = NULL;
}
static void tunnel_channel_uninit(belle_sip_channel_t *obj) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
if (chan->tunnelsocket != NULL) {
tunnel_channel_close(obj);
}
if (chan->pollingtimer != NULL) {
belle_sip_main_loop_remove_source(obj->stack->ml, chan->pollingtimer);
belle_sip_object_unref(chan->pollingtimer);
chan->pollingtimer = NULL;
}
}
static int tunnel_polling_timer(belle_sip_tunnel_channel_t *chan) {
if ((chan->tunnelsocket != NULL) && chan->tunnelsocket->hasData()) {
belle_sip_channel_process_data(reinterpret_cast<belle_sip_channel_t *>(chan), BELLE_SIP_EVENT_READ);
}
return BELLE_SIP_CONTINUE;
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_tunnel_channel_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tunnel_channel_t)=
{
{
{
BELLE_SIP_VPTR_INIT(belle_sip_tunnel_channel_t,belle_sip_channel_t,FALSE),
(belle_sip_object_destroy_t)tunnel_channel_uninit,
NULL,
NULL
},
"UDP",
0, /*is_reliable*/
tunnel_channel_connect,
tunnel_channel_send,
tunnel_channel_recv,
tunnel_channel_close
}
};
belle_sip_channel_t * belle_sip_channel_new_tunnel(belle_sip_stack_t *stack, void *tunnelclient, const char *bindip, int localport, const char *dest, int port){
belle_sip_tunnel_channel_t *obj = belle_sip_object_new(belle_sip_tunnel_channel_t);
belle_sip_channel_init((belle_sip_channel_t*)obj, stack, bindip, localport, NULL, dest, port);
obj->tunnelclient = static_cast<TunnelClient *>(tunnelclient);
obj->tunnelsocket = obj->tunnelclient->createSocket(5060, 6060);
obj->pollingtimer = belle_sip_timeout_source_new((belle_sip_source_func_t)tunnel_polling_timer, obj, TUNNEL_POLLING_DURATION);
belle_sip_object_set_name((belle_sip_object_t*)obj->pollingtimer, "tunnel_polling_timer");
belle_sip_main_loop_add_source(stack->ml, obj->pollingtimer);
return (belle_sip_channel_t*)obj;
}
#endif
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010-2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define DNS_H /* do not include dns.h in a CPP file! */
#include "belle_sip_internal.h"
#ifdef HAVE_TUNNEL
#include <tunnel/client.hh>
using namespace belledonnecomm;
struct belle_sip_tunnel_listening_point{
belle_sip_listening_point_t base;
TunnelClient *tunnelclient;
};
static belle_sip_channel_t *tunnel_create_channel(belle_sip_listening_point_t *lp, const belle_sip_hop_t *hop){
belle_sip_channel_t *chan=belle_sip_channel_new_tunnel(lp->stack, ((belle_sip_tunnel_listening_point_t*)lp)->tunnelclient,
belle_sip_uri_get_host(lp->listening_uri), belle_sip_uri_get_port(lp->listening_uri),
hop->host, hop->port);
return chan;
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_tunnel_listening_point_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tunnel_listening_point_t)={
{
{
BELLE_SIP_VPTR_INIT(belle_sip_tunnel_listening_point_t, belle_sip_listening_point_t,TRUE),
NULL,
NULL,
NULL
},
"UDP",
tunnel_create_channel
}
};
static void belle_sip_tunnel_listening_point_init(belle_sip_tunnel_listening_point_t *lp, belle_sip_stack_t *s, TunnelClient *tunnelclient) {
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,"0.0.0.0",5060);
lp->tunnelclient = tunnelclient;
}
belle_sip_listening_point_t * belle_sip_tunnel_listening_point_new(belle_sip_stack_t *s, void *tunnelclient){
belle_sip_tunnel_listening_point_t *lp=belle_sip_object_new(belle_sip_tunnel_listening_point_t);
belle_sip_tunnel_listening_point_init(lp,s,static_cast<TunnelClient *>(tunnelclient));
return (belle_sip_listening_point_t*)lp;
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment