Commit 6d51bbdc authored by Gildas Bazin's avatar Gildas Bazin

* ALL: New XML module type.

* include/vlc_xml.h, src/misc/xml.c: core wrapper for XML modules.
* modules/misc/xml/xtag.c: trivial XML parser module.
* modules/misc/xml/libxml.c: XML parser module using libxml2.
* modules/gui/skins2/parser/*: removed dependancy on libxml2 and use an XML module.
parent f90d9508
......@@ -116,6 +116,7 @@ HEADERS_include = \
include/vlc_video.h \
include/vlc_vlm.h \
include/vlc_vod.h \
include/vlc_xml.h \
include/vout_synchro.h \
include/win32_specific.h \
$(NULL)
......@@ -376,6 +377,7 @@ SOURCES_libvlc_common = \
src/misc/error.c \
src/misc/net.c \
src/misc/vlm.c \
src/misc/xml.c \
src/extras/libc.c \
$(NULL)
......
......@@ -444,7 +444,7 @@ AM_CONDITIONAL(BUILD_GETOPT, ${need_getopt})
if test "${SYS}" != "mingw32"; then
AC_TYPE_SIGNAL
AC_CHECK_LIB(m,cos,[
VLC_ADD_LDFLAGS([adjust distort a52tofloat32 dtstofloat32 x264],[-lm])
VLC_ADD_LDFLAGS([adjust distort a52tofloat32 dtstofloat32 x264 goom],[-lm])
])
AC_CHECK_LIB(m,pow,[
VLC_ADD_LDFLAGS([ffmpeg ffmpegaltivec stream_out_transrate i420_rgb faad toolame equalizer vlc],[-lm])
......@@ -954,7 +954,7 @@ VLC_ADD_PLUGINS([trivial_channel_mixer simple_channel_mixer headphone_channel_mi
VLC_ADD_PLUGINS([trivial_mixer spdif_mixer float32_mixer])
VLC_ADD_PLUGINS([aout_file equalizer])
VLC_ADD_PLUGINS([i420_rgb i420_yuy2 i422_yuy2 i420_ymga])
VLC_ADD_PLUGINS([id3 playlist export sgimb m3u])
VLC_ADD_PLUGINS([id3 playlist export sgimb m3u xtag])
VLC_ADD_PLUGINS([rawvideo blend scale time marq])
VLC_ADD_PLUGINS([wav araw subtitle vobsub adpcm a52sys dtssys au])
VLC_ADD_PLUGINS([access_file access_udp access_tcp access_http ipv4 access_mms])
......@@ -2857,6 +2857,39 @@ from http://www.freetype.org/, or configure with --disable-freetype. Have a nice
fi
fi
dnl
dnl libxml2 module
dnl
AC_ARG_ENABLE(libxml2,
[ --enable-libxml2 libxml2 support (default enabled)])
if test "${enable_libxml2}" != "no"
then
XML2_PATH="${PATH}"
AC_ARG_WITH(xml2-config-path,
[ --with-xml2-config-path=PATH xml2-config path (default search in \$PATH)],
[ if test "${with_xml2_config_path}" != "no"; then
XML2_PATH="${with_xml2_config_path}:${PATH}"
fi ])
AC_PATH_PROG(XML2_CONFIG, xml2-config, no, ${XML2_PATH})
if test "${XML2_CONFIG}" != "no"; then
VLC_ADD_CPPFLAGS([xml],[`${XML2_CONFIG} --cflags`])
VLC_ADD_LDFLAGS([xml],[`${XML2_CONFIG} --libs`])
dnl depends on the xmlTextReader extension
LDFLAGS="${LDFLAGS_save} ${LDFLAGS_xml}"
AC_CHECK_LIB(xml2,xmlTextReaderConstName,[
VLC_ADD_PLUGINS([xml]) ],[
AC_MSG_WARN([libxml2 missing the xmlTextReader extension, you should update your version])
if test "${enable_xml2}" = "yes"; then
AC_MSG_ERROR([libxml2 missing the xmlTextReader extension])
fi])
LDFLAGS="${LDFLAGS_save}"
else
if test "${enable_xml2}" = "yes"; then
AC_MSG_ERROR([Could not find libxml2])
fi
fi
fi
dnl
dnl SVG module
dnl
......@@ -3278,33 +3311,6 @@ if test "${enable_skins2}" = "yes" || (test "${SYS}" != "darwin" && test "${SYS}
fi
fi
dnl libxml2
XML2_PATH="${PATH}"
AC_ARG_WITH(xml2-config-path,
[ --with-xml2-config-path=PATH xml2-config path (default search in \$PATH)],
[ if test "${with_xml2_config_path}" != "no"; then
XML2_PATH="${with_xml2_config_path}:${PATH}"
fi ])
AC_PATH_PROG(XML2_CONFIG, xml2-config, no, ${XML2_PATH})
if test "${XML2_CONFIG}" != "no"; then
VLC_ADD_CPPFLAGS([skins2],[`${XML2_CONFIG} --cflags`])
VLC_ADD_LDFLAGS([skins2],[`${XML2_CONFIG} --libs`])
dnl skins2 depends on the xmlTextReader extension
LDFLAGS="${LDFLAGS_save} ${LDFLAGS_skins2}"
AC_CHECK_LIB(xml2,xmlTextReaderConstName,[],[
skins2_missing_lib="yes"
AC_MSG_WARN([libxml2 missing the xmlTextReader extension, you should update your version; maybe you are missing libpng.])
if test "${enable_skins2}" = "yes"; then
AC_MSG_ERROR([libxml2 missing the xmlTextReader extension (required for skins2)])
fi])
LDFLAGS="${LDFLAGS_save}"
else
skins2_missing_lib="yes"
if test "${enable_skins2}" = "yes"; then
AC_MSG_ERROR([Could not find libxml2 (required for skins2)])
fi
fi
if test "${skins2_missing_lib}" = "no" && (test "${SYS}" = "mingw32" -o "${SYS}" = "cygwin"); then
VLC_ADD_PLUGINS([skins2])
ALIASES="${ALIASES} svlc"
......@@ -3736,12 +3742,14 @@ then
fi
else
AC_CHECK_HEADERS(goom/goom.h, [
LDFLAGS="${LDFLAGS_save} ${LDFLAGS_goom}"
AC_CHECK_LIB(goom2, goom_init, [
VLC_ADD_PLUGINS([goom])
VLC_ADD_LDFLAGS([goom],[-lgoom2])
],[
AC_MSG_ERROR([Could not find goom on your system: you may get it from http://www.ios-software.com/.])
])
LDFLAGS="${LDFLAGS_save}"
])
fi
fi
......@@ -4225,6 +4233,7 @@ AC_CONFIG_FILES([
modules/misc/network/Makefile
modules/misc/testsuite/Makefile
modules/misc/playlist/Makefile
modules/misc/xml/Makefile
modules/mux/Makefile
modules/mux/mpeg/Makefile
modules/packetizer/Makefile
......
......@@ -370,6 +370,12 @@ typedef struct tls_t tls_t;
typedef struct tls_server_t tls_server_t;
typedef struct tls_session_t tls_session_t;
/* XML */
typedef struct xml_t xml_t;
typedef struct xml_sys_t xml_sys_t;
typedef struct xml_reader_t xml_reader_t;
typedef struct xml_reader_sys_t xml_reader_sys_t;
/* vod server */
typedef struct vod_t vod_t;
typedef struct vod_sys_t vod_sys_t;
......
......@@ -58,6 +58,7 @@
#define VLC_OBJECT_SPU (-24)
#define VLC_OBJECT_TLS (-25)
#define VLC_OBJECT_SD (-26)
#define VLC_OBJECT_XML (-27)
#define VLC_OBJECT_GENERIC (-666)
......
/*****************************************************************************
* xml.h
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id$
*
* Author: Gildas Bazin <gbazin@videolan.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
* (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.
*
* 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.
*****************************************************************************/
#ifndef _VLC_XML_H
#define _VLC_XML_H
struct xml_t
{
VLC_COMMON_MEMBERS
/* Module properties */
module_t *p_module;
xml_sys_t *p_sys;
xml_reader_t * (*pf_reader_create) ( xml_t *, const char * );
void (*pf_reader_delete) ( xml_reader_t * );
void (*pf_catalog_load) ( xml_t *, const char * );
void (*pf_catalog_add) ( xml_t *, const char *, const char *,
const char * );
};
#define xml_Create( a ) __xml_Create( VLC_OBJECT(a) )
VLC_EXPORT( xml_t *, __xml_Create, ( vlc_object_t * ) );
VLC_EXPORT( void, xml_Delete, ( xml_t * ) );
#define xml_ReaderCreate( a, b ) a->pf_reader_create( a, b )
#define xml_ReaderDelete( a, b ) a->pf_reader_delete( b )
#define xml_CatalogLoad( a, b ) a->pf_catalog_load( a, b )
#define xml_CatalogAdd( a, b, c, d ) a->pf_catalog_add( a, b, c, d )
struct xml_reader_t
{
xml_t *p_xml;
xml_reader_sys_t *p_sys;
int (*pf_read) ( xml_reader_t * );
int (*pf_node_type) ( xml_reader_t * );
char * (*pf_name) ( xml_reader_t * );
char * (*pf_value) ( xml_reader_t * );
int (*pf_next_attr) ( xml_reader_t * );
};
#define xml_ReaderRead( a ) a->pf_read( a )
#define xml_ReaderNodeType( a ) a->pf_node_type( a )
#define xml_ReaderName( a ) a->pf_name( a )
#define xml_ReaderValue( a ) a->pf_value( a )
#define xml_ReaderNextAttr( a ) a->pf_next_attr( a )
#define XML_READER_NONE 0
#define XML_READER_STARTELEM 1
#define XML_READER_ENDELEM 2
#define XML_READER_TEXT 3
#endif
This diff is collapsed.
......@@ -40,8 +40,6 @@ class SkinParser: public XMLParser
const BuilderData &getData() const { return m_data; }
private:
// Static variable to avoid initializing catalogs twice
static bool m_initialized;
/// Container for mapping data from the XML
BuilderData m_data;
/// Current IDs
......
......@@ -22,110 +22,157 @@
*****************************************************************************/
#include "xmlparser.hpp"
#include "../src/os_factory.hpp"
#include <sys/stat.h>
// Static variable to avoid initializing catalogs twice
static bool m_initialized = false;
XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
SkinObject( pIntf )
{
m_pReader = xmlNewTextReaderFilename( rFileName.c_str() );
m_pXML = xml_Create( pIntf );
if( !m_pXML )
{
msg_Err( getIntf(), "Failed to open XML parser" );
m_pReader = NULL;
return;
}
// Avoid duplicate initialization (mutex needed ?)
if( !m_initialized )
{
LoadCatalog();
m_initialized = true;
}
m_pReader = xml_ReaderCreate( m_pXML, rFileName.c_str() );
if( !m_pReader )
{
msg_Err( getIntf(), "Failed to open %s for parsing",
rFileName.c_str() );
return;
}
}
// Activate DTD validation
xmlTextReaderSetParserProp( m_pReader, XML_PARSER_DEFAULTATTRS, 1 );
xmlTextReaderSetParserProp( m_pReader, XML_PARSER_VALIDATE, 1 );
// Set the error handler
xmlTextReaderSetErrorHandler( m_pReader, handleError, this );
XMLParser::~XMLParser()
{
if( m_pReader && m_pXML ) xml_ReaderDelete( m_pXML, m_pReader );
if( m_pXML ) xml_Delete( m_pXML );
}
XMLParser::~XMLParser()
void XMLParser::LoadCatalog()
{
if( m_pReader )
// Get the resource path and look for the DTD
OSFactory *pOSFactory = OSFactory::instance( getIntf() );
const list<string> &resPath = pOSFactory->getResourcePath();
const string &sep = pOSFactory->getDirSeparator();
list<string>::const_iterator it;
struct stat statBuf;
// Try to load the catalog first (needed at least on win32 where
// we don't have a default catalog)
for( it = resPath.begin(); it != resPath.end(); it++ )
{
string catalog_path = (*it) + sep + "skin.catalog";
if( !stat( catalog_path.c_str(), &statBuf ) )
{
msg_Dbg( getIntf(), "Using catalog %s", catalog_path.c_str() );
xml_CatalogLoad( m_pXML, catalog_path.c_str() );
break;
}
}
if( it == resPath.end() )
{
xmlFreeTextReader( m_pReader );
// Ok, try the default one
xml_CatalogLoad( m_pXML, 0 );
}
}
for( it = resPath.begin(); it != resPath.end(); it++ )
{
string path = (*it) + sep + "skin.dtd";
if( !stat( path.c_str(), &statBuf ) )
{
// DTD found
msg_Dbg( getIntf(), "Using DTD %s", path.c_str() );
bool XMLParser::parse()
{
if( !m_pReader )
// Add an entry in the default catalog
xml_CatalogAdd( m_pXML, "public",
"-//VideoLAN//DTD VLC Skins V"
SKINS_DTD_VERSION "//EN", path.c_str() );
break;
}
}
if( it == resPath.end() )
{
return false;
msg_Err( getIntf(), "Cannot find the skins DTD !");
}
}
bool XMLParser::parse()
{
if( !m_pReader ) return false;
m_errors = false;
int ret = xmlTextReaderRead( m_pReader );
while (ret == 1)
int ret = xml_ReaderRead( m_pReader );
while( ret == 1 )
{
if( m_errors )
{
return false;
}
if( m_errors ) return false;
// Get the node type
int type = xmlTextReaderNodeType( m_pReader );
switch (type )
int type = xml_ReaderNodeType( m_pReader );
switch( type )
{
// Error
case -1:
return false;
break;
// Begin element
case 1:
case XML_READER_STARTELEM:
{
// Read the element name
const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
if( !eltName )
{
return false;
}
char *eltName = xml_ReaderName( m_pReader );
if( !eltName ) return false;
// Read the attributes
AttrList_t attributes;
while( xmlTextReaderMoveToNextAttribute( m_pReader ) == 1 )
while( xml_ReaderNextAttr( m_pReader ) == VLC_SUCCESS )
{
char *name = xml_ReaderName( m_pReader );
char *value = xml_ReaderValue( m_pReader );
if( !name || !value ) return false;
attributes[name] = value;
}
handleBeginElement( eltName, attributes );
map<const char*, const char*, ltstr> ::iterator it =
attributes.begin();
while( it != attributes.end() )
{
const xmlChar *name = xmlTextReaderConstName( m_pReader );
const xmlChar *value = xmlTextReaderConstValue( m_pReader );
if( !name || !value )
{
return false;
}
attributes[(const char*)name] = (const char*)value;
free( (char *)it->second );
it++;
}
handleBeginElement( (const char*)eltName, attributes);
break;
}
// End element
case 15:
case XML_READER_ENDELEM:
{
// Read the element name
const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
if( !eltName )
{
return false;
}
handleEndElement( (const char*)eltName );
char *eltName = xml_ReaderName( m_pReader );
if( !eltName ) return false;
handleEndElement( eltName );
free( eltName );
break;
}
}
ret = xmlTextReaderRead( m_pReader );
ret = xml_ReaderRead( m_pReader );
}
return (ret == 0 && !m_errors );
}
void XMLParser::handleError( void *pArg, const char *pMsg,
xmlParserSeverities severity,
xmlTextReaderLocatorPtr locator)
{
XMLParser *pThis = (XMLParser*)pArg;
int line = xmlTextReaderLocatorLineNumber( locator );
msg_Err( pThis->getIntf(), "XML parser error (line %d) : %s", line, pMsg );
pThis->m_errors = true;
}
......@@ -2,7 +2,7 @@
* xmlparser.hpp
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: xmlparser.hpp,v 1.6 2004/03/01 19:36:43 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
*
......@@ -25,9 +25,12 @@
#define XMLPARSER_HPP
#include "../src/skin_common.hpp"
#include <libxml/xmlreader.h>
#include "vlc_xml.h"
#include <map>
// Current DTD version
#define SKINS_DTD_VERSION "2.0"
/// XML parser using libxml2 text reader API
class XMLParser: public SkinObject
{
......@@ -54,17 +57,16 @@ class XMLParser: public SkinObject
bool m_errors;
/// Callbacks
virtual void handleBeginElement( const string &rName, AttrList_t &attr ) {}
virtual void handleBeginElement( const string &rName,
AttrList_t &attr ) {}
virtual void handleEndElement( const string &rName ) {}
private:
/// Reader context
xmlTextReaderPtr m_pReader;
void LoadCatalog();
/// Callback for validation errors
static void handleError( void *pArg, const char *pMsg,
xmlParserSeverities severity,
xmlTextReaderLocatorPtr locator);
/// Reader context
xml_t *m_pXML;
xml_reader_t *m_pReader;
};
#endif
......@@ -2,7 +2,7 @@
* ft2_bitmap.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ft2_bitmap.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* logger.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: logger.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* os_graphics.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: os_graphics.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* os_timer.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: os_timer.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* os_tooltip.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: os_tooltip.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* png_bitmap.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: png_bitmap.hpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* scaled_bitmap.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: scaled_bitmap.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
......@@ -2,7 +2,7 @@
* tooltip.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: tooltip.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
......
SOURCES_xtag = xtag.c
SOURCES_xml = libxml.c
/*****************************************************************************
* libxml.c: XML parser using libxml2
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.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
* (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.
*
* 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.
*****************************************************************************/
#include <stdlib.h>
#include <vlc/vlc.h>
#include "vlc_xml.h"
#include <libxml/xmlreader.h>
#include <libxml/catalog.h>
/*****************************************************************************
* 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();
struct xml_reader_sys_t
{
/* libxml2 reader context */
xmlTextReaderPtr p_reader;
};
static xml_reader_t *ReaderCreate( xml_t *, const char * );
static void ReaderDelete( xml_reader_t * );
static int ReaderRead( xml_reader_t * );
static int ReaderNodeType( xml_reader_t * );
static char *ReaderName( xml_reader_t * );
static char *ReaderValue( xml_reader_t * );
static int ReaderNextAttr( xml_reader_t * );
static void CatalogLoad( xml_t *, const char * );
static void CatalogAdd( xml_t *, const char *, const char *, const char * );
/*****************************************************************************
* Module initialization
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
xml_t *p_xml = (xml_t *)p_this;
p_xml->pf_reader_create = ReaderCreate;
p_xml->pf_reader_delete = ReaderDelete;
p_xml->pf_catalog_load = CatalogLoad;
p_xml->pf_catalog_add = CatalogAdd;
return VLC_SUCCESS;
}
/*****************************************************************************
* Module deinitialization
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
return;
}
/*****************************************************************************
* Catalogue functions
*****************************************************************************/
static void CatalogLoad( xml_t *p_xml, const char *psz_filename )
{
if( !psz_filename ) xmlInitializeCatalog();
else xmlLoadCatalog( psz_filename );
}
static void CatalogAdd( xml_t *p_xml, const char *psz_arg1,
const char *psz_arg2, const char *psz_filename )
{
xmlCatalogAdd( psz_arg1, psz_arg2, psz_filename );
}
/*****************************************************************************
* Reader functions
*****************************************************************************/
static void ReaderErrorHandler( void *p_arg, const char *p_msg,
xmlParserSeverities severity,
xmlTextReaderLocatorPtr locator)
{
xml_reader_t *p_reader = (xml_reader_t *)p_arg;
int line = xmlTextReaderLocatorLineNumber( locator );
msg_Err( p_reader->p_xml, "XML parser error (line %d) : %s", line, p_msg );
}
static xml_reader_t *ReaderCreate( xml_t *p_xml, const char *psz_filename )
{
xml_reader_t *p_reader;
xml_reader_sys_t *p_sys;
xmlTextReaderPtr p_libxml_reader;
p_libxml_reader = xmlNewTextReaderFilename( psz_filename );
if( !p_libxml_reader )
{
msg_Err( p_xml, "failed to open file %s for parsing", psz_filename );
return 0;
}
p_reader = malloc( sizeof(xml_reader_t) );
p_reader->p_sys = p_sys = malloc( sizeof(xml_reader_sys_t) );
p_reader->p_sys->p_reader = p_libxml_reader;
p_reader->p_xml = p_xml;
/* Activate DTD validation */
xmlTextReaderSetParserProp( p_libxml_reader, XML_PARSER_DEFAULTATTRS, 1 );
xmlTextReaderSetParserProp( p_libxml_reader, XML_PARSER_VALIDATE, 1 );
/* Set the error handler */
xmlTextReaderSetErrorHandler( p_libxml_reader,
ReaderErrorHandler, p_reader );
p_reader->pf_read = ReaderRead;
p_reader->pf_node_type = ReaderNodeType;
p_reader->pf_name = ReaderName;
p_reader->pf_value = ReaderValue;
p_reader->pf_next_attr = ReaderNextAttr;
return p_reader;
}
static void ReaderDelete( xml_reader_t *p_reader )
{
xmlFreeTextReader( p_reader->p_sys->p_reader );
free( p_reader->p_sys );
free( p_reader );
}
static int ReaderRead( xml_reader_t *p_reader )
{
int i_ret = xmlTextReaderRead( p_reader->p_sys->p_reader );
#if 0
switch( i_ret )
{
default:
}
#endif
return i_ret;
}
static int ReaderNodeType( xml_reader_t *p_reader )
{
int i_ret = xmlTextReaderNodeType( p_reader->p_sys->p_reader );
switch( i_ret )
{
case XML_READER_TYPE_ELEMENT:
i_ret = XML_READER_STARTELEM;
break;
case XML_READER_TYPE_END_ELEMENT:
i_ret = XML_READER_ENDELEM;
break;
case -1:
i_ret = -1;
break;
default:
i_ret = XML_READER_NONE;
break;
}
return i_ret;
}
static char *ReaderName( xml_reader_t *p_reader )
{
const xmlChar *psz_name =
xmlTextReaderConstName( p_reader->p_sys->p_reader );
if( psz_name ) return strdup( psz_name );
else return 0;
}
static char *ReaderValue( xml_reader_t *p_reader )
{
const xmlChar *psz_value =
xmlTextReaderConstValue( p_reader->p_sys->p_reader );
if( psz_value ) return strdup( psz_value );
else return 0;
}
static int ReaderNextAttr( xml_reader_t *p_reader )
{
return ( xmlTextReaderMoveToNextAttribute( p_reader->p_sys->p_reader )
== 1 ) ? VLC_SUCCESS : VLC_EGENERIC;
}
This diff is collapsed.
......@@ -100,6 +100,7 @@
#include "osd.h"
#include "vlc_httpd.h"
#include "vlc_tls.h"
#include "vlc_xml.h"
#include "iso_lang.h"
#include "charset.h"
......
......@@ -54,6 +54,7 @@
#include "vlc_vlm.h"
#include "vlc_vod.h"
#include "vlc_tls.h"
#include "vlc_xml.h"
/*****************************************************************************
* Local prototypes
......@@ -194,6 +195,10 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
i_size = sizeof( tls_t );
psz_type = "tls";
break;
case VLC_OBJECT_XML:
i_size = sizeof( xml_t );
psz_type = "xml";
break;
case VLC_OBJECT_OPENGL:
i_size = sizeof( vout_thread_t );
psz_type = "opengl provider";
......
/*****************************************************************************
* xml.c: XML parser wrapper for XML modules
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.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
* (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.
*
* 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.
*****************************************************************************/
#include <stdlib.h>
#include <vlc/vlc.h>
#include "vlc_xml.h"
/*****************************************************************************
* xml_Create:
*****************************************************************************
* Create an instance of an XML parser.
* Returns NULL on error.
*****************************************************************************/
xml_t *__xml_Create( vlc_object_t *p_this )
{
xml_t *p_xml;
p_xml = vlc_object_create( p_this, VLC_OBJECT_XML );
vlc_object_attach( p_xml, p_this );
p_xml->p_module = module_Need( p_xml, "xml", 0, 0 );
if( !p_xml->p_module )
{
vlc_object_detach( p_xml );
vlc_object_destroy( p_xml );
msg_Err( p_this, "XML provider not found" );
return NULL;
}
return p_xml;
}
/*****************************************************************************
* xml_Delete: Deletes an instance of xml_t
*****************************************************************************/
void xml_Delete( xml_t *p_xml )
{
module_Unneed( p_xml, p_xml->p_module );
vlc_object_detach( p_xml );
vlc_object_destroy( p_xml );
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment