[vlc-commits] ftp: load and unload X.509 certs only once
Rémi Denis-Courmont
git at videolan.org
Tue Jan 12 20:58:13 CET 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jan 11 23:39:44 2016 +0200| [1348cb1c47fcc50b2420ecc18cd1d2ad2e96ee4c] | committer: Rémi Denis-Courmont
ftp: load and unload X.509 certs only once
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1348cb1c47fcc50b2420ecc18cd1d2ad2e96ee4c
---
modules/access/ftp.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/modules/access/ftp.c b/modules/access/ftp.c
index 83f77d2..2297e45 100644
--- a/modules/access/ftp.c
+++ b/modules/access/ftp.c
@@ -286,7 +286,8 @@ static int ftp_RecvCommand( vlc_object_t *obj, access_sys_t *sys,
static int ftp_StartStream( vlc_object_t *, access_sys_t *, uint64_t, bool );
static int ftp_StopStream ( vlc_object_t *, access_sys_t * );
-static void readTLSMode( access_sys_t *p_sys, const char * psz_access )
+static int readTLSMode( vlc_object_t *obj, access_sys_t *p_sys,
+ const char * psz_access )
{
if ( !strncmp( psz_access, "ftps", 4 ) )
p_sys->tlsmode = IMPLICIT;
@@ -294,15 +295,19 @@ static void readTLSMode( access_sys_t *p_sys, const char * psz_access )
if ( !strncmp( psz_access, "ftpes", 5 ) )
p_sys->tlsmode = EXPLICIT;
else
+ {
+ p_sys->p_creds = NULL;
p_sys->tlsmode = NONE;
+ return 0;
+ }
+
+ p_sys->p_creds = vlc_tls_ClientCreate( obj );
+ return (p_sys->p_creds != NULL) ? 0 : -1;
}
static int createCmdTLS( vlc_object_t *p_access, access_sys_t *p_sys, int fd,
const char *psz_session_name )
{
- p_sys->p_creds = vlc_tls_ClientCreate( p_access );
- if( p_sys->p_creds == NULL ) return -1;
-
/* TLS/SSL handshake */
p_sys->cmd.p_tls = vlc_tls_ClientSessionCreate( p_sys->p_creds, fd,
p_sys->url.psz_host,
@@ -320,9 +325,7 @@ static int createCmdTLS( vlc_object_t *p_access, access_sys_t *p_sys, int fd,
static void clearCmdTLS( access_sys_t *p_sys )
{
if ( p_sys->cmd.p_tls ) vlc_tls_SessionDelete( p_sys->cmd.p_tls );
- if ( p_sys->p_creds ) vlc_tls_Delete( p_sys->p_creds );
p_sys->cmd.p_tls = NULL;
- p_sys->p_creds = NULL;
}
static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
@@ -650,7 +653,9 @@ static int InOpen( vlc_object_t *p_this )
p_sys->out = false;
p_sys->offset = 0;
p_sys->size = UINT64_MAX;
- readTLSMode( p_sys, p_access->psz_access );
+
+ if( readTLSMode( p_this, p_sys, p_access->psz_access ) )
+ goto exit_error;
if( parseURL( &p_sys->url, p_access->psz_location, p_sys->tlsmode ) )
goto exit_error;
@@ -707,6 +712,7 @@ error:
exit_error:
vlc_UrlClean( &p_sys->url );
+ vlc_tls_Delete( p_sys->p_creds );
free( p_sys );
return VLC_EGENERIC;
}
@@ -724,7 +730,9 @@ static int OutOpen( vlc_object_t *p_this )
/* Init p_access */
p_sys->data.fd = -1;
p_sys->out = true;
- readTLSMode( p_sys, p_access->psz_access );
+
+ if( readTLSMode( p_this, p_sys, p_access->psz_access ) )
+ goto exit_error;
if( parseURL( &p_sys->url, p_access->psz_path, p_sys->tlsmode ) )
goto exit_error;
@@ -754,6 +762,7 @@ static int OutOpen( vlc_object_t *p_this )
exit_error:
vlc_UrlClean( &p_sys->url );
+ vlc_tls_Delete( p_sys->p_creds );
free( p_sys );
return VLC_EGENERIC;
}
@@ -781,6 +790,7 @@ static void Close( vlc_object_t *p_access, access_sys_t *p_sys )
/* free memory */
vlc_UrlClean( &p_sys->url );
+ vlc_tls_Delete( p_sys->p_creds );
free( p_sys );
}
More information about the vlc-commits
mailing list