Commit 551ad114 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix and simplify client-side API

(failed to release allocated data in some error cases)
parent d68b6075
...@@ -98,13 +98,12 @@ VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) ); ...@@ -98,13 +98,12 @@ VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) );
# define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a)) # define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a))
# define __tls_ClientCreate( a, b ) (((tls_t *)a)->pf_client_create (a, b )) # 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 * ) ); VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, const char *, int ) );
VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) ); VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
# define tls_SessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b)) # define tls_SessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b))
# define tls_SessionClose( a ) (((tls_session_t *)a)->pf_close (a)) # define tls_SessionClose( a ) (((tls_session_t *)a)->pf_close (a))
# define __tls_ClientDelete( a ) tls_SessionClose( a )
/* NOTE: It is assumed that a->sock.p_sys = 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 )) # define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
......
...@@ -78,7 +78,7 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert, ...@@ -78,7 +78,7 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
/***************************************************************************** /*****************************************************************************
* tls_ServerDelete: * tls_ServerDelete:
***************************************************************************** *****************************************************************************
* Releases data allocated with tls_ServerCreate * Releases data allocated with tls_ServerCreate.
*****************************************************************************/ *****************************************************************************/
void void
tls_ServerDelete( tls_server_t *p_server ) tls_ServerDelete( tls_server_t *p_server )
...@@ -96,11 +96,11 @@ tls_ServerDelete( tls_server_t *p_server ) ...@@ -96,11 +96,11 @@ tls_ServerDelete( tls_server_t *p_server )
/***************************************************************************** /*****************************************************************************
* tls_ClientCreate: * tls_ClientCreate:
***************************************************************************** *****************************************************************************
* Allocates a client's TLS credentials. * Allocates a client's TLS credentials and shakes hands through the network.
* Returns NULL on error. * Returns NULL on error.
*****************************************************************************/ *****************************************************************************/
tls_session_t * tls_session_t *
tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca ) tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
{ {
tls_t *p_tls; tls_t *p_tls;
tls_session_t *p_session; tls_session_t *p_session;
...@@ -113,10 +113,16 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca ) ...@@ -113,10 +113,16 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca )
{ {
p_session = __tls_ClientCreate( p_tls, psz_ca ); p_session = __tls_ClientCreate( p_tls, psz_ca );
if( p_session != NULL ) if( p_session != NULL )
{
p_session = tls_SessionHandshake( p_session, fd );
if( p_session != NULL )
{ {
msg_Dbg( p_this, "TLS/SSL provider initialized" ); msg_Dbg( p_this, "TLS/SSL provider initialized" );
return p_session; return p_session;
} }
else
msg_Err( p_this, "TLS/SSL session handshake error" );
}
else else
msg_Err( p_this, "TLS/SSL provider error" ); msg_Err( p_this, "TLS/SSL provider error" );
module_Unneed( p_tls, p_tls->p_module ); module_Unneed( p_tls, p_tls->p_module );
...@@ -133,14 +139,14 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca ) ...@@ -133,14 +139,14 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca )
/***************************************************************************** /*****************************************************************************
* tls_ClientDelete: * tls_ClientDelete:
***************************************************************************** *****************************************************************************
* Releases data allocated with tls_ClientCreate * Releases data allocated with tls_ClientCreate.
*****************************************************************************/ *****************************************************************************/
void void
tls_ClientDelete( tls_session_t *p_session ) tls_ClientDelete( tls_session_t *p_session )
{ {
tls_t *p_tls = p_session->p_tls; tls_t *p_tls = p_session->p_tls;
__tls_ClientDelete( p_session ); tls_SessionClose( p_session );
module_Unneed( p_tls, p_tls->p_module ); module_Unneed( p_tls, p_tls->p_module );
vlc_object_detach( p_tls ); 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