Commit 6f15ed52 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Namespace/rename vlc URI decode/encode functions

parent 04fb7e89
......@@ -57,6 +57,51 @@ VLC_API char *vlc_path2uri(const char *path, const char *scheme) VLC_MALLOC;
*/
VLC_API char *vlc_uri2path(const char *url) VLC_MALLOC;
/**
* 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 <b>This function does NOT decode entire URIs.</b>
* 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 <b>different</b> from Javascript escaping. Especially,
* white spaces and Unicode non-ASCII code points are encoded differently.
*
* \param str null-terminated component
* \return str is returned on success. NULL if str was not properly encoded.
*/
VLC_API char *vlc_uri_decode(char *str);
/**
* Decodes an URI component.
*
* See also vlc_uri_decode() for the in-place variant.
*
* \return a heap-allocated string on success or NULL on error.
*/
VLC_API char *vlc_uri_decode_duplicate(const char *str) VLC_MALLOC;
/**
* 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.
*
* @param str nul-terminated UTF-8 representation of the component.
* @note Obviously, a URI containing nul bytes cannot be passed.
* @return heap-allocated string, or NULL if out of memory.
*/
VLC_API char *vlc_uri_encode(const char *str) VLC_MALLOC;
/** @} */
struct vlc_url_t
{
char *psz_protocol;
......@@ -70,12 +115,6 @@ struct vlc_url_t
char *psz_buffer; /* to be freed */
};
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 void vlc_UrlParse (vlc_url_t *, const char *);
VLC_API void vlc_UrlClean (vlc_url_t *);
......
......@@ -317,7 +317,7 @@ int AccessOpen(vlc_object_t *p_object)
char *psz_name = psz_base + (sep - p_access->psz_location);
*(psz_name++) = '\0';
if (decode_URI(psz_base) == NULL)
if (vlc_uri_decode(psz_base) == NULL)
{
free(psz_base);
return VLC_EGENERIC;
......
......@@ -163,7 +163,7 @@ input_item_t *DirRead(access_t *access)
}
/* Create an input item for the current entry */
char *encoded= encode_URI_component(entry);
char *encoded= vlc_uri_encode(entry);
if (unlikely(entry == NULL))
continue;
......
......@@ -152,7 +152,7 @@ int FileOpen( vlc_object_t *p_this )
fd = vlc_dup (oldfd);
else if (*end == '/' && end > p_access->psz_location)
{
char *name = decode_URI_duplicate (end - 1);
char *name = vlc_uri_decode_duplicate (end - 1);
if (name != NULL)
{
name[0] = '.';
......
......@@ -612,7 +612,7 @@ static int parseURL( vlc_url_t *url, const char *path, enum tls_mode_e mode )
if( strchr( "iI", type[6] ) == NULL )
return VLC_EGENERIC; /* ASCII and directory not supported */
}
decode_URI( url->psz_path );
vlc_uri_decode( url->psz_path );
return VLC_SUCCESS;
}
......
......@@ -514,7 +514,7 @@ static void Port_finder( demux_t *p_demux )
for( token = strtok_r( psz_expr, ",", &state ); token;
token = strtok_r( NULL, ",", &state ) )
{
psz_uri = decode_URI_duplicate( token );
psz_uri = vlc_uri_decode_duplicate( token );
/* get the ports which match the regexp */
pp_jack_port_output = jack_get_ports( p_sys->p_jack_client,
psz_uri, NULL, JackPortIsOutput );
......
......@@ -153,7 +153,7 @@ int RarAccessOpen(vlc_object_t *object)
return VLC_ENOMEM;
name++;
decode_URI(base);
vlc_uri_decode(base);
stream_t *s = stream_UrlNew(access, base);
if (!s || RarProbe(s))
......
......@@ -113,7 +113,7 @@ int RarStreamOpen(vlc_object_t *object)
* (becareful about '\' and '/'.
*/
char *base;
char *encoded = encode_URI_component(s->psz_url);
char *encoded = vlc_uri_encode(s->psz_url);
if (!encoded || asprintf(&base, "rar://%s", encoded) < 0)
base = NULL;
free(encoded);
......
......@@ -475,7 +475,7 @@ static input_item_t* DirRead( access_t *p_access )
char *psz_full_uri, *psz_uri;
psz_uri = encode_URI_component( psz_file );
psz_uri = vlc_uri_encode( psz_file );
if( psz_uri == NULL )
continue;
......
......@@ -261,7 +261,7 @@ char *ProcessMRL( const char *psz_mrl, const char *psz_prefix )
/* This a relative path, prepend the prefix */
char *ret;
char *postfix = encode_URI_component( psz_mrl );
char *postfix = vlc_uri_encode( psz_mrl );
/* FIXME: postfix may not be encoded correctly (esp. slashes) */
if( postfix == NULL
|| asprintf( &ret, "%s%s", psz_prefix, postfix ) == -1 )
......
......@@ -294,7 +294,7 @@ static int Demux( demux_t *p_demux )
}
else if( !strcmp( psz_param, "author" ) )
{
psz_author = decode_URI_duplicate(psz_value);
psz_author = vlc_uri_decode_duplicate(psz_value);
EnsureUTF8( psz_author );
}
else if( !strcmp( psz_param, "start" )
......@@ -320,12 +320,12 @@ static int Demux( demux_t *p_demux )
}
else if( !strcmp( psz_param, "title" ) )
{
psz_title = decode_URI_duplicate(psz_value);
psz_title = vlc_uri_decode_duplicate(psz_value);
EnsureUTF8( psz_title );
}
else if( !strcmp( psz_param, "copyright" ) )
{
psz_copyright = decode_URI_duplicate(psz_value);
psz_copyright = vlc_uri_decode_duplicate(psz_value);
EnsureUTF8( psz_copyright );
}
else
......@@ -446,19 +446,19 @@ static void ParseClipInfo( const char *psz_clipinfo, char **ppsz_artist, char **
}
/* Put into args */
if( !strcmp( psz_param, "artist name" ) )
*ppsz_artist = decode_URI_duplicate( psz_value );
*ppsz_artist = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "title" ) )
*ppsz_title = decode_URI_duplicate( psz_value );
*ppsz_title = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "album name" ) )
*ppsz_album = decode_URI_duplicate( psz_value );
*ppsz_album = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "genre" ) )
*ppsz_genre = decode_URI_duplicate( psz_value );
*ppsz_genre = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "year" ) )
*ppsz_year = decode_URI_duplicate( psz_value );
*ppsz_year = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "cdnum" ) )
*ppsz_cdnum = decode_URI_duplicate( psz_value );
*ppsz_cdnum = vlc_uri_decode_duplicate( psz_value );
else if( !strcmp( psz_param, "comments" ) )
*ppsz_comments = decode_URI_duplicate( psz_value );
*ppsz_comments = vlc_uri_decode_duplicate( psz_value );
free( psz_suboption );
psz_option_next++;
......
......@@ -546,7 +546,7 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
free(psz_value);
} else if ([o_identifier isEqualToString:URI_COLUMN]) {
psz_value = decode_URI(input_item_GetURI(p_input));
psz_value = vlc_uri_decode(input_item_GetURI(p_input));
o_value = toNSStr(psz_value);
free(psz_value);
......
......@@ -777,7 +777,7 @@
if (![self isValidResumeItem:p_item])
return;
char *psz_url = decode_URI(input_item_GetURI(p_item));
char *psz_url = vlc_uri_decode(input_item_GetURI(p_item));
if (!psz_url)
return;
NSString *url = toNSStr(psz_url);
......@@ -827,7 +827,7 @@
if (![self isValidResumeItem:p_item])
return;
char *psz_url = decode_URI(input_item_GetURI(p_item));
char *psz_url = vlc_uri_decode(input_item_GetURI(p_item));
if (!psz_url)
return;
NSString *url = toNSStr(psz_url);
......
......@@ -218,7 +218,7 @@
libvlc_MetaRequest(VLCIntf->p_libvlc, p_item, META_REQUEST_OPTION_NONE);
/* fill uri info */
char *psz_url = decode_URI(input_item_GetURI(p_item));
char *psz_url = vlc_uri_decode(input_item_GetURI(p_item));
[_uriTextField setStringValue:toNSStr(psz_url)];
free(psz_url);
......
......@@ -31,7 +31,7 @@
#include "recents.hpp"
#include <vlc_keys.h> /* ACTION_ID */
#include <vlc_url.h> /* decode_URI */
#include <vlc_url.h> /* vlc_uri_decode */
#include <vlc_strings.h> /* str_format_meta */
#include <vlc_aout.h> /* audio_output_t */
......@@ -525,7 +525,7 @@ void InputManager::UpdateName()
char *file = uri ? strrchr( uri, '/' ) : NULL;
if( file != NULL )
{
decode_URI( ++file );
vlc_uri_decode( ++file );
name = qfu(file);
}
else
......
......@@ -1585,7 +1585,7 @@ void VLCMenuBar::updateRecents( intf_thread_t *p_intf )
for( int i = 0; i < __MIN( l.count(), 10) ; ++i )
{
QString mrl = l.at( i );
char *psz = decode_URI_duplicate( qtu( mrl ) );
char *psz = vlc_uri_decode_duplicate( qtu( mrl ) );
QString text = qfu( psz );
text.replace("&", "&&");
......
......@@ -51,11 +51,10 @@ static int vlclua_decode_uri( lua_State *L )
for( i = 1; i <= i_top; i++ )
{
const char *psz_cstring = luaL_checkstring( L, 1 );
char *psz_string = strdup( psz_cstring );
char *psz_string = vlc_uri_decode_duplicate( psz_cstring );
lua_remove( L, 1 ); /* remove elements to prevent being limited by
* the stack's size (this function will work with
* up to (stack size - 1) arguments */
decode_URI( psz_string );
lua_pushstring( L, psz_string );
free( psz_string );
}
......@@ -69,7 +68,7 @@ static int vlclua_encode_uri_component( lua_State *L )
for( i = 1; i <= i_top; i++ )
{
const char *psz_cstring = luaL_checkstring( L, 1 );
char *psz_string = encode_URI_component( psz_cstring );
char *psz_string = vlc_uri_encode( psz_cstring );
lua_remove( L,1 );
lua_pushstring( L, psz_string );
free( psz_string );
......
......@@ -168,7 +168,7 @@ static void ReadMetaData(intf_thread_t *p_this, input_thread_t *p_input)
#define ALLOC_ITEM_META(a, b) do { \
char *psz_meta = input_item_Get##b(p_item); \
if (psz_meta && *psz_meta) \
a = encode_URI_component(psz_meta); \
a = vlc_uri_encode(psz_meta); \
free(psz_meta); \
} while (0)
......
......@@ -330,7 +330,7 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
/* Make the name more readable */
if( p_i->psz_name )
{
decode_URI( p_i->psz_name );
vlc_uri_decode( p_i->psz_name );
EnsureUTF8( p_i->psz_name );
}
}
......
......@@ -87,8 +87,6 @@ decoder_SynchroNewPicture
decoder_SynchroRelease
decoder_SynchroReset
decoder_SynchroTrash
decode_URI
decode_URI_duplicate
demux_Delete
demux_PacketizerDestroy
demux_PacketizerNew
......@@ -105,7 +103,6 @@ dialog_Question
dialog_Register
dialog_Unregister
dialog_VFatal
encode_URI_component
EndMD5
es_format_Clean
es_format_Copy
......@@ -246,6 +243,9 @@ vlc_UrlParse
vlc_UrlClean
vlc_path2uri
vlc_uri2path
vlc_uri_decode
vlc_uri_decode_duplicate
vlc_uri_encode
mdate
module_config_free
module_config_get
......
......@@ -60,7 +60,7 @@ static void test (conv_t f, const char *in, const char *out)
static inline void test_decode (const char *in, const char *out)
{
test (decode_URI_duplicate, in, out);
test (vlc_uri_decode_duplicate, in, out);
}
static inline void test_b64 (const char *in, const char *out)
......
......@@ -36,14 +36,10 @@
#include <vlc_fs.h>
#include <ctype.h>
/**
* Decodes an encoded URI component. See also decode_URI().
* \return decoded string allocated on the heap, or NULL on error.
*/
char *decode_URI_duplicate (const char *str)
char *vlc_uri_decode_duplicate (const char *str)
{
char *buf = strdup (str);
if (decode_URI (buf) == NULL)
if (vlc_uri_decode (buf) == NULL)
{
free (buf);
buf = NULL;
......@@ -51,20 +47,7 @@ char *decode_URI_duplicate (const char *str)
return buf;
}
/**
* Decodes an encoded URI component in place.
* <b>This function does NOT decode entire URIs.</b> Instead, it decodes one
* component at a time (e.g. host name, directory, file name).
* Decoded URIs do not exist in the real world (see RFC3986 §2.4).
* Complete URIs are always "encoded" (or they are syntaxically invalid).
*
* Note that URI encoding is different from Javascript escaping. Especially,
* white spaces and Unicode non-ASCII code points are encoded differently.
*
* \param str nul-terminated URI component to decode
* \return str on success, NULL if it was not properly encoded
*/
char *decode_URI (char *str)
char *vlc_uri_decode (char *str)
{
char *in = str, *out = str;
if (in == NULL)
......@@ -127,14 +110,7 @@ static char *encode_URI_bytes (const char *str, size_t *restrict lenp)
return likely(out != NULL) ? out : buf;
}
/**
* Encodes a URI component (RFC3986 §2).
*
* @param str nul-terminated UTF-8 representation of the component.
* @note Obviously, a URI containing nul bytes cannot be passed.
* @return encoded string (must be free()'d), or NULL for ENOMEM.
*/
char *encode_URI_component (const char *str)
char *vlc_uri_encode (const char *str)
{
size_t len = strlen (str);
char *ret = encode_URI_bytes (str, &len);
......@@ -265,7 +241,7 @@ char *vlc_uri2path (const char *url)
return NULL; /* boom! */
/* Decode path */
decode_URI (path);
vlc_uri_decode (path);
if (schemelen == 4 && !strncasecmp (url, "file", 4))
{
......@@ -412,9 +388,9 @@ void vlc_UrlParse (vlc_url_t *restrict url, const char *str)
{
*(next++) = '\0';
url->psz_password = next;
decode_URI (url->psz_password);
vlc_uri_decode (url->psz_password);
}
decode_URI (url->psz_username);
vlc_uri_decode (url->psz_username);
}
/* Host name */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment