VLC_EXPORT( char *, decode_URI_duplicate, ( const char *psz ) );
VLC_EXPORT( char *, decode_URI, ( char *psz ) );
VLC_EXPORT( char *, encode_URI_component, ( const char *psz ) );
-VLC_EXPORT( char *, make_URI, ( const char *path ) );
+VLC_EXPORT( char *, make_URI, ( const char *path, const char *scheme ) );
VLC_EXPORT( char *, make_path, ( const char *url ) );
/*****************************************************************************
uri = NULL;
}
else
- uri = make_URI (p_access->psz_filepath);
+ uri = make_URI (p_access->psz_filepath, "file");
if (unlikely(uri == NULL))
goto error;
return ret;
uri:
- return make_URI( psz_mrl );
+ return make_URI( psz_mrl, NULL );
}
bool b_start = !i && !b_enqueue;
input_item_t *p_input;
- char* psz_uri = make_URI( qtu( itemsMRL[i] ) );
+ char* psz_uri = make_URI( qtu( itemsMRL[i] ), "file" );
p_input = input_item_New( p_intf, psz_uri, NULL );
free( psz_uri );
files.sort();
foreach( const QString &file, files )
{
- char* psz_uri = make_URI( qtu( toNativeSeparators(file) ) );
+ char* psz_uri = make_URI( qtu( toNativeSeparators(file) ), NULL );
playlist_Add( THEPL, psz_uri, NULL,
go ? ( PLAYLIST_APPEND | ( i ? PLAYLIST_PREPARSE : PLAYLIST_GO ) )
: ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
**/
void DialogsProvider::playMRL( const QString &mrl )
{
- char* psz_uri = make_URI( qtu(mrl) );
+ char* psz_uri = make_URI( qtu(mrl), NULL );
playlist_Add( THEPL, psz_uri, NULL,
PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
free( psz_uri );
{
if( url.isValid() )
{
- char* psz_uri = make_URI( qtu( url.toString() ) );
+ char* psz_uri = make_URI( qtu( url.toString() ), NULL );
playlist_Add( THEPL, psz_uri, NULL,
PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
PLAYLIST_END, true, pl_Unlocked );
if( !mimeData->hasUrls() && mimeData->hasText() &&
QUrl(mimeData->text()).isValid() )
{
- char *psz_uri = make_URI( qtu( mimeData->text() ) );
+ char *psz_uri = make_URI( qtu( mimeData->text() ), NULL );
playlist_Add( THEPL, psz_uri, NULL,
PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
PLAYLIST_END, true, pl_Unlocked );
if( !pPlaylist )
return;
- char* psz_uri = make_URI( m_name.c_str() );
+ char* psz_uri = make_URI( m_name.c_str(), NULL );
if( !psz_uri )
return;
// }
LoadCatalog();
- char* psz_uri = make_URI( rFileName.c_str() );
+ char* psz_uri = make_URI( rFileName.c_str(), NULL );
m_pStream = stream_UrlNew( pIntf, psz_uri );
free( psz_uri );
fmt_out.i_chroma = VLC_CODEC_RGBA;
- char* psz_uri = make_URI( fileName.c_str() );
+ char* psz_uri = make_URI( fileName.c_str(), NULL );
pPic = image_ReadUrl( pImageHandler, psz_uri, &fmt_in, &fmt_out );
free( psz_uri );
if( vlc_stat( psz_filename, &a ) != -1 )
{
- char *psz_uri = make_URI( psz_filename );
+ char *psz_uri = make_URI( psz_filename, "file" );
if( psz_uri )
{
input_item_SetArtURL( p_item, psz_uri );
!S_ISDIR( st.st_mode ) )
continue;
- char* psz_uri = make_URI( psz_dir );
+ char* psz_uri = make_URI( psz_dir, "file" );
input_item_t* p_root = input_item_New( p_sd, psz_uri, NULL );
if( p_sys->i_type == Picture )
if( !psz_file || !*psz_file )
return VLC_EGENERIC;
- char* psz_uri = make_URI( psz_file );
+ char* psz_uri = make_URI( psz_file, "file" );
input_item_t* p_item = input_item_New( p_sd, psz_uri, NULL );
if( p_sys->i_type == Picture )
if( p_filter->p_sys->p_mask )
picture_Release( p_filter->p_sys->p_mask );
p_image = image_HandlerCreate( p_filter );
- char *psz_url = make_URI( psz_filename );
+ char *psz_url = make_URI( psz_filename, NULL );
p_filter->p_sys->p_mask =
image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
free( psz_url );
memset( &fmt_out, 0, sizeof( video_format_t ) );
fmt_out.i_chroma = VLC_CODEC_YUVA;
p_image = image_HandlerCreate( p_filter );
- char *psz_url = make_URI( psz_filename );
+ char *psz_url = make_URI( psz_filename, NULL );
p_filter->p_sys->p_mask =
image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
free( psz_url );
if( !p_image )
return NULL;
- char *psz_url = make_URI( psz_filename );
+ char *psz_url = make_URI( psz_filename, NULL );
picture_t *p_pic = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
free( psz_url );
image_HandlerDelete( p_image );
libvlc_media_t *libvlc_media_new_path( libvlc_instance_t *p_instance,
const char *path )
{
- char *mrl = make_URI( path );
+ char *mrl = make_URI( path, "file" );
if( unlikely(mrl == NULL) )
{
libvlc_printerr( "Not enough memory" );
free( psz_path );
}
- char *url = make_URI( psz_subtitle );
+ char *url = make_URI( psz_subtitle, "file" );
var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
}
}
- /* TODO: write an internal function of this one, to avoid
- * unnecessary lookups. */
- char *mrl = make_URI( args[n] );
+ char *mrl = make_URI( args[n], NULL );
if( !mrl )
continue;
if( asprintf( &psz_file, "%s" DIR_SEP "%s",
psz_path, psz_filename ) != -1 )
{
- char *psz_uri = make_URI( psz_file );
+ char *psz_uri = make_URI( psz_file, "file" );
if( psz_uri )
{
input_item_SetArtURL( p_item, psz_uri );
if( !psz_filename )
return VLC_EGENERIC;
- char *psz_uri = make_URI( psz_filename );
+ char *psz_uri = make_URI( psz_filename, "file" );
if( !psz_uri )
{
free( psz_filename );
{
input_item_t *p_input;
const char *const psz_option = "meta-file";
- char *psz_uri = make_URI( psz_file );
+ char *psz_uri = make_URI( psz_file, NULL );
if( psz_uri == NULL )
return VLC_EGENERIC;
int playlist_MLLoad( playlist_t *p_playlist )
{
- char *psz_datadir;
- char *psz_uri = NULL;
input_item_t *p_input;
- psz_datadir = config_GetUserDir( VLC_DATA_DIR );
-
+ char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
if( !psz_datadir ) /* XXX: This should never happen */
{
msg_Err( p_playlist, "no data directory, cannot load media library") ;
return VLC_EGENERIC;
}
- if( asprintf( &psz_uri, "%s" DIR_SEP "ml.xspf", psz_datadir ) != -1 )
- { /* loosy check for media library file */
- struct stat st;
- int ret = vlc_stat( psz_uri , &st );
- free( psz_uri );
- if( ret )
- {
- free( psz_datadir );
- return VLC_EGENERIC;
- }
- }
-
- psz_uri = make_URI( psz_datadir );
+ char *psz_file;
+ if( asprintf( &psz_file, "%s" DIR_SEP "ml.xspf", psz_datadir ) != -1 )
+ psz_file = NULL;
free( psz_datadir );
- psz_datadir = psz_uri;
- if( psz_datadir == NULL )
+ if( psz_file == NULL )
+ return VLC_ENOMEM;
+
+ /* loosy check for media library file */
+ struct stat st;
+ int ret = vlc_stat( psz_file, &st );
+ free( psz_file );
+ if( ret )
return VLC_EGENERIC;
- /* Force XSPF demux (psz_datadir was a path, now it is a file URI) */
- if( asprintf( &psz_uri, "file/xspf-open%s/ml.xspf", psz_datadir+4 ) == -1 )
- psz_uri = NULL;
- free( psz_datadir );
- psz_datadir = NULL;
+ char *psz_uri = make_URI( psz_file, "file/xspf-open" );
+ free( psz_file );
if( psz_uri == NULL )
return VLC_ENOMEM;
test (vlc_b64_encode, in, out);
}
+static char *make_URI_def (const char *in)
+{
+ return make_URI (in, NULL);
+}
+
static inline void test_path (const char *in, const char *out)
{
- test (make_URI, in, out);
+ test (make_URI_def, in, out);
}
static inline void test_current_directory_path (const char *in, const char *cwd, const char *out)
int val = asprintf(&expected_result, "file://%s/%s", cwd, out);
assert (val != -1);
- test (make_URI, in, expected_result);
+ test (make_URI_def, in, expected_result);
}
int main (void)
/**
* Convert a file path to an URI.
* If already an URI, return a copy of the string.
- * @path path path to convert (or URI to copy)
+ * @param path path to convert (or URI to copy)
+ * @param scheme URI scheme to use (default is auto: "file", "fd" or "smb")
* @return a nul-terminated URI string (use free() to release it),
* or NULL in case of error
*/
-char *make_URI (const char *path)
+char *make_URI (const char *path, const char *scheme)
{
if (path == NULL)
return NULL;
- if (!strcmp (path, "-"))
+ if (scheme == NULL && !strcmp (path, "-"))
return strdup ("fd://0"); // standard input
if (strstr (path, "://") != NULL)
return strdup (path); /* Already an URI */
#ifdef WIN32
if (isalpha (path[0]) && (path[1] == ':'))
{
- if (asprintf (&buf, "file:///%c:", path[0]) == -1)
+ if (asprintf (&buf, "%s:///%c:", scheme, path[0]) == -1)
buf = NULL;
path += 2;
}
if (!strncmp (path, "\\\\", 2))
{ /* Windows UNC paths */
#ifndef WIN32
+ if (scheme != NULL)
+ return NULL; /* remote files not supported */
+
/* \\host\share\path -> smb://host/share/path */
if (strchr (path + 2, '\\') != NULL)
{ /* Convert backslashes to slashes */
if (dup[i] == '\\')
dup[i] = DIR_SEP_CHAR;
- char *ret = make_URI (dup);
+ char *ret = make_URI (dup, scheme);
free (dup);
return ret;
}
return NULL;
if (asprintf (&buf, "%s/%s", cwd, path) == -1)
return NULL;
- char *ret = make_URI (buf);
+ char *ret = make_URI (buf, scheme);
free (buf);
return ret;
}
else
- buf = strdup ("file://");
+ if (asprintf (&buf, "%s://", scheme ? scheme : "file") == -1)
+ buf = NULL;
if (buf == NULL)
return NULL;
i_options++;
}
- char *psz_URI = make_URI( ppsz_argv[i_opt] );
+ char *psz_URI = make_URI( ppsz_argv[i_opt], NULL );
playlist_AddExt( p_playlist, psz_URI,
NULL, PLAYLIST_APPEND |
( ( i_opt || p_data->enqueue ) ? 0 : PLAYLIST_GO ),