VLC 4.0.0-dev
Collaboration diagram for Uniform Resource Locator (URL):

Files

file  vlc_url.h
 

Data Structures

struct  vlc_url_t
 

Functions

char * vlc_path2uri (const char *path, const char *scheme)
 Converts local path to URL. More...
 
char * vlc_uri2path (const char *url)
 Converts a URI to a local path. More...
 
char * vlc_uri_decode (char *str)
 Decodes an URI component in place. More...
 
char * vlc_uri_decode_duplicate (const char *str)
 Decodes an URI component. More...
 
char * vlc_uri_encode (const char *str)
 Encodes a URI component. More...
 
char * vlc_uri_compose (const vlc_url_t *)
 Composes an URI. More...
 
char * vlc_uri_resolve (const char *base, const char *ref)
 Resolves an URI reference. More...
 
char * vlc_uri_fixup (const char *)
 Fixes up a URI string. More...
 
int vlc_UrlParse (vlc_url_t *url, const char *str)
 Parses an URI or IRI. More...
 
int vlc_UrlParseFixup (vlc_url_t *url, const char *str)
 Parses an URI or IRI and fix up the path part. More...
 
void vlc_UrlClean (vlc_url_t *)
 Releases resources allocated by vlc_UrlParse(). More...
 

Detailed Description

Function Documentation

◆ vlc_path2uri()

char * vlc_path2uri ( const char *  path,
const char *  scheme 
)

Converts local path to URL.

Builds a URL representation from a local UTF-8 null-terminated file path.

Parameters
pathfile path
schemeURI scheme to use (default is auto: "file", "fd" or "smb")
Returns
a heap-allocated URI string on success or NULL in case of error (errno will be set accordingly)

References asprintf(), DIR_SEP, DIR_SEP_CHAR, encode_URI_bytes(), p, strdup(), unlikely, vlc_getcwd(), and vlc_path2uri().

Referenced by GetDefaultArtUri(), GetFilenames(), GetVarSlaves(), input_FindArtInCache(), input_SaveArt(), input_SubtitleFile2Uri(), subtitles_Detect(), system_Configure(), system_ConfigureDbus(), vlc_path2uri(), vlc_playlist_Export(), and vlm_ControlMediaInstanceStart().

◆ vlc_uri2path()

char * vlc_uri2path ( const char *  url)

Converts a URI to a local path.

Builds a local path (UTF-8-encoded null-terminated string) from a URI if the URI scheme allows.

Parameters
urlURI
Returns
a heap-allocated string or success or NULL on error

References asprintf(), p, strdup(), strndup(), unlikely, and vlc_uri_decode().

Referenced by access_New(), demux_NewAdvanced(), input_item_WriteMeta(), InputGetExtraFilesPattern(), and subtitles_Detect().

◆ vlc_uri_compose()

char * vlc_uri_compose ( const vlc_url_t uri)

Composes an URI.

Converts a decomposed/parsed URI structure (vlc_url_t) into a nul-terminated URI literal string.

See also IETF RFC3986 section 5.3 for details.

Bug:
URI fragments (i.e. HTML anchors) are not handled
Returns
a heap-allocated nul-terminated string or NULL if out of memory

References vlc_memstream::error, vlc_url_t::i_port, vlc_url_t::psz_fragment, vlc_url_t::psz_host, vlc_url_t::psz_option, vlc_url_t::psz_password, vlc_url_t::psz_path, vlc_url_t::psz_protocol, vlc_url_t::psz_username, vlc_memstream::stream, unlikely, vlc_memstream_close(), vlc_memstream_open(), vlc_memstream_printf(), vlc_memstream_putc(), vlc_memstream_puts(), vlc_memstream_write(), and vlc_uri_encode().

Referenced by vlc_getProxyUrl(), and vlc_uri_resolve().

◆ vlc_uri_decode()

char * vlc_uri_decode ( char *  str)

Decodes an URI component in place.

Decodes one null-terminated UTF-8 URI component to aa null-terminated UTF-8 string in place.

See also vlc_uri_decode_duplicate() for the not-in-place variant.

Warning
This function does NOT decode entire URIs. URI can only be decoded (and encoded) one component at a time (e.g. the host name, one directory, the file name). Complete URIs are always "encoded" (or they are syntaxically invalid). See IETF RFC3986, especially §2.4 for details.
Note
URI encoding is different from Javascript escaping. Especially, white spaces and Unicode non-ASCII code points are encoded differently.
Parameters
strnull-terminated component
Returns
str is returned on success. NULL if str was not properly encoded.

References hex_to_char().

