]> git.sesse.net Git - vlc/blobdiff - modules/access/ftp.c
DVB: use utf8_open() so we get O_CLOEXEC right
[vlc] / modules / access / ftp.c
index 268d2cd266e538378796752401fac390c9b58b98..dffea0dd7a0cad40ab772d5cbb55146d72aefe40 100644 (file)
@@ -76,6 +76,7 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_ACCESS )
     add_integer( "ftp-caching", 2 * DEFAULT_PTS_DELAY / 1000, NULL,
                  CACHING_TEXT, CACHING_LONGTEXT, true )
+        change_safe()
     add_string( "ftp-user", "anonymous", NULL, USER_TEXT, USER_LONGTEXT,
                 false )
     add_string( "ftp-pwd", "anonymous@example.com", NULL, PASS_TEXT,
@@ -91,6 +92,7 @@ vlc_module_begin ()
         set_capability( "sout access", 0 )
         set_category( CAT_SOUT )
         set_subcategory( SUBCAT_SOUT_ACO )
+        add_shortcut( "ftp" )
         set_callbacks( OutOpen, OutClose )
 vlc_module_end ()
 
@@ -300,12 +302,20 @@ static int parseURL( vlc_url_t *url, const char *path )
     if( url->i_port <= 0 )
         url->i_port = IPPORT_FTP; /* default port */
 
-    /* FTP URLs are relative to user's default directory (RFC1738)
+    /* FTP URLs are relative to user's default directory (RFC1738 ยง3.2)
     For absolute path use ftp://foo.bar//usr/local/etc/filename */
-
+    /* FIXME: we should issue a series of CWD, one per slash */
     if( url->psz_path && *url->psz_path == '/' )
         url->psz_path++;
 
+    char *type = strstr( url->psz_path, ";type=" );
+    if( type )
+    {
+        *type = '\0';
+        if( strchr( "iI", type[6] ) == NULL )
+            return VLC_EGENERIC; /* ASCII and directory not supported */
+    }
+    decode_URI( url->psz_path );
     return VLC_SUCCESS;
 }
 
@@ -332,12 +342,14 @@ static int InOpen( vlc_object_t *p_this )
         goto exit_error;
 
     /* get size */
-    if( ftp_SendCommand( p_this, p_sys, "SIZE %s", p_sys->url.psz_path ? : "" ) < 0 ||
-        ftp_ReadCommand( p_this, p_sys, NULL, &psz_arg ) != 2 )
+    if( ftp_SendCommand( p_this, p_sys, "SIZE %s", p_sys->url.psz_path
+                                               ? p_sys->url.psz_path : "" ) < 0
+     || ftp_ReadCommand( p_this, p_sys, NULL, &psz_arg ) != 2 )
     {
         msg_Dbg( p_access, "cannot get file size" );
         msg_Dbg( p_access, "will try to get directory contents" );
-        if( ftp_SendCommand( p_this, p_sys, "CWD %s", p_sys->url.psz_path ?: "" ) < 0 ||
+        if( ftp_SendCommand( p_this, p_sys, "CWD %s", p_sys->url.psz_path
+                             ? p_sys->url.psz_path : "" ) < 0 ||
         ftp_ReadCommand( p_this, p_sys, NULL, &psz_arg ) != 2 )
         {
             msg_Err( p_access, "file or directory doesn't exist" );
@@ -797,8 +809,8 @@ static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
         /* "1xx" message */
         if( ftp_SendCommand( p_access, p_sys, "%s %s",
                              p_sys->out ? "STOR" : "RETR",
-                             p_sys->url.psz_path ?: "" ) < 0 ||
-            ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) > 2 )
+                           p_sys->url.psz_path ? p_sys->url.psz_path : "" ) < 0
+         || ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) > 2 )
         {
             msg_Err( p_access, "cannot retrieve file" );
             return VLC_EGENERIC;