[vlc-devel] [RFC PATCH] podcast: accept "text/xml" mime type

Thomas Guillem thomas at gllm.fr
Mon Oct 30 09:34:34 CET 2017


And add the "rss" check from the Open function.

Fixes #18995

--
Not sure if the !"rss" check is enough.
---
 modules/demux/playlist/playlist.c |  2 +-
 modules/demux/playlist/playlist.h |  1 +
 modules/demux/playlist/podcast.c  | 48 ++++++++++++++++++++-------------------
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/modules/demux/playlist/playlist.c b/modules/demux/playlist/playlist.c
index 449d5fd5b7..e4105e11fc 100644
--- a/modules/demux/playlist/playlist.c
+++ b/modules/demux/playlist/playlist.c
@@ -90,7 +90,7 @@ vlc_module_begin ()
         set_description( N_("Podcast parser") )
         add_shortcut( "podcast" )
         set_capability( "stream_filter", 10 )
-        set_callbacks( Import_podcast, NULL )
+        set_callbacks( Import_podcast, Close_podcast )
     add_submodule ()
         set_description( N_("XSPF playlist import") )
         set_capability( "stream_filter", 10 )
diff --git a/modules/demux/playlist/playlist.h b/modules/demux/playlist/playlist.h
index d9a6d7c478..fe1f54cabf 100644
--- a/modules/demux/playlist/playlist.h
+++ b/modules/demux/playlist/playlist.h
@@ -36,6 +36,7 @@ int Import_B4S ( vlc_object_t * );
 int Import_DVB ( vlc_object_t * );
 
 int Import_podcast ( vlc_object_t * );
+void Close_podcast ( vlc_object_t * );
 
 int Import_xspf ( vlc_object_t * );
 void Close_xspf ( vlc_object_t * );
diff --git a/modules/demux/playlist/podcast.c b/modules/demux/playlist/podcast.c
index 8c47d5ab6f..29b35b1eb9 100644
--- a/modules/demux/playlist/podcast.c
+++ b/modules/demux/playlist/podcast.c
@@ -49,9 +49,26 @@ int Import_podcast( vlc_object_t *p_this )
     stream_t *p_demux = (stream_t *)p_this;
 
     CHECK_FILE(p_demux);
-    if( !stream_IsMimeType( p_demux->p_source, "application/rss+xml" ) )
+    if( !stream_IsMimeType( p_demux->p_source, "application/xml" )
+     && !stream_IsMimeType( p_demux->p_source, "text/xml" ) )
         return VLC_EGENERIC;
 
+    xml_reader_t *p_xml_reader = xml_ReaderCreate( p_demux, p_demux->p_source );
+    if( !p_xml_reader )
+        return VLC_EGENERIC;
+
+    /* xml */
+    /* check root node */
+    const char *node;
+    if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
+     || strcmp( node, "rss" ) )
+    {
+        msg_Err( p_demux, "invalid file (no root node)" );
+        xml_ReaderDelete( p_xml_reader );
+        return VLC_EGENERIC;
+    }
+
+    p_demux->p_sys = p_xml_reader;
     p_demux->pf_readdir = ReadDir;
     p_demux->pf_control = access_vaDirectoryControlHelper;
     msg_Dbg( p_demux, "using podcast reader" );
@@ -65,7 +82,6 @@ static int ReadDir( stream_t *p_demux, input_item_node_t *p_subitems )
     bool b_item = false;
     bool b_image = false;
 
-    xml_reader_t *p_xml_reader;
     char *psz_elname = NULL;
     char *psz_item_mrl = NULL;
     char *psz_item_size = NULL;
@@ -85,23 +101,7 @@ static int ReadDir( stream_t *p_demux, input_item_node_t *p_subitems )
 
     input_item_t *p_current_input = GetCurrentItem(p_demux);
 
-    p_xml_reader = xml_ReaderCreate( p_demux, p_demux->p_source );
-    if( !p_xml_reader )
-        goto error;
-
-    /* xml */
-    /* check root node */
-    if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM )
-    {
-        msg_Err( p_demux, "invalid file (no root node)" );
-        goto error;
-    }
-
-    if( strcmp( node, "rss" ) )
-    {
-        msg_Err( p_demux, "invalid root node <%s>", node );
-        goto error;
-    }
+    xml_reader_t *p_xml_reader = p_demux->p_sys;
 
     while( (i_type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
     {
@@ -313,7 +313,6 @@ static int ReadDir( stream_t *p_demux, input_item_node_t *p_subitems )
 
     free( psz_art_url );
     free( psz_elname );
-    xml_ReaderDelete( p_xml_reader );
 
     return VLC_SUCCESS;
 
@@ -332,12 +331,15 @@ error:
     free( psz_art_url );
     free( psz_elname );
 
-    if( p_xml_reader )
-        xml_ReaderDelete( p_xml_reader );
-
     return VLC_EGENERIC;
 }
 
+void Close_podcast( vlc_object_t *p_this )
+{
+    stream_t *p_demux = (stream_t *)p_this;
+    xml_ReaderDelete( p_demux->p_sys );
+}
+
 static mtime_t strTimeToMTime( const char *psz )
 {
     int h, m, s;
-- 
2.11.0



More information about the vlc-devel mailing list