]> git.sesse.net Git - vlc/blob - modules/access/dsm/access.c
6e30adc13970b181c2268eb4b729480a8d210a55
[vlc] / modules / access / dsm / access.c
1 /*****************************************************************************
2  * bdsm/access.c: liBDSM based SMB/CIFS access module
3  *****************************************************************************
4  * Copyright (C) 2001-2014 VLC authors and VideoLAN
5  *
6  * Authors: Julien 'Lta' BALLET <contact # lta 'dot' io>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_services_discovery.h>
33 #include <vlc_url.h>
34 #include <vlc_access.h>
35 #include <vlc_variables.h>
36 #include <vlc_dialog.h>
37
38 #include <string.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42 #include <netdb.h>
43
44 #include <bdsm/bdsm.h>
45
46 /*****************************************************************************
47  * Module descriptor
48  *****************************************************************************/
49 int bdsm_SdOpen( vlc_object_t * );
50 void bdsm_SdClose( vlc_object_t * );
51 int bdsm_sd_probe_Open( vlc_object_t * );
52
53 static int Open( vlc_object_t * );
54 static void Close( vlc_object_t * );
55
56 #define vlc_sd_probe_Open bdsm_sd_probe_Open
57
58 #define USER_TEXT N_("Username")
59 #define USER_LONGTEXT N_("Username that will be used for the connection, " \
60         "if no username is set in the URL.")
61 #define PASS_TEXT N_("Password")
62 #define PASS_LONGTEXT N_("Password that will be used for the connection, " \
63         "if no username or password are set in URL.")
64 #define DOMAIN_TEXT N_("SMB domain")
65 #define DOMAIN_LONGTEXT N_("Domain/Workgroup that " \
66     "will be used for the connection. Domain of uri will also be tried.")
67
68 #define BDSM_LOGIN_DIALOG_RETRY 1
69
70 #define BDSM_HELP N_("libdsm's SMB (Windows network shares) input and browser")
71
72 vlc_module_begin ()
73     set_shortname( "dsm" )
74     set_description( N_("libdsm SMB input") )
75     set_help(BDSM_HELP)
76     set_capability( "access", 20 )
77     set_category( CAT_INPUT )
78     set_subcategory( SUBCAT_INPUT_ACCESS )
79     add_string( "smb-user", NULL, USER_TEXT, USER_LONGTEXT, false )
80     add_password( "smb-pwd", NULL, PASS_TEXT, PASS_LONGTEXT, false )
81     add_string( "smb-domain", NULL, DOMAIN_TEXT, DOMAIN_LONGTEXT, false )
82     add_shortcut( "smb", "cifs" )
83     set_callbacks( Open, Close )
84
85     add_submodule()
86         set_category( CAT_PLAYLIST )
87         set_subcategory( SUBCAT_PLAYLIST_SD )
88         set_capability( "services_discovery", 0 )
89         set_callbacks( bdsm_SdOpen, bdsm_SdClose )
90
91         VLC_SD_PROBE_SUBMODULE
92
93 vlc_module_end ()
94
95 /*****************************************************************************
96  * Local prototypes
97  *****************************************************************************/
98 static ssize_t Read( access_t *, uint8_t *, size_t );
99 static int Seek( access_t *, uint64_t );
100 static int Control( access_t *, int, va_list );
101 static int BrowserInit( access_t *p_access );
102
103 static void split_domain_login( char **psz_login, char **psz_domain );
104 static void get_credentials( access_t *p_access );
105 static int get_address( access_t *p_access );
106 static void login_dialog( access_t *p_access );
107 static int login( access_t *p_access );
108 static void backslash_path( vlc_url_t *p_url );
109 static bool get_path( access_t *p_access );
110 static int add_item( access_t *p_access,  input_item_node_t *p_node,
111                      const char *psz_name );
112
113 struct access_sys_t
114 {
115     netbios_ns         *p_ns;               /**< Netbios name service */
116     smb_session        *p_session;          /**< bdsm SMB Session object */
117     smb_creds           creds;              /**< Credentials used to connect */
118
119     vlc_url_t           url;
120     char               *psz_share;
121     char               *psz_path;
122
123     char                netbios_name[16];
124     struct in_addr      addr;
125
126     smb_fd              i_fd;               /**< SMB fd for the file we're reading */
127     smb_tid             i_tid;              /**< SMB Tree ID we're connected to */
128     bool                b_is_browsing;
129 };
130
131 /*****************************************************************************
132  * Dialog strings
133  *****************************************************************************/
134 #define BDSM_LOGIN_DIALOG_TITLE N_( "%s: Authentication required" )
135 #define BDSM_LOGIN_DIALOG_TEXT N_( "The computer you are trying to connect "   \
136     "to requires authentication.\n Please provide a username (and ideally a "  \
137     "domain name using the format DOMAIN\\username)\n and a password." )
138
139 /*****************************************************************************
140  * Open: Initialize module's data structures and libdsm
141  *****************************************************************************/
142 static int Open( vlc_object_t *p_this )
143 {
144     access_t     *p_access = (access_t*)p_this;
145     access_sys_t *p_sys;
146     smb_stat st;
147
148     /* Init p_access */
149     access_InitFields( p_access );
150     p_sys = p_access->p_sys = (access_sys_t*)calloc( 1, sizeof( access_sys_t ) );
151     if( p_access->p_sys == NULL )
152         return VLC_ENOMEM;
153
154     p_sys->p_ns = netbios_ns_new();
155     if( p_sys->p_ns == NULL )
156         goto error;
157
158     p_sys->p_session = smb_session_new();
159     if( p_sys->p_session == NULL )
160         goto error;
161
162     vlc_UrlParse( &p_sys->url, p_access->psz_location, 0 );
163     get_credentials( p_access );
164     if( get_address( p_access ) != VLC_SUCCESS )
165         goto error;
166
167     msg_Dbg( p_access, "Creds: username = %s, domain = %s",
168              p_sys->creds.login, p_sys->creds.domain );
169     msg_Dbg( p_access, "Session: Host name = %s, ip = %s", p_sys->netbios_name,
170              inet_ntoa( p_sys->addr ) );
171
172     /* Now that we have the required data, let's establish a session */
173     if( !smb_session_connect( p_sys->p_session, p_sys->netbios_name,
174                               p_sys->addr.s_addr, SMB_TRANSPORT_TCP ) )
175     {
176         msg_Err( p_access, "Unable to connect/negotiate SMB session");
177         goto error;
178     }
179
180     if( login( p_access ) != VLC_SUCCESS )
181         goto error;
182
183     if( !get_path( p_access ) )
184     {
185         p_sys->b_is_browsing = true;
186         return BrowserInit( p_access );
187     }
188
189     msg_Dbg( p_access, "Path: Share name = %s, path = %s", p_sys->psz_share,
190              p_sys->psz_path );
191
192     /* Connect to the share */
193     p_sys->i_tid = smb_tree_connect( p_sys->p_session, p_sys->psz_share );
194     if( !p_sys->i_tid )
195     {
196         msg_Err( p_access, "Unable to connect to share %s", p_sys->psz_share );
197         goto error;
198     }
199
200     /* Let's finally ask a handle to the file we wanna read ! */
201     p_sys->i_fd = smb_fopen( p_sys->p_session, p_sys->i_tid, p_sys->psz_path,
202                              SMB_MOD_RO );
203     if( !p_sys->i_fd )
204     {
205         msg_Err( p_access, "Unable to open file with path %s (in share %s)",
206                  p_sys->psz_path, p_sys->psz_share );
207         goto error;
208     }
209
210     st = smb_stat_fd( p_sys->p_session, p_sys->i_fd );
211     if( smb_stat_get( st, SMB_STAT_ISDIR ) )
212     {
213         smb_fclose( p_sys->p_session, p_sys->i_fd );
214         p_sys->b_is_browsing = true;
215         return BrowserInit( p_access );
216     }
217
218     msg_Dbg( p_access, "Successfully opened smb://%s", p_access->psz_location );
219
220     ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek );
221     return VLC_SUCCESS;
222
223     error:
224         Close( p_this );
225         return VLC_EGENERIC;
226 }
227
228 /*****************************************************************************
229  * Close: free unused data structures
230  *****************************************************************************/
231 static void Close( vlc_object_t *p_this )
232 {
233     access_t     *p_access = (access_t*)p_this;
234     access_sys_t *p_sys = p_access->p_sys;
235
236     if( p_sys->p_ns )
237         netbios_ns_destroy( p_sys->p_ns );
238     if( p_sys->i_fd )
239         smb_fclose( p_sys->p_session, p_sys->i_fd );
240     if( p_sys->p_session )
241         smb_session_destroy( p_sys->p_session );
242     vlc_UrlClean( &p_sys->url );
243     free( p_sys->creds.login );
244     free( p_sys->creds.password );
245     free( p_sys->creds.domain );
246     free( p_sys->psz_share );
247     free( p_sys->psz_path );
248     free( p_sys );
249 }
250
251 /*****************************************************************************
252  * Local functions
253  *****************************************************************************/
254
255 /* Split DOMAIN\User if it finds a '\' in psz_login. */
256 static void split_domain_login( char **psz_login, char **psz_domain )
257 {
258     char *user = strchr( *psz_login, '\\' );
259
260     if( user != NULL )
261     {
262         *psz_domain = *psz_login;
263         *user = '\0';
264         *psz_login = strdup( user + 1 );
265     }
266 }
267
268 /* Get credentials from uri or variables. */
269 static void get_credentials( access_t *p_access )
270 {
271     access_sys_t *p_sys = p_access->p_sys;
272
273     /* Fetch credentials, either from URI or from options if not provided */
274     if( p_sys->url.psz_password == NULL )
275         p_sys->creds.password = var_InheritString( p_access, "smb-pwd" );
276     else
277         p_sys->creds.password = strdup( p_sys->url.psz_password );
278
279     /* Here we support smb://DOMAIN\User:password@XXX, get user from options
280        or default to "Guest" as last resort */
281     if( p_sys->url.psz_username != NULL )
282     {
283         p_sys->creds.login = strdup( p_sys->url.psz_username );
284         split_domain_login( &p_sys->creds.login, &p_sys->creds.domain );
285     }
286     else
287     {
288         p_sys->creds.login = var_InheritString( p_access, "smb-user" );
289         if( p_sys->creds.login == NULL )
290             p_sys->creds.login = strdup( "Guest" );
291     }
292
293     if( p_sys->creds.domain == NULL )
294         p_sys->creds.domain = var_InheritString( p_access, "smb-domain" );
295 }
296
297 /* Returns VLC_EGENERIC if it wasn't able to get an ip address to connect to */
298 static int get_address( access_t *p_access )
299 {
300     access_sys_t *p_sys = p_access->p_sys;
301
302     if( !inet_aton( p_sys->url.psz_host, &p_sys->addr ) )
303     {
304         /* This is not an ip address, let's try netbios/dns resolve */
305         struct addrinfo *p_info = NULL;
306
307         /* Is this a netbios name on this LAN ? */
308         if( netbios_ns_resolve( p_sys->p_ns, p_sys->url.psz_host,
309                                 NETBIOS_FILESERVER,
310                                 &p_sys->addr.s_addr) )
311         {
312             strlcpy( p_sys->netbios_name, p_sys->url.psz_host, 16);
313             return VLC_SUCCESS;
314         }
315         /* or is it an existing dns name ? */
316         else if( getaddrinfo( p_sys->url.psz_host, NULL, NULL, &p_info ) == 0 )
317         {
318             if( p_info->ai_family == AF_INET )
319             {
320                 struct sockaddr_in *in = (struct sockaddr_in *)p_info->ai_addr;
321                 p_sys->addr.s_addr = in->sin_addr.s_addr;
322             }
323             freeaddrinfo( p_info );
324             if( p_info->ai_family != AF_INET )
325                 return VLC_EGENERIC;
326         }
327         else
328             return VLC_EGENERIC;
329     }
330
331     /* We have an IP address, let's find the NETBIOS name */
332     const char *psz_nbt = netbios_ns_inverse( p_sys->p_ns, p_sys->addr.s_addr );
333     if( psz_nbt != NULL )
334         strlcpy( p_sys->netbios_name, psz_nbt, 16 );
335     else
336     {
337         msg_Warn( p_access, "Unable to get netbios name of %s",
338             p_sys->url.psz_host );
339         p_sys->netbios_name[0] = '\0';
340     }
341
342     /* If no domain was explicitly specified, let's use the machine name */
343     if( p_sys->creds.domain == NULL && p_sys->netbios_name[0] )
344         p_sys->creds.domain = strdup( p_sys->netbios_name );
345
346     return VLC_SUCCESS;
347 }
348
349 /* Displays a dialog for the user to enter his/her credentials */
350 static void login_dialog( access_t *p_access )
351 {
352     access_sys_t *p_sys = p_access->p_sys;
353
354     char *psz_login = NULL, *psz_pass = NULL, *psz_title;
355     int i_ret;
356
357     i_ret = asprintf( &psz_title, BDSM_LOGIN_DIALOG_TITLE, p_sys->netbios_name );
358     if( i_ret != -1 )
359         dialog_Login( p_access, &psz_login, &psz_pass, psz_title,
360                       BDSM_LOGIN_DIALOG_TEXT );
361     else
362         dialog_Login( p_access, &psz_login, &psz_pass, BDSM_LOGIN_DIALOG_TITLE,
363                       BDSM_LOGIN_DIALOG_TEXT );
364     free( psz_title );
365
366     if( psz_login != NULL )
367     {
368         if( p_sys->creds.login != NULL )
369             free( p_sys->creds.login );
370         p_sys->creds.login = psz_login;
371         split_domain_login( &p_sys->creds.login, &p_sys->creds.domain );
372     }
373
374     if( psz_pass != NULL )
375     {
376         if( p_sys->creds.password != NULL )
377             free( p_sys->creds.password );
378         p_sys->creds.password = psz_pass;
379     }
380 }
381
382 /* Performs login with existing credentials and ask the user for new ones on
383    failure */
384 static int login( access_t *p_access )
385 {
386     access_sys_t *p_sys = p_access->p_sys;
387
388     if( p_sys->creds.login == NULL )
389         p_sys->creds.login = strdup( "Guest" );
390     if( p_sys->creds.password == NULL )
391         p_sys->creds.password = strdup( "Guest" );
392     if( p_sys->creds.domain == NULL )
393         p_sys->creds.domain = strdup( "WORKGROUP" );
394
395     /* Try to authenticate on the remote machine */
396     smb_session_set_creds( p_sys->p_session, p_sys->creds.domain,
397                            p_sys->creds.login, p_sys->creds.password );
398     if( !smb_session_login( p_sys->p_session ) )
399     {
400         for( int i = 0; i < BDSM_LOGIN_DIALOG_RETRY; i++ )
401         {
402             login_dialog( p_access );
403             smb_session_set_creds( p_sys->p_session, p_sys->creds.domain,
404                                    p_sys->creds.login, p_sys->creds.password );
405             if( smb_session_login( p_sys->p_session ) )
406                 return VLC_SUCCESS;
407         }
408
409         /* FIXME, Try to force netbios name as domain then WORKGROUP here */
410         msg_Err( p_access, "Unable to login with username = %s, domain = %s",
411                    p_sys->creds.login, p_sys->creds.domain );
412         return VLC_EGENERIC;
413     }
414     else if( smb_session_is_guest( p_sys->p_session ) == 1 )
415         msg_Warn( p_access, "Login failure but you were logged in as a Guest");
416
417     return VLC_SUCCESS;
418 }
419
420 static void backslash_path( vlc_url_t *p_url )
421 {
422     char *iter = p_url->psz_path;
423
424     /* Let's switch the path delimiters from / to \ */
425     while( *iter != '\0' )
426     {
427         if( *iter == '/' )
428             *iter = '\\';
429         iter++;
430     }
431 }
432
433 /* Get the share and filepath from uri (also replace all / by \ in url.psz_path) */
434 static bool get_path( access_t *p_access )
435 {
436     access_sys_t *p_sys = p_access->p_sys;
437     char *iter;
438
439     if( p_sys->url.psz_path == NULL )
440         return false;
441
442     backslash_path( &p_sys->url );
443
444     /* Is path longer than just "/" ? */
445     if( strlen( p_sys->url.psz_path ) > 1 )
446     {
447         iter = p_sys->url.psz_path;
448         while( *iter == '\\' ) iter++; /* Handle smb://Host/////Share/ */
449
450         p_sys->psz_share = strdup( iter );
451         if ( p_sys->psz_share == NULL )
452             return false;
453     }
454     else
455     {
456         msg_Dbg( p_access, "no share, nor file path provided, will switch to browser");
457         return false;
458     }
459
460
461     iter = strchr( p_sys->psz_share, '\\' );
462     if( iter == NULL || strlen(iter + 1) == 0 )
463     {
464         if( iter != NULL ) /* Remove the trailing \ */
465             *iter = '\0';
466         p_sys->psz_path = strdup( "" );
467
468         msg_Dbg( p_access, "no file path provided, will switch to browser ");
469         return true;
470     }
471
472     p_sys->psz_path = strdup( iter + 1); /* Skip the first \ */
473     *iter = '\0';
474     if( p_sys->psz_path == NULL )
475         return false;
476
477     return true;
478 }
479
480 /*****************************************************************************
481  * Seek: try to go at the right place
482  *****************************************************************************/
483 static int Seek( access_t *p_access, uint64_t i_pos )
484 {
485     access_sys_t *p_sys = p_access->p_sys;
486     int64_t      i_ret;
487
488     if( i_pos >= INT64_MAX )
489         return VLC_EGENERIC;
490
491     msg_Dbg( p_access, "seeking to %"PRId64, i_pos );
492
493     /* seek cannot fail in bdsm, but the subsequent read can */
494     i_ret = smb_fseek(p_sys->p_session, p_sys->i_fd, i_pos, SMB_SEEK_SET);
495
496     p_access->info.b_eof = false;
497     p_access->info.i_pos = i_ret;
498
499     return VLC_SUCCESS;
500 }
501
502 /*****************************************************************************
503  * Read:
504  *****************************************************************************/
505 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
506 {
507     access_sys_t *p_sys = p_access->p_sys;
508     int i_read;
509
510     if( p_access->info.b_eof ) return 0;
511
512     i_read = smb_fread( p_sys->p_session, p_sys->i_fd, p_buffer, i_len );
513     if( i_read < 0 )
514     {
515         msg_Err( p_access, "read failed" );
516         return -1;
517     }
518
519     if( i_read == 0 ) p_access->info.b_eof = true;
520     else if( i_read > 0 ) p_access->info.i_pos += i_read;
521
522     return i_read;
523 }
524
525 /*****************************************************************************
526  * Control:
527  *****************************************************************************/
528 static int Control( access_t *p_access, int i_query, va_list args )
529 {
530     switch( i_query )
531     {
532     case ACCESS_CAN_SEEK:
533     case ACCESS_CAN_FASTSEEK:
534     case ACCESS_CAN_PAUSE:
535     case ACCESS_CAN_CONTROL_PACE:
536         *va_arg( args, bool* ) = true;
537         break;
538
539     case ACCESS_GET_SIZE:
540     {
541         smb_stat st = smb_stat_fd( p_access->p_sys->p_session,
542                                    p_access->p_sys->i_fd );
543         *va_arg( args, uint64_t * ) = smb_stat_get( st, SMB_STAT_SIZE );
544         break;
545     }
546     case ACCESS_GET_PTS_DELAY:
547         *va_arg( args, int64_t * ) = INT64_C(1000)
548             * var_InheritInteger( p_access, "network-caching" );
549         break;
550
551     case ACCESS_SET_PAUSE_STATE:
552         /* Nothing to do */
553         break;
554
555     default:
556         return VLC_EGENERIC;
557     }
558
559     return VLC_SUCCESS;
560 }
561
562 static int add_item( access_t *p_access, input_item_node_t *p_node,
563                      const char *psz_name )
564 {
565     access_sys_t *p_sys = p_access->p_sys;
566     input_item_t *p_item;
567     char         *psz_uri, *psz_option;
568     int           i_ret;
569
570     i_ret = asprintf( &psz_uri, "%s/%s", p_node->p_item->psz_uri, psz_name );
571     if( i_ret == -1 )
572         return VLC_ENOMEM;
573
574     p_item = input_item_New( psz_uri, psz_name );
575     free( psz_uri );
576     if( p_item == NULL )
577         return VLC_ENOMEM;
578
579     /* Here we save on the node the credentials that allowed us to login.
580      * That way the user isn't prompted more than once for credentials */
581     i_ret = asprintf( &psz_option, "smb-user=%s", p_sys->creds.login );
582     if( i_ret == -1 )
583         return VLC_ENOMEM;
584     input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
585     free( psz_option );
586
587     i_ret = asprintf( &psz_option, "smb-pwd=%s", p_sys->creds.password );
588     if( i_ret == -1 )
589         return VLC_ENOMEM;
590     input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
591     free( psz_option );
592
593     i_ret = asprintf( &psz_option, "smb-domain=%s", p_sys->creds.domain );
594     if( i_ret == -1 )
595         return VLC_ENOMEM;
596     input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
597     free( psz_option );
598
599     input_item_CopyOptions( p_node->p_item, p_item );
600     i_ret = input_item_node_AppendItem( p_node, p_item ) != NULL ? VLC_SUCCESS
601                                                                  : VLC_EGENERIC;
602
603     input_item_Release( p_item );
604     return i_ret;
605 }
606
607 static int BrowseShare( access_t *p_access, input_item_node_t *p_node )
608 {
609     access_sys_t *p_sys = p_access->p_sys;
610     smb_share_list  shares;
611     const char     *psz_name;
612     size_t          share_count;
613     int             i_ret;
614
615     share_count = smb_share_get_list( p_sys->p_session, &shares );
616     if( !share_count )
617         return VLC_ENOITEM;
618
619     for( size_t i = 0; i < share_count; i++ )
620     {
621         psz_name = smb_share_list_at( shares, i );
622
623         if( psz_name[strlen( psz_name ) - 1] == '$')
624             continue;
625
626         i_ret = add_item( p_access, p_node, psz_name );
627         if( i_ret != VLC_SUCCESS )
628             goto error;
629     }
630
631     smb_share_list_destroy( shares );
632     return VLC_SUCCESS;
633     error:
634         smb_share_list_destroy( shares );
635         return i_ret;
636 }
637
638 static int BrowseDirectory( access_t *p_access, input_item_node_t *p_node )
639 {
640     access_sys_t *p_sys = p_access->p_sys;
641     smb_stat_list   files;
642     smb_stat        st;
643     char           *psz_query;
644     const char     *psz_name;
645     size_t          files_count;
646     int             i_ret;
647
648     if( p_sys->psz_path != NULL )
649     {
650         i_ret = asprintf( &psz_query, "%s\\*", p_sys->psz_path );
651         if( i_ret == -1 )
652             return VLC_ENOMEM;
653         files = smb_find( p_sys->p_session, p_sys->i_tid, psz_query );
654         free( psz_query );
655     }
656     else
657         files = smb_find( p_sys->p_session, p_sys->i_tid, "\\*" );
658
659     if( files == NULL )
660         return VLC_ENOITEM;
661
662     files_count = smb_stat_list_count( files );
663     for( size_t i = 0; i < files_count; i++ )
664     {
665         st = smb_stat_list_at( files, i );
666
667         if( st == NULL ) {
668             i_ret = VLC_ENOITEM;
669             goto error;
670         }
671
672         psz_name = smb_stat_name( st );
673
674         /* Avoid infinite loop */
675         if( !strcmp( psz_name, ".") || !strcmp( psz_name, "..") )
676             continue;
677
678         i_ret = add_item( p_access, p_node, psz_name );
679         if( i_ret != VLC_SUCCESS )
680             goto error;
681     }
682
683     smb_stat_list_destroy( files );
684     return VLC_SUCCESS;
685
686     error:
687         smb_stat_list_destroy( files );
688         return i_ret;
689 }
690
691 static int BrowserControl( access_t *p_access, int i_query, va_list args )
692 {
693     VLC_UNUSED( p_access );
694
695     switch( i_query )
696     {
697         case ACCESS_CAN_SEEK:
698         case ACCESS_CAN_FASTSEEK:
699             *va_arg( args, bool* ) = false;
700             break;
701
702         case ACCESS_CAN_PAUSE:
703         case ACCESS_CAN_CONTROL_PACE:
704             *va_arg( args, bool* ) = true;
705             break;
706
707         case ACCESS_GET_PTS_DELAY:
708             *va_arg( args, int64_t * ) = DEFAULT_PTS_DELAY * 1000;
709             break;
710
711         default:
712             return VLC_EGENERIC;
713      }
714      return VLC_SUCCESS;
715 }
716
717 static int BrowserInit( access_t *p_access )
718 {
719     access_sys_t *p_sys = p_access->p_sys;
720
721     if( p_sys->psz_share == NULL )
722         p_access->pf_readdir = BrowseShare;
723     else
724         p_access->pf_readdir = BrowseDirectory;
725     p_access->pf_control = BrowserControl;
726
727     return VLC_SUCCESS;
728 }