Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
c48ac548
Commit
c48ac548
authored
May 10, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 1.0-bugfix
parents
600d0295
7a0efcc7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
113 deletions
+147
-113
include/vlc_url.h
include/vlc_url.h
+2
-1
modules/misc/playlist/xspf.c
modules/misc/playlist/xspf.c
+6
-89
modules/misc/playlist/xspf.h
modules/misc/playlist/xspf.h
+0
-3
src/libvlccore.sym
src/libvlccore.sym
+1
-0
src/test/url.c
src/test/url.c
+27
-0
src/text/strings.c
src/text/strings.c
+111
-20
No files found.
include/vlc_url.h
View file @
c48ac548
...
@@ -48,8 +48,9 @@ struct vlc_url_t
...
@@ -48,8 +48,9 @@ struct vlc_url_t
VLC_EXPORT
(
char
*
,
unescape_URI_duplicate
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
unescape_URI_duplicate
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
void
,
unescape_URI
,
(
char
*
psz
)
);
VLC_EXPORT
(
void
,
unescape_URI
,
(
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
decode_URI_duplicate
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
decode_URI_duplicate
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
void
,
decode_URI
,
(
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
decode_URI
,
(
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
encode_URI_component
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
encode_URI_component
,
(
const
char
*
psz
)
);
VLC_EXPORT
(
char
*
,
make_URI
,
(
const
char
*
path
)
);
/*****************************************************************************
/*****************************************************************************
* vlc_UrlParse:
* vlc_UrlParse:
...
...
modules/misc/playlist/xspf.c
View file @
c48ac548
...
@@ -34,11 +34,14 @@
...
@@ -34,11 +34,14 @@
#include <vlc_playlist.h>
#include <vlc_playlist.h>
#include <vlc_input.h>
#include <vlc_input.h>
#include <vlc_strings.h>
#include <vlc_strings.h>
#include <vlc_
charset
.h>
#include <vlc_
url
.h>
#include "xspf.h"
#include "xspf.h"
#include <assert.h>
#include <assert.h>
static
void
xspf_export_item
(
playlist_item_t
*
,
FILE
*
,
int
*
);
static
void
xspf_extension_item
(
playlist_item_t
*
,
FILE
*
,
int
*
);
/**
/**
* \brief Prints the XSPF header to file, writes each item by xspf_export_item()
* \brief Prints the XSPF header to file, writes each item by xspf_export_item()
* and closes the open xml elements
* and closes the open xml elements
...
@@ -139,7 +142,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
...
@@ -139,7 +142,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
if
(
psz_uri
&&
*
psz_uri
)
if
(
psz_uri
&&
*
psz_uri
)
{
{
psz
=
assertUTF8
URI
(
psz_uri
);
psz
=
make_
URI
(
psz_uri
);
fprintf
(
p_file
,
"
\t\t\t
<location>%s</location>
\n
"
,
psz
);
fprintf
(
p_file
,
"
\t\t\t
<location>%s</location>
\n
"
,
psz
);
free
(
psz
);
free
(
psz
);
}
}
...
@@ -209,7 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
...
@@ -209,7 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
if
(
psz
==
NULL
)
psz
=
strdup
(
""
);
if
(
psz
==
NULL
)
psz
=
strdup
(
""
);
if
(
!
EMPTY_STR
(
psz
)
)
if
(
!
EMPTY_STR
(
psz
)
)
{
{
psz_uri
=
assertUTF8
URI
(
psz
);
psz_uri
=
make_
URI
(
psz
);
fprintf
(
p_file
,
"
\t\t\t
<image>%s</image>
\n
"
,
psz_uri
);
fprintf
(
p_file
,
"
\t\t\t
<image>%s</image>
\n
"
,
psz_uri
);
free
(
psz_uri
);
free
(
psz_uri
);
}
}
...
@@ -284,89 +287,3 @@ static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file,
...
@@ -284,89 +287,3 @@ static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file,
return
;
return
;
}
}
/**
* \param psz_name the location of the media ressource (e.g. local file,
* device, network stream, etc.)
* \return a new char buffer which asserts that the location is valid UTF-8
* and a valid URI
* \note the returned buffer must be freed, when it isn't used anymore
*/
static
char
*
assertUTF8URI
(
char
*
psz_name
)
{
char
*
psz_ret
=
NULL
;
/**< the new result buffer to return */
char
*
psz_s
=
NULL
,
*
psz_d
=
NULL
;
/**< src & dest pointers for URI conversion */
bool
b_uri_is_file
=
false
;
/**< we do additional %-encoding if the URI is a file:// one */
if
(
!
psz_name
||
!*
psz_name
)
return
NULL
;
/* check that string is valid UTF-8 */
/* XXX: Why do we even need to do that ? (all strings in core are UTF-8 encoded */
if
(
!
(
psz_s
=
EnsureUTF8
(
psz_name
)
)
)
return
NULL
;
/* max. 3x for URI conversion (percent escaping) and
8 bytes for "file://" and NULL-termination */
psz_ret
=
(
char
*
)
malloc
(
strlen
(
psz_name
)
*
6
*
3
+
8
);
if
(
!
psz_ret
)
return
NULL
;
/** \todo check for a valid scheme part preceding the colon */
if
(
strstr
(
psz_s
,
"://"
)
!=
NULL
)
{
size_t
i_delim
=
strcspn
(
psz_s
,
":"
);
i_delim
++
;
/* skip the ':' */
strncpy
(
psz_ret
,
psz_s
,
i_delim
);
psz_d
=
psz_ret
+
i_delim
;
if
(
!
strncmp
(
psz_s
,
"file://"
,
7
)
)
b_uri_is_file
=
true
;
psz_s
+=
i_delim
;
}
/* assume "file" scheme if no scheme-part is included */
else
{
strcpy
(
psz_ret
,
"file://"
);
psz_d
=
psz_ret
+
7
;
b_uri_is_file
=
true
;
}
while
(
*
psz_s
)
{
/* percent-encode all non-ASCII and the XML special characters and the percent sign itself */
if
(
*
psz_s
&
B10000000
||
*
psz_s
==
'<'
||
*
psz_s
==
'>'
||
*
psz_s
==
'&'
||
*
psz_s
==
' '
||
*
psz_s
==
'+'
||
*
psz_s
==
'%'
||
*
psz_s
==
'\\'
||
(
b_uri_is_file
&&
(
*
psz_s
==
':'
||
*
psz_s
==
'"'
||
*
psz_s
==
'?'
||
*
psz_s
==
'#'
||
*
psz_s
==
'['
||
*
psz_s
==
']'
||
*
psz_s
==
'@'
)
)
)
{
*
psz_d
++
=
'%'
;
*
psz_d
++
=
hexchars
[(
*
psz_s
>>
4
)
&
B00001111
];
*
psz_d
++
=
hexchars
[
*
psz_s
&
B00001111
];
}
else
{
*
psz_d
++
=
*
psz_s
;
}
psz_s
++
;
}
*
psz_d
=
'\0'
;
return
(
char
*
)
realloc
(
psz_ret
,
strlen
(
psz_ret
)
+
1
);
}
modules/misc/playlist/xspf.h
View file @
c48ac548
...
@@ -33,6 +33,3 @@ const char hexchars[16] = "0123456789ABCDEF";
...
@@ -33,6 +33,3 @@ const char hexchars[16] = "0123456789ABCDEF";
/* prototypes */
/* prototypes */
int
xspf_export_playlist
(
vlc_object_t
*
);
int
xspf_export_playlist
(
vlc_object_t
*
);
static
void
xspf_export_item
(
playlist_item_t
*
,
FILE
*
,
int
*
);
static
void
xspf_extension_item
(
playlist_item_t
*
,
FILE
*
,
int
*
);
static
char
*
assertUTF8URI
(
char
*
);
src/libvlccore.sym
View file @
c48ac548
...
@@ -216,6 +216,7 @@ libvlc_InternalInit
...
@@ -216,6 +216,7 @@ libvlc_InternalInit
libvlc_InternalWait
libvlc_InternalWait
libvlc_Quit
libvlc_Quit
LocaleFree
LocaleFree
make_URI
mdate
mdate
module_config_free
module_config_free
module_config_get
module_config_get
...
...
src/test/url.c
View file @
c48ac548
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <assert.h>
typedef
char
*
(
*
conv_t
)
(
const
char
*
);
typedef
char
*
(
*
conv_t
)
(
const
char
*
);
...
@@ -60,8 +61,15 @@ static inline void test_b64 (const char *in, const char *out)
...
@@ -60,8 +61,15 @@ static inline void test_b64 (const char *in, const char *out)
test
(
vlc_b64_encode
,
in
,
out
);
test
(
vlc_b64_encode
,
in
,
out
);
}
}
static
inline
void
test_path
(
const
char
*
in
,
const
char
*
out
)
{
test
(
make_URI
,
in
,
out
);
}
int
main
(
void
)
int
main
(
void
)
{
{
int
val
;
(
void
)
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
(
void
)
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
test_decode
(
"this_should_not_be_modified_1234"
,
test_decode
(
"this_should_not_be_modified_1234"
,
"this_should_not_be_modified_1234"
);
"this_should_not_be_modified_1234"
);
...
@@ -93,5 +101,24 @@ int main (void)
...
@@ -93,5 +101,24 @@ int main (void)
test_b64
(
"fooba"
,
"Zm9vYmE="
);
test_b64
(
"fooba"
,
"Zm9vYmE="
);
test_b64
(
"foobar"
,
"Zm9vYmFy"
);
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/music.ogg"
,
"file:///home/john/music.ogg"
);
//test_path ("\\\\server/pub/music.ogg", "file://server/pub/music.ogg");
/*int fd = open (".", O_RDONLY);
assert (fd != -1);*/
val
=
chdir
(
"/tmp"
);
assert
(
val
!=
-
1
);
test_path
(
"movie.ogg"
,
"file:///tmp/movie.ogg"
);
test_path
(
"."
,
"file:///tmp/."
);
test_path
(
""
,
"file:///tmp/"
);
/*val = fchdir (fd);
assert (val != -1);*/
return
0
;
return
0
;
}
}
src/text/strings.c
View file @
c48ac548
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
* strings.c: String related functions
* strings.c: String related functions
*****************************************************************************
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* Copyright (C) 2006 the VideoLAN team
* Copyright (C) 2008-2009 Rémi Denis-Courmont
* $Id$
* $Id$
*
*
* Authors: Antoine Cellerier <dionoea at videolan dot org>
* Authors: Antoine Cellerier <dionoea at videolan dot org>
...
@@ -130,7 +131,7 @@ void unescape_URI( char *psz )
...
@@ -130,7 +131,7 @@ void unescape_URI( char *psz )
}
}
/**
/**
* Decode encoded URI
string
* Decode encoded URI
component. See also decode_URI().
* \return decoded duplicated string
* \return decoded duplicated string
*/
*/
char
*
decode_URI_duplicate
(
const
char
*
psz
)
char
*
decode_URI_duplicate
(
const
char
*
psz
)
...
@@ -141,14 +142,23 @@ char *decode_URI_duplicate( const char *psz )
...
@@ -141,14 +142,23 @@ char *decode_URI_duplicate( const char *psz )
}
}
/**
/**
* Decode encoded URI string in place
* Decode an encoded URI component in place.
* \return nothing
* <b>This function does NOT decode entire URIs.</b>
* It decodes components (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.
*
* \return psz on success, NULL if it was not properly encoded
*/
*/
void
decode_URI
(
char
*
psz
)
char
*
decode_URI
(
char
*
psz
)
{
{
unsigned
char
*
in
=
(
unsigned
char
*
)
psz
,
*
out
=
in
,
c
;
unsigned
char
*
in
=
(
unsigned
char
*
)
psz
,
*
out
=
in
,
c
;
if
(
psz
==
NULL
)
if
(
psz
==
NULL
)
return
;
return
NULL
;
while
(
(
c
=
*
in
++
)
!=
'\0'
)
while
(
(
c
=
*
in
++
)
!=
'\0'
)
{
{
...
@@ -160,14 +170,14 @@ void decode_URI( char *psz )
...
@@ -160,14 +170,14 @@ void decode_URI( char *psz )
if
(
(
(
hex
[
0
]
=
*
in
++
)
==
0
)
if
(
(
(
hex
[
0
]
=
*
in
++
)
==
0
)
||
(
(
hex
[
1
]
=
*
in
++
)
==
0
)
)
||
(
(
hex
[
1
]
=
*
in
++
)
==
0
)
)
return
;
return
NULL
;
hex
[
2
]
=
'\0'
;
hex
[
2
]
=
'\0'
;
*
out
++
=
(
unsigned
char
)
strtoul
(
hex
,
NULL
,
0x10
);
*
out
++
=
(
unsigned
char
)
strtoul
(
hex
,
NULL
,
0x10
);
break
;
break
;
}
}
case
'+'
:
case
'+'
:
/* This is HTTP forms, not URI decoding... */
*
out
++
=
' '
;
*
out
++
=
' '
;
break
;
break
;
...
@@ -182,6 +192,7 @@ void decode_URI( char *psz )
...
@@ -182,6 +192,7 @@ void decode_URI( char *psz )
}
}
*
out
=
'\0'
;
*
out
=
'\0'
;
EnsureUTF8
(
psz
);
EnsureUTF8
(
psz
);
return
psz
;
}
}
static
inline
bool
isurisafe
(
int
c
)
static
inline
bool
isurisafe
(
int
c
)
...
@@ -193,23 +204,13 @@ static inline bool isurisafe( int c )
...
@@ -193,23 +204,13 @@ static inline bool isurisafe( int c )
||
(
strchr
(
"-._~"
,
c
)
!=
NULL
);
||
(
strchr
(
"-._~"
,
c
)
!=
NULL
);
}
}
/**
static
char
*
encode_URI_bytes
(
const
char
*
psz_uri
,
size_t
len
)
* Encodes an URI component (RFC3986 §2).
*
* @param psz_uri nul-terminated UTF-8 representation of the component.
* Obviously, you can't pass an URI containing a nul character, but you don't
* want to do that, do you?
*
* @return encoded string (must be free()'d), or NULL for ENOMEM.
*/
char
*
encode_URI_component
(
const
char
*
psz_uri
)
{
{
char
*
psz_enc
=
malloc
((
3
*
strlen
(
psz_uri
))
+
1
),
*
out
=
psz_enc
;
char
*
psz_enc
=
malloc
(
3
*
len
+
1
),
*
out
=
psz_enc
;
if
(
psz_enc
==
NULL
)
if
(
psz_enc
==
NULL
)
return
NULL
;
return
NULL
;
while
(
*
psz_uri
)
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
{
static
const
char
hex
[
16
]
=
"0123456789ABCDEF"
;
static
const
char
hex
[
16
]
=
"0123456789ABCDEF"
;
uint8_t
c
=
*
psz_uri
;
uint8_t
c
=
*
psz_uri
;
...
@@ -232,6 +233,21 @@ char *encode_URI_component( const char *psz_uri )
...
@@ -232,6 +233,21 @@ char *encode_URI_component( const char *psz_uri )
return
out
?
out
:
psz_enc
;
/* realloc() can fail (safe) */
return
out
?
out
:
psz_enc
;
/* realloc() can fail (safe) */
}
}
/**
* Encodes an URI component (RFC3986 §2).
*
* @param psz_uri nul-terminated UTF-8 representation of the component.
* Obviously, you can't pass an URI containing a nul character, but you don't
* want to do that, do you?
*
* @return encoded string (must be free()'d), or NULL for ENOMEM.
*/
char
*
encode_URI_component
(
const
char
*
psz_uri
)
{
return
encode_URI_bytes
(
psz_uri
,
strlen
(
psz_uri
));
}
static
const
struct
xml_entity_s
static
const
struct
xml_entity_s
{
{
char
psz_entity
[
8
];
char
psz_entity
[
8
];
...
@@ -1120,3 +1136,78 @@ void path_sanitize( char *str )
...
@@ -1120,3 +1136,78 @@ void path_sanitize( char *str )
str
++
;
str
++
;
}
}
}
}
#include <vlc_url.h>
/**
* Convert a file path to an URI. If already an URI, do nothing.
*/
char
*
make_URI
(
const
char
*
path
)
{
if
(
path
==
NULL
)
return
NULL
;
if
(
strstr
(
path
,
"://"
)
!=
NULL
)
return
strdup
(
path
);
/* Already an URI */
/* Note: VLC cannot handle URI schemes without double slash after the
* scheme name (such as mailto: or news:). */
char
*
buf
;
#ifdef WIN32
if
(
isalpha
(
path
[
0
])
&&
(
path
[
1
]
==
':'
))
{
if
(
asprintf
(
&
buf
,
"file:///%c:"
,
path
[
0
])
==
-
1
)
buf
=
NULL
;
path
+=
2
;
}
else
#endif
#if 0
/* Windows UNC paths (file://host/share/path instead of file:///path) */
if (!strncmp (path, "\\\\", 2))
{
path += 2;
buf = strdup ("file://");
}
else
#endif
if
(
path
[
0
]
!=
DIR_SEP_CHAR
)
{
/* Relative path: prepend the current working directory */
char
cwd
[
PATH_MAX
];
if
(
getcwd
(
cwd
,
sizeof
(
cwd
))
==
NULL
)
/* FIXME: UTF8? */
return
NULL
;
if
(
asprintf
(
&
buf
,
"%s/%s"
,
cwd
,
path
)
==
-
1
)
return
NULL
;
char
*
ret
=
make_URI
(
buf
);
free
(
buf
);
return
ret
;
}
else
buf
=
strdup
(
"file://"
);
if
(
buf
==
NULL
)
return
NULL
;
assert
(
path
[
0
]
==
DIR_SEP_CHAR
);
/* Absolute file path */
for
(
const
char
*
ptr
=
path
+
1
;;
ptr
++
)
{
size_t
len
=
strcspn
(
ptr
,
DIR_SEP
);
char
*
component
=
encode_URI_bytes
(
ptr
,
len
);
if
(
component
==
NULL
)
{
free
(
buf
);
return
NULL
;
}
char
*
uri
;
int
val
=
asprintf
(
&
uri
,
"%s/%s"
,
buf
,
component
);
free
(
component
);
free
(
buf
);
if
(
val
==
-
1
)
return
NULL
;
buf
=
uri
;
ptr
+=
len
;
if
(
*
ptr
==
'\0'
)
return
buf
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment