Skip to content

Commit

Permalink
vlc_path2uri(): rename from make_URI() and always convert path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Rémi Denis-Courmont committed Aug 20, 2012
1 parent 595db21 commit 33dfab3
Show file tree
Hide file tree
Showing 31 changed files with 140 additions and 101 deletions.
3 changes: 2 additions & 1 deletion include/vlc_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/*****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion lib/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion modules/access/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions modules/control/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion modules/demux/mkv/mkv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion modules/demux/playlist/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
5 changes: 2 additions & 3 deletions modules/gui/ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion modules/gui/qt4/components/open_panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 20 additions & 19 deletions modules/gui/qt4/dialogs_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion modules/gui/qt4/util/qt_dirs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

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("");

Expand Down
16 changes: 9 additions & 7 deletions modules/gui/skins2/commands/cmd_add_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
2 changes: 1 addition & 1 deletion modules/gui/skins2/parser/xmlparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion modules/gui/skins2/src/file_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
31 changes: 19 additions & 12 deletions modules/gui/skins2/vars/playtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions modules/lua/libs/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/meta_engine/folder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions modules/services_discovery/mediadirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion modules/services_discovery/udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/video_filter/alphamask.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion modules/video_filter/erase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion modules/video_filter/logo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 3 additions & 7 deletions src/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 );

Expand Down
Loading

0 comments on commit 33dfab3

Please sign in to comment.