X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fplaylist%2Fasx.c;h=030c3410cd6d40b848021df56d32bd323b5b1d7f;hb=7d5bf1ea1baaaad1dbd494312b725e18b00c1de9;hp=18740d571dc986295ba77e8a5564f6cfdf3b9a4f;hpb=7b9e1799ee5a6330222f62801abb29f15750611c;p=vlc diff --git a/modules/demux/playlist/asx.c b/modules/demux/playlist/asx.c index 18740d571d..030c3410cd 100644 --- a/modules/demux/playlist/asx.c +++ b/modules/demux/playlist/asx.c @@ -27,7 +27,11 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include @@ -40,8 +44,8 @@ struct demux_sys_t char *psz_prefix; char *psz_data; int64_t i_data_len; - vlc_bool_t b_utf8; - vlc_bool_t b_skip_ads; + bool b_utf8; + bool b_skip_ads; }; /***************************************************************************** @@ -57,7 +61,7 @@ static int StoreString( demux_t *p_demux, char **ppsz_string, demux_sys_t *p_sys = p_demux->p_sys; unsigned len = psz_source_end - psz_source_start; - if( *ppsz_string ) free( *ppsz_string ); + free( *ppsz_string ); char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1); if (buf == NULL) @@ -181,7 +185,7 @@ static int ParseTime(char *s, size_t i_strlen) /***************************************************************************** * Import_ASX: main import function *****************************************************************************/ -int E_(Import_ASX)( vlc_object_t *p_this ) +int Import_ASX( vlc_object_t *p_this ) { demux_t *p_demux = (demux_t *)p_this; const uint8_t *p_peek; @@ -190,9 +194,9 @@ int E_(Import_ASX)( vlc_object_t *p_this ) // skip over possible leading empty lines and empty spaces p_peek = (uint8_t *)SkipBlanks((char *)p_peek, 6); - if( POKE( p_peek, "p_sys->psz_prefix = E_(FindPrefix)( p_demux ); + p_demux->p_sys->psz_prefix = FindPrefix( p_demux ); p_demux->p_sys->psz_data = NULL; p_demux->p_sys->i_data_len = -1; - p_demux->p_sys->b_utf8 = VLC_FALSE; + p_demux->p_sys->b_utf8 = false; p_demux->p_sys->b_skip_ads = config_GetInt( p_demux, "playlist-skip-ads" ); return VLC_SUCCESS; @@ -212,13 +216,13 @@ int E_(Import_ASX)( vlc_object_t *p_this ) /***************************************************************************** * Deactivate: frees unused data *****************************************************************************/ -void E_(Close_ASX)( vlc_object_t *p_this ) +void Close_ASX( vlc_object_t *p_this ) { demux_t *p_demux = (demux_t *)p_this; demux_sys_t *p_sys = p_demux->p_sys; - if( p_sys->psz_prefix ) free( p_sys->psz_prefix ); - if( p_sys->psz_data ) free( p_sys->psz_data ); + free( p_sys->psz_prefix ); + free( p_sys->psz_data ); free( p_sys ); } @@ -227,8 +231,7 @@ static int Demux( demux_t *p_demux ) demux_sys_t *p_sys = p_demux->p_sys; char *psz_parse = NULL; char *psz_backup = NULL; - vlc_bool_t b_entry = VLC_FALSE; - input_item_t *p_input; + bool b_entry = false; INIT_PLAYLIST_STUFF; /* init txt */ @@ -237,13 +240,13 @@ static int Demux( demux_t *p_demux ) int64_t i_pos = 0; p_sys->i_data_len = stream_Size( p_demux->s ) +1; /* This is a cheat to prevent unnecessary realloc */ if( p_sys->i_data_len <= 0 && p_sys->i_data_len < 16384 ) p_sys->i_data_len = 1024; - p_sys->psz_data = malloc( p_sys->i_data_len * sizeof(char) +1); + p_sys->psz_data = malloc( p_sys->i_data_len +1); /* load the complete file */ for( ;; ) { int i_read = stream_Read( p_demux->s, &p_sys->psz_data[i_pos], p_sys->i_data_len - i_pos ); - p_sys->psz_data[i_read] = '\0'; + p_sys->psz_data[i_pos + i_read] = '\0'; if( i_read < p_sys->i_data_len - i_pos ) break; /* Done */ @@ -276,7 +279,7 @@ static int Demux( demux_t *p_demux ) char *psz_moreinfo_entry = NULL; char *psz_abstract_entry = NULL; int i_entry_count = 0; - vlc_bool_t b_skip_entry = VLC_FALSE; + bool b_skip_entry = false; char *psz_href = NULL; int i_starttime = 0; @@ -295,7 +298,7 @@ static int Demux( demux_t *p_demux ) } else if( !strncasecmp( psz_parse, "b_utf8 = VLC_TRUE; + if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = true; free( psz_string ); } else continue; @@ -452,12 +455,14 @@ static int Demux( demux_t *p_demux ) { i_strlen = psz_parse-psz_backup; if( i_strlen < 1 ) continue; - psz_string = malloc( i_strlen*sizeof( char ) +1); + psz_string = malloc( i_strlen +1); memcpy( psz_string, psz_backup, i_strlen ); psz_string[i_strlen] = '\0'; - p_input = input_ItemNew( p_playlist, psz_string, psz_title_asx ); - input_ItemCopyOptions( p_current_input, p_input ); - input_ItemAddSubItem( p_current_input, p_input, VLC_FALSE ); + input_item_t *p_input; + p_input = input_item_New( p_demux, psz_string, psz_title_asx ); + input_item_CopyOptions( p_current_input, p_input ); + input_item_AddSubItem( p_current_input, p_input ); + vlc_gc_decref( p_input ); free( psz_string ); } else continue; @@ -492,42 +497,57 @@ static int Demux( demux_t *p_demux ) if( p_sys->b_skip_ads && b_skip_entry ) { + char *psz_current_input_name = input_item_GetName( p_current_input ); + msg_Dbg( p_demux, "skipped entry %d %s (%s)", - i_entry_count, ( psz_title_entry ? psz_title_entry : p_current_input->psz_name ), psz_href ); + i_entry_count, + ( psz_title_entry ? psz_title_entry : psz_current_input_name ), psz_href ); + free( psz_current_input_name ); } else { if( i_starttime || i_duration ) { - if( i_starttime ) { - asprintf(ppsz_options+i_options, ":start-time=%d", i_starttime); - ++i_options; + if( i_starttime ) + { + if( asprintf(ppsz_options+i_options, ":start-time=%d", i_starttime) == -1 ) + *(ppsz_options+i_options) = NULL; + else + ++i_options; } - if( i_duration ) { - asprintf(ppsz_options+i_options, ":stop-time=%d", i_starttime + i_duration); - ++i_options; + if( i_duration ) + { + if( asprintf(ppsz_options+i_options, ":stop-time=%d", i_starttime + i_duration) == -1 ) + *(ppsz_options+i_options) = NULL; + else + ++i_options; } } /* create the new entry */ - asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : p_current_input->psz_name ) ); - - p_entry = input_ItemNewExt( p_playlist, psz_href, psz_name, i_options, (const char * const *)ppsz_options, -1 ); - FREENULL( psz_name ); - input_ItemCopyOptions( p_current_input, p_entry ); - while( i_options ) + char *psz_current_input_name = input_item_GetName( p_current_input ); + if( asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : psz_current_input_name ) ) != -1 ) { - psz_name = ppsz_options[--i_options]; - FREENULL(psz_name); + p_entry = input_item_NewExt( p_demux, psz_href, psz_name, + i_options, (const char * const *)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 ); + free( psz_name ); + input_item_CopyOptions( p_current_input, p_entry ); + while( i_options ) + { + psz_name = ppsz_options[--i_options]; + free( psz_name ); + } + psz_name = NULL; + + if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry ); + if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry ); + if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry ); + if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry ); + if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry ); + input_item_AddSubItem( p_current_input, p_entry ); + vlc_gc_decref( p_entry ); } - - if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry ); - if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry ); - if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry ); - if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry ); - if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry ); - input_ItemAddSubItem( p_current_input, p_entry, VLC_FALSE ); - vlc_gc_decref( p_entry ); + free( psz_current_input_name ); } /* cleanup entry */; @@ -538,7 +558,7 @@ static int Demux( demux_t *p_demux ) FREENULL( psz_copyright_entry ); FREENULL( psz_moreinfo_entry ); FREENULL( psz_abstract_entry ); - b_entry = VLC_FALSE; + b_entry = false; } else if( !strncasecmp( psz_parse, "" ); @@ -559,7 +579,6 @@ static int Demux( demux_t *p_demux ) // init entry details FREENULL(psz_href); - psz_href = NULL; i_starttime = 0; i_duration = 0; } @@ -584,8 +603,8 @@ static int Demux( demux_t *p_demux ) i_strlen = psz_parse-psz_backup; if( i_strlen < 1 ) continue; - FREENULL(psz_href); - psz_href = malloc( i_strlen*sizeof( char ) +1); + free( psz_href ); + psz_href = malloc( i_strlen +1); memcpy( psz_href, psz_backup, i_strlen ); psz_href[i_strlen] = '\0'; psz_tmp = psz_href + (i_strlen-1); @@ -694,5 +713,6 @@ static int Demux( demux_t *p_demux ) static int Control( demux_t *p_demux, int i_query, va_list args ) { + VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); return VLC_EGENERIC; }