]> git.sesse.net Git - vlc/commitdiff
make_URI: add scheme parameter
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 7 Jul 2010 18:12:46 +0000 (21:12 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 7 Jul 2010 18:12:46 +0000 (21:12 +0300)
22 files changed:
include/vlc_url.h
modules/access/directory.c
modules/demux/playlist/playlist.c
modules/gui/qt4/dialogs/open.cpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/main_interface.cpp
modules/gui/skins2/commands/cmd_add_item.cpp
modules/gui/skins2/parser/xmlparser.cpp
modules/gui/skins2/src/file_bitmap.cpp
modules/meta_engine/folder.c
modules/services_discovery/mediadirs.c
modules/video_filter/alphamask.c
modules/video_filter/erase.c
modules/video_filter/logo.c
src/control/media.c
src/input/input.c
src/libvlc.c
src/playlist/art.c
src/playlist/loadsave.c
src/test/url.c
src/text/strings.c
src/win32/specific.c

index 35bea922fdccb977d479e16bd4a2a50117fd4179..ef163d42cbda9062ce9144b4f853561af16076b1 100644 (file)
@@ -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 ) );
 
 /*****************************************************************************
index 8c4950f491eb629db1552e48207615e0dc990f3e..121f6225044f8bf8aa744654d52739209228983a 100644 (file)
@@ -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;
 
index a8f88e4625e02a77274890c50fb74149c32fb54f..94536f3553946ce8ea70c217c553a5f3cd656818 100644 (file)
@@ -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 );
 }
index bb45cfafdd0e0417eb7d1a29149fc981cc288cf5..3b157888fbc00d416757ccbfc6d40d46d865b484 100644 (file)
@@ -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 );
 
index 13dbbfa86a924d4c4f736f2700162957174b6372..f4fccfc0dad23a1478f0e2bbb091d36bbff6b4f9 100644 (file)
@@ -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 );
index 56751526a91898a34a3aeaf784c5fd62c5c5df74..02e3bb885ee004ab7fb2ec7c40527cbbd60cc964 100644 (file)
@@ -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 );
index 604a87efef6e9b92bbd0c791cdf0f07303f8c17c..877461b6b3fe76d4e8c594a8c18adf48226acd77 100644 (file)
@@ -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;
 
index b00ee27b622b1dd4b0393b3a8f74efc9ecbbd415..e2f1e8bc361c5b881bd44ef4cff7af27031df6c9 100644 (file)
@@ -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 );
 
index 00bf4f41fe7d73bcbce5d04d06d4359ac75581db..051de8a693dba47122afd34b72bf94f992433cda 100644 (file)
@@ -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 );
 
index a607a77063b6b6539f123531206cf4ea90d75df8..99c640ce0a3efd52d6f2fafdb3231e6ea9c0f704 100644 (file)
@@ -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 );
index f1e265e434f3978a1ea07047c8130880ecd98874..63f9cb7110e9fdf9b3ae1234d16d80b154a5dfcb 100644 (file)
@@ -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 )
index a8e927342b4a574a20e7e55a434b8230b0cab853..c8a1f917a19368385ca887305ebfd5ccc5f283d7 100644 (file)
@@ -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 );
index 874dab92a0c3f9c70a768a456afbd5898026b7db..4633bdfee14e49d2e3c965082c72f1f559af48b8 100644 (file)
@@ -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 );
index d3188b92ca732495213bf9d3c9d2333dfc7bf20a..7bf4cc46a3e2fcb2ee5f4151abbe3563ec6e11c7 100644 (file)
@@ -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 );
index 3fad99e283ff4cacc9f6935669fd11ac63968d8f..3f39841bd785178383c386cbd6a5f11e6156e822 100644 (file)
@@ -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" );
index af7137fa230d490c1a4629aba5d91ed99fc465df..bf1dbccf45847c362bdb3888a5ae9abbe1765053 100644 (file)
@@ -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 );
 
index 094d2c80a8f74234b4c3458973efc53ef5a992ee..dcb693b31d4414122d323ee723f61ee109f247be 100644 (file)
@@ -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;
 
index 315fd4e62b19ca5ed6678b132f25b52b6f101b65..497fdbdf775715524aa678f9f35d282c7849fccb 100644 (file)
@@ -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 );
index 4a6b0bc38db634e1669fcbcf4e47b3927876ba34..ce9f9d13a68911f97db67f6051bb6a57da29f6a7 100644 (file)
@@ -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;
 
index 80f564fb453f72f32fee329384e99ba37045f4d1..39b101d25248258d8f1a31bf4ecad9c70cdcb04e 100644 (file)
@@ -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)
index 1d87eb83a0cbbf020cafadc7353f6943b6b10c0a..90bae5edff80e7dfececb91f4e3e07e5861e7443 100644 (file)
@@ -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;
 
index 1436c9363b362828ec4f566384c00c65b9983c2f..531e29271a6fc4dcecab4de3654ad79ddc9c2935 100644 (file)
@@ -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 ),