]> git.sesse.net Git - vlc/commitdiff
vlc_path2uri(): rename from make_URI() and always convert path
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 20 Aug 2012 17:31:05 +0000 (20:31 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 20 Aug 2012 18:01:33 +0000 (21:01 +0300)
When there is an ambiguity, the caller is responsible for determining
whether a string is an URL or a path. In most cases, the string is
known as a file path.

31 files changed:
include/vlc_url.h
lib/media.c
modules/access/directory.c
modules/control/rc.c
modules/demux/mkv/mkv.cpp
modules/demux/playlist/playlist.c
modules/gui/ncurses.c
modules/gui/qt4/components/open_panels.cpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/util/qt_dirs.cpp
modules/gui/skins2/commands/cmd_add_item.cpp
modules/gui/skins2/parser/xmlparser.cpp
modules/gui/skins2/src/file_bitmap.cpp
modules/gui/skins2/vars/playtree.cpp
modules/lua/libs/strings.c
modules/meta_engine/folder.c
modules/services_discovery/mediadirs.c
modules/services_discovery/udev.c
modules/video_filter/alphamask.c
modules/video_filter/erase.c
modules/video_filter/logo.c
src/input/input.c
src/input/vlm.c
src/input/vlmshell.c
src/libvlc.c
src/libvlccore.sym
src/playlist/art.c
src/playlist/loadsave.c
src/test/url.c
src/text/url.c
src/win32/specific.c

index a5e9438d5a1d34566854261bc4b36f8c27e5fa04..fa7677c5231c792f6afb87a1300267c9fc1d4130 100644 (file)
@@ -30,6 +30,8 @@
  * This file defines functions for manipulating URL in vlc
  */
 
+VLC_API char *vlc_path2uri (const char *path, const char *scheme) VLC_MALLOC;
+
 struct vlc_url_t
 {
     char *psz_protocol;
@@ -48,7 +50,6 @@ struct vlc_url_t
 VLC_API char * decode_URI_duplicate( const char *psz ) VLC_MALLOC;
 VLC_API char * decode_URI( char *psz );
 VLC_API char * encode_URI_component( const char *psz ) VLC_MALLOC;
-VLC_API char * make_URI( const char *path, const char *scheme ) VLC_MALLOC;
 VLC_API char * make_path( const char *url ) VLC_MALLOC;
 
 /*****************************************************************************
index 2c01c80abee996e193721b7c73aa23ef68667c27..afafdff963e04a22d1c221d0ec3df13847cc3398 100644 (file)
@@ -313,7 +313,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, "file" );
+    char *mrl = vlc_path2uri( path, "file" );
     if( unlikely(mrl == NULL) )
     {
         libvlc_printerr( "Not enough memory" );
index 4ab97af51f54603d107b485187fc7aade9f4e813..2ae9b3bf8cbb136c4b97f9d0abeec4019de72e4a 100644 (file)
@@ -133,7 +133,7 @@ int DirInit (access_t *p_access, DIR *handle)
             uri = NULL;
     }
     else
-        uri = make_URI (p_access->psz_filepath, "file");
+        uri = vlc_path2uri (p_access->psz_filepath, "file");
     if (unlikely(uri == NULL))
         goto error;
 
index efa2db4b512cf2700b362aebd03d6a1471b275ff..188573019a4da1c9a61103f850d382d688a0eb87 100644 (file)
@@ -2080,8 +2080,11 @@ static input_item_t *parse_MRL( const char *mrl )
 
         if( !psz_item_mrl )
         {
-            psz_item_mrl = make_URI( psz_item, NULL );
-            if( !psz_item_mrl )
+            if( strstr( psz_item_mrl, "://" ) != NULL )
+                psz_item_mrl = strdup( psz_item );
+            else
+                psz_item_mrl = vlc_path2uri( psz_item, NULL );
+            if( psz_item_mrl == NULL )
             {
                 free( psz_orig );
                 return NULL;
index 1bd4a4fcc5822d52287a03a515bc59812abc7fa5..16b60f0f1f2bb20050437eab41a32574071b0c8c 100644 (file)
@@ -189,7 +189,8 @@ static int Open( vlc_object_t * p_this )
                             // test whether this file belongs to our family
                             const uint8_t *p_peek;
                             bool          file_ok = false;
-                            std::string   s_url = make_URI( s_filename.c_str(), "file" );
+#warning Memory leak!
+                            std::string   s_url = vlc_path2uri( s_filename.c_str(), "file" );
                             stream_t      *p_file_stream = stream_UrlNew(
                                                             p_demux,
                                                             s_url.c_str() );
index f024eafb405dd43ba53b7859454f5576dd737040..e0f70ce061b2f156d9228f180d718b4bf65938ad 100644 (file)
@@ -221,5 +221,5 @@ char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
     return ret;
 
 uri:
-    return make_URI( psz_mrl, NULL );
+    return vlc_path2uri( psz_mrl, NULL );
 }
index a20ad50df4ac933d553e8b20fdd9181a762ad663..f266415c38ef4ed575b05d171db9bc161f6e2c2d 100644 (file)
@@ -1409,8 +1409,7 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key)
             return true;
         }
 
-        char *uri = make_URI(path, dir_entry->file ? "file"
-                                                             : "directory");
+        char *uri = vlc_path2uri(path, "file");
         free(path);
         if (uri == NULL)
             return true;
@@ -1447,7 +1446,7 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key)
 static void OpenSelection(intf_thread_t *intf)
 {
     intf_sys_t *sys = intf->p_sys;
-    char *uri = make_URI(sys->open_chain, NULL);
+    char *uri = vlc_path2uri(sys->open_chain, NULL);
     if (uri == NULL)
         return;
 
index 60616eda8c4a5a119844c261a7f3306ea252d9c2..d4be6035b875fbc780c7e608153a3b656e13aa57 100644 (file)
@@ -563,7 +563,7 @@ void DiscOpenPanel::updateMRL()
     else
         scheme = "cdda";
 
-    char *mrl = make_URI( qtu(discPath), scheme );
+    char *mrl = vlc_path2uri( qtu(discPath), scheme );
     if( unlikely(mrl == NULL) )
         return;
 
index 7e339b4e2fec129e12b0e3f04446e275f385d2c5..6a8b0dc8c08dc748d13c9044dc02d40f480fb217 100644 (file)
@@ -475,26 +475,27 @@ void DialogsProvider::simpleMLAppendDialog()
  **/
 void DialogsProvider::openUrlDialog()
 {
-    OpenUrlDialog *oud = new OpenUrlDialog( p_intf );
-    if( oud->exec() == QDialog::Accepted )
+    OpenUrlDialog oud( p_intf );
+    if( oud.exec() != QDialog::Accepted )
+        return;
+
+    QString url = oud.url();
+    if( url.isEmpty() )
+        return;
+
+    if( !url.contains( qfu( "://" ) ) )
     {
-        QString url = oud->url();
-        if( !url.isEmpty() )
-        {
-            char *uri = make_URI( qtu( url ), NULL );
-            if( likely( uri != NULL ) )
-            {
-                playlist_Add( THEPL, uri,
-                              NULL, !oud->shouldEnqueue() ?
-                                      ( PLAYLIST_APPEND | PLAYLIST_GO )
-                                    : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
-                              PLAYLIST_END, true, false );
-                RecentsMRL::getInstance( p_intf )->addRecent( url );
-                free( uri );
-            }
-        }
+        char *uri = vlc_path2uri( qtu( url ), NULL );
+        if( uri == NULL )
+            return;
+        url = qfu(uri);
+        free( uri );
     }
-    delete oud;
+    playlist_Add( THEPL, qtu(url), NULL,
+                  !oud.shouldEnqueue() ? ( PLAYLIST_APPEND | PLAYLIST_GO )
+                                     : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
+                  PLAYLIST_END, true, false );
+    RecentsMRL::getInstance( p_intf )->addRecent( url );
 }
 
 /* Directory */
@@ -521,7 +522,7 @@ static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
         dir.remove( "BDMV" );
     }
 
-    char *uri = make_URI( qtu( toNativeSeparators( dir ) ), scheme );
+    char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
     if( unlikely(uri == NULL) )
         return;
 
index 3d09fd173b3a561378258c545ee4a90dcd75cb5c..6815f168b01f331a03b4a831474b3c16dd9cb831 100644 (file)
 
 QString toURI( const QString& s )
 {
-    char *psz = make_URI( qtu(s), NULL );
+    if( s.contains( qfu("://") ) )
+        return s;
+
+    char *psz = vlc_path2uri( qtu(s), NULL );
     if( psz == NULL )
         return qfu("");
 
index 877461b6b3fe76d4e8c594a8c18adf48226acd77..5d03ad4d20adcde9cb1ab548a2abe36dc11ea8d4 100644 (file)
@@ -37,13 +37,15 @@ void CmdAddItem::execute()
     if( !pPlaylist )
         return;
 
-    char* psz_uri = make_URI(  m_name.c_str(), NULL );
-    if( !psz_uri )
-        return;
-
-    playlist_Add( pPlaylist, psz_uri, NULL,
+    if( strstr( m_name.c_str(), "://" ) == NULL )
+    {
+        char *psz_uri = vlc_path2uri( m_name.c_str(), NULL );
+        if( !psz_uri )
+            return;
+        m_name = psz_uri;
+        free( psz_uri );
+    }
+    playlist_Add( pPlaylist, m_name.c_str(), NULL,
                   m_playNow ? PLAYLIST_APPEND | PLAYLIST_GO : PLAYLIST_APPEND,
                   PLAYLIST_END, true, false );
-
-    free( psz_uri );
 }
index bbb40c301762cbd8d2f48dad1f476a02dad9a358..4c19beded1c8c050b791e172573fba2d2dfdd228 100644 (file)
@@ -39,7 +39,7 @@ XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName )
 
     LoadCatalog();
 
-    char* psz_uri = make_URI( rFileName.c_str(), NULL );
+    char *psz_uri = vlc_path2uri( rFileName.c_str(), NULL );
     m_pStream = stream_UrlNew( pIntf, psz_uri );
     free( psz_uri );
     if( !m_pStream )
index d7ed27aac70d5184c6f0a7bdfaa5f92ff7c24237..51dee1741c713f20f62a499bd2f8c2d8095591c2 100644 (file)
@@ -43,7 +43,7 @@ FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
     video_format_Init( &fmt_in, 0 );
     video_format_Init( &fmt_out, VLC_CODEC_RGBA );
 
-    char* psz_uri = make_URI( fileName.c_str(), NULL );
+    char* psz_uri = vlc_path2uri( fileName.c_str(), NULL );
     pPic = image_ReadUrl( pImageHandler, psz_uri, &fmt_in, &fmt_out );
     free( psz_uri );
 
index 9b3c4db5ed0a2a044a5d609ae4dc7c71d4834808..88905e03b8e925a3c084cbe856875dccbaa00e62 100644 (file)
@@ -326,21 +326,28 @@ void Playtree::insertItems( VarTree& elem, const list<string>& files, bool start
     for( list<string>::const_iterator it = files.begin();
          it != files.end(); ++it, i_pos++, first = false )
     {
-        char* psz_uri = make_URI( it->c_str(), NULL );
-        if( !psz_uri )
-            continue;
+        input_item_t *pItem;
 
-        input_item_t* pItem = input_item_New( psz_uri, NULL );
-        if( pItem )
+        if( strstr( it->c_str(), "://" ) )
+            pItem = input_item_New( it->c_str(), NULL );
+        else
         {
-            int i_mode = PLAYLIST_APPEND;
-            if( first && start )
-                i_mode |= PLAYLIST_GO;
-
-            playlist_NodeAddInput( m_pPlaylist, pItem, p_node,
-                                   i_mode, i_pos, pl_Locked );
+            char *psz_uri = vlc_path2uri( it->c_str(), NULL );
+            if( psz_uri == NULL )
+                continue;
+            pItem = input_item_New( psz_uri, NULL );
+            free( psz_uri );
         }
-        free( psz_uri );
+
+        if( pItem == NULL)
+            continue;
+
+        int i_mode = PLAYLIST_APPEND;
+        if( first && start )
+            i_mode |= PLAYLIST_GO;
+
+        playlist_NodeAddInput( m_pPlaylist, pItem, p_node,
+                               i_mode, i_pos, pl_Locked );
     }
 
 fin:
index dfe1fa2d4c8eaab569cf108bbd1d542ed4f7b8f5..39ae85e70aa10fdd2a89497346d1a00ac6f98da3 100644 (file)
@@ -81,9 +81,14 @@ static int vlclua_make_uri( lua_State *L )
 {
     const char *psz_input = luaL_checkstring( L, 1 );
     const char *psz_scheme = luaL_optstring( L, 2, NULL );
-    char *psz_uri = make_URI( psz_input, psz_scheme );
-    lua_pushstring( L, psz_uri );
-    free( psz_uri );
+    if( strstr( psz_input, "://" ) == NULL )
+    {
+        char *psz_uri = vlc_path2uri( psz_input, psz_scheme );
+        lua_pushstring( L, psz_uri );
+        free( psz_uri );
+    }
+    else
+        lua_pushstring( L, psz_input );
     return 1;
 }
 
index 7ca42566d16c6d67d3e96d2b4d7ef9cf2087a6cb..4aa934d6258330ce60c399bb2511d8c2fa88fa78 100644 (file)
@@ -118,7 +118,7 @@ static int FindMeta( vlc_object_t *p_this )
         struct stat dummy;
         if( vlc_stat( filepath, &dummy ) == 0 )
         {
-            char *psz_uri = make_URI( filepath, "file" );
+            char *psz_uri = vlc_path2uri( filepath, "file" );
             if( psz_uri )
             {
                 input_item_SetArtURL( p_item, psz_uri );
index dd841a58fa07e1f0d7e93c80c4b40d7c0177f599..030fcf5a37a9471cb768f4e6eb1709a662cdbf00 100644 (file)
@@ -189,7 +189,7 @@ static void *Run( void *data )
             !S_ISDIR( st.st_mode ) )
             continue;
 
-        char* psz_uri = make_URI( psz_dir, "file" );
+        char* psz_uri = vlc_path2uri( psz_dir, "file" );
 
         input_item_t* p_root = input_item_New( psz_uri, NULL );
         if( p_sys->i_type == Picture )
@@ -267,7 +267,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, "file" );
+    char* psz_uri = vlc_path2uri( psz_file, "file" );
     input_item_t* p_item = input_item_New( psz_uri, NULL );
 
     if( p_sys->i_type == Picture )
index 4b44cb746de43f301469c0ddfbbd856b63799fdb..8dbc2b354bdba615e867a0c49fc7bfe675567e91 100644 (file)
@@ -557,7 +557,7 @@ static char *disc_get_mrl (struct udev_device *dev)
         return NULL;
 
     val = udev_device_get_devnode (dev);
-    return make_URI (val, scheme);
+    return vlc_path2uri (val, scheme);
 }
 
 static char *disc_get_name (struct udev_device *dev)
index bda9fbe521a7facc853724e5127878fb2b02a053..2478a042c211be8640e2c5a1bf4c6a1126d739ff 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, NULL );
+    char *psz_url = vlc_path2uri( psz_filename, NULL );
     p_filter->p_sys->p_mask =
         image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
     free( psz_url );
