* 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;
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;
/*****************************************************************************
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" );
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;
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;
// 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() );
return ret;
uri:
- return make_URI( psz_mrl, NULL );
+ return vlc_path2uri( psz_mrl, NULL );
}
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;
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;
else
scheme = "cdda";
- char *mrl = make_URI( qtu(discPath), scheme );
+ char *mrl = vlc_path2uri( qtu(discPath), scheme );
if( unlikely(mrl == NULL) )
return;
**/
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 */
dir.remove( "BDMV" );
}
- char *uri = make_URI( qtu( toNativeSeparators( dir ) ), scheme );
+ char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
if( unlikely(uri == NULL) )
return;
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("");
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 );
}
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 )
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 );
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:
{
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;
}
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 );
!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 )
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 )
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)
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 );
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 );
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 );
if( *psz == 0 )
break;
- char *uri = make_URI( psz, NULL );
+ char *uri = vlc_path2uri( psz, NULL );
psz = psz_delim;
if( uri == NULL )
continue;
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 ) )
free( slave );
msg_Warn( p_input, "failed to add %s as slave", uri );
}
- free( uri );
}
break;
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 );
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 )
{
/* 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 )
{
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;
}
/* 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 )
}
}
- 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 );
}
}
libvlc_InternalInit
libvlc_Quit
libvlc_SetExitHandler
-make_URI
+vlc_path2uri
make_path
mdate
ml_Create
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 );
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 );
{
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;
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;
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)
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",
/**
* 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:). */
if (dup[i] == '\\')
dup[i] = DIR_SEP_CHAR;
- char *ret = make_URI (dup, scheme);
+ char *ret = vlc_path2uri (dup, scheme);
free (dup);
return ret;
}
buf = NULL;
free (cwd);
- ret = (buf != NULL) ? make_URI (buf, scheme) : NULL;
+ ret = (buf != NULL) ? vlc_path2uri (buf, scheme) : NULL;
free (buf);
return ret;
}
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,