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