]> git.sesse.net Git - vlc/blobdiff - modules/misc/xml/libxml.c
Require libxml2 < 2.7
[vlc] / modules / misc / xml / libxml.c
index 51704b04ccc944a2faa2c1ae1d696d785a193738..09c200e80e476d127dcd1b188c4a4e9d006193e5 100644 (file)
@@ -25,7 +25,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
 
 #include "vlc_block.h"
 #include <libxml/xmlreader.h>
 #include <libxml/catalog.h>
 
+#if !defined (LIBXML_VERSION) || (LIBXML_VERSION > 20700)
+# error Stale config.cache detected. Erase it and re-run configure.
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( _("XML Parser (using libxml2)") );
-    set_capability( "xml", 10 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("XML Parser (using libxml2)") )
+    set_capability( "xml", 10 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 struct xml_reader_sys_t
 {
@@ -67,6 +71,9 @@ static void CatalogLoad( xml_t *, const char * );
 static void CatalogAdd( xml_t *, const char *, const char *, const char * );
 static int StreamRead( void *p_context, char *p_buffer, int i_buffer );
 
+static unsigned refs = 0;
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+
 /*****************************************************************************
  * Module initialization
  *****************************************************************************/
@@ -74,6 +81,14 @@ static int Open( vlc_object_t *p_this )
 {
     xml_t *p_xml = (xml_t *)p_this;
 
+    if( !xmlHasFeature( XML_WITH_THREAD ) )
+        return VLC_EGENERIC;
+
+    vlc_mutex_lock( &lock );
+    if( refs++ == 0 )
+        xmlInitParser();
+    vlc_mutex_unlock( &lock );
+
     p_xml->pf_reader_create = ReaderCreate;
     p_xml->pf_reader_delete = ReaderDelete;
 
@@ -88,6 +103,11 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
+    vlc_mutex_lock( &lock );
+    if( --refs == 0 )
+        xmlCleanupParser();
+    vlc_mutex_unlock( &lock );
+
     VLC_UNUSED(p_this);
     return;
 }
@@ -134,11 +154,22 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *p_stream )
     if( !p_libxml_reader )
     {
         msg_Err( p_xml, "failed to create XML parser" );
-        return 0;
+        return NULL;
     }
 
     p_reader = malloc( sizeof(xml_reader_t) );
+    if( !p_reader )
+    {
+        xmlFreeTextReader( p_libxml_reader );
+        return NULL;
+    }
     p_reader->p_sys = p_sys = malloc( sizeof(xml_reader_sys_t) );
+    if( !p_sys )
+    {
+        xmlFreeTextReader( p_libxml_reader );
+        free( p_reader );
+        return NULL;
+    }
     p_reader->p_sys->p_reader = p_libxml_reader;
     p_reader->p_xml = p_xml;