[vlc-commits] demux/playlist: fix mime-type matching
Filip Roséen
git at videolan.org
Wed Mar 22 08:23:51 CET 2017
vlc | branch: master | Filip Roséen <filip at atch.se> | Wed Mar 22 04:38:34 2017 +0100| [5cde0de01244f3195ee24841ce2e085d71fd3a62] | committer: Rémi Denis-Courmont
demux/playlist: fix mime-type matching
The previous implementation would inaccurately truncate the mime-type
check in case of parameters in the content-type string, which in turn
would lead to false-positive matches.
As the usage of CheckContentType is really meant to check the
mime-type of the content-type string, besides fixing the inaccurate
comparision, the function is also renamed to CheckMimeType.
fixes: #18143
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5cde0de01244f3195ee24841ce2e085d71fd3a62
---
modules/demux/playlist/asx.c | 4 ++--
modules/demux/playlist/m3u.c | 7 +++++--
modules/demux/playlist/playlist.c | 24 +++++-------------------
modules/demux/playlist/playlist.h | 2 +-
4 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/modules/demux/playlist/asx.c b/modules/demux/playlist/asx.c
index 1b862a3..2e76d5e 100644
--- a/modules/demux/playlist/asx.c
+++ b/modules/demux/playlist/asx.c
@@ -150,8 +150,8 @@ int Import_ASX( vlc_object_t *p_this )
demux_IsPathExtension( p_demux, ".wax" ) ||
demux_IsPathExtension( p_demux, ".wvx" ) ||
(
- ( CheckContentType( p_demux->s, "video/x-ms-asf" ) ||
- CheckContentType( p_demux->s, "audio/x-ms-wax" ) ) && PeekASX( p_demux )
+ ( CheckMimeType( p_demux->s, "video/x-ms-asf" ) ||
+ CheckMimeType( p_demux->s, "audio/x-ms-wax" ) ) && PeekASX( p_demux )
) ||
demux_IsForced( p_demux, "asx-open" ) )
{
diff --git a/modules/demux/playlist/m3u.c b/modules/demux/playlist/m3u.c
index a3a23ef..5671398 100644
--- a/modules/demux/playlist/m3u.c
+++ b/modules/demux/playlist/m3u.c
@@ -79,14 +79,17 @@ int Import_M3U( vlc_object_t *p_this )
if( demux_IsPathExtension( p_demux, ".m3u8" )
|| demux_IsForced( p_demux, "m3u8" )
- || CheckContentType( p_demux->s, "application/vnd.apple.mpegurl" ) )
+ || CheckMimeType( p_demux->s, "application/vnd.apple.mpegurl" ) )
+ {
+ fprintf( stderr, "so apparently this is a m3u8\n" );
pf_dup = CheckUnicode; /* UTF-8 file type */
+ }
else
if( demux_IsPathExtension( p_demux, ".m3u" )
|| demux_IsPathExtension( p_demux, ".vlc" )
|| demux_IsForced( p_demux, "m3u" )
|| ContainsURL( p_demux )
- || CheckContentType( p_demux->s, "audio/x-mpegurl") )
+ || CheckMimeType( p_demux->s, "audio/x-mpegurl") )
; /* Guess encoding */
else
{
diff --git a/modules/demux/playlist/playlist.c b/modules/demux/playlist/playlist.c
index 48c531f..ef80a55 100644
--- a/modules/demux/playlist/playlist.c
+++ b/modules/demux/playlist/playlist.c
@@ -273,25 +273,11 @@ char *ProcessMRL(const char *str, const char *base)
/**
* Checks stream Content-Type against a known one
*/
-bool CheckContentType( stream_t * p_stream, const char * psz_ctype )
+bool CheckMimeType( stream_t *stream, const char *mime_type )
{
- char *psz_check = stream_ContentType( p_stream );
- if( !psz_check ) return false;
+ char* stream_mtype = stream_MimeType( stream );
+ bool const match = stream_mtype && !strcasecmp( mime_type, stream_mtype );
- int i_len = strlen( psz_check );
- if ( i_len == 0 )
- {
- free( psz_check );
- return false;
- }
-
- /* check for Content-Type: foo-type; charset=... */
- const char * psz_sep = strchr( psz_check, ';' );
- if ( psz_sep )
- i_len = __MIN( i_len, psz_sep - psz_check );
-
- int i_res = strncasecmp( psz_check, psz_ctype, i_len );
- free( psz_check );
-
- return ( i_res == 0 ) ? true : false;
+ free( stream_mtype );
+ return match;
}
diff --git a/modules/demux/playlist/playlist.h b/modules/demux/playlist/playlist.h
index da5e81d..4e659c7 100644
--- a/modules/demux/playlist/playlist.h
+++ b/modules/demux/playlist/playlist.h
@@ -78,7 +78,7 @@ void Close_Dir ( vlc_object_t * );
extern input_item_t * GetCurrentItem(demux_t *p_demux);
-bool CheckContentType( stream_t * p_stream, const char * psz_ctype );
+bool CheckMimeType( stream_t * p_stream, const char * psz_ctype );
#define CHECK_FILE() \
do { \
More information about the vlc-commits
mailing list