From d7a88fe038a9a1d56773d576365d4f6243f4d450 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 27 Aug 2015 21:22:25 +0300 Subject: [PATCH] url: remove vlc_UrlParse() option parameter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit That parameter assumed that the query was part of the path. However it is not, which leads to invalid host name, and eventually failure when the path is missing. In practice, passing any value other than '?' as separator would not work properly. Remaining vlc_UrlParse() call sites without the option separator do not support query at the protocol level anyway, so they are unaffected by the change. Signed-off-by: Rémi Denis-Courmont --- include/vlc_url.h | 2 +- modules/access/dsm/access.c | 2 +- modules/access/ftp.c | 2 +- modules/access/gnomevfs.c | 2 +- modules/access/http.c | 4 ++-- modules/access/live555.cpp | 2 +- modules/access/mms/mmsh.c | 6 +++--- modules/access/mms/mmstu.c | 2 +- modules/access/rdp.c | 2 +- modules/access/sftp.c | 2 +- modules/access/vnc.c | 2 +- modules/access_output/shout.c | 2 +- modules/control/oldrc.c | 2 +- modules/demux/adaptative/http/Chunk.cpp | 2 +- modules/lua/intf.c | 2 +- modules/lua/libs/net.c | 3 +-- modules/misc/audioscrobbler.c | 2 +- modules/misc/rtsp.c | 2 +- modules/services_discovery/upnp.cpp | 4 ++-- modules/stream_out/rtp.c | 2 +- modules/stream_out/vod.c | 2 +- share/lua/README.txt | 2 +- src/input/item.c | 2 +- src/network/httpd.c | 2 +- src/test/url.c | 2 +- src/text/url.c | 15 +++++---------- 26 files changed, 34 insertions(+), 40 deletions(-) diff --git a/include/vlc_url.h b/include/vlc_url.h index 820250f963..cbd67ab723 100644 --- a/include/vlc_url.h +++ b/include/vlc_url.h @@ -50,6 +50,6 @@ VLC_API char * decode_URI( char *psz ); VLC_API char * encode_URI_component( const char *psz ) VLC_MALLOC; VLC_API char * make_path( const char *url ) VLC_MALLOC; -VLC_API void vlc_UrlParse (vlc_url_t *, const char *, unsigned char); +VLC_API void vlc_UrlParse (vlc_url_t *, const char *); VLC_API void vlc_UrlClean (vlc_url_t *); #endif diff --git a/modules/access/dsm/access.c b/modules/access/dsm/access.c index 113914fbd4..60d21203fa 100644 --- a/modules/access/dsm/access.c +++ b/modules/access/dsm/access.c @@ -164,7 +164,7 @@ static int Open( vlc_object_t *p_this ) if( p_sys->p_session == NULL ) goto error; - vlc_UrlParse( &p_sys->url, p_access->psz_location, 0 ); + vlc_UrlParse( &p_sys->url, p_access->psz_location ); get_credentials( p_access ); if( get_address( p_access ) != VLC_SUCCESS ) goto error; diff --git a/modules/access/ftp.c b/modules/access/ftp.c index 36f7bb9f97..7810985d62 100644 --- a/modules/access/ftp.c +++ b/modules/access/ftp.c @@ -578,7 +578,7 @@ static int parseURL( vlc_url_t *url, const char *path, enum tls_mode_e mode ) while( *path == '/' ) path++; - vlc_UrlParse( url, path, 0 ); + vlc_UrlParse( url, path ); if( url->psz_host == NULL || *url->psz_host == '\0' ) return VLC_EGENERIC; diff --git a/modules/access/gnomevfs.c b/modules/access/gnomevfs.c index 9a07e461a7..18cb87dec1 100644 --- a/modules/access/gnomevfs.c +++ b/modules/access/gnomevfs.c @@ -136,7 +136,7 @@ static int Open( vlc_object_t *p_this ) char *psz_escaped_path; char *psz_path_begin; - vlc_UrlParse( &url, psz_unescaped, 0 ); + vlc_UrlParse( &url, psz_unescaped ); psz_escaped_path = gnome_vfs_escape_path_string( url.psz_path ); if( psz_escaped_path ) diff --git a/modules/access/http.c b/modules/access/http.c index 08d341f776..805f5ae230 100644 --- a/modules/access/http.c +++ b/modules/access/http.c @@ -287,7 +287,7 @@ static int OpenRedirected( vlc_object_t *p_this, const char *psz_access, p = psz = strdup( p_access->psz_location ); while( (p = strchr( p, ' ' )) != NULL ) *p = '+'; - vlc_UrlParse( &p_sys->url, psz, '?' ); + vlc_UrlParse( &p_sys->url, psz ); free( psz ); if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' ) @@ -372,7 +372,7 @@ static int OpenRedirected( vlc_object_t *p_this, const char *psz_access, if( psz != NULL ) { p_sys->b_proxy = true; - vlc_UrlParse( &p_sys->proxy, psz, '?' ); + vlc_UrlParse( &p_sys->proxy, psz ); free( psz ); psz = var_InheritString( p_access, "http-proxy-pwd" ); diff --git a/modules/access/live555.cpp b/modules/access/live555.cpp index 8d40dc7380..efd66f3e82 100644 --- a/modules/access/live555.cpp +++ b/modules/access/live555.cpp @@ -314,7 +314,7 @@ static int Open ( vlc_object_t *p_this ) vlc_mutex_init(&p_sys->timeout_mutex); /* parse URL for rtsp://[user:[passwd]@]serverip:port/options */ - vlc_UrlParse( &p_sys->url, p_sys->psz_path, '?' ); + vlc_UrlParse( &p_sys->url, p_sys->psz_path ); if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL ) { diff --git a/modules/access/mms/mmsh.c b/modules/access/mms/mmsh.c index 4241b21a2e..d9c4ffe6d3 100644 --- a/modules/access/mms/mmsh.c +++ b/modules/access/mms/mmsh.c @@ -105,7 +105,7 @@ int MMSHOpen( access_t *p_access ) if( psz_proxy ) { p_sys->b_proxy = true; - vlc_UrlParse( &p_sys->proxy, psz_proxy, '?' ); + vlc_UrlParse( &p_sys->proxy, psz_proxy ); free( psz_proxy ); } else @@ -114,7 +114,7 @@ int MMSHOpen( access_t *p_access ) if( http_proxy ) { p_sys->b_proxy = true; - vlc_UrlParse( &p_sys->proxy, http_proxy, '?' ); + vlc_UrlParse( &p_sys->proxy, http_proxy ); } } @@ -136,7 +136,7 @@ int MMSHOpen( access_t *p_access ) } /* open a tcp connection */ - vlc_UrlParse( &p_sys->url, p_access->psz_location, '?' ); + vlc_UrlParse( &p_sys->url, p_access->psz_location ); if( ( p_sys->url.psz_host == NULL ) || ( *p_sys->url.psz_host == '\0' ) ) { diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c index a0e5cec4f8..232bbd0ddd 100644 --- a/modules/access/mms/mmstu.c +++ b/modules/access/mms/mmstu.c @@ -105,7 +105,7 @@ int MMSTUOpen( access_t *p_access ) vlc_mutex_init( &p_sys->lock_netwrite ); /* *** Parse URL and get server addr/port and path *** */ - vlc_UrlParse( &p_sys->url, p_access->psz_location, '?' ); + vlc_UrlParse( &p_sys->url, p_access->psz_location ); if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' ) { msg_Err( p_access, "invalid server name" ); diff --git a/modules/access/rdp.c b/modules/access/rdp.c index 62611e9362..d9d05a2831 100644 --- a/modules/access/rdp.c +++ b/modules/access/rdp.c @@ -458,7 +458,7 @@ static int Open( vlc_object_t *p_this ) /* Parse uri params for pre-connect */ vlc_url_t url; - vlc_UrlParse( &url, p_demux->psz_location, 0 ); + vlc_UrlParse( &url, p_demux->psz_location ); if ( !EMPTY_STR(url.psz_host) ) p_sys->psz_hostname = strdup( url.psz_host ); diff --git a/modules/access/sftp.c b/modules/access/sftp.c index e308a18faa..7682918d7a 100644 --- a/modules/access/sftp.c +++ b/modules/access/sftp.c @@ -130,7 +130,7 @@ static int Open( vlc_object_t* p_this ) p_sys->i_socket = -1; /* Parse the URL */ - vlc_UrlParse( &url, p_access->psz_location, 0 ); + vlc_UrlParse( &url, p_access->psz_location ); /* Check for some parameters */ if( EMPTY_STR( url.psz_host ) ) diff --git a/modules/access/vnc.c b/modules/access/vnc.c index 9d898e0626..9a81f03c6c 100644 --- a/modules/access/vnc.c +++ b/modules/access/vnc.c @@ -442,7 +442,7 @@ static int Open( vlc_object_t *p_this ) /* Parse uri params */ vlc_url_t url; - vlc_UrlParse( &url, p_demux->psz_location, 0 ); + vlc_UrlParse( &url, p_demux->psz_location ); if ( !EMPTY_STR(url.psz_host) ) p_sys->p_client->serverHost = strdup( url.psz_host ); diff --git a/modules/access_output/shout.c b/modules/access_output/shout.c index 127af94ec6..5a844c7054 100644 --- a/modules/access_output/shout.c +++ b/modules/access_output/shout.c @@ -184,7 +184,7 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; } - vlc_UrlParse( &url , p_access->psz_path, 0 ); + vlc_UrlParse( &url , p_access->psz_path ); if( url.i_port <= 0 ) url.i_port = 8000; diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c index b0f62d1f55..6a6f1cd9a3 100644 --- a/modules/control/oldrc.c +++ b/modules/control/oldrc.c @@ -301,7 +301,7 @@ static int Activate( vlc_object_t *p_this ) { vlc_url_t url; - vlc_UrlParse( &url, psz_host, 0 ); + vlc_UrlParse( &url, psz_host ); msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port ); diff --git a/modules/demux/adaptative/http/Chunk.cpp b/modules/demux/adaptative/http/Chunk.cpp index 29c8d396a9..12ff8fb8e4 100644 --- a/modules/demux/adaptative/http/Chunk.cpp +++ b/modules/demux/adaptative/http/Chunk.cpp @@ -54,7 +54,7 @@ Chunk::Chunk (const std::string& url) : throw VLC_EGENERIC; vlc_url_t url_components; - vlc_UrlParse(&url_components, url.c_str(), '?'); + vlc_UrlParse(&url_components, url.c_str()); if(url_components.psz_path) path = url_components.psz_path; diff --git a/modules/lua/intf.c b/modules/lua/intf.c index c1835303d5..3fc48f91c7 100644 --- a/modules/lua/intf.c +++ b/modules/lua/intf.c @@ -90,7 +90,7 @@ static char *MakeConfig( intf_thread_t *p_intf, const char *name ) else { vlc_url_t url; - vlc_UrlParse( &url, psz_host, 0 ); + vlc_UrlParse( &url, psz_host ); unsigned i_port = var_InheritInteger( p_intf, "telnet-port" ); if ( url.i_port != 0 ) { diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c index b96c2d850a..3d760bf451 100644 --- a/modules/lua/libs/net.c +++ b/modules/lua/libs/net.c @@ -166,10 +166,9 @@ static void vlclua_fd_unmap_safe( lua_State *L, unsigned idx ) static int vlclua_url_parse( lua_State *L ) { const char *psz_url = luaL_checkstring( L, 1 ); - const char *psz_option = luaL_optstring( L, 2, NULL ); vlc_url_t url; - vlc_UrlParse( &url, psz_url, psz_option?*psz_option:0 ); + vlc_UrlParse( &url, psz_url ); lua_newtable( L ); lua_pushstring( L, url.psz_protocol ); diff --git a/modules/misc/audioscrobbler.c b/modules/misc/audioscrobbler.c index df436b7c13..bbbf69a04c 100644 --- a/modules/misc/audioscrobbler.c +++ b/modules/misc/audioscrobbler.c @@ -644,7 +644,7 @@ static int Handshake(intf_thread_t *p_this) goto oom; /* parse the submission url */ - vlc_UrlParse(&p_sys->p_submit_url, psz_url, 0); + vlc_UrlParse(&p_sys->p_submit_url, psz_url); free(psz_url); return VLC_SUCCESS; diff --git a/modules/misc/rtsp.c b/modules/misc/rtsp.c index 6dc8119def..5f22356834 100644 --- a/modules/misc/rtsp.c +++ b/modules/misc/rtsp.c @@ -256,7 +256,7 @@ static int Open( vlc_object_t *p_this ) vlc_url_t url; psz_url = var_InheritString( p_vod, "rtsp-host" ); - vlc_UrlParse( &url, psz_url, 0 ); + vlc_UrlParse( &url, psz_url ); free( psz_url ); p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) ); diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp index 27e965c19f..2eaaf20f8e 100644 --- a/modules/services_discovery/upnp.cpp +++ b/modules/services_discovery/upnp.cpp @@ -543,7 +543,7 @@ MediaServer::~MediaServer() input_item_t* MediaServer::newItem(const char *objectID, const char *title ) { vlc_url_t url; - vlc_UrlParse( &url, url_.c_str(), '?' ); + vlc_UrlParse( &url, url_.c_str() ); char* psz_url; if (asprintf( &psz_url, "upnp://%s://%s:%u%s?ObjectID=%s", url.psz_protocol, @@ -673,7 +673,7 @@ void MediaServer::fetchContents() { const char* objectID = ""; vlc_url_t url; - vlc_UrlParse( &url, access_->psz_location, '?'); + vlc_UrlParse( &url, access_->psz_location ); if ( url.psz_option && !strncmp( url.psz_option, "ObjectID=", strlen( "ObjectID=" ) ) ) { diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c index 7a03ba0ce0..b3a87266bf 100644 --- a/modules/stream_out/rtp.c +++ b/modules/stream_out/rtp.c @@ -699,7 +699,7 @@ static void SDPHandleUrl( sout_stream_t *p_stream, const char *psz_url ) sout_stream_sys_t *p_sys = p_stream->p_sys; vlc_url_t url; - vlc_UrlParse( &url, psz_url, 0 ); + vlc_UrlParse( &url, psz_url ); if( url.psz_protocol && !strcasecmp( url.psz_protocol, "http" ) ) { if( p_sys->p_httpd_file ) diff --git a/modules/stream_out/vod.c b/modules/stream_out/vod.c index f0e66c3192..9c751987ef 100644 --- a/modules/stream_out/vod.c +++ b/modules/stream_out/vod.c @@ -127,7 +127,7 @@ int OpenVoD( vlc_object_t *p_this ) else { vlc_url_t url; - vlc_UrlParse( &url, psz_url, 0 ); + vlc_UrlParse( &url, psz_url ); free( psz_url ); if( url.psz_path == NULL ) diff --git a/share/lua/README.txt b/share/lua/README.txt index a3fea240ca..ebe44a39df 100644 --- a/share/lua/README.txt +++ b/share/lua/README.txt @@ -163,7 +163,7 @@ Net /!\ NB: this namespace is ONLY usable for interfaces and extensions. --- ---------------------------------------------------------------- -net.url_parse( url, [option delimiter] ): Parse URL. Returns a table with +net.url_parse( url ): Parse URL. Returns a table with fields "protocol", "username", "password", "host", "port", path" and "option". net.listen_tcp( host, port ): Listen to TCP connections. This returns an diff --git a/src/input/item.c b/src/input/item.c index 6f38e32d94..3248a8438a 100644 --- a/src/input/item.c +++ b/src/input/item.c @@ -339,7 +339,7 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri ) int r; vlc_url_t url; - vlc_UrlParse( &url, psz_uri, 0 ); + vlc_UrlParse( &url, psz_uri ); if( url.psz_protocol ) { if( url.i_port > 0 ) diff --git a/src/network/httpd.c b/src/network/httpd.c index 2af6b4e4ca..7c924a869f 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -916,7 +916,7 @@ static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this, unsigned port = var_InheritInteger(p_this, portvar); vlc_url_t url; - vlc_UrlParse(&url, hostname, 0); + vlc_UrlParse(&url, hostname); free(hostname); if (url.i_port != 0) { msg_Err(p_this, "Ignoring port %d (using %d)", url.i_port, port); diff --git a/src/test/url.c b/src/test/url.c index f1fa69a1a3..38f5296963 100644 --- a/src/test/url.c +++ b/src/test/url.c @@ -99,7 +99,7 @@ static void test_url_parse(const char* in, const char* protocol, const char* use assert(b != NULL && !strcmp((a), (b))) vlc_url_t url; - vlc_UrlParse( &url, in, '?' ); + vlc_UrlParse( &url, in ); CHECK( url.psz_protocol, protocol ); CHECK( url.psz_username, user ); CHECK( url.psz_password, pass ); diff --git a/src/text/url.c b/src/text/url.c index 9ba900f13e..aeebfea877 100644 --- a/src/text/url.c +++ b/src/text/url.c @@ -350,13 +350,11 @@ static char *vlc_idna_to_ascii (const char *); * Splits an URL into parts. * \param url structure of URL parts [OUT] * \param str nul-terminated URL string to split - * \param opt if non-zero, character separating paths from options, - * normally the question mark * \note Use vlc_UrlClean() to free associated resources * \bug Errors cannot be detected. * \return nothing */ -void vlc_UrlParse (vlc_url_t *restrict url, const char *str, unsigned char opt) +void vlc_UrlParse (vlc_url_t *restrict url, const char *str) { url->psz_protocol = NULL; url->psz_username = NULL; @@ -396,14 +394,11 @@ void vlc_UrlParse (vlc_url_t *restrict url, const char *str, unsigned char opt) } /* Query parameters */ - if (opt != '\0') + char *query = strchr (cur, '?'); + if (query != NULL) { - char *query = strchr (cur, opt); - if (query != NULL) - { - *(query++) = '\0'; - url->psz_option = query; - } + *(query++) = '\0'; + url->psz_option = query; } /* Path */ -- 2.20.1