Commit ad10f794 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

XML: return node (element name or text value) as const

This simplifies memory handling in most cases.
parent d4546731
......@@ -70,8 +70,7 @@ struct xml_reader_t
stream_t *p_stream;
module_t *p_module;
int (*pf_next_node) ( xml_reader_t * );
char * (*pf_name) ( xml_reader_t * );
int (*pf_next_node) ( xml_reader_t *, const char ** );
char * (*pf_value) ( xml_reader_t * );
const char *(*pf_next_attr) ( xml_reader_t * );
......@@ -83,14 +82,9 @@ VLC_EXPORT( xml_reader_t *, xml_ReaderCreate, (vlc_object_t *, stream_t *) LIBVL
VLC_EXPORT( void, xml_ReaderDelete, (xml_reader_t *) );
VLC_EXPORT( xml_reader_t *, xml_ReaderReset, (xml_reader_t *, stream_t *) LIBVLC_USED );
static inline int xml_ReaderNextNode( xml_reader_t *reader )
static inline int xml_ReaderNextNode( xml_reader_t *reader, const char **pval )
{
return reader->pf_next_node( reader );
}
static inline char *xml_ReaderName( xml_reader_t *reader )
{
return reader->pf_name( reader );
return reader->pf_next_node( reader, pval );
}
static inline char *xml_ReaderValue( xml_reader_t *reader )
......
......@@ -528,37 +528,29 @@ static int ParseImageAttachments( decoder_t *p_dec )
static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
{
decoder_sys_t *p_sys = p_dec->p_sys;
char *psz_node;
const char *node;
ssa_style_t *p_ssa_style = NULL;
int i_style_level = 0;
int i_metadata_level = 0;
int type;
while( (type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( type )
{
case XML_READER_ENDELEM:
psz_node = xml_ReaderName( p_xml_reader );
if( !psz_node )
break;
switch (i_style_level)
{
case 0:
if( !strcasecmp( "metadata", psz_node ) && (i_metadata_level == 1) )
{
if( !strcasecmp( "metadata", node ) && (i_metadata_level == 1) )
i_metadata_level--;
}
break;
case 1:
if( !strcasecmp( "styles", psz_node ) )
{
if( !strcasecmp( "styles", node ) )
i_style_level--;
}
break;
case 2:
if( !strcasecmp( "style", psz_node ) )
if( !strcasecmp( "style", node ) )
{
TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_ssa_style );
......@@ -567,20 +559,12 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
}
break;
}
free( psz_node );
break;
case XML_READER_STARTELEM:
psz_node = xml_ReaderName( p_xml_reader );
if( !psz_node )
break;
if( !strcasecmp( "metadata", psz_node ) && (i_style_level == 0) )
{
case XML_READER_STARTELEM:
if( !strcasecmp( "metadata", node ) && (i_style_level == 0) )
i_metadata_level++;
}
else if( !strcasecmp( "resolution", psz_node ) &&
else if( !strcasecmp( "resolution", node ) &&
( i_metadata_level == 1) )
{
const char *attr;
......@@ -597,27 +581,23 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
free( psz_value );
}
}
else if( !strcasecmp( "styles", psz_node ) && (i_style_level == 0) )
else if( !strcasecmp( "styles", node ) && (i_style_level == 0) )
{
i_style_level++;
}
else if( !strcasecmp( "style", psz_node ) && (i_style_level == 1) )
else if( !strcasecmp( "style", node ) && (i_style_level == 1) )
{
i_style_level++;
p_ssa_style = calloc( 1, sizeof(ssa_style_t) );
if( !p_ssa_style )
{
free( psz_node );
if( unlikely(!p_ssa_style) )
return;
}
/* All styles are supposed to default to Default, and then
* one or more settings are over-ridden.
* At the moment this only effects styles defined AFTER
* Default in the XML
*/
int i;
for( i = 0; i < p_sys->i_ssa_styles; i++ )
for( int i = 0; i < p_sys->i_ssa_styles; i++ )
{
if( !strcasecmp( p_sys->pp_ssa_styles[i]->psz_stylename, "Default" ) )
{
......@@ -646,7 +626,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
free( psz_value );
}
}
else if( !strcasecmp( "fontstyle", psz_node ) && (i_style_level == 2) )
else if( !strcasecmp( "fontstyle", node ) && (i_style_level == 2) )
{
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
......@@ -749,7 +729,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
free( psz_value );
}
}
else if( !strcasecmp( "position", psz_node ) && (i_style_level == 2) )
else if( !strcasecmp( "position", node ) && (i_style_level == 2) )
{
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
......@@ -808,8 +788,6 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
free( psz_value );
}
}
free( psz_node );
break;
}
}
......@@ -991,16 +969,13 @@ static void ParseUSFHeader( decoder_t *p_dec )
p_xml_reader = xml_ReaderCreate( p_dec, p_sub );
if( likely(p_xml_reader) )
{
/* Look for Root Node */
if( xml_ReaderNextNode( p_xml_reader ) == XML_READER_STARTELEM )
{
char *psz_node = xml_ReaderName( p_xml_reader );
const char *node;
if( !strcasecmp( "usfsubtitles", psz_node ) )
/* Look for Root Node */
if( xml_ReaderNextNode( p_xml_reader, &node ) == XML_READER_STARTELEM
&& !strcasecmp( "usfsubtitles", node ) )
ParseUSFHeaderTags( p_dec, p_xml_reader );
free( psz_node );
}
xml_ReaderDelete( p_xml_reader );
}
stream_Delete( p_sub );
......
......@@ -73,6 +73,7 @@ static int Demux( demux_t *p_demux )
xml_reader_t *p_xml_reader = NULL;
char *psz_elname = NULL;
const char *node;
input_item_t *p_input;
char *psz_mrl = NULL, *psz_title = NULL, *psz_genre = NULL;
char *psz_now = NULL, *psz_listeners = NULL, *psz_bitrate = NULL;
......@@ -84,42 +85,38 @@ static int Demux( demux_t *p_demux )
p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
if( !p_xml_reader )
goto end;
return -1;
/* xml */
/* check root node */
if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM )
if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM )
{
msg_Err( p_demux, "invalid file (no root node)" );
goto end;
}
if( ( psz_elname = xml_ReaderName( p_xml_reader ) ) == NULL ||
strcmp( psz_elname, "WinampXML" ) )
if( strcmp( node, "WinampXML" ) )
{
msg_Err( p_demux, "invalid root node: %s", psz_elname );
msg_Err( p_demux, "invalid root node: %s", node );
goto end;
}
FREENULL( psz_elname );
/* root node should not have any attributes, and should only
* contain the "playlist node */
/* Skip until 1st child node */
while( (i_ret = xml_ReaderNextNode( p_xml_reader )) != XML_READER_STARTELEM )
while( (i_ret = xml_ReaderNextNode( p_xml_reader, &node )) != XML_READER_STARTELEM )
if( i_ret <= 0 )
{
msg_Err( p_demux, "invalid file (no child node)" );
goto end;
}
if( ( psz_elname = xml_ReaderName( p_xml_reader ) ) == NULL ||
strcmp( psz_elname, "playlist" ) )
if( strcmp( node, "playlist" ) )
{
msg_Err( p_demux, "invalid child node %s", psz_elname );
msg_Err( p_demux, "invalid child node %s", node );
goto end;
}
FREENULL( psz_elname );
// Read the attributes
const char *attr;
......@@ -144,7 +141,7 @@ static int Demux( demux_t *p_demux )
p_subitems = input_item_node_Create( p_current_input );
while( (i_ret = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_ret = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
// Get the node type
switch( i_ret )
......@@ -153,8 +150,8 @@ static int Demux( demux_t *p_demux )
{
// Read the element name
free( psz_elname );
psz_elname = xml_ReaderName( p_xml_reader );
if( !psz_elname )
psz_elname = strdup( node );
if( unlikely(!psz_elname) )
goto end;
// Read the attributes
......@@ -180,55 +177,41 @@ static int Demux( demux_t *p_demux )
}
break;
}
case XML_READER_TEXT:
{
char *psz_text = xml_ReaderValue( p_xml_reader );
if( IsWhitespace( psz_text ) )
{
free( psz_text );
char **p;
if( psz_elname == NULL )
break;
if( IsWhitespace( node ) )
break;
}
if( !strcmp( psz_elname, "Name" ) )
{
psz_title = psz_text;
}
p = &psz_title;
else if( !strcmp( psz_elname, "Genre" ) )
{
psz_genre = psz_text;
}
p = &psz_genre;
else if( !strcmp( psz_elname, "Nowplaying" ) )
{
psz_now = psz_text;
}
p = &psz_now;
else if( !strcmp( psz_elname, "Listeners" ) )
{
psz_listeners = psz_text;
}
p = &psz_listeners;
else if( !strcmp( psz_elname, "Bitrate" ) )
{
psz_bitrate = psz_text;
}
else if( !strcmp( psz_elname, "" ) )
{
free( psz_text );
}
p = &psz_bitrate;
else
{
msg_Warn( p_demux, "unexpected text in element '%s'",
msg_Warn( p_demux, "unexpected text in element <%s>",
psz_elname );
free( psz_text );
break;
}
free( *p );
*p = strdup( node );
break;
}
// End element
case XML_READER_ENDELEM:
{
// Read the element name
free( psz_elname );
psz_elname = xml_ReaderName( p_xml_reader );
if( !psz_elname )
goto end;
if( !strcmp( psz_elname, "entry" ) )
if( !strcmp( node, "entry" ) )
{
p_input = input_item_New( p_demux, psz_mrl, psz_title );
if( psz_now )
......@@ -249,9 +232,7 @@ static int Demux( demux_t *p_demux )
FREENULL( psz_listeners );
FREENULL( psz_now );
}
free( psz_elname );
psz_elname = strdup( "" );
FREENULL( psz_elname );
break;
}
}
......
......@@ -68,7 +68,7 @@ void Close_iTML( vlc_object_t *p_this )
int Demux( demux_t *p_demux )
{
xml_reader_t *p_xml_reader;
char *psz_name = NULL;
const char *node;
input_item_t *p_current_input = GetCurrentItem(p_demux);
p_demux->p_sys->i_ntracks = 0;
......@@ -82,19 +82,19 @@ int Demux( demux_t *p_demux )
int type;
do
{
type = xml_ReaderNextNode( p_xml_reader );
type = xml_ReaderNextNode( p_xml_reader, &node );
if( type <= 0 )
{
msg_Err( p_demux, "can't read xml stream" );
goto end;
}
} while( type != XML_READER_STARTELEM );
}
while( type != XML_READER_STARTELEM );
/* checking root node name */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || strcmp( psz_name, "plist" ) )
if( strcmp( node, "plist" ) )
{
msg_Err( p_demux, "invalid root node name: %s", psz_name );
msg_Err( p_demux, "invalid root node <%s>", node );
goto end;
}
......@@ -108,7 +108,6 @@ int Demux( demux_t *p_demux )
vlc_gc_decref(p_current_input);
end:
free( psz_name );
if( p_xml_reader )
xml_ReaderDelete( p_xml_reader );
......@@ -177,34 +176,32 @@ static bool parse_dict( demux_t *p_demux, input_item_node_t *p_input_node,
const char *psz_element, xml_elem_hnd_t *p_handlers )
{
int i_node;
char *psz_name = NULL;
const char *node;
char *psz_value = NULL;
char *psz_key = NULL;
xml_elem_hnd_t *p_handler = NULL;
bool b_ret = false;
while( (i_node = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_node = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( i_node )
{
case XML_READER_STARTELEM:
/* element start tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || !*psz_name )
case XML_READER_STARTELEM:
if( !*node )
{
msg_Err( p_demux, "invalid xml stream" );
msg_Err( p_demux, "invalid XML stream" );
goto end;
}
/* choose handler */
for( p_handler = p_handlers;
p_handler->name && strcmp( psz_name, p_handler->name );
p_handler->name && strcmp( node, p_handler->name );
p_handler++ );
if( !p_handler->name )
{
msg_Err( p_demux, "unexpected element <%s>", psz_name );
msg_Err( p_demux, "unexpected element <%s>", node );
goto end;
}
FREE_NAME();
/* complex content is parsed in a separate function */
if( p_handler->type == COMPLEX_CONTENT )
{
......@@ -220,37 +217,28 @@ static bool parse_dict( demux_t *p_demux, input_item_node_t *p_input_node,
}
break;
case XML_READER_TEXT:
/* simple element content */
case XML_READER_TEXT:
free( psz_value );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream" );
psz_value = strdup( node );
if( unlikely(!psz_value) )
goto end;
}
break;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
goto end;
}
case XML_READER_ENDELEM:
/* leave if the current parent node <track> is terminated */
if( !strcmp( psz_name, psz_element ) )
if( !strcmp( node, psz_element ) )
{
b_ret = true;
goto end;
}
/* there MUST have been a start tag for that element name */
if( !p_handler || !p_handler->name
|| strcmp( p_handler->name, psz_name ) )
|| strcmp( p_handler->name, node ) )
{
msg_Err( p_demux, "there's no open element left for <%s>",
psz_name );
node );
goto end;
}
/* special case: key */
......@@ -268,12 +256,10 @@ static bool parse_dict( demux_t *p_demux, input_item_node_t *p_input_node,
p_handler = NULL;
break;
}
FREE_NAME();
}
msg_Err( p_demux, "unexpected end of XML data" );
end:
free( psz_name );
free( psz_value );
free( psz_key );
return b_ret;
......@@ -461,24 +447,11 @@ static bool skip_element( demux_t *p_demux, input_item_node_t *p_input_node,
{
VLC_UNUSED(p_demux); VLC_UNUSED(p_input_node);
VLC_UNUSED(p_track); VLC_UNUSED(p_handlers);
char *psz_endname;
const char *node;
int type;
while( (type = xml_ReaderNextNode( p_xml_reader )) > 0 )
{
if( type == XML_READER_ENDELEM )
{
psz_endname = xml_ReaderName( p_xml_reader );
if( !psz_endname )
return false;
if( !strcmp( psz_element, psz_endname ) )
{
free( psz_endname );
while( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
if( type == XML_READER_ENDELEM && !strcmp( psz_element, node ) )
return true;
}
else
free( psz_endname );
}
}
return false;
}
......@@ -26,11 +26,10 @@
*/
/* defines */
#define FREE_NAME() FREENULL( psz_name )
#define FREE_VALUE() FREENULL( psz_value )
#define FREE_KEY() FREENULL( psz_key )
#define FREE_ATT() do{ FREE_NAME();FREE_VALUE(); }while(0)
#define FREE_ATT_KEY() do{ FREE_NAME();FREE_VALUE();FREE_KEY();} while(0)
#define FREE_ATT() FREE_VALUE()
#define FREE_ATT_KEY() do{ FREE_VALUE();FREE_KEY();} while(0)
#define UNKNOWN_CONTENT 0
#define SIMPLE_CONTENT 1
......
......@@ -86,6 +86,7 @@ static int Demux( demux_t *p_demux )
char *psz_item_subtitle = NULL;
char *psz_item_summary = NULL;
char *psz_art_url = NULL;
const char *node;
int i_type;
input_item_t *p_input;
input_item_node_t *p_subitems = NULL;
......@@ -98,42 +99,35 @@ static int Demux( demux_t *p_demux )
/* xml */
/* check root node */
if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM
|| ( psz_elname = xml_ReaderName( p_xml_reader ) ) == NULL)
if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM )
{
msg_Err( p_demux, "invalid file (no root node)" );
goto error;
}
if( strcmp( psz_elname, "rss" ) )
if( strcmp( node, "rss" ) )
{
msg_Err( p_demux, "invalid root node: %s", psz_elname );
msg_Err( p_demux, "invalid root node <%s>", node );
goto error;
}
FREENULL( psz_elname );
p_subitems = input_item_node_Create( p_current_input );
while( (i_type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( i_type )
{
case XML_READER_STARTELEM:
{
// Read the element name
free( psz_elname );
psz_elname = xml_ReaderName( p_xml_reader );
if( !psz_elname )
psz_elname = strdup( node );
if( unlikely(!node) )
goto error;
if( !strcmp( psz_elname, "item" ) )
{
if( !strcmp( node, "item" ) )
b_item = true;
}
else if( !strcmp( psz_elname, "image" ) )
{
else if( !strcmp( node, "image" ) )
b_image = true;
}
// Read the attributes
const char *attr;
......@@ -146,7 +140,7 @@ static int Demux( demux_t *p_demux )
goto error;
}
if( !strcmp( psz_elname, "enclosure" ) )
if( !strcmp( node, "enclosure" ) )
{
if( !strcmp( attr, "url" ) )
{
......@@ -166,68 +160,64 @@ static int Demux( demux_t *p_demux )
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
attr, psz_elname );
attr, node );
free( psz_value );
}
}
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
attr, psz_elname );
attr, node );
free( psz_value );
}
}
break;
}
case XML_READER_TEXT:
{
if(!psz_elname) break;
char *psz_text = xml_ReaderValue( p_xml_reader );
#define SET_DATA( field, name ) \
else if( !strcmp( psz_elname, name ) ) \
{ \
field = psz_text; \
}
/* item specific meta data */
if( b_item == true )
if( b_item )
{
char **p;
if( !strcmp( psz_elname, "title" ) )
{
psz_item_name = psz_text;
}
p = &psz_item_name;
else if( !strcmp( psz_elname, "itunes:author" ) ||
!strcmp( psz_elname, "author" ) )
{ /* <author> isn't standard iTunes podcast stuff */
psz_item_author = psz_text;
}
/* <author> isn't standard iTunes podcast stuff */
p = &psz_item_author;
else if( !strcmp( psz_elname, "itunes:summary" ) ||
!strcmp( psz_elname, "description" ) )
{ /* <description> isn't standard iTunes podcast stuff */
psz_item_summary = psz_text;
}
SET_DATA( psz_item_date, "pubDate" )
SET_DATA( psz_item_category, "itunes:category" )
SET_DATA( psz_item_duration, "itunes:duration" )
SET_DATA( psz_item_keywords, "itunes:keywords" )
SET_DATA( psz_item_subtitle, "itunes:subtitle" )
/* <description> isn't standard iTunes podcast stuff */
p = &psz_item_summary;
else if( !strcmp( psz_elname, "pubDate" ) )
p = &psz_item_date;
else if( !strcmp( psz_elname, "itunes:category" ) )
p = &psz_item_category;
else if( !strcmp( psz_elname, "itunes:duration" ) )
p = &psz_item_duration;
else if( !strcmp( psz_elname, "itunes:keywords" ) )
p = &psz_item_keywords;
else if( !strcmp( psz_elname, "itunes:subtitle" ) )
p = &psz_item_subtitle;
else
free( psz_text );
}
#undef SET_DATA
break;
free( *p );
*p = strdup( node );
}
/* toplevel meta data */
else if( b_image == false )
else if( !b_image )
{
if( !strcmp( psz_elname, "title" ) )
{
input_item_SetName( p_current_input, psz_text );
}
input_item_SetName( p_current_input, node );
#define ADD_GINFO( info, name ) \
else if( !strcmp( psz_elname, name ) ) \
input_item_AddInfo( p_current_input, _("Podcast Info"), \
info, "%s", psz_text );
info, "%s", node );
ADD_GINFO( _("Podcast Link"), "link" )
ADD_GINFO( _("Podcast Copyright"), "copyright" )
ADD_GINFO( _("Podcast Category"), "itunes:category" )
......@@ -239,46 +229,52 @@ static int Demux( demux_t *p_demux )
{ /* <description> isn't standard iTunes podcast stuff */
input_item_AddInfo( p_current_input,
_( "Podcast Info" ), _( "Podcast Summary" ),
"%s", psz_text );
"%s", node );
}
free( psz_text );
}
else
{
if( !strcmp( psz_elname, "url" ) )
{
free( psz_art_url );
psz_art_url = psz_text;
psz_art_url = strdup( node );
}
else
{
msg_Dbg( p_demux, "unhandled text in element '%s'",
msg_Dbg( p_demux, "unhandled text in element <%s>",
psz_elname );
free( psz_text );
}
}
break;
}
// End element
case XML_READER_ENDELEM:
{
// Read the element name
free( psz_elname );
psz_elname = xml_ReaderName( p_xml_reader );
if( !psz_elname )
goto error;
if( !strcmp( psz_elname, "item" ) )
FREENULL( psz_elname );
if( !strcmp( node, "item" ) )
{
if( psz_item_mrl == NULL )
{
msg_Err( p_demux, "invalid XML (no enclosure markup)" );
goto error;
}
p_input = input_item_New( p_demux, psz_item_mrl, psz_item_name );
if( p_input == NULL ) break;
FREENULL( psz_item_mrl );
FREENULL( psz_item_name );
if( p_input == NULL )
break; /* FIXME: meta data memory leaks? */
/* Set the duration if available */
if( psz_item_duration )
input_item_SetDuration( p_input, strTimeToMTime( psz_item_duration ) );
#define ADD_INFO( info, field ) \
if( field ) { input_item_AddInfo( p_input, \
_( "Podcast Info" ), info, "%s", field ); }
if( field ) { \
input_item_AddInfo( p_input, _( "Podcast Info" ), (info), "%s", \
(field) ); \
FREENULL( field ); }
ADD_INFO( _("Podcast Publication Date"), psz_item_date );
ADD_INFO( _("Podcast Author"), psz_item_author );
ADD_INFO( _("Podcast Subcategory"), psz_item_category );
......@@ -289,9 +285,6 @@ static int Demux( demux_t *p_demux )
ADD_INFO( _("Podcast Type"), psz_item_type );
#undef ADD_INFO
/* Set the duration if available */
if( psz_item_duration )
input_item_SetDuration( p_input, strTimeToMTime( psz_item_duration ) );
/* Add the global art url to this item, if any */
if( psz_art_url )
input_item_SetArtURL( p_input, psz_art_url );
......@@ -303,29 +296,16 @@ static int Demux( demux_t *p_demux )
_( "Podcast Size" ),
_("%s bytes"),
psz_item_size );
FREENULL( psz_item_size );
}
input_item_node_AppendItem( p_subitems, p_input );
vlc_gc_decref( p_input );
FREENULL( psz_item_name );
FREENULL( psz_item_mrl );
FREENULL( psz_item_size );
FREENULL( psz_item_type );
FREENULL( psz_item_date );
FREENULL( psz_item_author );
FREENULL( psz_item_category );
FREENULL( psz_item_duration );
FREENULL( psz_item_keywords );
FREENULL( psz_item_subtitle );
FREENULL( psz_item_summary );
b_item = false;
}
else if( !strcmp( psz_elname, "image" ) )
{
b_image = false;
}
free( psz_elname );
psz_elname = strdup( "" );
break;
}
}
......
......@@ -103,7 +103,7 @@ void Close_QTL( vlc_object_t *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,26 +130,20 @@ static int Demux( demux_t *p_demux )
goto error;
/* check root node */
if( xml_ReaderNextNode( 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: %s", 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" );
if( xml_ReaderNextNode( 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: %s", psz_eltname );
free( psz_eltname );
msg_Err( p_demux, "invalid root node <%s>", node );
goto error;
}
}
free( psz_eltname );
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) != NULL )
......
......@@ -80,7 +80,7 @@ void Close_Shoutcast( vlc_object_t *p_this )
static int Demux( demux_t *p_demux )
{
xml_reader_t *p_xml_reader = NULL;
char *psz_eltname = NULL;
const char *node;
int i_ret = -1;
input_item_t *p_current_input = GetCurrentItem(p_demux);
input_item_node_t *p_input_node = NULL;
......@@ -90,23 +90,21 @@ static int Demux( demux_t *p_demux )
goto error;
/* check root node */
if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM )
if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM )
{
msg_Err( p_demux, "invalid file (no root node)" );
goto error;
}
if( ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
( strcmp( psz_eltname, "genrelist" )
&& strcmp( psz_eltname, "stationlist" ) ) )
if( strcmp( node, "genrelist" ) && strcmp( node, "stationlist" ) )
{
msg_Err( p_demux, "invalid root node: %s", psz_eltname );
msg_Err( p_demux, "invalid root node <%s>", node );
goto error;
}
p_input_node = input_item_node_Create( p_current_input );
if( !strcmp( psz_eltname, "genrelist" ) )
if( !strcmp( node, "genrelist" ) )
{
/* we're reading a genre list */
if( DemuxGenre( p_demux, p_xml_reader, p_input_node ) )
......@@ -128,7 +126,6 @@ static int Demux( demux_t *p_demux )
error:
if( p_xml_reader )
xml_ReaderDelete( p_xml_reader );
free( psz_eltname );
if( p_input_node ) input_item_node_Delete( p_input_node );
vlc_gc_decref(p_current_input);
return i_ret;
......@@ -148,21 +145,17 @@ error:
static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
input_item_node_t *p_input_node )
{
const char *node;
char *psz_name = NULL; /* genre name */
int type;
while( (type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( type )
{
case XML_READER_STARTELEM:
{
// Read the element name
char *psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
goto error;
if( !strcmp( psz_eltname, "genre" ) )
if( !strcmp( node, "genre" ) )
{
// Read the attributes
const char *attrname;
......@@ -180,29 +173,19 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, psz_eltname );
attrname, node );
free( psz_attrvalue );
}
}
}
free( psz_eltname );
break;
}
case XML_READER_TEXT:
break;
// End element
case XML_READER_ENDELEM:
{
// Read the element name
char *psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
goto error;
if( !strcmp( psz_eltname, "genre" ) )
if( !strcmp( node, "genre" ) && psz_name != NULL )
{
char* psz_mrl;
if( asprintf( &psz_mrl, SHOUTCAST_BASE_URL "?genre=%s",
psz_name ) != -1 )
{
......@@ -215,13 +198,10 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
}
FREENULL( psz_name );
}
free( psz_eltname );
break;
}
}
}
error:
free( psz_name );
return 0;
}
......@@ -268,20 +248,16 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
char *psz_rt = NULL; /* rating for shoutcast TV */
char *psz_load = NULL; /* load for shoutcast TV */
char *psz_eltname = NULL; /* tag name */
const char *node; /* tag name */
int i_type;
while( (i_type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( i_type )
{
case XML_READER_STARTELEM:
// Read the element name
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) return -1;
// Read the attributes
if( !strcmp( psz_eltname, "tunein" ) )
if( !strcmp( node, "tunein" ) )
{
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
......@@ -289,7 +265,6 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_eltname );
free( psz_attrvalue );
return -1;
}
......@@ -299,12 +274,12 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, psz_eltname );
attrname, node );
free( psz_attrvalue );
}
}
}
else if( !strcmp( psz_eltname, "station" ) )
else if( !strcmp( node, "station" ) )
{
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
......@@ -312,7 +287,6 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_eltname );
free( psz_attrvalue );
return -1;
}
......@@ -330,23 +304,16 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, psz_eltname );
attrname, node );
free( psz_attrvalue );
}
}
}
free( psz_eltname );
break;
case XML_READER_TEXT:
break;
// End element
case XML_READER_ENDELEM:
// Read the element name
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) return -1;
if( !strcmp( psz_eltname, "station" ) &&
if( !strcmp( node, "station" ) &&
( psz_base || ( psz_rt && psz_load &&
( b_adult || strcmp( psz_rt, "NC17" ) ) ) ) )
{
......@@ -399,10 +366,10 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
FREENULL( psz_rt );
FREENULL( psz_load );
}
free( psz_eltname );
break;
}
}
/* FIXME: leaks on missing ENDELEMENT? */
return 0;
}
......
......@@ -81,7 +81,7 @@ int Demux( demux_t *p_demux )
{
int i_ret = -1;
xml_reader_t *p_xml_reader = NULL;
char *psz_name = NULL;
const char *name = NULL;
input_item_t *p_current_input = GetCurrentItem(p_demux);
p_demux->p_sys->pp_tracklist = NULL;
p_demux->p_sys->i_tracklist_entries = 0;
......@@ -94,21 +94,18 @@ int Demux( demux_t *p_demux )
goto end;
/* locating the root node */
if( xml_ReaderNextNode( p_xml_reader ) != XML_READER_STARTELEM )
if( xml_ReaderNextNode( p_xml_reader, &name ) != XML_READER_STARTELEM )
{
msg_Err( p_demux, "can't read xml stream" );
goto end;
}
/* checking root node name */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || strcmp( psz_name, "playlist" ) )
if( strcmp( name, "playlist" ) )
{
msg_Err( p_demux, "invalid root node name: %s", psz_name );
free( psz_name );
msg_Err( p_demux, "invalid root node name <%s>", name );
goto end;
}
free( psz_name );
input_item_node_t *p_subitems =
input_item_node_Create( p_current_input );
......@@ -151,7 +148,6 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
static bool parse_playlist_node COMPLEX_INTERFACE
{
input_item_t *p_input_item = p_input_node->p_item;
char *psz_name = NULL;
char *psz_value = NULL;
bool b_version_found = false;
int i_node;
......@@ -212,27 +208,25 @@ static bool parse_playlist_node COMPLEX_INTERFACE
msg_Warn( p_demux, "<playlist> requires \"version\" attribute" );
/* parse the child elements - we only take care of <trackList> */
psz_name = NULL;
psz_value = NULL;
while( (i_node = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_node = xml_ReaderNextNode( p_xml_reader, &name )) > 0 )
{
switch( i_node )
{
case XML_READER_STARTELEM:
/* element start tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || !*psz_name )
case XML_READER_STARTELEM:
if( !*name )
{
msg_Err( p_demux, "invalid xml stream" );
msg_Err( p_demux, "invalid XML stream" );
goto end;
}
/* choose handler */
for( p_handler = pl_elements;
p_handler->name && strcmp( psz_name, p_handler->name );
p_handler->name && strcmp( name, p_handler->name );
p_handler++ );
if( !p_handler->name )
{
msg_Err( p_demux, "unexpected element <%s>", psz_name );
msg_Err( p_demux, "unexpected element <%s>", name );
goto end;
}
/* complex content is parsed in a separate function */
......@@ -253,37 +247,27 @@ static bool parse_playlist_node COMPLEX_INTERFACE
}
break;
case XML_READER_TEXT:
/* simple element content */
free( psz_value );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream" );
case XML_READER_TEXT:
psz_value = strdup( name );
if( unlikely(!name) )
goto end;
}
break;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
goto end;
}
case XML_READER_ENDELEM:
/* leave if the current parent node <playlist> is terminated */
if( !strcmp( psz_name, psz_element ) )
if( !strcmp( name, psz_element ) )
{
b_ret = true;
goto end;
}
/* there MUST have been a start tag for that element name */
if( !p_handler || !p_handler->name
|| strcmp( p_handler->name, psz_name ))
|| strcmp( p_handler->name, name ))
{
msg_Err( p_demux, "there's no open element left for <%s>",
psz_name );
name );
goto end;
}
......@@ -299,7 +283,6 @@ static bool parse_playlist_node COMPLEX_INTERFACE
}
end:
free( psz_name );
free( psz_value );
return b_ret;
}
......@@ -310,30 +293,21 @@ end:
static bool parse_tracklist_node COMPLEX_INTERFACE
{
VLC_UNUSED(psz_element);
char *psz_name;
int i_ntracks = 0;
const char *name;
unsigned i_ntracks = 0;
int i_node;
/* now parse the <track>s */
while( (i_node = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_node = xml_ReaderNextNode( p_xml_reader, &name )) > 0 )
{
if( i_node == XML_READER_STARTELEM )
{
char *psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
{
msg_Err( p_demux, "unexpected end of xml data" );
free( psz_eltname );
return false;
}
if( strcmp( psz_eltname, "track") )
if( strcmp( name, "track") )
{
msg_Err( p_demux, "unexpected child of <trackList>: <%s>",
psz_eltname );
free( psz_eltname );
name );
return false;
}
free( psz_eltname );
/* parse the track data in a separate function */
if( parse_track_node( p_demux, p_input_node,
......@@ -350,16 +324,13 @@ static bool parse_tracklist_node COMPLEX_INTERFACE
msg_Err( p_demux, "there's a missing </trackList>" );
return false;
}
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || strcmp( psz_name, "trackList" ) )
if( strcmp( name, "trackList" ) )
{
msg_Err( p_demux, "expected: </trackList>, found: </%s>", psz_name );
free( psz_name );
msg_Err( p_demux, "expected: </trackList>, found: </%s>", name );
return false;
}
free( psz_name );
msg_Dbg( p_demux, "parsed %i tracks successfully", i_ntracks );
msg_Dbg( p_demux, "parsed %u tracks successfully", i_ntracks );
return true;
}
......@@ -370,7 +341,7 @@ static bool parse_tracklist_node COMPLEX_INTERFACE
static bool parse_track_node COMPLEX_INTERFACE
{
input_item_t *p_input_item = p_input_node->p_item;
char *psz_name = NULL;
const char *name;
char *psz_value = NULL;
xml_elem_hnd_t *p_handler = NULL;
demux_sys_t *p_sys = p_demux->p_sys;
......@@ -406,25 +377,24 @@ static bool parse_track_node COMPLEX_INTERFACE
/* reset i_track_id */
p_sys->i_track_id = -1;
while( (i_node = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_node = xml_ReaderNextNode( p_xml_reader, &name )) > 0 )
{
switch( i_node )
{
case XML_READER_STARTELEM:
/* element start tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || !*psz_name )
case XML_READER_STARTELEM:
if( !*name )
{
msg_Err( p_demux, "invalid xml stream" );
msg_Err( p_demux, "invalid XML stream" );
goto end;
}
/* choose handler */
for( p_handler = track_elements;
p_handler->name && strcmp( psz_name, p_handler->name );
p_handler->name && strcmp( name, p_handler->name );
p_handler++ );
if( !p_handler->name )
{
msg_Err( p_demux, "unexpected element <%s>", psz_name );
msg_Err( p_demux, "unexpected element <%s>", name );
goto end;
}
/* complex content is parsed in a separate function */
......@@ -437,48 +407,32 @@ static bool parse_track_node COMPLEX_INTERFACE
p_xml_reader,
p_handler->name );
if( b_res )
{
p_handler = NULL;
}
else
{
return false;
}
}
break;
case XML_READER_TEXT:
/* simple element content */
case XML_READER_TEXT:
free( psz_value );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream" );
psz_value = strdup( name );
if( unlikely(!psz_value) )
goto end;
}
break;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
goto end;
}
case XML_READER_ENDELEM:
/* leave if the current parent node <track> is terminated */
if( !strcmp( psz_name, psz_element ) )
if( !strcmp( name, psz_element ) )
{
free( psz_name );
free( psz_value );
/* Make sure we have a URI */
char *psz_uri = input_item_GetURI( p_new_input );
if( !psz_uri )
{
input_item_SetURI( p_new_input, "vlc://nop" );
}
else
free( psz_uri );
if( p_sys->i_track_id < 0 )
......@@ -505,10 +459,10 @@ static bool parse_track_node COMPLEX_INTERFACE
}
/* there MUST have been a start tag for that element name */
if( !p_handler || !p_handler->name
|| strcmp( p_handler->name, psz_name ))
|| strcmp( p_handler->name, name ))
{
msg_Err( p_demux, "there's no open element left for <%s>",
psz_name );
name );
goto end;
}
......@@ -559,7 +513,6 @@ static bool parse_track_node COMPLEX_INTERFACE
msg_Err( p_demux, "unexpected end of xml data" );
end:
free( psz_name );
free( psz_value );
return b_ret;
}
......@@ -578,35 +531,22 @@ static bool set_item_info SIMPLE_INTERFACE
/* handle each info element in a separate "if" clause */
if( !strcmp( psz_name, "title" ) )
{
input_item_SetTitle( p_input, psz_value );
}
else if( !strcmp( psz_name, "creator" ) )
{
input_item_SetArtist( p_input, psz_value );
}
else if( !strcmp( psz_name, "album" ) )
{
input_item_SetAlbum( p_input, psz_value );
}
else if( !strcmp( psz_name, "trackNum" ) )
{
input_item_SetTrackNum( p_input, psz_value );
}
else if( !strcmp( psz_name, "duration" ) )
{
long i_num = atol( psz_value );
input_item_SetDuration( p_input, (mtime_t) i_num*1000 );
}
else if( !strcmp( psz_name, "annotation" ) )
{
input_item_SetDescription( p_input, psz_value );
}
else if( !strcmp( psz_name, "image" ) )
{
input_item_SetArtURL( p_input, psz_value );
}
return true;
}
......@@ -633,7 +573,6 @@ static bool set_option SIMPLE_INTERFACE
static bool parse_extension_node COMPLEX_INTERFACE
{
input_item_t *p_input_item = p_input_node->p_item;
char *psz_name = NULL;
char *psz_value = NULL;
char *psz_title = NULL;
char *psz_application = NULL;
......@@ -719,7 +658,7 @@ static bool parse_extension_node COMPLEX_INTERFACE
free( psz_application );
/* Skip all children */
for( unsigned lvl = 1; lvl; )
switch( xml_ReaderNextNode( p_xml_reader ) )
switch( xml_ReaderNextNode( p_xml_reader, NULL ) )
{
case XML_READER_STARTELEM: lvl++; break;
case XML_READER_ENDELEM: lvl--; break;
......@@ -732,14 +671,13 @@ static bool parse_extension_node COMPLEX_INTERFACE
/* parse the child elements */
while( (i_node = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (i_node = xml_ReaderNextNode( p_xml_reader, &name )) > 0 )
{
switch( i_node )
{
case XML_READER_STARTELEM:
/* element start tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name || !*psz_name )
case XML_READER_STARTELEM:
if( !*name )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
......@@ -748,11 +686,11 @@ static bool parse_extension_node COMPLEX_INTERFACE
}
/* choose handler */
for( p_handler = pl_elements;
p_handler->name && strcmp( psz_name, p_handler->name );
p_handler->name && strcmp( name, p_handler->name );
p_handler++ );
if( !p_handler->name )
{
msg_Err( p_demux, "unexpected element <%s>", psz_name );
msg_Err( p_demux, "unexpected element <%s>", name );
FREE_ATT();
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
......@@ -780,28 +718,19 @@ static bool parse_extension_node COMPLEX_INTERFACE
case XML_READER_TEXT:
/* simple element content */
FREE_ATT();
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
psz_value = strdup( name );
if( unlikely(!psz_value) )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
}
break;
case XML_READER_ENDELEM:
/* element end tag */
psz_name = xml_ReaderName( p_xml_reader );
if( !psz_name )
{
msg_Err( p_demux, "invalid xml stream" );
FREE_ATT();
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
}
case XML_READER_ENDELEM:
/* leave if the current parent node is terminated */
if( !strcmp( psz_name, psz_element ) )
if( !strcmp( name, psz_element ) )
{
FREE_ATT();
if( b_release_input_item ) vlc_gc_decref( p_new_input );
......@@ -809,10 +738,10 @@ static bool parse_extension_node COMPLEX_INTERFACE
}
/* there MUST have been a start tag for that element name */
if( !p_handler || !p_handler->name
|| strcmp( p_handler->name, psz_name ))
|| strcmp( p_handler->name, name ))
{
msg_Err( p_demux, "there's no open element left for <%s>",
psz_name );
name );
FREE_ATT();
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
......@@ -900,7 +829,7 @@ static bool skip_element COMPLEX_INTERFACE
VLC_UNUSED(psz_element);
for( unsigned lvl = 1; lvl; )
switch( xml_ReaderNextNode( p_xml_reader ) )
switch( xml_ReaderNextNode( p_xml_reader, NULL ) )
{
case XML_READER_STARTELEM: lvl++; break;
case XML_READER_ENDELEM: lvl--; break;
......
......@@ -132,6 +132,7 @@ void XMLParser::LoadCatalog()
bool XMLParser::parse()
{
const char *node;
int type;
int ret;
......@@ -139,7 +140,7 @@ bool XMLParser::parse()
m_errors = false;
while( (ret = xml_ReaderNextNode( m_pReader )) > 0 )
while( (ret = xml_ReaderNextNode( m_pReader, &node )) > 0 )
{
if( m_errors ) return false;
......@@ -147,10 +148,6 @@ bool XMLParser::parse()
{
case XML_READER_STARTELEM:
{
// Read the element name
char *eltName = xml_ReaderName( m_pReader );
if( !eltName ) return false;
// Read the attributes
AttrList_t attributes;
const char *name;
......@@ -165,8 +162,7 @@ bool XMLParser::parse()
attributes[strdup(name)] = value;
}
handleBeginElement( eltName, attributes );
free( eltName );
handleBeginElement( node, attributes );
map<const char*, const char*, ltstr> ::iterator it =
attributes.begin();
......@@ -182,12 +178,7 @@ bool XMLParser::parse()
// End element
case XML_READER_ENDELEM:
{
// Read the element name
char *eltName = xml_ReaderName( m_pReader );
if( !eltName ) return false;
handleEndElement( eltName );
free( eltName );
handleEndElement( node );
break;
}
}
......
......@@ -2160,11 +2160,11 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
if( p_xml_reader )
{
/* Look for Root Node */
if( xml_ReaderNextNode( p_xml_reader ) == XML_READER_STARTELEM )
{
char *psz_node = xml_ReaderName( p_xml_reader );
const char *node;
if( !strcasecmp( "karaoke", psz_node ) )
if( xml_ReaderNextNode( p_xml_reader, &node ) == XML_READER_STARTELEM )
{
if( !strcasecmp( "karaoke", node ) )
{
/* We're going to have to render the text a number
* of times to show the progress marker on the text.
......@@ -2172,20 +2172,19 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
var_SetBool( p_filter, "text-rerender", true );
b_karaoke = true;
}
else if( !strcasecmp( "text", psz_node ) )
else if( !strcasecmp( "text", node ) )
{
b_karaoke = false;
}
else
{
/* Only text and karaoke tags are supported */
msg_Dbg( p_filter, "Unsupported top-level tag '%s' ignored.", psz_node );
msg_Dbg( p_filter, "Unsupported top-level tag <%s> ignored.",
node );
p_filter->p_sys->p_xml = xml_ReaderReset( p_xml_reader, NULL );
p_xml_reader = NULL;
rv = VLC_EGENERIC;
}
free( psz_node );
}
}
......
......@@ -84,13 +84,11 @@ static int vlclua_xml_create( lua_State *L )
* XML Reader
*****************************************************************************/
static int vlclua_xml_reader_next_node( lua_State * );
static int vlclua_xml_reader_name( lua_State * );
static int vlclua_xml_reader_value( lua_State * );
static int vlclua_xml_reader_next_attr( lua_State * );
static const luaL_Reg vlclua_xml_reader_reg[] = {
{ "next_node", vlclua_xml_reader_next_node },
{ "name", vlclua_xml_reader_name },
{ "value", vlclua_xml_reader_value },
{ "next_attr", vlclua_xml_reader_next_attr },
{ NULL, NULL }
......@@ -131,14 +129,7 @@ static int vlclua_xml_create_reader( lua_State *L )
static int vlclua_xml_reader_next_node( lua_State *L )
{
xml_reader_t *p_reader = *(xml_reader_t**)luaL_checkudata( L, 1, "xml_reader" );
lua_pushinteger( L, xml_ReaderNextNode( p_reader ) );
return 1;
}
static int vlclua_xml_reader_name( lua_State *L )
{
xml_reader_t *p_reader = *(xml_reader_t**)luaL_checkudata( L, 1, "xml_reader" );
lua_pushstring( L, xml_ReaderName( p_reader ) );
lua_pushinteger( L, xml_ReaderNextNode( p_reader, NULL ) );
return 1;
}
......
......@@ -558,46 +558,38 @@ static int ProcessNodes( filter_t *p_filter,
if( rv != VLC_SUCCESS )
return rv;
const char *node;
int type;
while ( (type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while ( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch ( type )
{
case XML_READER_ENDELEM:
psz_node = xml_ReaderName( p_xml_reader );
if( psz_node )
{
if( !strcasecmp( "font", psz_node ) )
if( !strcasecmp( "font", node ) )
PopFont( &p_fonts );
else if( !strcasecmp( "b", psz_node ) )
else if( !strcasecmp( "b", node ) )
b_bold = false;
else if( !strcasecmp( "i", psz_node ) )
else if( !strcasecmp( "i", node ) )
b_italic = false;
else if( !strcasecmp( "u", psz_node ) )
else if( !strcasecmp( "u", node ) )
b_uline = false;
else if( !strcasecmp( "s", psz_node ) )
else if( !strcasecmp( "s", node ) )
b_through = false;
free( psz_node );
}
break;
case XML_READER_STARTELEM:
psz_node = xml_ReaderName( p_xml_reader );
if( psz_node )
{
if( !strcasecmp( "font", psz_node ) )
if( !strcasecmp( "font", node ) )
rv = HandleFontAttributes( p_xml_reader, &p_fonts, i_scale );
else if( !strcasecmp( "b", psz_node ) )
else if( !strcasecmp( "b", node ) )
b_bold = true;
else if( !strcasecmp( "i", psz_node ) )
else if( !strcasecmp( "i", node ) )
b_italic = true;
else if( !strcasecmp( "u", psz_node ) )
else if( !strcasecmp( "u", node ) )
b_uline = true;
else if( !strcasecmp( "s", psz_node ) )
else if( !strcasecmp( "s", node ) )
b_through = true;
else if( !strcasecmp( "br", psz_node ) )
else if( !strcasecmp( "br", node ) )
{
SetupLine( p_filter, "\n", &psz_text,
pi_runs, ppi_run_lengths, ppp_styles,
......@@ -608,29 +600,26 @@ static int ProcessNodes( filter_t *p_filter,
b_uline,
b_through) );
}
else if( !strcasecmp( "k", psz_node ) )
else if( !strcasecmp( "k", node ) )
{
/* Only valid in karaoke */
if( b_karaoke )
{
if( *pi_k_runs > 0 )
{
SetKaraokeLen( *pi_runs, *ppi_run_lengths,
*pi_k_runs, *ppi_k_run_lengths );
}
SetupKaraoke( p_xml_reader, pi_k_runs,
ppi_k_run_lengths, ppi_k_durations );
}
}
free( psz_node );
}
break;
case XML_READER_TEXT:
psz_node = xml_ReaderValue( p_xml_reader );
if( psz_node )
{
/* */
char *psz_node = strdup( node );
if( unlikely(!psz_node) )
break;
HandleWhiteSpace( psz_node );
resolve_xml_special_chars( psz_node );
......@@ -643,9 +632,9 @@ static int ProcessNodes( filter_t *p_filter,
b_uline,
b_through) );
free( psz_node );
}
break;
}
}
if( rv != VLC_SUCCESS )
{
psz_text = psz_text_orig;
......
......@@ -60,8 +60,7 @@ vlc_module_begin ()
vlc_module_end ()
static int ReaderNextNode( xml_reader_t * );
static char *ReaderName( xml_reader_t * );
static int ReaderNextNode( xml_reader_t *, const char ** );
static char *ReaderValue( xml_reader_t * );
static const char *ReaderNextAttr( xml_reader_t * );
......@@ -138,9 +137,16 @@ static void ReaderErrorHandler( void *p_arg, const char *p_msg,
msg_Err( p_reader, "XML parser error (line %d) : %s", line, p_msg );
}
struct xml_reader_sys_t
{
xmlTextReaderPtr xml;
char *node;
};
static int ReaderOpen( vlc_object_t *p_this )
{
xml_reader_t *p_reader = (xml_reader_t *)p_this;
xml_reader_sys_t *p_sys = malloc( sizeof( *p_sys ) );
xmlTextReaderPtr p_libxml_reader;
if( !xmlHasFeature( XML_WITH_THREAD ) )
......@@ -150,22 +156,25 @@ static int ReaderOpen( vlc_object_t *p_this )
xmlInitParser();
vlc_mutex_unlock( &lock );
if( unlikely(!p_sys) )
return VLC_ENOMEM;
p_libxml_reader = xmlReaderForIO( StreamRead, NULL, p_reader->p_stream,
NULL, NULL, 0 );
if( !p_libxml_reader )
{
msg_Err( p_this, "failed to create XML parser" );
free( p_sys );
return VLC_ENOMEM;
}
p_reader->p_sys = (void *)p_libxml_reader;
/* Set the error handler */
xmlTextReaderSetErrorHandler( p_libxml_reader,
ReaderErrorHandler, p_reader );
p_sys->xml = p_libxml_reader;
p_sys->node = NULL;
p_reader->p_sys = p_sys;
p_reader->pf_next_node = ReaderNextNode;
p_reader->pf_name = ReaderName;
p_reader->pf_value = ReaderValue;
p_reader->pf_next_attr = ReaderNextAttr;
p_reader->pf_use_dtd = ReaderUseDTD;
......@@ -176,13 +185,16 @@ static int ReaderOpen( vlc_object_t *p_this )
static void ReaderClose( vlc_object_t *p_this )
{
xml_reader_t *p_reader = (xml_reader_t *)p_this;
xml_reader_sys_t *p_sys = p_reader->p_sys;
xmlFreeTextReader( (void *)p_reader->p_sys );
xmlFreeTextReader( p_sys->xml );
#ifdef LIBXML_GETS_A_CLUE_ABOUT_REENTRANCY_AND_MEMORY_LEAKS
vlc_mutex_lock( &lock );
xmlCleanupParser();
vlc_mutex_unlock( &lock );
#endif
free( p_sys->node );
free( p_sys );
}
static int ReaderUseDTD ( xml_reader_t *p_reader )
......@@ -196,10 +208,17 @@ static int ReaderUseDTD ( xml_reader_t *p_reader )
return VLC_SUCCESS;
}
static int ReaderNextNode( xml_reader_t *p_reader )
static int ReaderNextNode( xml_reader_t *p_reader, const char **pval )
{
xml_reader_sys_t *p_sys = p_reader->p_sys;
const xmlChar *node;
int ret;
free( p_sys->node );
p_sys->node = NULL;
skip:
switch( xmlTextReaderRead( (void *)p_reader->p_sys ) )
switch( xmlTextReaderRead( p_sys->xml ) )
{
case 0: /* EOF */
return 0;
......@@ -207,28 +226,38 @@ skip:
return -1;
}
switch( xmlTextReaderNodeType( (void *)p_reader->p_sys ) )
switch( xmlTextReaderNodeType( p_sys->xml ) )
{
case XML_READER_TYPE_ELEMENT:
return XML_READER_STARTELEM;
node = xmlTextReaderConstName( p_sys->xml );
ret = XML_READER_STARTELEM;
break;
case XML_READER_TYPE_END_ELEMENT:
return XML_READER_ENDELEM;
node = xmlTextReaderConstName( p_sys->xml );
ret = XML_READER_ENDELEM;
break;
case XML_READER_TYPE_CDATA:
case XML_READER_TYPE_TEXT:
return XML_READER_TEXT;
node = xmlTextReaderConstValue( p_sys->xml );
ret = XML_READER_TEXT;
break;
case -1:
return -1;
default:
goto skip;
}
}
static char *ReaderName( xml_reader_t *p_reader )
{
const xmlChar *psz_name =
xmlTextReaderConstName( (void *)p_reader->p_sys );
if( unlikely(node == NULL) )
return -1;
return psz_name ? strdup( (const char *)psz_name ) : NULL;
p_sys->node = strdup( (const char *)node );
if( pval != NULL )
*pval = p_sys->node;
return likely(p_sys->node != NULL) ? ret : -1;
}
static char *ReaderValue( xml_reader_t *p_reader )
......
......@@ -679,6 +679,7 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
rss_feed_t *p_feed )
{
VLC_UNUSED(p_filter);
const char *node;
char *psz_eltname = NULL;
bool b_is_item = false;
......@@ -687,21 +688,20 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
int i_item = 0;
int type;
while( (type = xml_ReaderNextNode( p_xml_reader )) > 0 )
while( (type = xml_ReaderNextNode( p_xml_reader, &node )) > 0 )
{
switch( type )
{
case XML_READER_STARTELEM:
free( psz_eltname );
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
goto end;
#ifdef RSS_DEBUG
msg_Dbg( p_filter, "element name: %s", psz_eltname );
msg_Dbg( p_filter, "element <%s>", node );
#endif
psz_eltname = strdup( node );
if( unlikely(!psz_eltname) )
goto end;
/* rss or atom */
if( !strcmp( psz_eltname, "item" ) || !strcmp( psz_eltname, "entry" ) )
if( !strcmp( node, "item" ) || !strcmp( node, "entry" ) )
{
b_is_item = true;
p_feed->i_items++;
......@@ -712,12 +712,12 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
p_feed->p_items[p_feed->i_items-1].psz_link = NULL;
}
/* rss */
else if( !strcmp( psz_eltname, "image" ) )
else if( !strcmp( node, "image" ) )
{
b_is_image = true;
}
/* atom */
else if( !strcmp( psz_eltname, "link" ) )
else if( !strcmp( node, "link" ) )
{
const char *name;
char *psz_href = NULL;
......@@ -772,42 +772,32 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
break;
case XML_READER_ENDELEM:
free( psz_eltname );
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
goto end;
FREENULL( psz_eltname );
#ifdef RSS_DEBUG
msg_Dbg( p_filter, "element end : %s", psz_eltname );
msg_Dbg( p_filter, "element end </%s>", node );
#endif
/* rss or atom */
if( !strcmp( psz_eltname, "item" ) || !strcmp( psz_eltname, "entry" ) )
if( !strcmp( node, "item" ) || !strcmp( node, "entry" ) )
{
b_is_item = false;
i_item++;
}
/* rss */
else if( !strcmp( psz_eltname, "image" ) )
else if( !strcmp( node, "image" ) )
{
b_is_image = false;
}
FREENULL( psz_eltname );
break;
case XML_READER_TEXT:
{
if( !psz_eltname )
break;
char *psz_eltvalue = xml_ReaderValue( p_xml_reader );
if( !psz_eltvalue )
goto end;
char *psz_clean = removeWhiteChars( psz_eltvalue );
free( psz_eltvalue );
psz_eltvalue = psz_clean;
char *psz_eltvalue = removeWhiteChars( node );
#ifdef RSS_DEBUG
msg_Dbg( p_filter, " text : <%s>", psz_eltvalue );
msg_Dbg( p_filter, " text : \"%s\"", psz_eltvalue );
#endif
/* Is it an item ? */
if( b_is_item )
......
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