]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/qtl.c
b4s: memory leak
[vlc] / modules / demux / playlist / qtl.c
index 5b2965c90f0caf090a824b760e554067fcf36973..958b29e0afd783c8703515c0843ac306dbc98ea9 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * qtl.c: QuickTime Media Link Importer
  *****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*
@@ -57,6 +57,7 @@ volume - 0 (mute) - 100 (max)
 
 #include "playlist.h"
 #include <vlc_xml.h>
+#include <vlc_strings.h>
 
 typedef enum { FULLSCREEN_NORMAL,
                FULLSCREEN_DOUBLE,
@@ -73,7 +74,6 @@ const char* ppsz_loop[] = { "true", "false", "palindrome" };
  * Local prototypes
  *****************************************************************************/
 static int Demux( demux_t *p_demux);
-static int Control( demux_t *p_demux, int i_query, va_list args );
 
 /*****************************************************************************
  * Import_QTL: main import function
@@ -92,18 +92,10 @@ int Import_QTL( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * Deactivate: frees unused data
- *****************************************************************************/
-void Close_QTL( vlc_object_t *p_this )
-{
-    (void)p_this;
-}
-
 static int Demux( demux_t *p_demux )
 {
     xml_reader_t *p_xml_reader;
-    char *psz_eltname = NULL;
+    const char *node;
     input_item_t *p_input;
     int i_ret = -1;
 
@@ -130,146 +122,88 @@ static int Demux( demux_t *p_demux )
         goto error;
 
     /* check root node */
-    if( xml_ReaderRead( p_xml_reader ) != 1 )
-    {
-        msg_Err( p_demux, "invalid file (no root node)" );
-        goto error;
-    }
-
-    if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
-        ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
-        strcmp( psz_eltname, "embed" ) )
+    if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
+     || strcmp( node, "embed" ) )
     {
-        msg_Err( p_demux, "invalid root node %i, %s",
-                 xml_ReaderNodeType( p_xml_reader ), psz_eltname );
-        free( psz_eltname );
-        psz_eltname = NULL;
+        msg_Err( p_demux, "invalid root node <%s>", node );
 
         /* second line has <?quicktime tag ... so we try to skip it */
         msg_Dbg( p_demux, "trying to read one more node" );
-        xml_ReaderRead( p_xml_reader );
-        if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
-            ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
-            strcmp( psz_eltname, "embed" ) )
+        if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
+         || strcmp( node, "embed" ) )
         {
-            msg_Err( p_demux, "invalid root node %i, %s",
-                     xml_ReaderNodeType( p_xml_reader ), psz_eltname );
-            free( psz_eltname );
+            msg_Err( p_demux, "invalid root node <%s>", node );
             goto error;
         }
     }
-    free( psz_eltname );
 
