Commit 71e0f389 authored by Ghislain MARY's avatar Ghislain MARY

Fix bug of connection timeout not happening on TLS channel.

The object-oriented architecture was not used correctly for the TLS channel. The call to belle_sip_channel_set_socket was reinitializing the belle_sip_source_t and so erasing the timeout value initialized by stream_channel_connect.
The fix is to just replace the notify callback (that was the only goal of the call to belle_sip_channel_set_socket).
Also added a unit test to check this.
parent eb1bc137
......@@ -243,6 +243,7 @@ struct belle_sip_source{
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t fd, unsigned int events, unsigned int timeout_value_ms);
void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_fd_t fd, unsigned int events, unsigned int timeout_value_ms);
void belle_sip_source_uninit(belle_sip_source_t *s);
void belle_sip_source_set_notify(belle_sip_source_t *s, belle_sip_source_func_t func);
#define belle_list_next(elem) ((elem)->next)
......@@ -174,6 +174,10 @@ void belle_sip_source_uninit(belle_sip_source_t *obj){
void belle_sip_source_set_notify(belle_sip_source_t *s, belle_sip_source_func_t func) {
s->notify = func;
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t sock, unsigned int events, unsigned int timeout_value_ms){
#ifdef WIN32
/*on windows, the fd to poll is not the socket */
......@@ -130,8 +130,7 @@ static int tls_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
static int tls_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
int err= stream_channel_connect((belle_sip_stream_channel_t*)obj,ai);
if (err==0){
belle_sip_socket_t sock=belle_sip_source_get_socket((belle_sip_source_t*)obj);
belle_sip_source_set_notify((belle_sip_source_t *)obj, (belle_sip_source_func_t)tls_process_data);
return 0;
return -1;
......@@ -30,7 +30,7 @@ const char *auth_domain="";
const char *client_auth_domain="";
const char *client_auth_outbound_proxy="";
const char *no_server_running_here=";transport=tcp";
const char *no_response_here="sip:;transport=tcp";
const char *no_response_here="sip:;transport=%s";
const char *test_domain_tls_to_tcp=";transport=tls";
static int is_register_ok;
......@@ -501,17 +501,27 @@ static void test_connection_failure(void){
if (req) belle_sip_object_unref(req);
static void test_connection_too_long(void){
static void test_connection_too_long(const char *transport){
belle_sip_request_t *req;
int orig=belle_sip_stack_get_transport_timeout(stack);
char *no_response_here_with_transport = belle_sip_strdup_printf(no_response_here, transport);
req=try_register_user_at_domain(stack, prov, "TCP",1,"tester","",no_response_here,0);
req=try_register_user_at_domain(stack, prov, transport,1,"tester","",no_response_here_with_transport,0);
if (req) belle_sip_object_unref(req);
static void test_connection_too_long_tcp(void){
static void test_connection_too_long_tls(void){
static void test_tls_to_tcp(void){
belle_sip_request_t *req;
int orig=belle_sip_stack_get_transport_timeout(stack);
......@@ -558,7 +568,8 @@ test_t register_tests[] = {
{ "TLS client cert authentication", test_register_client_authenticated },
{ "Channel inactive", test_register_channel_inactive },
{ "TCP connection failure", test_connection_failure },
{ "TCP connection too long", test_connection_too_long },
{ "TCP connection too long", test_connection_too_long_tcp },
{ "TLS connection too long", test_connection_too_long_tls },
{ "TLS connection to TCP server", test_tls_to_tcp },
{ "Register with DNS SRV failover TCP", register_dns_srv_tcp },
{ "Register with DNS SRV failover TLS", register_dns_srv_tls }
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