This simplifies error and memory handling.
A few memory leaks were fixed.
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 * );
};
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 )
else if( !strcasecmp( "resolution", node ) &&
( i_metadata_level == 1) )
{
- const char *attr;
- while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
+ const char *attr, *val;
+ while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{
- char *psz_value = xml_ReaderValue ( p_xml_reader );
- if( !psz_value )
- continue;
-
if( !strcasecmp( "x", attr ) )
- p_sys->i_original_width = atoi( psz_value );
+ p_sys->i_original_width = atoi( val );
else if( !strcasecmp( "y", attr ) )
- p_sys->i_original_height = atoi( psz_value );
- free( psz_value );
+ p_sys->i_original_height = atoi( val );
}
}
else if( !strcasecmp( "styles", node ) && (i_style_level == 0) )
}
}
- const char *attr;
- while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
+ const char *attr, *val;
+ while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{
- char *psz_value = xml_ReaderValue ( p_xml_reader );
- if( !psz_value )
- continue;
-
if( !strcasecmp( "name", attr ) )
{
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) )
{
- const char *attr;
- while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
+ const char *attr, *val;
+ while( (attr = xml_ReaderNextAttr( p_xml_reader, &val )) )
{
- char *psz_value = xml_ReaderValue ( p_xml_reader );
- if( !psz_value )
- continue;
-
if( !strcasecmp( "face", attr ) )
{
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 ) )
{
- 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 ) )
p_ssa_style->font_style.i_font_size +=
p_ssa_style->font_style.i_font_size = i_value;
}
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 ) )
{
- if( !strcasecmp( "yes", psz_value ))
+ if( !strcasecmp( "yes", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_ITALIC;
else
p_ssa_style->font_style.i_style_flags &= ~STYLE_ITALIC;
}
else if( !strcasecmp( "weight", attr ) )
{
- if( !strcasecmp( "bold", psz_value ))
+ if( !strcasecmp( "bold", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_BOLD;
else
p_ssa_style->font_style.i_style_flags &= ~STYLE_BOLD;
}
else if( !strcasecmp( "underline", attr ) )
{
- if( !strcasecmp( "yes", psz_value ))
+ if( !strcasecmp( "yes", val ))
p_ssa_style->font_style.i_style_flags |= STYLE_UNDERLINE;
else
p_ssa_style->font_style.i_style_flags &= ~STYLE_UNDERLINE;
}
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_alpha = (col >> 24) & 0xff;
}
}
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_alpha = (col >> 24) & 0xff;
}
}
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 ) )
{
- 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_alpha = (col >> 24) & 0xff;
}
}
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 ) )
{
- 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_alpha = (col >> 24) & 0xff;
}
}
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) )
{
- const char *attr;
- while( (attr = xml_ReaderNextAttr( p_xml_reader )) )
+ const char *attr, *val;
+ 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( "TopLeft", psz_value ) )
+ if( !strcasecmp( "TopLeft", val ) )
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;
- else if( !strcasecmp( "TopRight", psz_value ) )
+ else if( !strcasecmp( "TopRight", val ) )
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;
- else if( !strcasecmp( "MiddleCenter", psz_value ) )
+ else if( !strcasecmp( "MiddleCenter", val ) )
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;
- else if( !strcasecmp( "BottomLeft", psz_value ) )
+ else if( !strcasecmp( "BottomLeft", val ) )
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;
- else if( !strcasecmp( "BottomRight", psz_value ) )
+ else if( !strcasecmp( "BottomRight", val ) )
p_ssa_style->i_align = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT;
}
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_percent_h = atoi( psz_value );
+ p_ssa_style->i_margin_percent_h = atoi( val );
}
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;
}
}
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_percent_v = atoi( psz_value );
+ p_ssa_style->i_margin_percent_v = atoi( val );
}
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;
}
}
- free( psz_value );
}
}
break;
}
// 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 );
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;
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 !!! */
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;
}
}
}
- 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)",
return i_ret;
}
-#define GET_VALUE( a ) \
- if( !strcmp( attrname, #a ) ) \
- { \
- free(psz_ ## a); \
- psz_ ## a = psz_attrvalue; \
- }
/* <genrelist>
* <genre name="the name"></genre>
* ...
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;
// 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;
};
/* 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" ) )
/* unknown attribute */
else
msg_Warn( p_demux, "invalid <playlist> attribute: \"%s\"", name);
-
- free( psz_value );
}
/* attribute version is mandatory !!! */
if( !b_version_found )
};
/* 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> */
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 */
{
// 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 );
* 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 }
};
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;
}
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
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;
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,
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;
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;
}
}
}
- 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,
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 )
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 );
}
}
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 * );
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;
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 )
/* 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 */
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)