Commit 626d0aed authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Common disconnection code in Disconnect()

parent fd520c5d
...@@ -156,6 +156,7 @@ static int Control( access_t *, int, va_list ); ...@@ -156,6 +156,7 @@ static int Control( access_t *, int, va_list );
static void ParseURL( access_sys_t *, char *psz_url ); static void ParseURL( access_sys_t *, char *psz_url );
static int Connect( access_t *, int64_t ); static int Connect( access_t *, int64_t );
static int Request( access_t *p_access, int64_t i_tell ); static int Request( access_t *p_access, int64_t i_tell );
static void Disconnect( access_t * );
/***************************************************************************** /*****************************************************************************
* Open: * Open:
...@@ -354,11 +355,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -354,11 +355,7 @@ static int Open( vlc_object_t *p_this )
if( p_sys->psz_user ) free( p_sys->psz_user ); if( p_sys->psz_user ) free( p_sys->psz_user );
if( p_sys->psz_passwd ) free( p_sys->psz_passwd ); if( p_sys->psz_passwd ) free( p_sys->psz_passwd );
/* FIXME: cleanup SSL */ Disconnect( p_access );
if( p_sys->fd > 0 )
{
net_Close( p_sys->fd );
}
free( p_sys ); free( p_sys );
/* Do new Open() run with new data */ /* Do new Open() run with new data */
...@@ -410,12 +407,7 @@ error: ...@@ -410,12 +407,7 @@ error:
if( p_sys->psz_user ) free( p_sys->psz_user ); if( p_sys->psz_user ) free( p_sys->psz_user );
if( p_sys->psz_passwd ) free( p_sys->psz_passwd ); if( p_sys->psz_passwd ) free( p_sys->psz_passwd );
if( p_sys->p_tls != NULL ) Disconnect( p_access );
tls_ClientDelete( p_sys->p_tls );
if( p_sys->fd > 0 )
{
net_Close( p_sys->fd );
}
free( p_sys ); free( p_sys );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -444,12 +436,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -444,12 +436,7 @@ static void Close( vlc_object_t *p_this )
if( p_sys->psz_user_agent ) free( p_sys->psz_user_agent ); if( p_sys->psz_user_agent ) free( p_sys->psz_user_agent );
if( p_sys->p_tls != NULL ) Disconnect( p_access );
tls_ClientDelete( p_sys->p_tls );
if( p_sys->fd > 0 )
{
net_Close( p_sys->fd );
}
free( p_sys ); free( p_sys );
} }
...@@ -572,13 +559,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ) ...@@ -572,13 +559,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
if( p_sys->b_reconnect ) if( p_sys->b_reconnect )
{ {
msg_Dbg( p_access, "got disconnected, trying to reconnect" ); msg_Dbg( p_access, "got disconnected, trying to reconnect" );
if( p_sys->p_tls != NULL ) Disconnect( p_access );
{
tls_ClientDelete( p_sys->p_tls );
p_sys->p_tls = NULL;
p_sys->p_vs = NULL;
}
net_Close( p_sys->fd ); p_sys->fd = -1;
if( Connect( p_access, p_access->info.i_pos ) ) if( Connect( p_access, p_access->info.i_pos ) )
{ {
msg_Dbg( p_access, "reconnection failed" ); msg_Dbg( p_access, "reconnection failed" );
...@@ -673,17 +654,9 @@ static int ReadICYMeta( access_t *p_access ) ...@@ -673,17 +654,9 @@ static int ReadICYMeta( access_t *p_access )
*****************************************************************************/ *****************************************************************************/
static int Seek( access_t *p_access, int64_t i_pos ) static int Seek( access_t *p_access, int64_t i_pos )
{ {
access_sys_t *p_sys = p_access->p_sys;
msg_Dbg( p_access, "trying to seek to "I64Fd, i_pos ); msg_Dbg( p_access, "trying to seek to "I64Fd, i_pos );
if( p_sys->p_tls != NULL ) Disconnect( p_access );
{
tls_ClientDelete( p_sys->p_tls );
p_sys->p_tls = NULL;
p_sys->p_vs = NULL;
}
net_Close( p_sys->fd ); p_sys->fd = -1;
if( Connect( p_access, i_pos ) ) if( Connect( p_access, i_pos ) )
{ {
...@@ -864,8 +837,7 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -864,8 +837,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
if( p_sys->b_proxy ) if( p_sys->b_proxy )
{ {
msg_Err( p_access, "HTTP/SSL through HTTP proxy not supported yet" ); msg_Err( p_access, "HTTP/SSL through HTTP proxy not supported yet" );
net_Close( p_sys->fd ); Disconnect( p_access );
p_sys->fd = -1;
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -873,8 +845,7 @@ static int Connect( access_t *p_access, int64_t i_tell ) ...@@ -873,8 +845,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
if( p_sys->p_tls == NULL ) if( p_sys->p_tls == NULL )
{ {
msg_Err( p_access, "cannot establish HTTP/SSL session" ); msg_Err( p_access, "cannot establish HTTP/SSL session" );
net_Close( p_sys->fd ); Disconnect( p_access );
p_sys->fd = -1;
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_sys->p_vs = &p_sys->p_tls->sock; p_sys->p_vs = &p_sys->p_tls->sock;
...@@ -973,13 +944,7 @@ static int Request( access_t *p_access, int64_t i_tell ) ...@@ -973,13 +944,7 @@ static int Request( access_t *p_access, int64_t i_tell )
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "\r\n" ) < 0 ) if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "\r\n" ) < 0 )
{ {
msg_Err( p_access, "failed to send request" ); msg_Err( p_access, "failed to send request" );
if( p_sys->p_tls != NULL ) Disconnect( p_access );
{
tls_ClientDelete( p_sys->p_tls );
p_sys->p_tls = NULL;
p_sys->p_vs = NULL;
}
net_Close( p_sys->fd ); p_sys->fd = -1;
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -1152,14 +1117,27 @@ static int Request( access_t *p_access, int64_t i_tell ) ...@@ -1152,14 +1117,27 @@ static int Request( access_t *p_access, int64_t i_tell )
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
if( p_sys->p_tls != NULL ) Disconnect( p_access );
return VLC_EGENERIC;
}
/*****************************************************************************
* Disconnect:
*****************************************************************************/
static void Disconnect( access_t *p_access )
{
access_sys_t *p_sys = p_access->p_sys;
if( p_sys->p_tls != NULL)
{ {
tls_ClientDelete( p_sys->p_tls ); tls_ClientDelete( p_sys->p_tls );
p_sys->p_tls = NULL; p_sys->p_tls = NULL;
p_sys->p_vs = NULL; p_sys->p_vs = NULL;
} }
if( p_sys->fd != -1)
{
net_Close(p_sys->fd);
p_sys->fd = -1;
}
net_Close( p_sys->fd ); p_sys->fd = -1;
return VLC_EGENERIC;
} }
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