index 4bcb02090cfeb886502dc110e1832f1f1cac0cbe..ce8f8bfd85d05353897e83a15a5a909af88dff57 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, NULL );
+    char *psz_url = vlc_path2uri( psz_filename, NULL );
     p_filter->p_sys->p_mask =
         image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
     free( psz_url );
index 00e5d0e1fb881b1c026c793f8306535614111daf..1f50a9bcbb5f34fe4da026dc311a639244d40d63 100644 (file)
@@ -625,7 +625,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, NULL );
+    char *psz_url = vlc_path2uri( 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 bd7f859099a454383444186726eb4dbdd60f8574..88366efb62414c292414e14531be0a9485c48947 100644 (file)
@@ -1098,7 +1098,7 @@ static void LoadSlaves( input_thread_t *p_input )
         if( *psz == 0 )
             break;
 
-        char *uri = make_URI( psz, NULL );
+        char *uri = vlc_path2uri( psz, NULL );
         psz = psz_delim;
         if( uri == NULL )
             continue;
@@ -2041,10 +2041,7 @@ static bool Control( input_thread_t *p_input,
         case INPUT_CONTROL_ADD_SLAVE:
             if( val.psz_string )
             {
-                char *uri = make_URI( val.psz_string, NULL );
-                if( uri == NULL )
-                    break;
-
+                const char *uri = val.psz_string;
                 input_source_t *slave = InputSourceNew( p_input );
 
                 if( slave && !InputSourceInit( p_input, slave, uri, NULL, false ) )
@@ -2089,7 +2086,6 @@ static bool Control( input_thread_t *p_input,
                     free( slave );
                     msg_Warn( p_input, "failed to add %s as slave", uri );
                 }
-                free( uri );
             }
             break;
 
@@ -3156,7 +3152,7 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, unsigned i
         free( psz_path );
     }
 
-    char *url = make_URI( psz_subtitle, "file" );
+    char *url = vlc_path2uri( psz_subtitle, NULL );
 
     var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
 
index 6813591d2154b6592128a2b0bd7675f3238f6dd3..0b811507ec4839c31c62f98819c0096624a07dfa 100644 (file)
@@ -628,9 +628,16 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
 
             vlc_gc_decref( p_media->vod.p_item );
 
-            char *psz_uri = make_URI( p_cfg->ppsz_input[0], NULL );
-            p_media->vod.p_item = input_item_New( psz_uri, p_cfg->psz_name );
-            free( psz_uri );
+            if( strstr( p_cfg->ppsz_input[0], "://" ) == NULL )
+            {
+                char *psz_uri = vlc_path2uri( p_cfg->ppsz_input[0], NULL );
+                p_media->vod.p_item = input_item_New( psz_uri,
+                                                      p_cfg->psz_name );
+                free( psz_uri );
+            }
+            else
+                p_media->vod.p_item = input_item_New( p_cfg->ppsz_input[0],
+                                                      p_cfg->psz_name );
 
             if( p_cfg->psz_output )
             {
@@ -1029,10 +1036,15 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
 
     /* Start new one */
     p_instance->i_index = i_input_index;
-    char *psz_uri = make_URI( p_media->cfg.ppsz_input[p_instance->i_index],
-                              NULL );
-    input_item_SetURI( p_instance->p_item, psz_uri ) ;
-    free( psz_uri );
+    if( strstr( p_media->cfg.ppsz_input[p_instance->i_index], "://" ) == NULL )
+    {
+        char *psz_uri = vlc_path2uri(
+                          p_media->cfg.ppsz_input[p_instance->i_index], NULL );
+        input_item_SetURI( p_instance->p_item, psz_uri ) ;
+        free( psz_uri );
+    }
+    else
+        input_item_SetURI( p_instance->p_item, p_media->cfg.ppsz_input[p_instance->i_index] ) ;
 
     if( asprintf( &psz_log, _("Media: %s"), p_media->cfg.psz_name ) != -1 )
     {
index afa7ed2be60be8a2dae7aac63c9a20cf3f18d262..8f1dbb2cd3030887b048c02c73cf4867e86fede2 100644 (file)
@@ -525,7 +525,7 @@ error:
 
 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_path, vlm_message_t **pp_status )
 {
-    char *psz_url = make_URI( psz_path, NULL );
+    char *psz_url = vlc_path2uri( psz_path, NULL );
     stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
     free( psz_url );
     uint64_t i_size;
index 0aac070808ffdee12e7b27d1949806095c85e0d2..1b968e03b2053386324c95a16d1990e1aaff016b 100644 (file)
@@ -337,7 +337,11 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
                     }
 
                     /* We need to resolve relative paths in this instance */
-                    char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
+                    char *psz_mrl;
+                    if( strstr( psz_mrl, "://" ) )
+                        psz_mrl = strdup( ppsz_argv[i_input] );
+                    else
+                        psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL );
                     const char *psz_after_track = MPRIS_APPEND;
 
                     if( psz_mrl == NULL )
@@ -815,13 +819,18 @@ static void GetFilenames( libvlc_int_t *p_vlc, unsigned n,
             }
         }
 
