Commit 1644d683 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

make_URI: add scheme parameter

parent a0112f4b
......@@ -48,7 +48,7 @@ struct vlc_url_t
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 ) );
/*****************************************************************************
......
......@@ -122,7 +122,7 @@ int DirInit (access_t *p_access, DIR *handle)
uri = NULL;
}
else
uri = make_URI (p_access->psz_filepath);
uri = make_URI (p_access->psz_filepath, "file");
if (unlikely(uri == NULL))
goto error;
......
......@@ -238,5 +238,5 @@ char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
return ret;
uri:
return make_URI( psz_mrl );
return make_URI( psz_mrl, NULL );
}
......@@ -338,7 +338,7 @@ void OpenDialog::finish( bool b_enqueue = false )
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 );
......
......@@ -436,7 +436,7 @@ void DialogsProvider::addFromSimple( bool pl, bool go)
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 ),
......@@ -719,7 +719,7 @@ void DialogsProvider::SDMenuAction( const QString& data )
**/
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 );
......
......@@ -1059,7 +1059,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
{
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 );
......@@ -1075,7 +1075,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
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 );
......
......@@ -37,7 +37,7 @@ void CmdAddItem::execute()
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;
......
......@@ -55,7 +55,7 @@ XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName,
// }
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 );
......
......@@ -42,7 +42,7 @@ FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
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 );
......
......@@ -116,7 +116,7 @@ static int FindMeta( vlc_object_t *p_this )
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 );
......
......@@ -190,7 +190,7 @@ static void *Run( void *data )
!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 )
......@@ -268,7 +268,7 @@ static int onNewFileAdded( vlc_object_t *p_this, char const *psz_var,
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 )
......
......@@ -182,7 +182,7 @@ static void LoadMask( filter_t *p_filter, const char *psz_filename )
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 );
......
......@@ -105,7 +105,7 @@ static void LoadMask( filter_t *p_filter, const char *psz_filename )
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 );
......
......@@ -615,7 +615,7 @@ static picture_t *LoadImage( vlc_object_t *p_this, const char *psz_filename )
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 );
......
......@@ -328,7 +328,7 @@ libvlc_media_t *libvlc_media_new_location( libvlc_instance_t *p_instance,
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" );
......
......@@ -3167,7 +3167,7 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_for
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 );
......
......@@ -1163,9 +1163,7 @@ static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
}
}
/* 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;
......
......@@ -178,7 +178,7 @@ int playlist_FindArtInCache( input_item_t *p_item )
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 );
......@@ -208,7 +208,7 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
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 );
......
......@@ -86,7 +86,7 @@ int playlist_Import( playlist_t *p_playlist, const char *psz_file )
{
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;
......@@ -118,41 +118,31 @@ static void input_item_subitem_tree_added( const vlc_event_t * p_event,
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;
......
......@@ -68,9 +68,14 @@ static inline void test_b64 (const char *in, const char *out)
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)
......@@ -79,7 +84,7 @@ static inline void test_current_directory_path (const char *in, const char *cwd,
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)
......
......@@ -1034,15 +1034,16 @@ void path_sanitize( char *str )
/**
* 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 */
......@@ -1053,7 +1054,7 @@ char *make_URI (const char *path)
#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;
}
......@@ -1062,6 +1063,9 @@ char *make_URI (const char *path)
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 */
......@@ -1072,7 +1076,7 @@ char *make_URI (const char *path)
if (dup[i] == '\\')
dup[i] = DIR_SEP_CHAR;
char *ret = make_URI (dup);
char *ret = make_URI (dup, scheme);
free (dup);
return ret;
}
......@@ -1098,12 +1102,13 @@ char *make_URI (const char *path)
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;
......
......@@ -350,7 +350,7 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
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 ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment