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 ...@@ -71,8 +71,7 @@ struct xml_reader_t
module_t *p_module; module_t *p_module;
int (*pf_next_node) ( xml_reader_t *, const char ** ); 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 ** );
const char *(*pf_next_attr) ( xml_reader_t * );
int (*pf_use_dtd) ( xml_reader_t * ); int (*pf_use_dtd) ( xml_reader_t * );
}; };
...@@ -87,14 +86,10 @@ static inline int xml_ReaderNextNode( xml_reader_t *reader, const char **pval ) ...@@ -87,14 +86,10 @@ static inline int xml_ReaderNextNode( xml_reader_t *reader, const char **pval )
return reader->pf_next_node( reader, 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 ); return reader->pf_next_attr( reader, pval );
}
static inline const char *xml_ReaderNextAttr( xml_reader_t *reader )
{
return reader->pf_next_attr( reader );
} }
static inline int xml_ReaderUseDTD( xml_reader_t *reader ) static inline int xml_ReaderUseDTD( xml_reader_t *reader )
......
...@@ -567,18 +567,13 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -567,18 +567,13 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
else if( !strcasecmp( "resolution", node ) && else if( !strcasecmp( "resolution", node ) &&
( i_metadata_level == 1) ) ( i_metadata_level == 1) )
{ {
const char *attr; const char *attr, *val;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) ) while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{ {
char *psz_value = xml_ReaderValue ( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "x", attr ) ) if( !strcasecmp( "x", attr ) )
p_sys->i_original_width = atoi( psz_value ); p_sys->i_original_width = atoi( val );
else if( !strcasecmp( "y", attr ) ) else if( !strcasecmp( "y", attr ) )
p_sys->i_original_height = atoi( psz_value ); p_sys->i_original_height = atoi( val );
free( psz_value );
} }
} }
else if( !strcasecmp( "styles", node ) && (i_style_level == 0) ) else if( !strcasecmp( "styles", node ) && (i_style_level == 0) )
...@@ -611,40 +606,31 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -611,40 +606,31 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
} }
} }
const char *attr; const char *attr, *val;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) ) while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{ {
char *psz_value = xml_ReaderValue ( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "name", attr ) ) if( !strcasecmp( "name", attr ) )
{ {
free( p_ssa_style->psz_stylename ); free( p_ssa_style->psz_stylename );
p_ssa_style->psz_stylename = strdup( psz_value ); p_ssa_style->psz_stylename = strdup( val );
} }
free( psz_value );
} }
} }
else if( !strcasecmp( "fontstyle", node ) && (i_style_level == 2) ) else if( !strcasecmp( "fontstyle", node ) && (i_style_level == 2) )
{ {
const char *attr; const char *attr, *val;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) ) while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{ {
char *psz_value = xml_ReaderValue ( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "face", attr ) ) if( !strcasecmp( "face", attr ) )
{ {
free( p_ssa_style->font_style.psz_fontname ); free( p_ssa_style->font_style.psz_fontname );
p_ssa_style->font_style.psz_fontname = strdup( psz_value ); p_ssa_style->font_style.psz_fontname = strdup( val );
} }
else if( !strcasecmp( "size", attr ) ) else if( !strcasecmp( "size", attr ) )
{ {
if( ( *psz_value == '+' ) || ( *psz_value == '-' ) ) if( ( *val == '+' ) || ( *val == '-' ) )
{ {
int i_value = atoi( psz_value ); int i_value = atoi( val );
if( ( i_value >= -5 ) && ( i_value <= 5 ) ) if( ( i_value >= -5 ) && ( i_value <= 5 ) )
p_ssa_style->font_style.i_font_size += p_ssa_style->font_style.i_font_size +=
...@@ -655,137 +641,131 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader ) ...@@ -655,137 +641,131 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
p_ssa_style->font_style.i_font_size = i_value; p_ssa_style->font_style.i_font_size = i_value;
} }
else else
p_ssa_style->font_style.i_font_size = atoi( psz_value ); p_ssa_style->font_style.i_font_size = atoi( val );
} }
else if( !strcasecmp( "italic", attr ) ) else if( !strcasecmp( "italic", attr ) )
{ {
if( !strcasecmp( "yes", psz_value )) if( !strcasecmp( "yes", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC; p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
else else
p_ssa_style->font_style.i_style_flags &= ~STYLE_ITALIC; p_ssa_style->font_style.i_style_flags &= ~STYLE_ITALIC;
} }
else if( !strcasecmp( "weight", attr ) ) else if( !strcasecmp( "weight", attr ) )
{ {
if( !strcasecmp( "bold", psz_value )) if( !strcasecmp( "bold", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_BOLD; p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
else else
p_ssa_style->font_style.i_style_flags &= ~STYLE_BOLD; p_ssa_style->font_style.i_style_flags &= ~STYLE_BOLD;
} }
else if( !strcasecmp( "underline", attr ) ) else if( !strcasecmp( "underline", attr ) )
{ {
if( !strcasecmp( "yes", psz_value )) if( !strcasecmp( "yes", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE; p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE;
else else
p_ssa_style->font_style.i_style_flags &= ~STYLE_UNDERLINE; p_ssa_style->font_style.i_style_flags &= ~STYLE_UNDERLINE;
} }
else if( !strcasecmp( "color", attr ) ) else if( !strcasecmp( "color", attr ) )
{ {
if( *psz_value == '#' ) if( *val == '#' )
{ {
unsigned long col = strtol(psz_value+1, NULL, 16); unsigned long col = strtol(val+1, NULL, 16);
p_ssa_style->font_style.i_font_color = (col & 0x00ffffff); p_ssa_style->font_style.i_font_color = (col & 0x00ffffff);
p_ssa_style->font_style.i_font_alpha = (col >> 24) & 0xff; p_ssa_style->font_style.i_font_alpha = (col >> 24) & 0xff;
} }
} }
else if( !strcasecmp( "outline-color", attr ) ) else if( !strcasecmp( "outline-color", attr ) )
{ {
if( *psz_value == '#' ) if( *val == '#' )
{ {
unsigned long col = strtol(psz_value+1, NULL, 16); unsigned long col = strtol(val+1, NULL, 16);
p_ssa_style->font_style.i_outline_color = (col & 0x00ffffff); p_ssa_style->font_style.i_outline_color = (col & 0x00ffffff);
p_ssa_style->font_style.i_outline_alpha = (col >> 24) & 0xff; p_ssa_style->font_style.i_outline_alpha = (col >> 24) & 0xff;
} }
} }
else if( !strcasecmp( "outline-level", attr ) ) else if( !strcasecmp( "outline-level", attr ) )
{ {
p_ssa_style->font_style.i_outline_width = atoi( psz_value ); p_ssa_style->font_style.i_outline_width = atoi( val );
} }
else if( !strcasecmp( "shadow-color", attr ) ) else if( !strcasecmp( "shadow-color", attr ) )
{ {
if( *psz_value == '#' ) if( *val == '#' )
{ {
unsigned long col = strtol(psz_value+1, NULL, 16); unsigned long col = strtol(val+1, NULL, 16);
p_ssa_style->font_style.i_shadow_color = (col & 0x00ffffff); p_ssa_style->font_style.i_shadow_color = (col & 0x00ffffff);
p_ssa_style->font_style.i_shadow_alpha = (col >> 24) & 0xff; p_ssa_style->font_style.i_shadow_alpha = (col >> 24) & 0xff;
} }
} }
else if( !strcasecmp( "shadow-level", attr ) ) else if( !strcasecmp( "shadow-level", attr ) )
{ {
p_ssa_style->font_style.i_shadow_width = atoi( psz_value ); p_ssa_style->font_style.i_shadow_width = atoi( val );
} }
else if( !strcasecmp( "back-color", attr ) ) else if( !strcasecmp( "back-color", attr ) )
{ {
if( *psz_value == '#' ) if( *val == '#' )
{ {
unsigned long col = strtol(psz_value+1, NULL, 16); unsigned long col = strtol(val+1, NULL, 16);
p_ssa_style->font_style.i_karaoke_background_color = (col & 0x00ffffff); p_ssa_style->font_style.i_karaoke_background_color = (col & 0x00ffffff);
p_ssa_style->font_style.i_karaoke_background_alpha = (col >> 24) & 0xff; p_ssa_style->font_style.i_karaoke_background_alpha = (col >> 24) & 0xff;
} }
} }
else if( !strcasecmp( "spacing", attr ) ) else if( !strcasecmp( "spacing", attr ) )
{ {
p_ssa_style->font_style.i_spacing = atoi( psz_value ); p_ssa_style->font_style.i_spacing = atoi( val );
} }
free( psz_value );
} }
} }
else if( !strcasecmp( "position", node ) && (i_style_level == 2) ) else if( !strcasecmp( "position", node ) && (i_style_level == 2) )
{ {
const char *attr; const char *attr, *val;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) ) while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{ {
char *psz_value = xml_ReaderValue ( p_xml_reader );
if( !psz_value )
continue;
if( !strcasecmp( "alignment", attr ) ) if( !strcasecmp( "alignment", attr ) )
{ {
if( !strcasecmp( "TopLeft", psz_value ) ) if( !strcasecmp( "TopLeft", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT; p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
else if( !strcasecmp( "TopCenter", psz_value ) ) else if( !strcasecmp( "TopCenter", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP; p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP;
else if( !strcasecmp( "TopRight", psz_value ) ) else if( !strcasecmp( "TopRight", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_RIGHT; p_ssa_style->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_RIGHT;
else if( !strcasecmp( "MiddleLeft", psz_value ) ) else if( !strcasecmp( "MiddleLeft", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_LEFT; p_ssa_style->i_align = SUBPICTURE_ALIGN_LEFT;
else if( !strcasecmp( "MiddleCenter", psz_value ) ) else if( !strcasecmp( "MiddleCenter", val ) )
p_ssa_style->i_align = 0; p_ssa_style->i_align = 0;
else if( !strcasecmp( "MiddleRight", psz_value ) ) else if( !strcasecmp( "MiddleRight", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_RIGHT; p_ssa_style->i_align = SUBPICTURE_ALIGN_RIGHT;
else if( !strcasecmp( "BottomLeft", psz_value ) ) else if( !strcasecmp( "BottomLeft", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_LEFT; p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_LEFT;
else if( !strcasecmp( "BottomCenter", psz_value ) ) else if( !strcasecmp( "BottomCenter", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM; p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM;
else if( !strcasecmp( "BottomRight", psz_value ) ) else if( !strcasecmp( "BottomRight", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT; p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT;
} }
else if( !strcasecmp( "horizontal-margin", attr ) ) else if( !strcasecmp( "horizontal-margin", attr ) )
{ {
if( strchr( psz_value, '%' ) ) if( strchr( val, '%' ) )
{ {
p_ssa_style->i_margin_h = 0; p_ssa_style->i_margin_h = 0;
p_ssa_style->i_margin_percent_h = atoi( psz_value ); p_ssa_style->i_margin_percent_h = atoi( val );
} }
else else
{ {
p_ssa_style->i_margin_h = atoi( psz_value ); p_ssa_style->i_margin_h = atoi( val );
p_ssa_style->i_margin_percent_h = 0; p_ssa_style->i_margin_percent_h = 0;
} }
} }
else if( !strcasecmp( "vertical-margin", attr ) ) else if( !strcasecmp( "vertical-margin", attr ) )
{ {
if( strchr( psz_value, '%' ) ) if( strchr( val, '%' ) )
{ {
p_ssa_style->i_margin_v = 0; p_ssa_style->i_margin_v = 0;
p_ssa_style->i_margin_percent_v = atoi( psz_value ); p_ssa_style->i_margin_percent_v = atoi( val );
} }
else else
{ {
p_ssa_style->i_margin_v = atoi( psz_value ); p_ssa_style->i_margin_v = atoi( val );
p_ssa_style->i_margin_percent_v = 0; p_ssa_style->i_margin_percent_v = 0;
} }
} }
free( psz_value );
} }
} }
break; break;
......
...@@ -119,24 +119,16 @@ static int Demux( demux_t *p_demux ) ...@@ -119,24 +119,16 @@ static int Demux( demux_t *p_demux )
} }
// Read the attributes // Read the attributes
const char *attr; const char *attr, *value;
while( (attr = xml_ReaderNextAttr( p_xml_reader )) != NULL ) 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" ) ) 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" ) ) else if( !strcmp( attr, "label" ) )
input_item_SetName( p_current_input, psz_value ); input_item_SetName( p_current_input, value );
else else
msg_Warn( p_demux, "stray attribute %s with value %s in element" msg_Warn( p_demux, "stray attribute %s with value %s in element"
" 'playlist'", attr, psz_value ); " <playlist>", attr, value );
free( psz_value );
} }
p_subitems = input_item_node_Create( p_current_input ); p_subitems = input_item_node_Create( p_current_input );
...@@ -155,24 +147,18 @@ static int Demux( demux_t *p_demux ) ...@@ -155,24 +147,18 @@ static int Demux( demux_t *p_demux )
goto end; goto end;
// Read the attributes // 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" ) && if( !strcmp( psz_elname, "entry" ) &&
!strcmp( attr, "Playstring" ) ) !strcmp( attr, "Playstring" ) )
{ {
psz_mrl = psz_value; free( psz_mrl );
psz_mrl = strdup( value );
} }
else else
{ {
msg_Warn( p_demux, "unexpected attribute %s in element %s", msg_Warn( p_demux, "unexpected attribute %s in <%s>",
attr, psz_elname ); attr, psz_elname );
free( psz_value );
} }
} }
break; break;
......
...@@ -131,32 +131,22 @@ static bool parse_plist_node( demux_t *p_demux, input_item_node_t *p_input_node, ...@@ -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 ) xml_elem_hnd_t *p_handlers )
{ {
VLC_UNUSED(p_track); VLC_UNUSED(psz_element); VLC_UNUSED(p_track); VLC_UNUSED(psz_element);
const char *attr; const char *attr, *value;
char *psz_value;
bool b_version_found = false; bool b_version_found = false;
/* read all playlist attributes */ /* 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 */ /* attribute: version */
if( !strcmp( attr, "version" ) ) if( !strcmp( attr, "version" ) )
{ {
b_version_found = true; b_version_found = true;
if( strcmp( psz_value, "1.0" ) ) if( strcmp( value, "1.0" ) )
msg_Warn( p_demux, "unsupported iTunes Media Library version" ); msg_Warn( p_demux, "unsupported iTunes Media Library version" );
} }
/* unknown attribute */ /* unknown attribute */
else else
msg_Warn( p_demux, "invalid <plist> attribute:\"%s\"", attr ); msg_Warn( p_demux, "invalid <plist> attribute:\"%s\"", attr );
free( psz_value );
} }
/* attribute version is mandatory !!! */ /* attribute version is mandatory !!! */
......
...@@ -130,46 +130,30 @@ static int Demux( demux_t *p_demux ) ...@@ -130,46 +130,30 @@ static int Demux( demux_t *p_demux )
b_image = true; b_image = true;
// Read the attributes // Read the attributes
const char *attr; const char *attr, *value;
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 error;
}
if( !strcmp( node, "enclosure" ) ) if( !strcmp( node, "enclosure" ) )
{ {
const char **p = NULL;
if( !strcmp( attr, "url" ) ) if( !strcmp( attr, "url" ) )
{ p = &psz_item_mrl;
free( psz_item_mrl );
psz_item_mrl = psz_value;
}
else if( !strcmp( attr, "length" ) ) else if( !strcmp( attr, "length" ) )
{ p = &psz_item_size;
free( psz_item_size );
psz_item_size = psz_value;
}
else if( !strcmp( attr, "type" ) ) else if( !strcmp( attr, "type" ) )
p = &psz_item_type;
if( p != NULL )
{ {
free( psz_item_type ); free( *p );
psz_item_type = psz_value; *p = strdup( value );
} }
else else
{ msg_Dbg( p_demux,"unhandled attribute %s in <%s>",
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
attr, node ); attr, node );
free( psz_value );
}
} }
else else
{ msg_Dbg( p_demux,"unhandled attribute %s in <%s>",
msg_Dbg( p_demux,"unhandled attribute %s in element %s",
attr, node ); attr, node );
free( psz_value );
}
} }
break; break;
} }
......
...@@ -145,82 +145,73 @@ static int Demux( demux_t *p_demux ) ...@@ -145,82 +145,73 @@ static int Demux( demux_t *p_demux )
} }
} }
const char *attrname; const char *attrname, *value;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) != NULL ) 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" ) ) if( !strcmp( attrname, "autoplay" ) )
b_autoplay = !strcmp( psz_attrvalue, "true" ); b_autoplay = !strcmp( value, "true" );
else if( !strcmp( attrname, "controler" ) ) else if( !strcmp( attrname, "controler" ) )
b_controler = !strcmp( psz_attrvalue, "false" ); b_controler = !strcmp( attrname, "false" );
else if( !strcmp( attrname, "fullscreen" ) ) else if( !strcmp( attrname, "fullscreen" ) )
{ {
if( !strcmp( psz_attrvalue, "double" ) ) if( !strcmp( value, "double" ) )
fullscreen = FULLSCREEN_DOUBLE; fullscreen = FULLSCREEN_DOUBLE;
else if( !strcmp( psz_attrvalue, "half" ) ) else if( !strcmp( value, "half" ) )
fullscreen = FULLSCREEN_HALF; fullscreen = FULLSCREEN_HALF;
else if( !strcmp( psz_attrvalue, "current" ) ) else if( !strcmp( value, "current" ) )
fullscreen = FULLSCREEN_CURRENT; fullscreen = FULLSCREEN_CURRENT;
else if( !strcmp( psz_attrvalue, "full" ) ) else if( !strcmp( value, "full" ) )
fullscreen = FULLSCREEN_FULL; fullscreen = FULLSCREEN_FULL;
else else
fullscreen = FULLSCREEN_NORMAL; fullscreen = FULLSCREEN_NORMAL;
} }
else if( !strcmp( attrname, "href" ) ) else if( !strcmp( attrname, "href" ) )
{ {
psz_href = psz_attrvalue; free( psz_href );
psz_attrvalue = NULL; psz_href = strdup( value );
} }
else if( !strcmp( attrname, "kioskmode" ) ) else if( !strcmp( attrname, "kioskmode" ) )
b_kioskmode = !strcmp( psz_attrvalue, "true" ); b_kioskmode = !strcmp( value, "true" );
else if( !strcmp( attrname, "loop" ) ) else if( !strcmp( attrname, "loop" ) )
{ {
if( !strcmp( psz_attrvalue, "true" ) ) if( !strcmp( value, "true" ) )
loop = LOOP_TRUE; loop = LOOP_TRUE;
else if( !strcmp( psz_attrvalue, "palindrome" ) ) else if( !strcmp( value, "palindrome" ) )
loop = LOOP_PALINDROME; loop = LOOP_PALINDROME;
else else
loop = LOOP_FALSE; loop = LOOP_FALSE;
} }
else if( !strcmp( attrname, "movieid" ) ) else if( !strcmp( attrname, "movieid" ) )
i_movieid = atoi( psz_attrvalue ); i_movieid = atoi( value );
else if( !strcmp( attrname, "moviename" ) ) else if( !strcmp( attrname, "moviename" ) )
{ {
psz_moviename = psz_attrvalue; free( psz_moviename );
psz_attrvalue = NULL; psz_moviename = strdup( value );
} }
else if( !strcmp( attrname, "playeveryframe" ) ) else if( !strcmp( attrname, "playeveryframe" ) )
b_playeveryframe = !strcmp( psz_attrvalue, "true" ); b_playeveryframe = !strcmp( value, "true" );
else if( !strcmp( attrname, "qtnext" ) ) else if( !strcmp( attrname, "qtnext" ) )
{ {
psz_qtnext = psz_attrvalue; free( psz_qtnext );
psz_attrvalue = NULL; psz_qtnext = strdup( value );
} }
else if( !strcmp( attrname, "quitwhendone" ) ) else if( !strcmp( attrname, "quitwhendone" ) )
b_quitwhendone = !strcmp( psz_attrvalue, "true" ); b_quitwhendone = !strcmp( value, "true" );
else if( !strcmp( attrname, "src" ) ) else if( !strcmp( attrname, "src" ) )
{ {
psz_src = psz_attrvalue; free( psz_src );
psz_attrvalue = NULL; psz_src = strdup( value );
} }
else if( !strcmp( attrname, "mimetype" ) ) else if( !strcmp( attrname, "mimetype" ) )
{ {
psz_mimetype = psz_attrvalue; free( psz_mimetype );
psz_attrvalue = NULL; psz_mimetype = strdup( value );
} }
else if( !strcmp( attrname, "volume" ) ) else if( !strcmp( attrname, "volume" ) )
i_volume = atoi( psz_attrvalue ); i_volume = atoi( value );
else else
msg_Dbg( p_demux, "Attribute %s with value %s isn't valid", msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
attrname, psz_attrvalue ); attrname, value );
free( psz_attrvalue );
} }
msg_Dbg( p_demux, "autoplay: %s (unused by VLC)", msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
......
...@@ -131,12 +131,6 @@ error: ...@@ -131,12 +131,6 @@ error:
return i_ret; return i_ret;
} }
#define GET_VALUE( a ) \
if( !strcmp( attrname, #a ) ) \
{ \
free(psz_ ## a); \
psz_ ## a = psz_attrvalue; \
}
/* <genrelist> /* <genrelist>
* <genre name="the name"></genre> * <genre name="the name"></genre>
* ... * ...
...@@ -158,24 +152,18 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader, ...@@ -158,24 +152,18 @@ static int DemuxGenre( demux_t *p_demux, xml_reader_t *p_xml_reader,
if( !strcmp( node, "genre" ) ) if( !strcmp( node, "genre" ) )
{ {
// Read the attributes // Read the attributes
const char *attrname; const char *name, *value;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) ) while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{ {
char *psz_attrvalue = xml_ReaderValue( p_xml_reader ); if( !strcmp( name, "name" ) )
if( !psz_attrvalue )
{ {
free( psz_attrvalue ); free(psz_name);
break; psz_name = strdup( value );
} }
GET_VALUE( name )
else else
{
msg_Warn( p_demux, msg_Warn( p_demux,
"unexpected attribute %s in element %s", "unexpected attribute %s in <%s>",
attrname, node ); name, node );
free( psz_attrvalue );
}
} }
} }
break; break;
...@@ -259,54 +247,53 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader, ...@@ -259,54 +247,53 @@ static int DemuxStation( demux_t *p_demux, xml_reader_t *p_xml_reader,
// Read the attributes // Read the attributes
if( !strcmp( node, "tunein" ) ) if( !strcmp( node, "tunein" ) )
{ {
const char *attrname; const char *name, *value;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) ) while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{ {
char *psz_attrvalue = xml_ReaderValue( p_xml_reader ); if( !strcmp( name, "base" ) )
if( !psz_attrvalue )
{ {
free( psz_attrvalue ); free( psz_base );
return -1; psz_base = strdup( value );
} }
GET_VALUE( base )
else else
{
msg_Warn( p_demux, msg_Warn( p_demux,
"unexpected attribute %s in element %s", "unexpected attribute %s in <%s>",
attrname, node ); name, node );
free( psz_attrvalue );
}
} }
} }
else if( !strcmp( node, "station" ) ) else if( !strcmp( node, "station" ) )
{ {
const char *attrname; const char *name, *value;
while( (attrname = xml_ReaderNextAttr( p_xml_reader )) ) while( (name = xml_ReaderNextAttr( p_xml_reader, &value )) )
{ {
char *psz_attrvalue = xml_ReaderValue( p_xml_reader ); char **p = NULL;
if( !psz_attrvalue ) 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 ); free( *p );
return -1; *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 else
{
msg_Warn( p_demux, msg_Warn( p_demux,
"unexpected attribute %s in element %s", "unexpected attribute %s in <%s>",
attrname, node ); name, node );
free( psz_attrvalue );
}
} }
} }
break; break;
......
...@@ -173,21 +173,15 @@ static bool parse_playlist_node COMPLEX_INTERFACE ...@@ -173,21 +173,15 @@ static bool parse_playlist_node COMPLEX_INTERFACE
}; };
/* read all playlist attributes */ /* read all playlist attributes */
const char *name; const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL ) 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 */ /* attribute: version */
if( !strcmp( name, "version" ) ) if( !strcmp( name, "version" ) )
{ {
b_version_found = true; b_version_found = true;
if( strcmp( psz_value, "0" ) && strcmp( psz_value, "1" ) ) if( strcmp( value, "0" ) && strcmp( value, "1" ) )
msg_Warn( p_demux, "unsupported XSPF version" ); msg_Warn( p_demux, "unsupported XSPF version %s", value );
} }
/* attribute: xmlns */ /* attribute: xmlns */
else if( !strcmp( name, "xmlns" ) || !strcmp( name, "xmlns:vlc" ) ) else if( !strcmp( name, "xmlns" ) || !strcmp( name, "xmlns:vlc" ) )
...@@ -200,8 +194,6 @@ static bool parse_playlist_node COMPLEX_INTERFACE ...@@ -200,8 +194,6 @@ static bool parse_playlist_node COMPLEX_INTERFACE
/* unknown attribute */ /* unknown attribute */
else else
msg_Warn( p_demux, "invalid <playlist> attribute: \"%s\"", name); msg_Warn( p_demux, "invalid <playlist> attribute: \"%s\"", name);
free( psz_value );
} }
/* attribute version is mandatory !!! */ /* attribute version is mandatory !!! */
if( !b_version_found ) if( !b_version_found )
...@@ -590,37 +582,27 @@ static bool parse_extension_node COMPLEX_INTERFACE ...@@ -590,37 +582,27 @@ static bool parse_extension_node COMPLEX_INTERFACE
}; };
/* read all extension node attributes */ /* read all extension node attributes */
const char *name; const char *name, *value;
while( (name = xml_ReaderNextAttr( p_xml_reader )) != NULL ) 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 */ /* attribute: title */
if( !strcmp( name, "title" ) ) if( !strcmp( name, "title" ) )
{ {
resolve_xml_special_chars( psz_value );
free( psz_title ); 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 */ /* extension attribute: application */
else if( !strcmp( name, "application" ) ) else if( !strcmp( name, "application" ) )
{ {
free( psz_application ); free( psz_application );
psz_application = psz_value; psz_application = strdup( value );
} }
/* unknown attribute */ /* unknown attribute */
else else
{
msg_Warn( p_demux, "invalid <%s> attribute:\"%s\"", psz_element, msg_Warn( p_demux, "invalid <%s> attribute:\"%s\"", psz_element,
name ); name );
FREE_VALUE();
}
psz_value = NULL;
} }
/* attribute title is mandatory except for <extension> */ /* attribute title is mandatory except for <extension> */
...@@ -776,24 +758,15 @@ static bool parse_extitem_node COMPLEX_INTERFACE ...@@ -776,24 +758,15 @@ static bool parse_extitem_node COMPLEX_INTERFACE
int i_tid = -1; int i_tid = -1;
/* read all extension item attributes */ /* read all extension item attributes */
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 )
{ {
msg_Err( p_demux, "invalid xml stream @ <vlc:item>" );
free( psz_value );
return false;
}
/* attribute: href */ /* attribute: href */
if( !strcmp( name, "tid" ) ) if( !strcmp( name, "tid" ) )
i_tid = atoi( psz_value ); i_tid = atoi( value );
/* unknown attribute */ /* unknown attribute */
else else
msg_Warn( p_demux, "invalid <vlc:item> attribute: \"%s\"", name); msg_Warn( p_demux, "invalid <vlc:item> attribute: \"%s\"", name);
free( psz_value );
} }
/* attribute href is mandatory */ /* attribute href is mandatory */
......
...@@ -150,17 +150,9 @@ bool XMLParser::parse() ...@@ -150,17 +150,9 @@ bool XMLParser::parse()
{ {
// Read the attributes // Read the attributes
AttrList_t attributes; AttrList_t attributes;
const char *name; const char *name, *value;
while( (name = xml_ReaderNextAttr( m_pReader )) != NULL ) while( (name = xml_ReaderNextAttr( m_pReader, &value )) != NULL )
{ attributes[strdup(name)] = strdup(value);
char *value = xml_ReaderValue( m_pReader );
if( !value )
{
free( value );
return false;
}
attributes[strdup(name)] = value;
}
handleBeginElement( node, attributes ); handleBeginElement( node, attributes );
......
...@@ -84,12 +84,10 @@ static int vlclua_xml_create( lua_State *L ) ...@@ -84,12 +84,10 @@ static int vlclua_xml_create( lua_State *L )
* XML Reader * XML Reader
*****************************************************************************/ *****************************************************************************/
static int vlclua_xml_reader_next_node( lua_State * ); 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 int vlclua_xml_reader_next_attr( lua_State * );
static const luaL_Reg vlclua_xml_reader_reg[] = { static const luaL_Reg vlclua_xml_reader_reg[] = {
{ "next_node", vlclua_xml_reader_next_node }, { "next_node", vlclua_xml_reader_next_node },
{ "value", vlclua_xml_reader_value },
{ "next_attr", vlclua_xml_reader_next_attr }, { "next_attr", vlclua_xml_reader_next_attr },
{ NULL, NULL } { NULL, NULL }
}; };
...@@ -135,17 +133,13 @@ static int vlclua_xml_reader_next_node( lua_State *L ) ...@@ -135,17 +133,13 @@ static int vlclua_xml_reader_next_node( lua_State *L )
return 2; 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 ) static int vlclua_xml_reader_next_attr( lua_State *L )
{ {
xml_reader_t *p_reader = *(xml_reader_t**)luaL_checkudata( L, 1, "xml_reader" ); 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; return 1;
} }
......
...@@ -483,7 +483,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -483,7 +483,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
uint32_t i_font_color = 0xffffff; uint32_t i_font_color = 0xffffff;
int i_font_alpha = 0; int i_font_alpha = 0;
int i_font_size = 24; 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 // Default all attributes to the top font in the stack -- in case not
// all attributes are specified in the sub-font // all attributes are specified in the sub-font
...@@ -498,23 +498,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -498,23 +498,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff; i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff; 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 ) ) if( !strcasecmp( "face", attr ) )
{ {
free( psz_fontname ); free( psz_fontname );
psz_fontname = strdup( psz_value ); psz_fontname = strdup( value );
} }
else if( !strcasecmp( "size", attr ) ) 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 ) ) if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10; i_font_size += ( i_value * i_font_size ) / 10;
...@@ -524,22 +519,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -524,22 +519,18 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_size = i_value; i_font_size = i_value;
} }
else else
i_font_size = atoi( psz_value ); i_font_size = atoi( value );
} }
else if( !strcasecmp( "color", attr ) && else if( !strcasecmp( "color", attr ) && ( value[0] == '#' ) )
( psz_value[0] == '#' ) )
{ {
i_font_color = strtol( psz_value + 1, NULL, 16 ); i_font_color = strtol( value + 1, NULL, 16 );
i_font_color &= 0x00ffffff; i_font_color &= 0x00ffffff;
} }
else if( !strcasecmp( "alpha", attr ) && else if( !strcasecmp( "alpha", attr ) && ( value[0] == '#' ) )
( psz_value[0] == '#' ) )
{ {
i_font_alpha = strtol( psz_value + 1, NULL, 16 ); i_font_alpha = strtol( value + 1, NULL, 16 );
i_font_alpha &= 0xff; i_font_alpha &= 0xff;
} }
free( psz_value );
} }
rv = PushFont( p_fonts, rv = PushFont( p_fonts,
psz_fontname, psz_fontname,
......
...@@ -331,23 +331,19 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -331,23 +331,19 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_alpha = (i_font_color >> 24) & 0xff; i_font_alpha = (i_font_color >> 24) & 0xff;
i_font_color &= 0x00ffffff; i_font_color &= 0x00ffffff;
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( "face", name ) ) if( !strcasecmp( "face", name ) )
{ {
free( psz_fontname ); free( psz_fontname );
psz_fontname = strdup( psz_value ); psz_fontname = strdup( value );
} }
else if( !strcasecmp( "size", name ) ) 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 ) ) if( ( i_value >= -5 ) && ( i_value <= 5 ) )
i_font_size += ( i_value * i_font_size ) / 10; i_font_size += ( i_value * i_font_size ) / 10;
...@@ -357,20 +353,20 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -357,20 +353,20 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
i_font_size = i_value; i_font_size = i_value;
} }
else else
i_font_size = atoi( psz_value ); i_font_size = atoi( value );
} }
else if( !strcasecmp( "color", name ) ) 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; i_font_color &= 0x00ffffff;
} }
else 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( value, p_html_colors[i].psz_name, strlen(p_html_colors[i].psz_name) ) )
{ {
i_font_color = p_html_colors[i].i_value; i_font_color = p_html_colors[i].i_value;
break; break;
...@@ -378,12 +374,11 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader, ...@@ -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; i_font_alpha &= 0xff;
} }
free( psz_value );
} }
rv = PushFont( p_fonts, rv = PushFont( p_fonts,
psz_fontname, psz_fontname,
...@@ -427,14 +422,10 @@ static void SetupKaraoke( xml_reader_t *p_xml_reader, uint32_t *pi_k_runs, ...@@ -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_run_lengths,
uint32_t **ppi_k_durations ) 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( !strcasecmp( "t", name ) )
{ {
if( ppi_k_durations && ppi_k_run_lengths ) 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, ...@@ -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 ) ); malloc( *pi_k_runs * sizeof( uint32_t ) );
} }
if( *ppi_k_durations ) 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 ) if( *ppi_k_run_lengths )
(*ppi_k_run_lengths)[ *pi_k_runs - 1 ] = 0; (*ppi_k_run_lengths)[ *pi_k_runs - 1 ] = 0;
} }
} }
free( psz_value );
} }
} }
......
...@@ -61,8 +61,7 @@ vlc_module_begin () ...@@ -61,8 +61,7 @@ vlc_module_begin ()
vlc_module_end () vlc_module_end ()
static int ReaderNextNode( xml_reader_t *, const char ** ); static int ReaderNextNode( xml_reader_t *, const char ** );
static char *ReaderValue( xml_reader_t * ); static const char *ReaderNextAttr( xml_reader_t *, const char ** );
static const char *ReaderNextAttr( xml_reader_t * );
static int ReaderUseDTD ( xml_reader_t * ); static int ReaderUseDTD ( xml_reader_t * );
...@@ -175,7 +174,6 @@ static int ReaderOpen( vlc_object_t *p_this ) ...@@ -175,7 +174,6 @@ static int ReaderOpen( vlc_object_t *p_this )
p_sys->node = NULL; p_sys->node = NULL;
p_reader->p_sys = p_sys; p_reader->p_sys = p_sys;
p_reader->pf_next_node = ReaderNextNode; p_reader->pf_next_node = ReaderNextNode;
p_reader->pf_value = ReaderValue;
p_reader->pf_next_attr = ReaderNextAttr; p_reader->pf_next_attr = ReaderNextAttr;
p_reader->pf_use_dtd = ReaderUseDTD; p_reader->pf_use_dtd = ReaderUseDTD;
...@@ -268,11 +266,18 @@ static char *ReaderValue( xml_reader_t *p_reader ) ...@@ -268,11 +266,18 @@ static char *ReaderValue( xml_reader_t *p_reader )
return psz_value ? strdup( (const char *)psz_value ) : NULL; 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 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 ) 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, ...@@ -719,27 +719,22 @@ static bool ParseFeed( filter_t *p_filter, xml_reader_t *p_xml_reader,
/* atom */ /* atom */
else if( !strcmp( node, "link" ) ) else if( !strcmp( node, "link" ) )
{ {
const char *name; const char *name, *value;
char *psz_href = NULL; char *psz_href = NULL;
char *psz_rel = 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" ) ) if( !strcmp( name, "rel" ) )
{ {
free( psz_rel ); free( psz_rel );
psz_rel = psz_value; psz_rel = strdup( value );
} }
else if( !strcmp( name, "href" ) ) else if( !strcmp( name, "href" ) )
{ {
free( psz_href ); free( psz_href );
psz_href = psz_value; psz_href = strdup( value );
} }
else
free( psz_value );
} }
/* "rel" and "href" must be defined */ /* "rel" and "href" must be defined */
......
...@@ -41,10 +41,10 @@ local function parsexml(stream, errormsg) ...@@ -41,10 +41,10 @@ local function parsexml(stream, errormsg)
while nodetype > 0 do while nodetype > 0 do
if nodetype == 1 then if nodetype == 1 then
local node = { name= nodename, attributes= {}, children= {} } local node = { name= nodename, attributes= {}, children= {} }
local attr = reader:next_attr() local attr, value = reader:next_attr()
while attr ~= nil do while attr ~= nil do
node.attributes[attr] = reader:value() node.attributes[attr] = value
attr = reader:next_attr() attr, value = reader:next_attr()
end end
if tree then if tree then
table.insert(tree.children, node) 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