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

XML: return attribute value as const

This simplifies error and memory handling.
A few memory leaks were fixed.
parent 92864777
......@@ -71,8 +71,7 @@ struct xml_reader_t
module_t *p_module;
int (*pf_next_node) ( xml_reader_t *, const char ** );
char * (*pf_value) ( xml_reader_t * );
const char *(*pf_next_attr) ( xml_reader_t * );
const char *(*pf_next_attr) ( xml_reader_t *, const char ** );
int (*pf_use_dtd) ( xml_reader_t * );
};
......@@ -87,14 +86,10 @@ static inline int xml_ReaderNextNode( xml_reader_t *reader, const char **pval )
return reader->pf_next_node( reader, pval );
}
static inline char *xml_ReaderValue( xml_reader_t *reader )
static inline const char *xml_ReaderNextAttr( xml_reader_t *reader,
const char **pval )
{
return reader->pf_value( reader );
}
static inline const char *xml_ReaderNextAttr( xml_reader_t *reader )
{
return reader->pf_next_attr( reader );
return reader->pf_next_attr( reader, pval );
}
static inline int xml_ReaderUseDTD( xml_reader_t *reader )
......
This diff is collapsed.
......@@ -119,24 +119,16 @@ static int Demux( demux_t *p_demux )
}
// Read the attributes
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *attr, *value;
while( (attr = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
free( psz_value );
goto end;
}
if( !strcmp( attr, "num_entries" ) )
msg_Dbg( p_demux, "playlist has %d entries", atoi(psz_value) );
msg_Dbg( p_demux, "playlist has %d entries", atoi(value) );
else if( !strcmp( attr, "label" ) )
input_item_SetName( p_current_input, psz_value );
input_item_SetName( p_current_input, value );
else
msg_Warn( p_demux, "stray attribute %s with value %s in element"
" 'playlist'", attr, psz_value );
free( psz_value );
" <playlist>", attr, value );
}
p_subitems = input_item_node_Create( p_current_input );
......@@ -155,24 +147,18 @@ static int Demux( demux_t *p_demux )
goto end;
// Read the attributes
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
while( (attr = xml_ReaderNextAttr( p_xml_reader, &value )) )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
free( psz_value );
goto end;
}
if( !strcmp( psz_elname, "entry" ) &&
!strcmp( attr, "Playstring" ) )
{
psz_mrl = psz_value;
free( psz_mrl );
psz_mrl = strdup( value );
}
else
{
msg_Warn( p_demux, "unexpected attribute %s in element %s",
msg_Warn( p_demux, "unexpected attribute %s in <%s>",
attr, psz_elname );
free( psz_value );
}
}
break;
......
......@@ -131,32 +131,22 @@ static bool parse_plist_node( demux_t *p_demux, input_item_node_t *p_input_node,
xml_elem_hnd_t *p_handlers )
{
VLC_UNUSED(p_track); VLC_UNUSED(psz_element);
const char *attr;
char *psz_value;
const char *attr, *value;
bool b_version_found = false;
/* read all playlist attributes */
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
while( (attr = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <plist>" );
free( psz_value );
return false;
}
/* attribute: version */
if( !strcmp( attr, "version" ) )
{
b_version_found = true;
if( strcmp( psz_value, "1.0" ) )
if( strcmp( value, "1.0" ) )
msg_Warn( p_demux, "unsupported iTunes Media Library version" );
}
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <plist> attribute:\"%s\"", attr );
free( psz_value );
}
/* attribute version is mandatory !!! */
......
......@@ -130,46 +130,30 @@ static int Demux( demux_t *p_demux )
b_image = true;
// Read the attributes
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
const char *attr, *value;
while( (attr = xml_ReaderNextAttr( p_xml_reader, &value )) )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
free( psz_value );
goto error;
}
if( !strcmp( node, "enclosure" ) )
{
const char **p = NULL;
if( !strcmp( attr, "url" ) )
{
free( psz_item_mrl );
psz_item_mrl = psz_value;
}
p = &psz_item_mrl;
else if( !strcmp( attr, "length" ) )
{
free( psz_item_size );
psz_item_size = psz_value;
}
p = &psz_item_size;
else if( !strcmp( attr, "type" ) )
p = &psz_item_type;
if( p != NULL )
{
free( psz_item_type );
psz_item_type = psz_value;
free( *p );
*p = strdup( value );
}
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
msg_Dbg( p_demux,"unhandled attribute %s in <%s>",
attr, node );
free( psz_value );
}
}
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
msg_Dbg( p_demux,"unhandled attribute %s in <%s>",
attr, node );
free( psz_value );
}
}
break;
}
......
......@@ -145,82 +145,73 @@ static int Demux( demux_t *p_demux )
}
}
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *attrname, *value;
while( (attrname = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_attrvalue );
goto error;
}
if( !strcmp( attrname, "autoplay" ) )
b_autoplay = !strcmp( psz_attrvalue, "true" );
b_autoplay = !strcmp( value, "true" );
else if( !strcmp( attrname, "controler" ) )
b_controler = !strcmp( psz_attrvalue, "false" );
b_controler = !strcmp( attrname, "false" );
else if( !strcmp( attrname, "fullscreen" ) )
{
if( !strcmp( psz_attrvalue, "double" ) )
if( !strcmp( value, "double" ) )
fullscreen = FULLSCREEN_DOUBLE;
else if( !strcmp( psz_attrvalue, "half" ) )
else if( !strcmp( value, "half" ) )
fullscreen = FULLSCREEN_HALF;
else if( !strcmp( psz_attrvalue, "current" ) )
else if( !strcmp( value, "current" ) )
fullscreen = FULLSCREEN_CURRENT;
else if( !strcmp( psz_attrvalue, "full" ) )
else if( !strcmp( value, "full" ) )
fullscreen = FULLSCREEN_FULL;
else
fullscreen = FULLSCREEN_NORMAL;
}
else if( !strcmp( attrname, "href" ) )
{
psz_href = psz_attrvalue;
psz_attrvalue = NULL;
free( psz_href );
psz_href = strdup( value );
}
else if( !strcmp( attrname, "kioskmode" ) )
b_kioskmode = !strcmp( psz_attrvalue, "true" );
b_kioskmode = !strcmp( value, "true" );
else if( !strcmp( attrname, "loop" ) )
{
if( !strcmp( psz_attrvalue, "true" ) )
if( !strcmp( value, "true" ) )
loop = LOOP_TRUE;
else if( !strcmp( psz_attrvalue, "palindrome" ) )
else if( !strcmp( value, "palindrome" ) )
loop = LOOP_PALINDROME;
else
loop = LOOP_FALSE;
}
else if( !strcmp( attrname, "movieid" ) )
i_movieid = atoi( psz_attrvalue );
i_movieid = atoi( value );
else if( !strcmp( attrname, "moviename" ) )
{
psz_moviename = psz_attrvalue;
psz_attrvalue = NULL;
free( psz_moviename );
psz_moviename = strdup( value );
}
else if( !strcmp( attrname, "playeveryframe" ) )
b_playeveryframe = !strcmp( psz_attrvalue, "true" );
b_playeveryframe = !strcmp( value, "true" );
else if( !strcmp( attrname, "qtnext" ) )
{
psz_qtnext = psz_attrvalue;
psz_attrvalue = NULL;
free( psz_qtnext );
psz_qtnext = strdup( value );
}
else if( !strcmp( attrname, "quitwhendone" ) )
b_quitwhendone = !strcmp( psz_attrvalue, "true" );
b_quitwhendone = !strcmp( value, "true" );
else if( !strcmp( attrname, "src" ) )
{
psz_src = psz_attrvalue;
psz_attrvalue = NULL;
free( psz_src );
psz_src = strdup( value );
}
else if( !strcmp( attrname, "mimetype" ) )
{
psz_mimetype = psz_attrvalue;
psz_attrvalue = NULL;
free( psz_mimetype );
psz_mimetype = strdup( value );
}
else if( !strcmp( attrname, "volume" ) )
i_volume = atoi( psz_attrvalue );
i_volume = atoi( value );
else
msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
attrname, psz_attrvalue );
free( psz_attrvalue );
attrname, value );
}
msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
......
......@@ -131,12 +131,6 @@ error:
return i_ret;
}
#define GET_VALUE( a ) \
if( !strcmp( attrname, #a ) ) \
{ \
free(psz_ ## a); \
psz_ ## a = psz_attrvalue; \
}
/* <genrelist>
* <genre name="the name"></genre>
* ...
......@@ -158,24 +152,18 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
if( !strcmp( node, "genre" ) )
{
// Read the attributes
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
if( !strcmp( name, "name" ) )
{
free( psz_attrvalue );
break;
free(psz_name);
psz_name = strdup( value );
}
GET_VALUE( name )
else
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, node );
free( psz_attrvalue );
}
"unexpected attribute %s in <%s>",
name, node );
}
}
break;
......@@ -259,54 +247,53 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
// Read the attributes
if( !strcmp( node, "tunein" ) )
{
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
if( !strcmp( name, "base" ) )
{
free( psz_attrvalue );
return -1;
free( psz_base );
psz_base = strdup( value );
}
GET_VALUE( base )
else
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, node );
free( psz_attrvalue );
}
"unexpected attribute %s in <%s>",
name, node );
}
}
else if( !strcmp( node, "station" ) )
{
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
char **p = NULL;
if( !strcmp( name, "name" ) )
p = &psz_name;
else if ( !strcmp( name, "mt" ) )
p = &psz_mt;
else if ( !strcmp( name, "id" ) )
p = &psz_id;
else if ( !strcmp( name, "br" ) )
p = &psz_br;
else if ( !strcmp( name, "genre" ) )
p = &psz_genre;
else if ( !strcmp( name, "ct" ) )
p = &psz_ct;
else if ( !strcmp( name, "lc" ) )
p = &psz_lc;
else if ( !strcmp( name, "rt" ) )
p = &psz_rt;
else if ( !strcmp( name, "load" ) )
p = &psz_load;
if( p != NULL )
{
free( psz_attrvalue );
return -1;
free( *p );
*p = strdup( value );
}
GET_VALUE( name )
else GET_VALUE( mt )
else GET_VALUE( id )
else GET_VALUE( br )
else GET_VALUE( genre )
else GET_VALUE( ct )
else GET_VALUE( lc )
else GET_VALUE( rt )
else GET_VALUE( load )
else
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
attrname, node );
free( psz_attrvalue );
}
"unexpected attribute %s in <%s>",
name, node );
}
}
break;
......
......@@ -173,21 +173,15 @@ static bool parse_playlist_node COMPLEX_INTERFACE
};
/* read all playlist attributes */
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <playlist>" );
goto end;
}
/* attribute: version */
if( !strcmp( name, "version" ) )
{
b_version_found = true;
if( strcmp( psz_value, "0" ) && strcmp( psz_value, "1" ) )
msg_Warn( p_demux, "unsupported XSPF version" );
if( strcmp( value, "0" ) && strcmp( value, "1" ) )
msg_Warn( p_demux, "unsupported XSPF version %s", value );
}
/* attribute: xmlns */
else if( !strcmp( name, "xmlns" ) || !strcmp( name, "xmlns:vlc" ) )
......@@ -200,8 +194,6 @@ static bool parse_playlist_node COMPLEX_INTERFACE
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <playlist> attribute: \"%s\"", name);
free( psz_value );
}
/* attribute version is mandatory !!! */
if( !b_version_found )
......@@ -590,37 +582,27 @@ static bool parse_extension_node COMPLEX_INTERFACE
};
/* read all extension node attributes */
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <vlc:node>" );
FREE_ATT();
return false;
}
/* attribute: title */
if( !strcmp( name, "title" ) )
{
resolve_xml_special_chars( psz_value );
free( psz_title );
psz_title = psz_value;
psz_title = strdup( value );
if( likely(psz_title != NULL) )
resolve_xml_special_chars( psz_title );
}
/* extension attribute: application */
else if( !strcmp( name, "application" ) )
{
free( psz_application );
psz_application = psz_value;
psz_application = strdup( value );
}
/* unknown attribute */
else
{
msg_Warn( p_demux, "invalid <%s> attribute:\"%s\"", psz_element,
name );
FREE_VALUE();
}
psz_value = NULL;
}
/* attribute title is mandatory except for <extension> */
......@@ -776,24 +758,15 @@ static bool parse_extitem_node COMPLEX_INTERFACE
int i_tid = -1;
/* read all extension item attributes */
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <vlc:item>" );
free( psz_value );
return false;
}
/* attribute: href */
if( !strcmp( name, "tid" ) )
i_tid = atoi( psz_value );
i_tid = atoi( value );
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <vlc:item> attribute: \"%s\"", name);
free( psz_value );
}
/* attribute href is mandatory */
......
......@@ -150,17 +150,9 @@ bool XMLParser::parse()
{
// Read the attributes
AttrList_t attributes;
const char *name;
while( (name = xml_ReaderNextAttr( m_pReader )) != NULL )
{
char *value = xml_ReaderValue( m_pReader );
if( !value )
{
free( value );
return false;
}
attributes[strdup(name)] = value;
}
const char *name, *value;
while( (name = xml_ReaderNextAttr( m_pReader, &value )) != NULL )
attributes[strdup(name)] = strdup(value);
handleBeginElement( node, attributes );
......
......@@ -84,12 +84,10 @@ static int vlclua_xml_create( lua_State *L )
* XML Reader
*****************************************************************************/
static int vlclua_xml_reader_next_node( 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 },
{ "value", vlclua_xml_reader_value },
{ "next_attr", vlclua_xml_reader_next_attr },
{ NULL, NULL }
};
......@@ -135,17 +133,13 @@ static int vlclua_xml_reader_next_node( lua_State *L )
return 2;
}
static int vlclua_xml_reader_value( lua_State *L )
{
xml_reader_t *p_reader = *(xml_reader_t**)luaL_checkudata( L, 1, "xml_reader" );
lua_pushstring( L, xml_ReaderValue( p_reader ) );
return 1;
}
static int vlclua_xml_reader_next_attr( lua_State *L )
{
xml_reader_t *p_reader = *(xml_reader_t**)luaL_checkudata( L, 1, "xml_reader" );
lua_pushstring( L, xml_ReaderNextAttr( p_reader ) );
const char *psz_value;
lua_pushstring( L, xml_ReaderNextAttr( p_reader, &psz_value ) );
lua_pushstring( L, psz_value );
return 1;
}
......
......@@ -483,7 +483,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
uint32_t i_font_color = 0xffffff;
int i_font_alpha = 0;
int i_font_size = 24;
const char *attr;
const char *attr, *value;
// Default all attributes to the top font in the stack -- in case not
// all attributes are specified in the sub-font
......@@ -498,23 +498,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff;
while ( (attr = xml_ReaderNextAttr( p_xml_reader )) )
while ( (attr = xml_ReaderNextAttr( p_xml_reader, &psz_value )) )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "face", attr ) )
{
free( psz_fontname );
psz_fontname = strdup( psz_value );
psz_fontname = strdup( value );
}
else if( !strcasecmp( "size", attr ) )
{
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) )
if( ( *value == '+' ) || ( *value == '-' ) )
{
int i_value = atoi( psz_value );
int i_value = atoi( value );
if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10;
......@@ -524,22 +519,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_size = i_value;
}
else
i_font_size = atoi( psz_value );
i_font_size = atoi( value );
}
else if( !strcasecmp( "color", attr ) &&
( psz_value[0] == '#' ) )
else if( !strcasecmp( "color", attr ) && ( value[0] == '#' ) )
{
i_font_color = strtol( psz_value + 1, NULL, 16 );
i_font_color = strtol( value + 1, NULL, 16 );
i_font_color &= 0x00ffffff;
}
else if( !strcasecmp( "alpha", attr ) &&
( psz_value[0] == '#' ) )
else if( !strcasecmp( "alpha", attr ) && ( value[0] == '#' ) )
{
i_font_alpha = strtol( psz_value + 1, NULL, 16 );
i_font_alpha = strtol( value + 1, NULL, 16 );
i_font_alpha &= 0xff;
}
free( psz_value );
}
rv = PushFont( p_fonts,
psz_fontname,
......
......@@ -331,23 +331,19 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff;
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "face", name ) )
{
free( psz_fontname );
psz_fontname = strdup( psz_value );
psz_fontname = strdup( value );
}
else if( !strcasecmp( "size", name ) )
{
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) )
if( ( *value == '+' ) || ( *value == '-' ) )
{
int i_value = atoi( psz_value );
int i_value = atoi( value );
if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10;
......@@ -357,20 +353,20 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_size = i_value;
}
else
i_font_size = atoi( psz_value );
i_font_size = atoi( value );
}
else if( !strcasecmp( "color", name ) )
{
if( psz_value[0] == '#' )
if( value[0] == '#' )
{
i_font_color = strtol( psz_value + 1, NULL, 16 );
i_font_color = strtol( value + 1, NULL, 16 );
i_font_color &= 0x00ffffff;
}
else
{
for( int i = 0; p_html_colors[i].psz_name != NULL; i++ )
{
if( !strncasecmp( psz_value, p_html_colors[i].psz_name, strlen(p_html_colors[i].psz_name) ) )
if( !strncasecmp( value, p_html_colors[i].psz_name, strlen(p_html_colors[i].psz_name) ) )
{
i_font_color = p_html_colors[i].i_value;
break;
......@@ -378,12 +374,11 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
}
}
}
else if( !strcasecmp( "alpha", name ) && ( psz_value[0] == '#' ) )
else if( !strcasecmp( "alpha", name ) && ( value[0] == '#' ) )
{
i_font_alpha = strtol( psz_value + 1, NULL, 16 );
i_font_alpha = strtol( value + 1, NULL, 16 );
i_font_alpha &= 0xff;
}
free( psz_value );
}
rv = PushFont( p_fonts,
psz_fontname,
......@@ -427,14 +422,10 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs,
uint32_t **ppi_k_run_lengths,
uint32_t **ppi_k_durations )
{
const char *name;
const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "t", name ) )
{
if( ppi_k_durations && ppi_k_run_lengths )
......@@ -463,13 +454,12 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs,
malloc( *pi_k_runs * sizeof( uint32_t ) );
}
if( *ppi_k_durations )
(*ppi_k_durations)[ *pi_k_runs - 1 ] = atoi( psz_value );
(*ppi_k_durations)[ *pi_k_runs - 1 ] = atoi( value );
if( *ppi_k_run_lengths )
(*ppi_k_run_lengths)[ *pi_k_runs - 1 ] = 0;
}
}
free( psz_value );
}
}
......
......@@ -61,8 +61,7 @@ vlc_module_begin ()
vlc_module_end ()
static int ReaderNextNode( xml_reader_t *, const char ** );
static char *ReaderValue( xml_reader_t * );
static const char *ReaderNextAttr( xml_reader_t * );
static const char *ReaderNextAttr( xml_reader_t *, const char ** );
static int ReaderUseDTD ( xml_reader_t * );
......@@ -175,7 +174,6 @@ static int ReaderOpen( vlc_object_t *p_this )
p_sys->node = NULL;
p_reader->p_sys = p_sys;
p_reader->pf_next_node = ReaderNextNode;
p_reader->pf_value = ReaderValue;
p_reader->pf_next_attr = ReaderNextAttr;
p_reader->pf_use_dtd = ReaderUseDTD;
......@@ -268,11 +266,18 @@ static char *ReaderValue( xml_reader_t *p_reader )
return psz_value ? strdup( (const char *)psz_value ) : NULL;
}
static const char *ReaderNextAttr( xml_reader_t *p_reader )
static const char *ReaderNextAttr( xml_reader_t *p_reader, const char **pval )
{
if( xmlTextReaderMoveToNextAttribute( p_reader->p_sys->xml ) != 1 )
xmlTextReaderPtr xml = p_reader->p_sys->xml;
const xmlChar *name, *value;
if( xmlTextReaderMoveToNextAttribute( xml ) != 1
|| (name = xmlTextReaderConstName( xml )) == NULL
|| (value = xmlTextReaderConstValue( xml )) == NULL )
return NULL;
return (const char *)xmlTextReaderConstName( p_reader->p_sys->xml );
*pval = (const char *)value;
return (const char *)name;
}
static int StreamRead( void *p_context, char *p_buffer, int i_buffer )
......
......@@ -719,27 +719,22 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
/* atom */
else if( !strcmp( node, "link" ) )
{
const char *name;
const char *name, *value;
char *psz_href = NULL;
char *psz_rel = NULL;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
{
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( !strcmp( name, "rel" ) )
{
free( psz_rel );
psz_rel = psz_value;
psz_rel = strdup( value );
}
else if( !strcmp( name, "href" ) )
{
free( psz_href );
psz_href = psz_value;
psz_href = strdup( value );
}
else
free( psz_value );
}
/* "rel" and "href" must be defined */
......
......@@ -41,10 +41,10 @@ local function parsexml(stream, errormsg)
while nodetype > 0 do
if nodetype == 1 then
local node = { name= nodename, attributes= {}, children= {} }
local attr = reader:next_attr()
local attr, value = reader:next_attr()
while attr ~= nil do
node.attributes[attr] = reader:value()
attr = reader:next_attr()
node.attributes[attr] = value
attr, value = reader:next_attr()
end
if tree then
table.insert(tree.children, node)
......
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