-        char *mrl = make_URI( args[n], NULL );
-        if( !mrl )
-            continue;
+        char *mrl = NULL;
+        if( strstr( args[n], "://" ) == NULL )
+        {
+            mrl = vlc_path2uri( args[n], NULL );
+            if( !mrl )
+                continue;
+        }
 
-        playlist_AddExt( pl_Get( p_vlc ), mrl, NULL, PLAYLIST_INSERT,
-                0, -1, i_options, ( i_options ? &args[n + 1] : NULL ),
-                VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
+        playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
+                         PLAYLIST_INSERT, 0, -1, i_options,
+                         ( i_options ? &args[n + 1] : NULL ),
+                         VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
         free( mrl );
     }
 }
index 2188f9d69ca622e1a23df8832a2d141ee4cc6d60..d35b8003dbdde6a221a37044e540044584bf1b92 100644 (file)
@@ -221,7 +221,7 @@ libvlc_InternalDestroy
 libvlc_InternalInit
 libvlc_Quit
 libvlc_SetExitHandler
-make_URI
+vlc_path2uri
 make_path
 mdate
 ml_Create
index 79ca30f92e5d65d9155074bdab44da0ca58f5db3..67848479b1317a191e92738d57b76b506c974c73 100644 (file)
@@ -184,7 +184,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, "file" );
+                char *psz_uri = vlc_path2uri( psz_file, "file" );
                 if( psz_uri )
                 {
                     input_item_SetArtURL( p_item, psz_uri );
@@ -274,7 +274,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, "file" );
+    char *psz_uri = vlc_path2uri( psz_filename, "file" );
     if( !psz_uri )
     {
         free( psz_filename );
index 33b0f3e595661b6f614988bb7f7be9d771b41cd3..85a3e9eb8bb54d966038a385b86f574f99f280ec 100644 (file)
@@ -85,7 +85,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, NULL );
+    char *psz_uri = vlc_path2uri( psz_file, NULL );
 
     if( psz_uri == NULL )
         return VLC_EGENERIC;
