[vlc-devel] [PATCH] sftp: fix browsing home directory
Jean-Baptiste Kempf
jb at videolan.org
Mon Mar 7 14:10:57 CET 2016
Applied
On 07 Mar, Petri Hintukainen wrote :
> ( ex. vlc sftp://127.0.0.1 )
> ---
> modules/access/sftp.c | 27 ++++++++++++++++++++++++++-
> 1 file changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/modules/access/sftp.c b/modules/access/sftp.c
> index 6d12958..75df74a 100644
> --- a/modules/access/sftp.c
> +++ b/modules/access/sftp.c
> @@ -90,6 +90,7 @@ struct access_sys_t
> LIBSSH2_SFTP* sftp_session;
> LIBSSH2_SFTP_HANDLE* file;
> uint64_t filesize;
> + char *psz_base_url;
> };
>
>
> @@ -255,6 +256,17 @@ static int Open( vlc_object_t* p_this )
> }
> psz_remote_home[i_ret] = '\0';
> psz_path = psz_remote_home;
> +
> + /* store base url for directory read */
> + char *base = vlc_path2uri( psz_path, "sftp" );
> + if( !base )
> + goto error;
> + if( -1 == asprintf( &p_sys->psz_base_url, "sftp://%s%s", p_access->psz_location, base + 7 ) )
> + {
> + free( base );
> + goto error;
> + }
> + free( base );
> }
> else
> psz_path = url.psz_path;
> @@ -282,6 +294,17 @@ static int Open( vlc_object_t* p_this )
>
> p_access->pf_readdir = DirRead;
> p_access->pf_control = DirControl;
> +
> + if( !p_sys->psz_base_url )
> + {
> + if( asprintf( &p_sys->psz_base_url, "sftp://%s", p_access->psz_location ) == -1 )
> + goto error;
> +
> + /* trim trailing '/' */
> + size_t len = strlen( p_sys->psz_base_url );
> + if( len > 0 && p_sys->psz_base_url[ len - 1 ] == '/' )
> + p_sys->psz_base_url[ len - 1 ] = 0;
> + }
> }
>
> if( !p_sys->file )
> @@ -301,6 +324,7 @@ error:
> libssh2_sftp_close_handle( p_sys->file );
> if( p_sys->ssh_session )
> libssh2_session_free( p_sys->ssh_session );
> + free( p_sys->psz_base_url );
> free( psz_remote_home );
> vlc_UrlClean( &url );
> vlc_credential_clean( &credential );
> @@ -324,6 +348,7 @@ static void Close( vlc_object_t* p_this )
> libssh2_session_free( p_sys->ssh_session );
> net_Close( p_sys->i_socket );
>
> + free( p_sys->psz_base_url );
> free( p_sys );
> }
>
> @@ -456,7 +481,7 @@ static input_item_t* DirRead( access_t *p_access )
> if( psz_uri == NULL )
> continue;
>
> - if( asprintf( &psz_full_uri, "sftp://%s/%s", p_access->psz_location, psz_uri ) == -1 )
> + if( asprintf( &psz_full_uri, "%s/%s", p_sys->psz_base_url, psz_uri ) == -1 )
> {
> free( psz_uri );
> continue;
> --
> 2.5.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
More information about the vlc-devel
mailing list