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

Return XML attribute as const from NextAttr

The attribute name is valid until the next attribute or next node.
This simplifies the code a bit: fewer error paths, and free() calls.

A few potential memory leaks were fixed too.
parent 4bea014b
......@@ -73,7 +73,7 @@ struct xml_reader_t
int (*pf_next_node) ( xml_reader_t * );
char * (*pf_name) ( xml_reader_t * );
char * (*pf_value) ( xml_reader_t * );
int (*pf_next_attr) ( xml_reader_t * );
const char *(*pf_next_attr) ( xml_reader_t * );
int (*pf_use_dtd) ( xml_reader_t * );
};
......@@ -98,7 +98,7 @@ static inline char *xml_ReaderValue( xml_reader_t *reader )
return reader->pf_value( reader );
}
static inline int xml_ReaderNextAttr( xml_reader_t *reader )
static inline const char *xml_ReaderNextAttr( xml_reader_t *reader )
{
return reader->pf_next_attr( reader );
}
......
This diff is collapsed.
......@@ -122,30 +122,23 @@ static int Demux( demux_t *p_demux )
FREENULL( psz_elname );
// Read the attributes
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
free( psz_name );
free( psz_value );
goto end;
}
if( !strcmp( psz_name, "num_entries" ) )
{
if( !strcmp( attr, "num_entries" ) )
msg_Dbg( p_demux, "playlist has %d entries", atoi(psz_value) );
}
else if( !strcmp( psz_name, "label" ) )
{
else if( !strcmp( attr, "label" ) )
input_item_SetName( p_current_input, psz_value );
}
else
{
msg_Warn( p_demux, "stray attribute %s with value %s in element"
" 'playlist'", psz_name, psz_value );
}
free( psz_name );
" 'playlist'", attr, psz_value );
free( psz_value );
}
......@@ -165,28 +158,25 @@ static int Demux( demux_t *p_demux )
goto end;
// Read the attributes
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
free( psz_name );
free( psz_value );
goto end;
}
if( !strcmp( psz_elname, "entry" ) &&
!strcmp( psz_name, "Playstring" ) )
!strcmp( attr, "Playstring" ) )
{
psz_mrl = psz_value;
}
else
{
msg_Warn( p_demux, "unexpected attribute %s in element %s",
psz_name, psz_elname );
attr, psz_elname );
free( psz_value );
}
free( psz_name );
}
break;
}
......
......@@ -132,24 +132,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);
char *psz_name;
const char *attr;
char *psz_value;
bool b_version_found = false;
/* read all playlist attributes */
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
{
psz_name = xml_ReaderName( p_xml_reader );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <plist>" );
free( psz_name );
free( psz_value );
return false;
}
/* attribute: version */
if( !strcmp( psz_name, "version" ) )
if( !strcmp( attr, "version" ) )
{
b_version_found = true;
if( strcmp( psz_value, "1.0" ) )
......@@ -157,9 +155,8 @@ static bool parse_plist_node( demux_t *p_demux, input_item_node_t *p_input_node,
}
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <plist> attribute:\"%s\"", psz_name);
msg_Warn( p_demux, "invalid <plist> attribute:\"%s\"", attr );
free( psz_name );
free( psz_value );
}
......
......@@ -136,30 +136,29 @@ static int Demux( demux_t *p_demux )
}
// Read the attributes
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attr;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
free( psz_name );
free( psz_value );
goto error;
}
if( !strcmp( psz_elname, "enclosure" ) )
{
if( !strcmp( psz_name, "url" ) )
if( !strcmp( attr, "url" ) )
{
free( psz_item_mrl );
psz_item_mrl = psz_value;
}
else if( !strcmp( psz_name, "length" ) )
else if( !strcmp( attr, "length" ) )
{
free( psz_item_size );
psz_item_size = psz_value;
}
else if( !strcmp( psz_name, "type" ) )
else if( !strcmp( attr, "type" ) )
{
free( psz_item_type );
psz_item_type = psz_value;
......@@ -167,17 +166,16 @@ static int Demux( demux_t *p_demux )
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
psz_name, psz_elname );
attr, psz_elname );
free( psz_value );
}
}
else
{
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
psz_name, psz_elname );
attr, psz_elname );
free( psz_value );
}
free( psz_name );
}
break;
}
......
......@@ -151,115 +151,81 @@ static int Demux( demux_t *p_demux )
}
free( psz_eltname );
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_attrname = xml_ReaderName( p_xml_reader );
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrname || !psz_attrvalue )
if( !psz_attrvalue )
{
free( psz_attrname );
free( psz_attrvalue );
goto error;
}
if( !strcmp( psz_attrname, "autoplay" ) )
{
if( !strcmp( attrname, "autoplay" ) )
b_autoplay = !strcmp( psz_attrvalue, "true" );
}
else if( !strcmp( psz_attrname, "controler" ) )
{
else if( !strcmp( attrname, "controler" ) )
b_controler = !strcmp( psz_attrvalue, "false" );
}
else if( !strcmp( psz_attrname, "fullscreen" ) )
else if( !strcmp( attrname, "fullscreen" ) )
{
if( !strcmp( psz_attrvalue, "double" ) )
{
fullscreen = FULLSCREEN_DOUBLE;
}
else if( !strcmp( psz_attrvalue, "half" ) )
{
fullscreen = FULLSCREEN_HALF;
}
else if( !strcmp( psz_attrvalue, "current" ) )
{
fullscreen = FULLSCREEN_CURRENT;
}
else if( !strcmp( psz_attrvalue, "full" ) )
{
fullscreen = FULLSCREEN_FULL;
}
else
{
fullscreen = FULLSCREEN_NORMAL;
}
}
else if( !strcmp( psz_attrname, "href" ) )
else if( !strcmp( attrname, "href" ) )
{
psz_href = psz_attrvalue;
psz_attrvalue = NULL;
}
else if( !strcmp( psz_attrname, "kioskmode" ) )
{
else if( !strcmp( attrname, "kioskmode" ) )
b_kioskmode = !strcmp( psz_attrvalue, "true" );
}
else if( !strcmp( psz_attrname, "loop" ) )
else if( !strcmp( attrname, "loop" ) )
{
if( !strcmp( psz_attrvalue, "true" ) )
{
loop = LOOP_TRUE;
}
else if( !strcmp( psz_attrvalue, "palindrome" ) )
{
loop = LOOP_PALINDROME;
}
else
{
loop = LOOP_FALSE;
}
}
else if( !strcmp( psz_attrname, "movieid" ) )
{
else if( !strcmp( attrname, "movieid" ) )
i_movieid = atoi( psz_attrvalue );
}
else if( !strcmp( psz_attrname, "moviename" ) )
else if( !strcmp( attrname, "moviename" ) )
{
psz_moviename = psz_attrvalue;
psz_attrvalue = NULL;
}
else if( !strcmp( psz_attrname, "playeveryframe" ) )
{
else if( !strcmp( attrname, "playeveryframe" ) )
b_playeveryframe = !strcmp( psz_attrvalue, "true" );
}
else if( !strcmp( psz_attrname, "qtnext" ) )
else if( !strcmp( attrname, "qtnext" ) )
{
psz_qtnext = psz_attrvalue;
psz_attrvalue = NULL;
}
else if( !strcmp( psz_attrname, "quitwhendone" ) )
{
else if( !strcmp( attrname, "quitwhendone" ) )
b_quitwhendone = !strcmp( psz_attrvalue, "true" );
}
else if( !strcmp( psz_attrname, "src" ) )
else if( !strcmp( attrname, "src" ) )
{
psz_src = psz_attrvalue;
psz_attrvalue = NULL;
}
else if( !strcmp( psz_attrname, "mimetype" ) )
else if( !strcmp( attrname, "mimetype" ) )
{
psz_mimetype = psz_attrvalue;
psz_attrvalue = NULL;
}
else if( !strcmp( psz_attrname, "volume" ) )
{
else if( !strcmp( attrname, "volume" ) )
i_volume = atoi( psz_attrvalue );
}
else
{
msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
psz_attrname, psz_attrvalue );
}
free( psz_attrname );
attrname, psz_attrvalue );
free( psz_attrvalue );
}
......
......@@ -135,7 +135,7 @@ error:
}
#define GET_VALUE( a ) \
if( !strcmp( psz_attrname, #a ) ) \
if( !strcmp( attrname, #a ) ) \
{ \
free(psz_ ## a); \
psz_ ## a = psz_attrvalue; \
......@@ -165,14 +165,12 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
if( !strcmp( psz_eltname, "genre" ) )
{
// Read the attributes
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
{
char *psz_attrname = xml_ReaderName( p_xml_reader );
char *psz_attrvalue =
xml_ReaderValue( p_xml_reader );
if( !psz_attrname || !psz_attrvalue )
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_attrname );
free( psz_attrvalue );
break;
}
......@@ -182,10 +180,9 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
psz_attrname, psz_eltname );
attrname, psz_eltname );
free( psz_attrvalue );
}
free( psz_attrname );
}
}
free( psz_eltname );
......@@ -286,15 +283,13 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
// Read the attributes
if( !strcmp( psz_eltname, "tunein" ) )
{
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
{
char *psz_attrname = xml_ReaderName( p_xml_reader );
char *psz_attrvalue =
xml_ReaderValue( p_xml_reader );
if( !psz_attrname || !psz_attrvalue )
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_eltname );
free( psz_attrname );
free( psz_attrvalue );
return -1;
}
......@@ -304,23 +299,20 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
psz_attrname, psz_eltname );
attrname, psz_eltname );
free( psz_attrvalue );
}
free( psz_attrname );
}
}
else if( !strcmp( psz_eltname, "station" ) )
{
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *attrname;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) )
{
char *psz_attrname = xml_ReaderName( p_xml_reader );
char *psz_attrvalue =
xml_ReaderValue( p_xml_reader );
if( !psz_attrname || !psz_attrvalue )
char *psz_attrvalue = xml_ReaderValue( p_xml_reader );
if( !psz_attrvalue )
{
free( psz_eltname );
free( psz_attrname );
free( psz_attrvalue );
return -1;
}
......@@ -338,10 +330,9 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
{
msg_Warn( p_demux,
"unexpected attribute %s in element %s",
psz_attrname, psz_eltname );
attrname, psz_eltname );
free( psz_attrvalue );
}
free( psz_attrname );
}
}
free( psz_eltname );
......
......@@ -177,34 +177,34 @@ static bool parse_playlist_node COMPLEX_INTERFACE
};
/* read all playlist attributes */
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
psz_name = xml_ReaderName( p_xml_reader );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <playlist>" );
goto end;
}
/* attribute: version */
if( !strcmp( psz_name, "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" );
}
/* attribute: xmlns */
else if( !strcmp( psz_name, "xmlns" ) || !strcmp( psz_name, "xmlns:vlc" ) )
else if( !strcmp( name, "xmlns" ) || !strcmp( name, "xmlns:vlc" ) )
;
else if( !strcmp( psz_name, "xml:base" ) )
else if( !strcmp( name, "xml:base" ) )
{
free( p_demux->p_sys->psz_base );
p_demux->p_sys->psz_base = strdup( psz_value );
}
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <playlist> attribute:\"%s\"", psz_name);
msg_Warn( p_demux, "invalid <playlist> attribute: \"%s\"", name);
free( psz_name );
free( psz_value );
}
/* attribute version is mandatory !!! */
......@@ -235,7 +235,6 @@ static bool parse_playlist_node COMPLEX_INTERFACE
msg_Err( p_demux, "unexpected element <%s>", psz_name );
goto end;
}
FREE_NAME();
/* complex content is parsed in a separate function */
if( p_handler->type == COMPLEX_CONTENT )
{
......@@ -428,7 +427,6 @@ static bool parse_track_node COMPLEX_INTERFACE
msg_Err( p_demux, "unexpected element <%s>", psz_name );
goto end;
}
FREE_NAME();
/* complex content is parsed in a separate function */
if( p_handler->type == COMPLEX_CONTENT )
{
......@@ -653,35 +651,36 @@ static bool parse_extension_node COMPLEX_INTERFACE
};
/* read all extension node attributes */
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
psz_name = xml_ReaderName( p_xml_reader );
psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <vlc:node>" );
FREE_ATT();
return false;
}
/* attribute: title */
if( !strcmp( psz_name, "title" ) )
if( !strcmp( name, "title" ) )
{
resolve_xml_special_chars( psz_value );
free( psz_title );
psz_title = psz_value;
}
/* extension attribute: application */
else if( !strcmp( psz_name, "application" ) )
else if( !strcmp( name, "application" ) )
{
free( psz_application );
psz_application = psz_value;
}
/* unknown attribute */
else
{
msg_Warn( p_demux, "invalid <%s> attribute:\"%s\"", psz_element,
psz_name );
name );
FREE_VALUE();
}
FREE_NAME();
psz_value = NULL;
}
......@@ -758,7 +757,6 @@ static bool parse_extension_node COMPLEX_INTERFACE
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
}
FREE_NAME();
/* complex content is parsed in a separate function */
if( p_handler->type == COMPLEX_CONTENT )
{
......@@ -834,7 +832,6 @@ static bool parse_extension_node COMPLEX_INTERFACE
p_handler = NULL;
break;
}
FREE_NAME();
}
if( b_release_input_item ) vlc_gc_decref( p_new_input );
return false;
......@@ -850,27 +847,23 @@ static bool parse_extitem_node COMPLEX_INTERFACE
int i_tid = -1;
/* read all extension item attributes */
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_name || !psz_value )
if( !psz_value )
{
msg_Err( p_demux, "invalid xml stream @ <vlc:item>" );
free( psz_name );
free( psz_value );
return false;
}
/* attribute: href */
if( !strcmp( psz_name, "tid" ) )
{
if( !strcmp( name, "tid" ) )
i_tid = atoi( psz_value );
}
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <vlc:item> attribute:\"%s\"", psz_name);
msg_Warn( p_demux, "invalid <vlc:item> attribute: \"%s\"", name);
free( psz_name );
free( psz_value );
}
......
......@@ -21,9 +21,8 @@
*/
/* defines */
#define FREE_NAME() free(psz_name);psz_name=NULL;
#define FREE_VALUE() free(psz_value);psz_value=NULL;
#define FREE_ATT() FREE_NAME();FREE_VALUE()
#define FREE_ATT() FREE_VALUE()
enum {
UNKNOWN_CONTENT,
......
......@@ -153,17 +153,16 @@ bool XMLParser::parse()
// Read the attributes
AttrList_t attributes;
while( xml_ReaderNextAttr( m_pReader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( m_pReader )) != NULL )
{
char *name = xml_ReaderName( m_pReader );
char *value = xml_ReaderValue( m_pReader );
if( !name || !value )
if( !value )
{
free( name );
free( value );
return false;
}
attributes[name] = value;
attributes[strdup(name)] = value;
}
handleBeginElement( eltName, attributes );
......
......@@ -152,7 +152,7 @@ static int vlclua_xml_reader_value( lua_State *L )
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_pushinteger( L, xml_ReaderNextAttr( p_reader ) );
lua_pushstring( L, xml_ReaderNextAttr( p_reader ) );
return 1;
}
......
......@@ -331,61 +331,58 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff;
while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( psz_name && psz_value )
if( !strcasecmp( "face", name ) )
{
if( !strcasecmp( "face", psz_name ) )
free( psz_fontname );
psz_fontname = strdup( psz_value );
}
else if( !strcasecmp( "size", name ) )
{
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) )
{
free( psz_fontname );
psz_fontname = strdup( psz_value );
int i_value = atoi( psz_value );
if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10;
else if( i_value < -5 )
i_font_size = - i_value;
else if( i_value > 5 )
i_font_size = i_value;
}
else if( !strcasecmp( "size", psz_name ) )
else
i_font_size = atoi( psz_value );
}
else if( !strcasecmp( "color", name ) )
{
if( psz_value[0] == '#' )
{
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) )
{
int i_value = atoi( psz_value );
if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10;
else if( i_value < -5 )
i_font_size = - i_value;
else if( i_value > 5 )
i_font_size = i_value;
}
else
i_font_size = atoi( psz_value );
i_font_color = strtol( psz_value + 1, NULL, 16 );
i_font_color &= 0x00ffffff;
}
else if( !strcasecmp( "color", psz_name ) )
else
{
if( psz_value[0] == '#' )
{
i_font_color = strtol( psz_value + 1, NULL, 16 );
i_font_color &= 0x00ffffff;
}
else
for( int i = 0; p_html_colors[i].psz_name != NULL; i++ )
{
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( psz_value, p_html_colors[i].psz_name, strlen(p_html_colors[i].psz_name) ) )
{
i_font_color = p_html_colors[i].i_value;
break;
}
i_font_color = p_html_colors[i].i_value;
break;
}
}
}
else if( !strcasecmp( "alpha", psz_name ) &&
( psz_value[0] == '#' ) )
{
i_font_alpha = strtol( psz_value + 1, NULL, 16 );
i_font_alpha &= 0xff;
}
}
free( psz_name );
else if( !strcasecmp( "alpha", name ) && ( psz_value[0] == '#' ) )
{
i_font_alpha = strtol( psz_value + 1, NULL, 16 );
i_font_alpha &= 0xff;
}
free( psz_value );
}
rv = PushFont( p_fonts,
......@@ -430,13 +427,15 @@ 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 )
{
while ( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
const char *name;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !psz_value )
continue;
if( psz_name && psz_value &&
!strcasecmp( "t", psz_name ) )
if( !strcasecmp( "t", name ) )
{
if( ppi_k_durations && ppi_k_run_lengths )
{
......@@ -470,7 +469,6 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs,
(*ppi_k_run_lengths)[ *pi_k_runs - 1 ] = 0;
}
}
free( psz_name );
free( psz_value );
}
}
......
......@@ -63,7 +63,7 @@ vlc_module_end ()
static int ReaderNextNode( xml_reader_t * );
static char *ReaderName( xml_reader_t * );
static char *ReaderValue( xml_reader_t * );
static int ReaderNextAttr( xml_reader_t * );
static const char *ReaderNextAttr( xml_reader_t * );
static int ReaderUseDTD ( xml_reader_t * );
......@@ -239,10 +239,11 @@ static char *ReaderValue( xml_reader_t *p_reader )
return psz_value ? strdup( (const char *)psz_value ) : NULL;
}
static int ReaderNextAttr( xml_reader_t *p_reader )
static const char *ReaderNextAttr( xml_reader_t *p_reader )
{
return ( xmlTextReaderMoveToNextAttribute( (void *)p_reader->p_sys )
== 1 ) ? VLC_SUCCESS : VLC_EGENERIC;
if( xmlTextReaderMoveToNextAttribute( (void *)p_reader->p_sys ) != 1 )
return NULL;
return (const char *)xmlTextReaderConstValue( (void *)p_reader->p_sys );
}
static int StreamRead( void *p_context, char *p_buffer, int i_buffer )
......
......@@ -719,27 +719,27 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
/* atom */
else if( !strcmp( psz_eltname, "link" ) )
{
const char *name;
char *psz_href = NULL;
char *psz_rel = NULL;
while( xml_ReaderNextAttr( p_xml_reader ) == VLC_SUCCESS )
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL )
{
char *psz_name = xml_ReaderName( p_xml_reader );
char *psz_value = xml_ReaderValue( p_xml_reader );
if( !strcmp( psz_name, "rel" ) )
if( !psz_value )
continue;
if( !strcmp( name, "rel" ) )
{
free( psz_rel );
psz_rel = psz_value;
}
else if( !strcmp( psz_name, "href" ) )
else if( !strcmp( name, "href" ) )
{
free( psz_href );
psz_href = psz_value;
}
else
{
free( psz_value );
}
free( psz_name );
}
/* "rel" and "href" must be defined */
......
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