# 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
{
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
*****************************************************************************/
{
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;
*****************************************************************************/
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;
}
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;