Commit 8d2e978d authored by jehan's avatar jehan

start tls transport integration

parent c302c988
......@@ -199,7 +199,7 @@
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526;cdt.managedbuild.tool.gnu.c.compiler.input.2089521215">
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
......@@ -242,7 +242,7 @@
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.779699347;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1327025999;cdt.managedbuild.tool.gnu.c.compiler.input.1517483722">
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290;cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526;cdt.managedbuild.tool.gnu.c.compiler.input.2089521215">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
<buildOutputProvider>
......
......@@ -92,7 +92,14 @@ fi
AC_SUBST(ANTLR_CFLAGS)
AC_SUBST(ANTLR_LIBS)
PKG_CHECK_MODULES(GNUTLS, gnutls, [found_gnutls=yes],foo=bar)
AM_CONDITIONAL([BUILD_TLS], [test "x$found_gnutls" = "xyes"])
if test "x$found_gnutls" = "xyes" ; then
AC_DEFINE(HAVE_TLS,1,[Defined when tls api is available])
fi
PKG_CHECK_MODULES(CUNIT, cunit, [found_cunit=yes],[found_cunit=no])
if test "$found_cunit" = "no" ; then
AC_CHECK_HEADERS(CUnit/CUnit.h,
[
......@@ -101,6 +108,7 @@ if test "$found_cunit" = "no" ; then
])
fi
case "$target_os" in
*darwin*)
#hack for macport
......
......@@ -39,9 +39,11 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_datagram_listening_point_t),
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_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_provider_t),
BELLE_SIP_TYPE_ID(belle_sip_main_loop_t),
BELLE_SIP_TYPE_ID(belle_sip_source_t),
......
......@@ -10,7 +10,7 @@
#include "belle-sip/list.h"
/*inherite from belle_sip_parameters_t*/
typedef struct _belle_sip_uri belle_sip_uri_t;
/**
......
......@@ -50,7 +50,11 @@ libbellesip_la_SOURCES= \
transports/udp_listeningpoint.c \
transports/udp_channel.c \
transports/stream_channel.c \
transports/stream_listeningpoint.c
transports/stream_listeningpoint.c \
transports/tls_listeningpoint.c
if BUILD_TLS
libbellesip_la_SOURCES+=transports/tls_channel.c
endif
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS)
......@@ -65,4 +69,4 @@ CLEANFILES=$(generated_src) *.tokens generated_src_stamp
discovery:
touch specs.cpp
$(CC) $(CFLAGS) $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.cpp
$(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) -E -P -v -dD specs.cpp
......@@ -69,7 +69,7 @@ struct belle_sip_main_loop{
};
void belle_sip_main_loop_remove_source(belle_sip_main_loop_t *ml, belle_sip_source_t *source){
if (!source->node.next && !source->node.prev) return; /*nothing to do*/
if (!source->node.next && !source->node.prev && &source->node!=ml->sources) return; /*nothing to do*/
ml->sources=belle_sip_list_remove_link(ml->sources,&source->node);
ml->nsources--;
......
......@@ -84,7 +84,7 @@ void belle_sip_parameters_set_parameter(belle_sip_parameters_t* params,const cha
}
const belle_sip_list_t* belle_sip_parameters_get_parameter_names(belle_sip_parameters_t* params) {
return params->paramnames_list;
return params?params->paramnames_list:NULL;
}
void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* params,const char* name) {
/*1 check if present*/
......
......@@ -68,6 +68,7 @@ typedef struct belle_sip_channel_input_stream{
}belle_sip_channel_input_stream_t;
typedef struct belle_sip_stream_channel belle_sip_stream_channel_t;
typedef struct belle_sip_tls_channel belle_sip_tls_channel_t;
struct belle_sip_channel{
belle_sip_source_t base;
......@@ -93,6 +94,8 @@ belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *sta
belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack, const char *bindip, int localport,const char *name, int port);
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_stack_t *stack, const char *bindip, int localport,const char *name, int port);
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);
......
......@@ -54,4 +54,12 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_STREAM_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_stream_listening_point_t)
belle_sip_listening_point_t * belle_sip_stream_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
/*tls*/
typedef struct belle_sip_tls_listening_point belle_sip_tls_listening_point_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tls_listening_point_t,belle_sip_listening_point_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
#define BELLE_SIP_TLS_LISTENING_POINT(obj) BELLE_SIP_CAST(obj,belle_sip_tls_listening_point_t)
belle_sip_listening_point_t * belle_sip_tls_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port);
#endif /* LISTENINGPOINT_INTERNAL_H_ */
......@@ -26,9 +26,9 @@
#include "belle_sip_internal.h"
#include "belle-sip/mainloop.h"
#include "channel.h"
#include "stream_channel.h"
/*************TCP********/
struct belle_sip_stream_channel{
belle_sip_channel_t base;
......@@ -107,46 +107,50 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_stream_channel_t)=
stream_channel_recv
}
};
static int process_data(belle_sip_channel_t *obj,unsigned int revents){
int finalize_stream_connection (belle_sip_fd_t fd, struct sockaddr *addr, socklen_t* slen) {
int err, errnum;
socklen_t optlen=sizeof(errnum);
err=getsockopt(fd,SOL_SOCKET,SO_ERROR,&errnum,&optlen);
if (err!=0){
belle_sip_error("Failed to retrieve connection status for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string());
return -1;
}else{
if (errnum==0){
/*obtain bind address for client*/
err=getsockname(fd,addr,slen);
if (err<0){
belle_sip_error("Failed to retrieve sockname for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string());
return -1;
}
return 0;
}else{
belle_sip_error("Connection failed for fd [%i]: cause [%s]",fd,belle_sip_get_socket_error_string());
return -1;
}
}
}
static int stream_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
struct sockaddr_storage ss;
socklen_t addrlen=sizeof(ss);
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING && (revents&BELLE_SIP_EVENT_WRITE)) {
err=getsockopt(fd,SOL_SOCKET,SO_ERROR,&errnum,&optlen);
if (err!=0){
belle_sip_error("Failed to retrieve connection status for channel [%p]: cause [%s]",obj,belle_sip_get_socket_error_string());
goto connect_error;
}else{
if (errnum==0){
/*obtain bind address for client*/
struct sockaddr_storage ss;
socklen_t addrlen=sizeof(ss);
err=getsockname(fd,(struct sockaddr*)&ss,&addrlen);
if (err<0){
belle_sip_error("Failed to retrieve sockname for channel [%p]: cause [%s]",obj,belle_sip_get_socket_error_string());
goto connect_error;
}
belle_sip_source_set_event((belle_sip_source_t*)obj,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_channel_set_ready(obj,(struct sockaddr*)&ss,addrlen);
return BELLE_SIP_CONTINUE;
}else{
belle_sip_error("Connection failed for channel [%p]: cause [%s]",obj,belle_sip_get_socket_error_string());
goto connect_error;
}
if (finalize_stream_connection(fd,(struct sockaddr*)&ss,&addrlen)) {
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return BELLE_SIP_STOP;
}
belle_sip_source_set_event((belle_sip_source_t*)obj,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_channel_set_ready(obj,(struct sockaddr*)&ss,addrlen);
return BELLE_SIP_CONTINUE;
} else if ( obj->state == BELLE_SIP_CHANNEL_READY) {
belle_sip_channel_process_data(obj,revents);
} else {
belle_sip_error("Unexpected event [%i], for channel [%p]",revents,obj);
belle_sip_warning("Unexpected event [%i], for channel [%p]",revents,obj);
}
return BELLE_SIP_CONTINUE;
connect_error:
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return BELLE_SIP_STOP;
}
belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack,const char *bindip, int localport, const char *dest, int port){
......@@ -154,7 +158,7 @@ belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack,const c
belle_sip_channel_init((belle_sip_channel_t*)obj
,stack
,socket(AF_INET, SOCK_STREAM, 0)
,(belle_sip_source_func_t)process_data
,(belle_sip_source_func_t)stream_channel_process_data
,bindip,localport,dest,port);
return (belle_sip_channel_t*)obj;
}
......@@ -171,3 +175,5 @@ belle_sip_channel_t * belle_sip_channel_new_tcp(belle_sip_stack_t *stack,const c
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 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/>.
*/
#ifndef STREAM_CHANNEL_H_
#define STREAM_CHANNEL_H_
#include "channel.h"
int stream_channel_connect(belle_sip_channel_t *obj, const struct sockaddr *addr, socklen_t socklen);
/*return 0 if succeed*/
int finalize_stream_connection (belle_sip_fd_t fd, struct sockaddr *addr, socklen_t* slen);
#endif /* STREAM_CHANNEL_H_ */
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 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/>.
*/
#include <sys/socket.h>
#include <netinet/tcp.h>
#include "belle_sip_internal.h"
#include "belle-sip/mainloop.h"
#include "stream_channel.h"
/*************tls********/
struct belle_sip_tls_channel{
belle_sip_channel_t base;
};
static void tls_channel_uninit(belle_sip_tls_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1)
close_socket(sock);
belle_sip_main_loop_remove_source(obj->base.stack->ml,(belle_sip_source_t*)obj);
}
static int tls_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
int err;
err=send(sock,buf,buflen,0);
if (err==-1){
belle_sip_fatal("Could not send tls packet on channel [%p]: %s",obj,strerror(errno));
return -errno;
}
return err;
}
static int tls_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
int err;
err=recv(sock,buf,buflen,MSG_DONTWAIT);
if (err==-1 && errno!=EWOULDBLOCK){
belle_sip_error("Could not receive tls packet: %s",strerror(errno));
return -errno;
}
return err;
}
int tls_channel_connect(belle_sip_channel_t *obj, const struct sockaddr *addr, socklen_t socklen){
return stream_channel_connect(obj,addr,socklen);
}
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tls_channel_t,belle_sip_channel_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_tls_channel_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tls_channel_t)=
{
{
{
BELLE_SIP_VPTR_INIT(belle_sip_tls_channel_t,belle_sip_channel_t,FALSE),
(belle_sip_object_destroy_t)tls_channel_uninit,
NULL,
NULL
},
"TLS",
1, /*is_reliable*/
tls_channel_connect,
tls_channel_send,
tls_channel_recv
}
};
static int process_data(belle_sip_channel_t *obj,unsigned int revents){
struct sockaddr_storage ss;
socklen_t addrlen=sizeof(ss);
belle_sip_fd_t fd=belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (obj->state == BELLE_SIP_CHANNEL_CONNECTING && (revents&BELLE_SIP_EVENT_WRITE)) {
if (finalize_stream_connection(fd,(struct sockaddr*)&ss,&addrlen)) {
belle_sip_error("Cannot connect to [%s://%s:%s]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
channel_process_queue(obj);
return BELLE_SIP_STOP;
}
/*connected, now etablishing TLS connection*/
belle_sip_source_set_event((belle_sip_source_t*)obj,BELLE_SIP_EVENT_READ|BELLE_SIP_EVENT_ERROR);
belle_sip_channel_set_ready(obj,(struct sockaddr*)&ss,addrlen);
return BELLE_SIP_CONTINUE;
} else if ( obj->state == BELLE_SIP_CHANNEL_READY) {
belle_sip_channel_process_data(obj,revents);
} else {
belle_sip_warning("Unexpected event [%i], for channel [%p]",revents,obj);
}
return BELLE_SIP_CONTINUE;
}
belle_sip_channel_t * belle_sip_channel_new_tls(belle_sip_stack_t *stack,const char *bindip, int localport, const char *dest, int port){
belle_sip_tls_channel_t *obj=belle_sip_object_new(belle_sip_tls_channel_t);
belle_sip_channel_init((belle_sip_channel_t*)obj
,stack
,socket(AF_INET, SOCK_STREAM, 0)
,(belle_sip_source_func_t)process_data
,bindip,localport,dest,port);
return (belle_sip_channel_t*)obj;
}
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 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/>.
*/
#include "belle_sip_internal.h"
#include "listeningpoint_internal.h"
#ifdef HAVE_TLS
struct belle_sip_tls_listening_point{
belle_sip_listening_point_t base;
};
static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){
}
static belle_sip_channel_t *tls_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
belle_sip_channel_t *chan=belle_sip_channel_new_tls(lp->stack,lp->addr,lp->port,dest_ip,port);
return chan;
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_tls_listening_point_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tls_listening_point_t)={
{
{
BELLE_SIP_VPTR_INIT(belle_sip_tls_listening_point_t, belle_sip_listening_point_t,FALSE),
(belle_sip_object_destroy_t)belle_sip_tls_listening_point_uninit,
NULL,
NULL
},
"TLS",
tls_create_channel
}
};
#endif
belle_sip_listening_point_t * belle_sip_tls_listening_point_new(belle_sip_stack_t *s, const char *ipaddress, int port){
#ifdef HAVE_TLS
belle_sip_tls_listening_point_t *lp=belle_sip_object_new(belle_sip_tls_listening_point_t);
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,ipaddress,port);
return BELLE_SIP_LISTENING_POINT(lp);
#else
belle_sip_error("Cannot create tls listening point because not compile with TLS support");
return NULL;
#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