]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/parser/xmlparser.cpp
* fixed build of skins2 interface on MacOS X (renamed Rect into SkinsRect
[vlc] / modules / gui / skins2 / parser / xmlparser.cpp
index 37ff58e998dba7ebdd61be3ecffe15b17ead6e38..dcfc2cde9df85feed98d2bb3caba4f2c9a2b0719 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * xmlparser.cpp
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "xmlparser.hpp"
 #include "../src/os_factory.hpp"
 
-#include <sys/stat.h>
+#ifdef HAVE_SYS_STAT_H
+#   include <sys/stat.h>
+#endif
 
 // Static variable to avoid initializing catalogs twice
 static bool m_initialized = false;
 
-XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
+XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName,
+                      bool useDTD ):
     SkinObject( pIntf )
 {
+    m_pReader = NULL;
+    m_pStream = NULL;
+
     m_pXML = xml_Create( pIntf );
     if( !m_pXML )
     {
-        msg_Err( getIntf(), "Failed to open XML parser" );
-        m_pReader = NULL;
+        msg_Err( getIntf(), "failed to open XML parser" );
         return;
     }
 
@@ -47,13 +52,23 @@ XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
         m_initialized = true;
     }
 
-    m_pReader = xml_ReaderCreate( m_pXML, rFileName.c_str() );
+    m_pStream = stream_UrlNew( pIntf, rFileName.c_str() );
+    if( !m_pStream )
+    {
+        msg_Err( getIntf(), "failed to open %s for reading",
+                 rFileName.c_str() );
+        return;
+    }
+    m_pReader = xml_ReaderCreate( m_pXML, m_pStream );
     if( !m_pReader )
     {
-        msg_Err( getIntf(), "Failed to open %s for parsing",
+        msg_Err( getIntf(), "failed to open %s for parsing",
                  rFileName.c_str() );
         return;
     }
+
+    xml_ReaderUseDTD( m_pReader, useDTD ? VLC_TRUE : VLC_FALSE );
+
 }
 
 
@@ -61,6 +76,7 @@ XMLParser::~XMLParser()
 {
     if( m_pReader && m_pXML ) xml_ReaderDelete( m_pXML, m_pReader );
     if( m_pXML ) xml_Delete( m_pXML );
+    if( m_pStream ) stream_Delete( m_pStream );
 }
 
 
@@ -71,6 +87,8 @@ void XMLParser::LoadCatalog()
     const list<string> &resPath = pOSFactory->getResourcePath();
     const string &sep = pOSFactory->getDirSeparator();
     list<string>::const_iterator it;
+
+#ifdef HAVE_SYS_STAT_H
     struct stat statBuf;
 
     // Try to load the catalog first (needed at least on win32 where
@@ -97,7 +115,7 @@ void XMLParser::LoadCatalog()
         if( !stat( path.c_str(), &statBuf ) )
         {
             // DTD found
-            msg_Dbg( getIntf(), "Using DTD %s", path.c_str() );
+            msg_Dbg( getIntf(), "using DTD %s", path.c_str() );
 
             // Add an entry in the default catalog
             xml_CatalogAdd( m_pXML, "public",
@@ -108,8 +126,9 @@ void XMLParser::LoadCatalog()
     }
     if( it == resPath.end() )
     {
-        msg_Err( getIntf(), "Cannot find the skins DTD !");
+        msg_Err( getIntf(), "cannot find the skins DTD");
     }
+#endif
 }
 
 bool XMLParser::parse()
@@ -149,11 +168,13 @@ bool XMLParser::parse()
                 }
 
                 handleBeginElement( eltName, attributes );
+                free( eltName );
 
                 map<const char*, const char*, ltstr> ::iterator it =
                     attributes.begin();
                 while( it != attributes.end() )
                 {
+                    free( (char *)it->first );
                     free( (char *)it->second );
                     it++;
                 }