-    while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
+    const char *attrname, *value;
+    while( (attrname = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
     {
-        char *psz_attrname = xml_ReaderName( p_xml_reader );
-        char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
-
-        if( !psz_attrname || !psz_attrvalue )
-        {
-            free( psz_attrname );
-            free( psz_attrvalue );
-            goto error;
-        }
-
-        if( !strcmp( psz_attrname, "autoplay" ) )
-        {
-            b_autoplay = !strcmp( psz_attrvalue, "true" );
-        }
-        else if( !strcmp( psz_attrname, "controler" ) )
+        if( !strcmp( attrname, "autoplay" ) )
+            b_autoplay = !strcmp( value, "true" );
+        else if( !strcmp( attrname, "controler" ) )
+            b_controler = !strcmp( attrname, "false" );
+        else if( !strcmp( attrname, "fullscreen" ) )
         {
-            b_controler = !strcmp( psz_attrvalue, "false" );
-        }
-        else if( !strcmp( psz_attrname, "fullscreen" ) )
-        {
-            if( !strcmp( psz_attrvalue, "double" ) )
-            {
+            if( !strcmp( value, "double" ) )
                 fullscreen = FULLSCREEN_DOUBLE;
-            }
-            else if( !strcmp( psz_attrvalue, "half" ) )
-            {
+            else if( !strcmp( value, "half" ) )
                 fullscreen = FULLSCREEN_HALF;
-            }
-            else if( !strcmp( psz_attrvalue, "current" ) )
-            {
+            else if( !strcmp( value, "current" ) )
                 fullscreen = FULLSCREEN_CURRENT;
-            }
-            else if( !strcmp( psz_attrvalue, "full" ) )
-            {
+            else if( !strcmp( value, "full" ) )
                 fullscreen = FULLSCREEN_FULL;
-            }
             else
-            {
                 fullscreen = FULLSCREEN_NORMAL;
-            }
-        }
-        else if( !strcmp( psz_attrname, "href" ) )
-        {
-            psz_href = psz_attrvalue;
-            psz_attrvalue = NULL;
         }
-        else if( !strcmp( psz_attrname, "kioskmode" ) )
+        else if( !strcmp( attrname, "href" ) )
         {
-            b_kioskmode = !strcmp( psz_attrvalue, "true" );
+            free( psz_href );
+            psz_href = strdup( value );
         }
-        else if( !strcmp( psz_attrname, "loop" ) )
+        else if( !strcmp( attrname, "kioskmode" ) )
+            b_kioskmode = !strcmp( value, "true" );
+        else if( !strcmp( attrname, "loop" ) )
         {
-            if( !strcmp( psz_attrvalue, "true" ) )
-            {
+            if( !strcmp( value, "true" ) )
                 loop = LOOP_TRUE;
-            }
-            else if( !strcmp( psz_attrvalue, "palindrome" ) )
-            {
+            else if( !strcmp( value, "palindrome" ) )
                 loop = LOOP_PALINDROME;
-            }
             else
-            {
                 loop = LOOP_FALSE;
-            }
-        }
-        else if( !strcmp( psz_attrname, "movieid" ) )
-        {
-            i_movieid = atoi( psz_attrvalue );
-        }
-        else if( !strcmp( psz_attrname, "moviename" ) )
-        {
-            psz_moviename = psz_attrvalue;
-            psz_attrvalue = NULL;
-        }
-        else if( !strcmp( psz_attrname, "playeveryframe" ) )
-        {
-            b_playeveryframe = !strcmp( psz_attrvalue, "true" );
-        }
-        else if( !strcmp( psz_attrname, "qtnext" ) )
-        {
-            psz_qtnext = psz_attrvalue;
-            psz_attrvalue = NULL;
         }
-        else if( !strcmp( psz_attrname, "quitwhendone" ) )
+        else if( !strcmp( attrname, "movieid" ) )
+            i_movieid = atoi( value );
+        else if( !strcmp( attrname, "moviename" ) )
         {
-            b_quitwhendone = !strcmp( psz_attrvalue, "true" );
+            free( psz_moviename );
+            psz_moviename = strdup( value );
         }
-        else if( !strcmp( psz_attrname, "src" ) )
+        else if( !strcmp( attrname, "playeveryframe" ) )
+            b_playeveryframe = !strcmp( value, "true" );
+        else if( !strcmp( attrname, "qtnext" ) )
         {
-            psz_src = psz_attrvalue;
-            psz_attrvalue = NULL;
+            free( psz_qtnext );
+            psz_qtnext = strdup( value );
         }
-        else if( !strcmp( psz_attrname, "mimetype" ) )
+        else if( !strcmp( attrname, "quitwhendone" ) )
+            b_quitwhendone = !strcmp( value, "true" );
+        else if( !strcmp( attrname, "src" ) )
         {
-            psz_mimetype = psz_attrvalue;
-            psz_attrvalue = NULL;
+            free( psz_src );
+            psz_src = strdup( value );
         }
-        else if( !strcmp( psz_attrname, "volume" ) )
+        else if( !strcmp( attrname, "mimetype" ) )
         {
-            i_volume = atoi( psz_attrvalue );
+            free( psz_mimetype );
+            psz_mimetype = strdup( value );
         }
+        else if( !strcmp( attrname, "volume" ) )
+            i_volume = atoi( value );
         else
-        {
             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
-                     psz_attrname, psz_attrvalue );
-        }
-        free( psz_attrname );
-        free( psz_attrvalue );
+                     attrname, value );
     }
 
     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
@@ -301,7 +235,7 @@ static int Demux( demux_t *p_demux )
     else
     {
         input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
-        p_input = input_item_New( p_demux, psz_src, psz_moviename );
+        p_input = input_item_New( psz_src, psz_moviename );
 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
                     p_input, "QuickTime Media Link", type, "%s", field ) ; }
         SADD_INFO( "href", psz_href );
@@ -310,7 +244,8 @@ static int Demux( demux_t *p_demux )
         vlc_gc_decref( p_input );
         if( psz_qtnext )
         {
-            p_input = input_item_New( p_demux, psz_qtnext, NULL );
+            resolve_xml_special_chars( psz_qtnext );
+            p_input = input_item_New( psz_qtnext, NULL );
             input_item_node_AppendItem( p_subitems, p_input );
             vlc_gc_decref( p_input );
         }
@@ -332,9 +267,3 @@ error:
     free( psz_mimetype );
     return i_ret;
 }
-
-static int Control( demux_t *p_demux, int i_query, va_list args )
-{
-    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
-    return VLC_EGENERIC;
-}