Esempio n. 1
0
static int BrowseDirectory( stream_t *p_access, input_item_node_t *p_node )
{
    access_sys_t *p_sys = p_access->p_sys;
    smb_stat_list   files;
    smb_stat        st;
    char           *psz_query;
    const char     *psz_name;
    size_t          files_count;
    int             i_ret = VLC_SUCCESS;

    if( p_sys->psz_path != NULL )
    {
        if( asprintf( &psz_query, "%s\\*", p_sys->psz_path ) == -1 )
            return VLC_ENOMEM;
        files = smb_find( p_sys->p_session, p_sys->i_tid, psz_query );
        free( psz_query );
    }
    else
        files = smb_find( p_sys->p_session, p_sys->i_tid, "\\*" );

    if( files == NULL )
        return VLC_EGENERIC;

    struct vlc_readdir_helper rdh;
    vlc_readdir_helper_init( &rdh, p_access, p_node );

    files_count = smb_stat_list_count( files );
    for( size_t i = 0; i < files_count && i_ret == VLC_SUCCESS; i++ )
    {
        int i_type;

        st = smb_stat_list_at( files, i );

        if( st == NULL )
        {
            continue;
        }

        psz_name = smb_stat_name( st );

        i_type = smb_stat_get( st, SMB_STAT_ISDIR ) ?
                 ITEM_TYPE_DIRECTORY : ITEM_TYPE_FILE;
        i_ret = add_item( p_access, &rdh, psz_name, i_type );
    }

    vlc_readdir_helper_finish( &rdh, i_ret == VLC_SUCCESS );

    smb_stat_list_destroy( files );
    return i_ret;
}
Esempio n. 2
0
static input_item_t* BrowseDirectory( access_t *p_access )
{
    access_sys_t *p_sys = p_access->p_sys;
    smb_stat        st;
    input_item_t   *p_item = NULL;
    char           *psz_query;
    const char     *psz_name;
    int             i_ret;

    if( !p_sys->i_browse_count )
    {
        if( p_sys->psz_path != NULL )
        {
            i_ret = asprintf( &psz_query, "%s\\*", p_sys->psz_path );
            if( i_ret == -1 )
                return NULL;
            p_sys->files = smb_find( p_sys->p_session, p_sys->i_tid, psz_query );
            free( psz_query );
        }
        else
            p_sys->files = smb_find( p_sys->p_session, p_sys->i_tid, "\\*" );
        if( p_sys->files == NULL )
            return NULL;
        p_sys->i_browse_count = smb_stat_list_count( p_sys->files );
    }

    if( p_sys->i_browse_idx < p_sys->i_browse_count )
    {
        int i_type;

        st = smb_stat_list_at( p_sys->files, p_sys->i_browse_idx++ );

        if( st == NULL )
            return NULL;

        psz_name = smb_stat_name( st );

        i_type = smb_stat_get( st, SMB_STAT_ISDIR ) ?
                 ITEM_TYPE_DIRECTORY : ITEM_TYPE_FILE;
        p_item = new_item( p_access, psz_name, i_type );
        if( !p_item )
            return NULL;
    }
    return p_item;
}