Commit 73ae5d90 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- TLS API cleanup

- some minor fixes as well
parent 1a90a3cd
/*****************************************************************************
* tls.c
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* Copyright (C) 2004-2005 VideoLAN
* $Id: httpd.c 8263 2004-07-24 09:06:58Z courmisch $
*
* Authors: Remi Denis-Courmont <courmisch@via.ecp.fr>
......@@ -34,13 +34,15 @@ struct tls_t
module_t *p_module;
void *p_sys;
tls_server_t * (*pf_server_create) ( tls_t *, const char *, const char * );
tls_session_t * (*pf_client_create) ( tls_t *, const char * );
tls_server_t * (*pf_server_create) ( tls_t *, const char *,
const char * );
tls_session_t * (*pf_client_create) ( tls_t * );
};
struct tls_server_t
{
tls_t *p_tls;
VLC_COMMON_MEMBERS
void *p_sys;
void (*pf_delete) ( tls_server_t * );
......@@ -53,13 +55,12 @@ struct tls_server_t
struct tls_session_t
{
tls_t *p_tls;
tls_server_t *p_server;
VLC_COMMON_MEMBERS
void *p_sys;
struct virtual_socket_t sock;
int (*pf_handshake) ( tls_session_t *, int );
int (*pf_handshake) ( tls_session_t *, int, const char * );
int (*pf_handshake2) ( tls_session_t * );
void (*pf_close) ( tls_session_t * );
};
......@@ -71,7 +72,6 @@ struct tls_session_t
* Allocates a whole server's TLS credentials.
* Returns NULL on error.
*****************************************************************************/
# define __tls_ServerCreate( a, b, c ) (((tls_t *)a)->pf_server_create (a, b, c))
VLC_EXPORT( tls_server_t *, tls_ServerCreate, ( vlc_object_t *, const char *, const char * ) );
/*****************************************************************************
......@@ -92,20 +92,20 @@ VLC_EXPORT( tls_server_t *, tls_ServerCreate, ( vlc_object_t *, const char *, co
# define tls_ServerAddCRL( a, b ) (((tls_server_t *)a)->pf_add_CRL (a, b))
# define __tls_ServerDelete( a ) (((tls_server_t *)a)->pf_delete ( a ))
VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) );
# define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a))
# define tls_ServerSessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b, NULL))
# define tls_ServerSessionClose( a ) (((tls_session_t *)a)->pf_close (a))
# define __tls_ClientCreate( a, b ) (((tls_t *)a)->pf_client_create (a, b ))
VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, const char *, int ) );
VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, int, const char * ) );
VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
# define tls_SessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b))
# define tls_ClientSessionHandshake( a, b, c ) (((tls_session_t *)a)->pf_handshake (a, b, c))
# define tls_SessionContinueHandshake( a ) (((tls_session_t *)a)->pf_handshake2 (a))
# define tls_SessionClose( a ) (((tls_session_t *)a)->pf_close (a))
/* NOTE: It is assumed that a->sock.p_sys = a */
# define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
......
......@@ -860,7 +860,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
return VLC_EGENERIC;
}
p_sys->p_tls = tls_ClientCreate( VLC_OBJECT(p_access), NULL, p_sys->fd );
p_sys->p_tls = tls_ClientCreate( VLC_OBJECT(p_access), p_sys->fd, NULL );
if( p_sys->p_tls == NULL )
{
msg_Err( p_access, "cannot establish HTTP/SSL session" );
......
This diff is collapsed.
......@@ -1539,7 +1539,7 @@ static void httpd_ClientClean( httpd_client_t *cl )
if( cl->fd >= 0 )
{
if( cl->p_tls != NULL )
tls_SessionClose( cl->p_tls );
tls_ServerSessionClose( cl->p_tls );
net_Close( cl->fd );
cl->fd = -1;
}
......@@ -2480,7 +2480,7 @@ static void httpd_HostThread( httpd_host_t *host )
if( p_tls != NULL)
{
switch ( tls_SessionHandshake( p_tls, fd ) )
switch ( tls_ServerSessionHandshake( p_tls, fd ) )
{
case -1:
msg_Err( host, "Rejecting TLS connection" );
......@@ -2553,6 +2553,9 @@ static void httpd_HostThread( httpd_host_t *host )
}
vlc_mutex_unlock( &host->lock );
}
if( p_tls != NULL )
tls_ServerSessionClose( p_tls );
}
#ifndef HAVE_GETADDRINFO
......
/*****************************************************************************
* tls.c
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* Copyright (C) 2004-2005 VideoLAN
* $Id: httpd.c 8263 2004-07-24 09:06:58Z courmisch $
*
* Authors: Remi Denis-Courmont <courmisch@via.ecp.fr>
......@@ -55,18 +55,18 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
if( psz_key == NULL )
psz_key = psz_cert;
p_server = __tls_ServerCreate( p_tls, psz_cert, psz_key );
p_server = p_tls->pf_server_create( p_tls, psz_cert, psz_key );
if( p_server != NULL )
{
msg_Dbg( p_this, "TLS/SSL provider initialized" );
msg_Dbg( p_tls, "TLS/SSL provider initialized" );
return p_server;
}
else
msg_Err( p_this, "TLS/SSL provider error" );
msg_Err( p_tls, "TLS/SSL provider error" );
module_Unneed( p_tls, p_tls->p_module );
}
else
msg_Err( p_this, "TLS/SSL provider not found" );
msg_Err( p_tls, "TLS/SSL provider not found" );
vlc_object_detach( p_tls );
vlc_object_destroy( p_tls );
......@@ -82,9 +82,9 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
void
tls_ServerDelete( tls_server_t *p_server )
{
tls_t *p_tls = p_server->p_tls;
tls_t *p_tls = (tls_t *)p_server->p_parent;
__tls_ServerDelete( p_server );
p_server->pf_delete( p_server );
module_Unneed( p_tls, p_tls->p_module );
vlc_object_detach( p_tls );
......@@ -99,7 +99,7 @@ tls_ServerDelete( tls_server_t *p_server )
* Returns NULL on error. This is a blocking network operation.
*****************************************************************************/
tls_session_t *
tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
tls_ClientCreate( vlc_object_t *p_this, int fd, const char *psz_hostname )
{
tls_t *p_tls;
tls_session_t *p_session;
......@@ -110,12 +110,14 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
if( p_tls->p_module != NULL )
{
p_session = __tls_ClientCreate( p_tls, psz_ca );
p_session = p_tls->pf_client_create( p_tls );
if( p_session != NULL )
{
int i_val;
for( i_val = tls_SessionHandshake( p_session, fd ); i_val > 0;
for( i_val = tls_ClientSessionHandshake( p_session, fd,
psz_hostname );
i_val > 0;
i_val = tls_SessionContinueHandshake( p_session ) );
if( i_val == 0 )
......@@ -146,9 +148,9 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
void
tls_ClientDelete( tls_session_t *p_session )
{
tls_t *p_tls = p_session->p_tls;
tls_t *p_tls = (tls_t *)p_session->p_parent;
tls_SessionClose( p_session );
p_session->pf_close( p_session );
module_Unneed( p_tls, p_tls->p_module );
vlc_object_detach( p_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