]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/shoutcast.c
Merge branch 'master' into lpcm_encoder
[vlc] / modules / demux / playlist / shoutcast.c
index 161156f6788c61b91dec173fa6a07eca62439a31..a8c2e5d92c02eb56fb4079917617d2d73b3ec192 100644 (file)
@@ -48,9 +48,9 @@ static int Demux( demux_t *p_demux);
 static int Control( demux_t *p_demux, int i_query, va_list args );
 
 static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
-                       input_item_t *p_current_input );
+                       input_item_node_t *p_input_node );
 static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
-                         input_item_t *p_current_input, bool b_adult );
+                         input_item_node_t *p_input_node, bool b_adult );
 
 /*****************************************************************************
  * Import_Shoutcast: main import function
@@ -79,17 +79,13 @@ void Close_Shoutcast( vlc_object_t *p_this )
 
 static int Demux( demux_t *p_demux )
 {
-    xml_t *p_xml;
     xml_reader_t *p_xml_reader = NULL;
     char *psz_eltname = NULL;
     int i_ret = -1;
     input_item_t *p_current_input = GetCurrentItem(p_demux);
+    input_item_node_t *p_input_node = NULL;
 
-    p_xml = xml_Create( p_demux );
-    if( !p_xml )
-        goto error;
-
-    p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
+    p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
     if( !p_xml_reader )
         goto error;
 
@@ -110,28 +106,32 @@ static int Demux( demux_t *p_demux )
         goto error;
     }
 
+    p_input_node = input_item_node_Create( p_current_input );
+
     if( !strcmp( psz_eltname, "genrelist" ) )
     {
         /* we're reading a genre list */
-        if( DemuxGenre( p_demux, p_xml_reader, p_current_input ) )
+        if( DemuxGenre( p_demux, p_xml_reader, p_input_node ) )
             goto error;
     }
     else
     {
         /* we're reading a station list */
-        if( DemuxStation( p_demux, p_xml_reader, p_current_input,
-                var_CreateGetBool( p_demux, "shoutcast-show-adult" ) ) )
+        if( DemuxStation( p_demux, p_xml_reader, p_input_node,
+                var_InheritBool( p_demux, "shoutcast-show-adult" ) ) )
             goto error;
     }
 
+    input_item_node_PostAndDelete( p_input_node );
+    p_input_node = NULL;
+
     i_ret = 0; /* Needed for correct operation of go back */
 
 error:
     if( p_xml_reader )
-        xml_ReaderDelete( p_xml, p_xml_reader );
-    if( p_xml )
-        xml_Delete( p_xml );
+        xml_ReaderDelete( p_xml_reader );
     free( psz_eltname );
+    if( p_input_node ) input_item_node_Delete( p_input_node );
     vlc_gc_decref(p_current_input);
     return i_ret;
 }
@@ -139,6 +139,7 @@ error:
 #define GET_VALUE( a ) \
                         if( !strcmp( psz_attrname, #a ) ) \
                         { \
+                            free(psz_ ## a); \
                             psz_ ## a = psz_attrvalue; \
                         }
 /* <genrelist>
@@ -147,7 +148,7 @@ error:
  * </genrelist>
  **/
 static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
-                       input_item_t *p_current_input )
+                       input_item_node_t *p_input_node )
 {
     char *psz_name = NULL; /* genre name */
     int i_ret = -1;
@@ -188,7 +189,7 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
                         else
                         {
                             msg_Warn( p_demux,
-                                      "unexpected attribure %s in element %s",
+                                      "unexpected attribute %s in element %s",
                                       psz_attrname, psz_eltname );
                             free( psz_attrvalue );
                         }
@@ -218,9 +219,9 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
                     {
                         input_item_t *p_input;
                         p_input = input_item_New( p_demux, psz_mrl, psz_name );
-                        input_item_CopyOptions( p_current_input, p_input );
+                        input_item_CopyOptions( p_input_node->p_item, p_input );
                         free( psz_mrl );
-                        input_item_AddSubItem( p_current_input, p_input );
+                        input_item_node_AppendItem( p_input_node, p_input );
                         vlc_gc_decref( p_input );
                     }
                     FREENULL( psz_name );
@@ -263,7 +264,7 @@ error:
  * </stationlist>
  **/
 static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
-                         input_item_t *p_current_input, bool b_adult )
+                         input_item_node_t *p_input_node, bool b_adult )
 {
     char *psz_base = NULL; /* */
 
@@ -319,7 +320,7 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
                         else
                         {
                             msg_Warn( p_demux,
-                                      "unexpected attribure %s in element %s",
+                                      "unexpected attribute %s in element %s",
                                       psz_attrname, psz_eltname );
                             free( psz_attrvalue );
                         }
@@ -394,7 +395,7 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
                     /* Create the item */
                     input_item_t *p_input;
                     p_input = input_item_New( p_demux, psz_mrl, psz_name );
-                    input_item_CopyOptions( p_current_input, p_input );
+                    input_item_CopyOptions( p_input_node->p_item, p_input );
                     free( psz_mrl );
 
 #define SADD_INFO( type, field ) \
@@ -411,8 +412,9 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
                         input_item_SetNowPlaying( p_input, psz_ct );
                     if( psz_rt )
                         input_item_SetRating( p_input, psz_rt );
-                    input_item_AddSubItem( p_current_input, p_input );
+                    input_item_node_AppendItem( p_input_node, p_input );
                     vlc_gc_decref( p_input );
+                    FREENULL( psz_base );
                     FREENULL( psz_name );
                     FREENULL( psz_mt );
                     FREENULL( psz_id );