]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/shoutcast.c
Contribs: update live555 patch
[vlc] / modules / demux / playlist / shoutcast.c
index daa0f5933e4340d7eb1c3a9d135f6a644554bc4a..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,16 +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;
-    INIT_PLAYLIST_STUFF;
+    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;
 
@@ -109,41 +106,40 @@ 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;
     }
 
-    if( p_xml_reader )
-        xml_ReaderDelete( p_xml, p_xml_reader );
-    if( p_xml )
-        xml_Delete( p_xml );
-    free( psz_eltname );
-    HANDLE_PLAY_AND_RELEASE;
-    return 0; /* Needed for correct operation of go back */
+    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 );
-    HANDLE_PLAY_AND_RELEASE;
-    return -1;
+    if( p_input_node ) input_item_node_Delete( p_input_node );
+    vlc_gc_decref(p_current_input);
+    return i_ret;
 }
 
 #define GET_VALUE( a ) \
                         if( !strcmp( psz_attrname, #a ) ) \
                         { \
+                            free(psz_ ## a); \
                             psz_ ## a = psz_attrvalue; \
                         }
 /* <genrelist>
@@ -152,28 +148,26 @@ 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;
 
     while( xml_ReaderRead( p_xml_reader ) == 1 )
     {
-        int i_type;
-
         // Get the node type
-        i_type = xml_ReaderNodeType( p_xml_reader );
-        switch( i_type )
+        switch( xml_ReaderNodeType( p_xml_reader ) )
         {
             // Error
             case -1:
-                return -1;
-                break;
+                goto error;
 
             case XML_READER_STARTELEM:
             {
                 // Read the element name
                 char *psz_eltname = xml_ReaderName( p_xml_reader );
-                if( !psz_eltname ) return -1;
+                if( !psz_eltname )
+                    goto error;
 
                 if( !strcmp( psz_eltname, "genre" ) )
                 {
@@ -185,18 +179,17 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
                             xml_ReaderValue( p_xml_reader );
                         if( !psz_attrname || !psz_attrvalue )
                         {
-                            FREENULL(psz_attrname);
-                            FREENULL(psz_attrvalue);
-                            free(psz_eltname);
-                            /*FIXME: isn't return a bit too much. what about break*/
-                            return -1;
+                            free( psz_attrname );
+                            free( psz_attrvalue );
+                            free( psz_eltname );
+                            break;
                         }
 
                         GET_VALUE( name )
                         else
                         {
                             msg_Warn( p_demux,
-                                      "unexpected attribure %s in element %s",
+                                      "unexpected attribute %s in element %s",
                                       psz_attrname, psz_eltname );
                             free( psz_attrvalue );
                         }
@@ -215,7 +208,9 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
             {
                 // Read the element name
                 char *psz_eltname = xml_ReaderName( p_xml_reader );
-                if( !psz_eltname ) return -1;
+                if( !psz_eltname )
+                    goto error;
+
                 if( !strcmp( psz_eltname, "genre" ) )
                 {
                     char* psz_mrl;
@@ -224,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 );
@@ -236,7 +231,11 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
             }
         }
     }
-    return 0;
+    i_ret = 0;
+
+error:
+    free( psz_name );
+    return i_ret;
 }
 
 /* radio stations:
@@ -265,7 +264,7 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
  * </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; /* */
 
@@ -321,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 );
                         }
@@ -396,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 ) \
@@ -413,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 );
@@ -423,6 +423,7 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
                     FREENULL( psz_ct );
                     FREENULL( psz_lc );
                     FREENULL( psz_rt );
+                    FREENULL( psz_load );
                 }
                 free( psz_eltname );
                 break;