[vlc-devel] commit: XSPF: use make_URI, should fix #2731 ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun May 10 14:27:20 CEST 2009
vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Sun May 10 15:25:39 2009 +0300| [7a0efcc70902471d4704e80c1518c3111c6b186f] | committer: Rémi Denis-Courmont
XSPF: use make_URI, should fix #2731
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7a0efcc70902471d4704e80c1518c3111c6b186f
---
modules/misc/playlist/xspf.c | 85 +----------------------------------------
1 files changed, 3 insertions(+), 82 deletions(-)
diff --git a/modules/misc/playlist/xspf.c b/modules/misc/playlist/xspf.c
index a33633a..0f5f82c 100644
--- a/modules/misc/playlist/xspf.c
+++ b/modules/misc/playlist/xspf.c
@@ -34,14 +34,13 @@
#include <vlc_playlist.h>
#include <vlc_input.h>
#include <vlc_strings.h>
-#include <vlc_charset.h>
+#include <vlc_url.h>
#include "xspf.h"
#include <assert.h>
static void xspf_export_item( playlist_item_t *, FILE *, int * );
static void xspf_extension_item( playlist_item_t *, FILE *, int * );
-static char *assertUTF8URI( const char * );
/**
* \brief Prints the XSPF header to file, writes each item by xspf_export_item()
@@ -143,7 +142,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
if( psz_uri && *psz_uri )
{
- psz = assertUTF8URI( psz_uri );
+ psz = make_URI( psz_uri );
fprintf( p_file, "\t\t\t<location>%s</location>\n", psz );
free( psz );
}
@@ -213,7 +212,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
if( psz == NULL ) psz = strdup( "" );
if( !EMPTY_STR( psz ) )
{
- psz_uri = assertUTF8URI( psz );
+ psz_uri = make_URI( psz );
fprintf( p_file, "\t\t\t<image>%s</image>\n", psz_uri );
free( psz_uri );
}
@@ -288,81 +287,3 @@ static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file,
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( const 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 */
-
- /* 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 );
-}
More information about the vlc-devel
mailing list