@@ -141,7 +141,7 @@ int playlist_MLLoad( playlist_t *p_playlist )
         return VLC_EGENERIC;
     }
 
-    char *psz_uri = make_URI( psz_file, "file/xspf-open" );
+    char *psz_uri = vlc_path2uri( psz_file, "file/xspf-open" );
     free( psz_file );
     if( psz_uri == NULL )
         return VLC_ENOMEM;
index db217a97a965db7f532f1862e7c42920142dfee2..6c263832902e2ef1fe9e8fa3d38707bad9775826 100644 (file)
@@ -70,7 +70,7 @@ static inline void test_b64 (const char *in, const char *out)
 
 static char *make_URI_def (const char *in)
 {
-    return make_URI (in, NULL);
+    return vlc_path2uri (in, NULL);
 }
 
 static inline void test_path (const char *in, const char *out)
@@ -119,9 +119,6 @@ int main (void)
     test_b64 ("foobar", "Zm9vYmFy");
 
     /* Path test */
-    test_path ("file:///", "file:///");
-    test_path ("http://www.example.com/%7Ejohn/",
-               "http://www.example.com/%7Ejohn/");
     test_path ("/", "file:///");
     test_path ("/home/john/", "file:///home/john/");
     test_path ("/home/john//too///many//slashes",
index 4b0dfb7f7a2e77375d752b7990226fb099e06f0b..f0c152b14fc34160a6ee62d365740c33de553c5a 100644 (file)
@@ -148,20 +148,17 @@ char *encode_URI_component (const char *str)
 
 /**
  * Builds a URL representation from a local file path.
- * If already a URI, return a copy of the string.
  * @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, const char *scheme)
+char *vlc_path2uri (const char *path, const char *scheme)
 {
     if (path == NULL)
         return NULL;
     if (scheme == NULL && !strcmp (path, "-"))
         return strdup ("fd://0"); // standard input
-    if (strstr (path, "://") != NULL)
-        return strdup (path); /* Already a URI */
     /* Note: VLC cannot handle URI schemes without double slash after the
      * scheme name (such as mailto: or news:). */
 
@@ -207,7 +204,7 @@ char *make_URI (const char *path, const char *scheme)
                 if (dup[i] == '\\')
                     dup[i] = DIR_SEP_CHAR;
 
-            char *ret = make_URI (dup, scheme);
+            char *ret = vlc_path2uri (dup, scheme);
             free (dup);
             return ret;
         }
@@ -238,7 +235,7 @@ char *make_URI (const char *path, const char *scheme)
             buf = NULL;
 
         free (cwd);
-        ret = (buf != NULL) ? make_URI (buf, scheme) : NULL;
+        ret = (buf != NULL) ? vlc_path2uri (buf, scheme) : NULL;
         free (buf);
         return ret;
     }
index 8b334d6b4b1cad779be56bca294b943d75e58c06..ce8c78072f3a728f6517e0cca29fa2f90b43ee91 100644 (file)
@@ -295,8 +295,14 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
                     i_options++;
                 }
 
-                char *psz_URI = make_URI( ppsz_argv[i_opt], NULL );
-                playlist_AddExt( p_playlist, psz_URI,
+#warning URI conversion must be done in calling process instead!
+                /* FIXME: This breaks relative paths if calling vlc.exe is
+                 * started from a different working directory. */
+                char *psz_URI = NULL;
+                if( strstr( psz_URI, "://" ) == NULL )
+                    psz_URI = vlc_path2uri( ppsz_argv[i_opt], NULL );
+                playlist_AddExt( p_playlist,
+                        (psz_URI != NULL) ? psz_URI : ppsz_argv[i_opt],
                         NULL, PLAYLIST_APPEND |
                         ( ( i_opt || p_data->enqueue ) ? 0 : PLAYLIST_GO ),
                         PLAYLIST_END, -1,