Referenced by input_item_SetURI(), mrl_FragmentSplit(), vlc_uri2path(), vlc_uri_decode_duplicate(), and vlc_UrlParseInner().

◆ vlc_uri_decode_duplicate()

char * vlc_uri_decode_duplicate ( const char *  str)

Decodes an URI component.

See also vlc_uri_decode() for the in-place variant.

Returns
a heap-allocated string on success or NULL on error.

References strdup(), and vlc_uri_decode().

Referenced by find_closest_path(), and vlc_credential_store().

◆ vlc_uri_encode()

char * vlc_uri_encode ( const char *  str)

Encodes a URI component.

Substitutes URI-unsafe, URI delimiters and non-ASCII characters into their URI-encoded URI-safe representation. See also IETF RFC3986 §2.

Parameters
strnul-terminated UTF-8 representation of the component.
Note
Obviously, a URI containing nul bytes cannot be passed.
Returns
heap-allocated string, or NULL if out of memory.

References encode_URI_bytes(), and likely.

Referenced by vlc_uri_compose().

◆ vlc_uri_fixup()

char * vlc_uri_fixup ( const char *  str)

Fixes up a URI string.

Attempts to convert a nul-terminated string into a syntactically valid URI. If the string is, or may be, a syntactically valid URI, an exact copy is returned. In any case, the result will only contain URI-safe and URI delimiter characters (generic delimiters or sub-delimiters) and all percent signs will be followed by two hexadecimal characters.

Returns
a heap-allocated string, or NULL if on out of memory.

References isurialnum(), isurihex(), p, vlc_memstream::stream, vlc_memstream_close(), vlc_memstream_open(), vlc_memstream_putc(), vlc_memstream_write(), and vlc_uri_putc().

Referenced by vlc_http_res_get_redirect().

◆ vlc_uri_resolve()

char * vlc_uri_resolve ( const char *  base,
const char *  ref 
)

Resolves an URI reference.

Resolves an URI reference relative to a base URI. If the reference is an absolute URI, then this function simply returns a copy of the URI reference.

Parameters
basebase URI (as a nul-terminated string)
refURI reference (also as a nul-terminated string)
Returns
a heap-allocated nul-terminated string representing the resolved absolute URI, or NULL if out of memory.

References vlc_memstream::error, vlc_url_t::i_port, vlc_url_t::psz_host, vlc_url_t::psz_option, vlc_url_t::psz_password, vlc_url_t::psz_path, vlc_url_t::psz_protocol, vlc_url_t::psz_username, strdup(), unlikely, vlc_uri_compose(), vlc_uri_merge_paths(), vlc_uri_remove_dot_segments(), vlc_UrlClean(), and vlc_UrlParse().

Referenced by vlc_http_res_get_redirect().

◆ vlc_UrlClean()

void vlc_UrlClean ( vlc_url_t )

Releases resources allocated by vlc_UrlParse().

◆ vlc_UrlParse()

int vlc_UrlParse ( vlc_url_t url,
const char *  str 
)

Parses an URI or IRI.

Extracts the following parts from an URI string:

  • scheme (i.e. protocol),
  • user (deprecated),
  • password (also deprecated),
  • host name or IP address literal,
  • port number,
  • path (including the filename preceded by any and all directories)
  • request parameters (excluding the leading question mark '?').

The function accepts URIs, as well as UTF-8-encoded IRIs. For IRIs, the hier part (specifically, the host name) is assumed to be an IDN and is decoded to ASCII according, so it can be used for DNS resolution. If the host is an IPv6 address literal, brackets are stripped.

Any missing part is set to nul. For historical reasons, the target structure is always initialized, even if parsing the URI string fails.

On error, errno is set to one of the following value:

  • ENOMEM in case of memory allocation failure,
  • EINVAL in case of syntax error in the input string.
Bug:
The URI fragment is discarded if present.
Note
This function allocates memory. vlc_UrlClean() must be used free associated the allocations, even if the function fails.
Parameters
urlstructure of URL parts [OUT]
strnul-terminated URL string to split
Return values
0success
-1failure

References vlc_url_t::psz_path, vlc_uri_path_validate(), and vlc_UrlParseInner().

Referenced by DeduceSlaveType(), input_item_SetURI(), Open(), vlc_getProxyUrl(), vlc_http_outfile_create(), vlc_http_request(), vlc_http_res_init(), vlc_https_connect_proxy(), vlc_renderer_item_new(), and vlc_uri_resolve().

◆ vlc_UrlParseFixup()

int vlc_UrlParseFixup ( vlc_url_t url,
const char *  str 
)