/*****************************************************************************
* ftp.c: FTP input module
*****************************************************************************
- * Copyright (C) 2001-2006 the VideoLAN team
+ * Copyright (C) 2001-2006 VLC authors and VideoLAN
* Copyright © 2006 Rémi Denis-Courmont
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr> - original code
* Rémi Denis-Courmont <rem # videolan.org> - EPSV support
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
return 0;
}
+static void FeaturesCheck( void *opaque, const char *feature )
+{
+ bool *unicode = opaque;
+
+ if( strcasestr( feature, "UTF8" ) != NULL )
+ *unicode = true;
+}
+
+static const char *IsASCII( const char *str )
+{
+ int8_t c;
+ for( const char *p = str; (c = *p) != '\0'; p++ )
+ if( c < 0 )
+ return NULL;
+ return str;
+}
+
static int Connect( vlc_object_t *p_access, access_sys_t *p_sys )
{
if( Login( p_access, p_sys ) < 0 )
if( ftp_SendCommand( p_access, p_sys, "EPSV ALL" ) < 0 )
{
msg_Err( p_access, "cannot request extended passive mode" );
- net_Close( p_sys->fd_cmd );
- return -1;
+ goto error;
}
if( ftp_RecvCommand( p_access, p_sys, NULL, NULL ) == 2 )
{
if( net_GetPeerAddress( p_sys->fd_cmd, p_sys->sz_epsv_ip, NULL ) )
- {
- net_Close( p_sys->fd_cmd );
- return -1;
- }
+ goto error;
}
else
{
net_Close( p_sys->fd_cmd );
if( Login( p_access, p_sys ) )
- {
- net_Close( p_sys->fd_cmd );
- return -1;
- }
+ goto error;
+ }
+
+ /* features check */
+ bool unicode = false;
+ if( ftp_SendCommand( p_access, p_sys, "FEAT" ) < 0
+ || ftp_RecvAnswer( p_access, p_sys, NULL, NULL,
+ FeaturesCheck, &unicode ) < 0 )
+ {
+ msg_Err( p_access, "cannot get server features" );
+ goto error;
+ }
+
+ if( (unicode ? IsUTF8 : IsASCII)(p_sys->url.psz_path) == NULL )
+ {
+ msg_Err( p_access, "unsupported path: \"%s\"", p_sys->url.psz_path );
+ goto error;
}
/* check binary mode support */
ftp_RecvCommand( p_access, p_sys, NULL, NULL ) != 2 )
{
msg_Err( p_access, "cannot set binary transfer mode" );
- net_Close( p_sys->fd_cmd );
- return -1;
+ goto error;
}
return 0;
+error:
+ net_Close( p_sys->fd_cmd );
+ return -1;
}
return VLC_EGENERIC; /* ASCII and directory not supported */
}
decode_URI( url->psz_path );
- /* FIXME: check for UTF-8 support, otherwise only ASCII is allowed */
- EnsureUTF8( url->psz_path );
return VLC_SUCCESS;
}