From: RĂ©mi Denis-Courmont Date: Wed, 7 Jul 2010 18:12:46 +0000 (+0300) Subject: make_URI: add scheme parameter X-Git-Tag: 1.2.0-pre1~5927 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=1644d683e9df1620685ed666865b4752bfcca3a0;p=vlc make_URI: add scheme parameter --- diff --git a/include/vlc_url.h b/include/vlc_url.h index 35bea922fd..ef163d42cb 100644 --- a/include/vlc_url.h +++ b/include/vlc_url.h @@ -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 ) ); /***************************************************************************** diff --git a/modules/access/directory.c b/modules/access/directory.c index 8c4950f491..121f622504 100644 --- a/modules/access/directory.c +++ b/modules/access/directory.c @@ -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; diff --git a/modules/demux/playlist/playlist.c b/modules/demux/playlist/playlist.c index a8f88e4625..94536f3553 100644 --- a/modules/demux/playlist/playlist.c +++ b/modules/demux/playlist/playlist.c @@ -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 ); } diff --git a/modules/gui/qt4/dialogs/open.cpp b/modules/gui/qt4/dialogs/open.cpp index bb45cfafdd..3b157888fb 100644 --- a/modules/gui/qt4/dialogs/open.cpp +++ b/modules/gui/qt4/dialogs/open.cpp @@ -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 ); diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp index 13dbbfa86a..f4fccfc0da 100644 --- a/modules/gui/qt4/dialogs_provider.cpp +++ b/modules/gui/qt4/dialogs_provider.cpp @@ -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 ); diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index 56751526a9..02e3bb885e 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -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 ); diff --git a/modules/gui/skins2/commands/cmd_add_item.cpp b/modules/gui/skins2/commands/cmd_add_item.cpp index 604a87efef..877461b6b3 100644 --- a/modules/gui/skins2/commands/cmd_add_item.cpp +++ b/modules/gui/skins2/commands/cmd_add_item.cpp @@ -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; diff --git a/modules/gui/skins2/parser/xmlparser.cpp b/modules/gui/skins2/parser/xmlparser.cpp index b00ee27b62..e2f1e8bc36 100644 --- a/modules/gui/skins2/parser/xmlparser.cpp +++ b/modules/gui/skins2/parser/xmlparser.cpp @@ -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 ); diff --git a/modules/gui/skins2/src/file_bitmap.cpp b/modules/gui/skins2/src/file_bitmap.cpp index 00bf4f41fe..051de8a693 100644 --- a/modules/gui/skins2/src/file_bitmap.cpp +++ b/modules/gui/skins2/src/file_bitmap.cpp @@ -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 ); diff --git a/modules/meta_engine/folder.c b/modules/meta_engine/folder.c index a607a77063..99c640ce0a 100644 --- a/modules/meta_engine/folder.c +++ b/modules/meta_engine/folder.c @@ -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 ); diff --git a/modules/services_discovery/mediadirs.c b/modules/services_discovery/mediadirs.c index f1e265e434..63f9cb7110 100644 --- a/modules/services_discovery/mediadirs.c +++ b/modules/services_discovery/mediadirs.c @@ -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 ) diff --git a/modules/video_filter/alphamask.c b/modules/video_filter/alphamask.c index a8e927342b..c8a1f917a1 100644 --- a/modules/video_filter/alphamask.c +++ b/modules/video_filter/alphamask.c @@ -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 ); diff --git a/modules/video_filter/erase.c b/modules/video_filter/erase.c index 874dab92a0..4633bdfee1 100644 --- a/modules/video_filter/erase.c +++ b/modules/video_filter/erase.c @@ -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 ); diff --git a/modules/video_filter/logo.c b/modules/video_filter/logo.c index d3188b92ca..7bf4cc46a3 100644 --- a/modules/video_filter/logo.c +++ b/modules/video_filter/logo.c @@ -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 ); diff --git a/src/control/media.c b/src/control/media.c index 3fad99e283..3f39841bd7 100644 --- a/src/control/media.c +++ b/src/control/media.c @@ -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" ); diff --git a/src/input/input.c b/src/input/input.c index af7137fa23..bf1dbccf45 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -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 ); diff --git a/src/libvlc.c b/src/libvlc.c index 094d2c80a8..dcb693b31d 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -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; diff --git a/src/playlist/art.c b/src/playlist/art.c index 315fd4e62b..497fdbdf77 100644 --- a/src/playlist/art.c +++ b/src/playlist/art.c @@ -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 ); diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c index 4a6b0bc38d..ce9f9d13a6 100644 --- a/src/playlist/loadsave.c +++ b/src/playlist/loadsave.c @@ -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; diff --git a/src/test/url.c b/src/test/url.c index 80f564fb45..39b101d252 100644 --- a/src/test/url.c +++ b/src/test/url.c @@ -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) diff --git a/src/text/strings.c b/src/text/strings.c index 1d87eb83a0..90bae5edff 100644 --- a/src/text/strings.c +++ b/src/text/strings.c @@ -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; diff --git a/src/win32/specific.c b/src/win32/specific.c index 1436c9363b..531e29271a 100644 --- a/src/win32/specific.c +++ b/src/win32/specific.c @@ -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 ),