Commit d387c508 authored by Boris Dorès's avatar Boris Dorès

- support for Windows style file names for relative paths

- when eol_tok is '\n', use last line even if eol_tok isn't present
parent e407c244
......@@ -2,7 +2,7 @@
* m3u.c: a meta demux to parse m3u and asx playlists
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: m3u.c,v 1.9 2002/11/26 18:58:33 sigmunau Exp $
* $Id: m3u.c,v 1.10 2002/12/14 01:05:53 babal Exp $
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
* Gildas Bazin <gbazin@netcourrier.com>
......@@ -166,72 +166,12 @@ static void Deactivate( vlc_object_t *p_this )
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
static int Demux ( input_thread_t *p_input )
static void ProcessLine ( input_thread_t *p_input , demux_sys_t *p_m3u
, playlist_t *p_playlist , char psz_line[MAX_LINE] )
{
data_packet_t *p_data;
char *p_buf, psz_line[MAX_LINE], *psz_bol, *psz_name, eol_tok;
int i_size, i_bufpos, i_linepos = 0;
playlist_t *p_playlist;
vlc_bool_t b_discard = VLC_FALSE;
demux_sys_t *p_m3u = (demux_sys_t *)p_input->p_demux_data;
p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
msg_Err( p_input, "can't find playlist" );
return -1;
}
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
/* Depending on wether we are dealing with an m3u/asf file, the end of
* line token will be different */
if( p_m3u->i_type == TYPE_ASX || p_m3u->i_type == TYPE_HTML )
eol_tok = '>';
else
eol_tok = '\n';
while( ( i_size = input_SplitBuffer( p_input, &p_data, MAX_LINE ) ) > 0 )
{
i_bufpos = 0; p_buf = p_data->p_payload_start;
while( i_size )
{
/* Build a line < MAX_LINE */
while( p_buf[i_bufpos] != eol_tok && i_size )
{
if( i_linepos == MAX_LINE || b_discard == VLC_TRUE )
{
/* line is bigger than MAX_LINE, discard it */
i_linepos = 0;
b_discard = VLC_TRUE;
}
else
{
if ( eol_tok != '\n' || p_buf[i_bufpos] != '\r' )
{
psz_line[i_linepos] = p_buf[i_bufpos];
i_linepos++;
}
}
i_size--; i_bufpos++;
}
char *psz_bol, *psz_name;
/* Check if we need more data */
if( !i_size ) continue;
i_size--; i_bufpos++;
b_discard = VLC_FALSE;
/* Check for empty line */
if( !i_linepos ) continue;
psz_line[i_linepos] = '\0';
psz_bol = psz_line;
i_linepos = 0;
/* Remove unnecessary tabs or spaces at the beginning of line */
while( *psz_bol == ' ' || *psz_bol == '\t' ||
......@@ -243,7 +183,7 @@ static int Demux ( input_thread_t *p_input )
/* Check for comment line */
if( *psz_bol == '#' )
/*line is comment or extended info, ignored for now */
continue;
return;
}
else if ( p_m3u->i_type == TYPE_ASX )
{
......@@ -256,13 +196,13 @@ static int Demux ( input_thread_t *p_input )
strncasecmp( psz_bol, "ref", sizeof("ref") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
while( *psz_bol &&
strncasecmp( psz_bol, "href", sizeof("href") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
while( *psz_bol &&
strncasecmp( psz_bol, "mms://",
......@@ -273,11 +213,11 @@ static int Demux ( input_thread_t *p_input )
sizeof("file://") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
psz_eol = strchr( psz_bol, '"');
if( !psz_eol )
continue;
return;
*psz_eol = '\0';
}
......@@ -292,24 +232,24 @@ static int Demux ( input_thread_t *p_input )
strncasecmp( psz_bol, "param", sizeof("param") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
while( *psz_bol &&
strncasecmp( psz_bol, "filename", sizeof("filename") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
while( *psz_bol &&
strncasecmp( psz_bol, "http://",
sizeof("http://") - 1 ) )
psz_bol++;
if( !*psz_bol ) continue;
if( !*psz_bol ) return;
psz_eol = strchr( psz_bol, '"');
if( !psz_eol )
continue;
return;
*psz_eol = '\0';
......@@ -325,18 +265,38 @@ static int Demux ( input_thread_t *p_input )
{
psz_name++;
}
#ifndef WIN32
if( !*psz_name && *psz_bol != '/' )
#else
if( !*psz_name && (strlen(psz_bol) < 2 ||
( *(psz_bol+1) != ':' &&
strncmp( psz_bol, "\\\\", 2 ) ) ) )
#endif
{
/* the line doesn't specify a protocol name.
* If this line doesn't begin with a '/' then assume the path
* is relative to the path of the m3u file. */
char *psz_path = strdup( p_input->psz_name );
#ifndef WIN32
psz_name = strrchr( psz_path, '/' );
#else
psz_name = strrchr( psz_path, '\\' );
if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
#endif
if( psz_name ) *psz_name = '\0';
else *psz_path = '\0';
#ifndef WIN32
psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
sprintf( psz_name, "%s/%s", psz_path, psz_bol );
#else
if ( *psz_path != '\0' )
{
psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
sprintf( psz_name, "%s\\%s", psz_path, psz_bol );
}
else psz_name = strdup( psz_bol );
#endif
free( psz_path );
}
else
......@@ -348,13 +308,86 @@ static int Demux ( input_thread_t *p_input )
PLAYLIST_APPEND, PLAYLIST_END );
free( psz_name );
}
continue;
static int Demux ( input_thread_t *p_input )
{
data_packet_t *p_data;
char *p_buf, psz_line[MAX_LINE], eol_tok;
int i_size, i_bufpos, i_linepos = 0;
playlist_t *p_playlist;
vlc_bool_t b_discard = VLC_FALSE;
demux_sys_t *p_m3u = (demux_sys_t *)p_input->p_demux_data;
p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
msg_Err( p_input, "can't find playlist" );
return -1;
}
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
/* Depending on wether we are dealing with an m3u/asf file, the end of
* line token will be different */
if( p_m3u->i_type == TYPE_ASX || p_m3u->i_type == TYPE_HTML )
eol_tok = '>';
else
eol_tok = '\n';
while( ( i_size = input_SplitBuffer( p_input, &p_data, MAX_LINE ) ) > 0 )
{
i_bufpos = 0; p_buf = p_data->p_payload_start;
while( i_size )
{
/* Build a line < MAX_LINE */
while( p_buf[i_bufpos] != eol_tok && i_size )
{
if( i_linepos == MAX_LINE || b_discard == VLC_TRUE )
{
/* line is bigger than MAX_LINE, discard it */
i_linepos = 0;
b_discard = VLC_TRUE;
}
else
{
if ( eol_tok != '\n' || p_buf[i_bufpos] != '\r' )
{
psz_line[i_linepos] = p_buf[i_bufpos];
i_linepos++;
}
}
i_size--; i_bufpos++;
}
/* Check if we need more data */
if( !i_size ) continue;
i_size--; i_bufpos++;
b_discard = VLC_FALSE;
/* Check for empty line */
if( !i_linepos ) continue;
psz_line[i_linepos] = '\0';
i_linepos = 0;
ProcessLine ( p_input, p_m3u , p_playlist , psz_line );
}
input_DeletePacket( p_input->p_method_data, p_data );
}
if ( i_linepos && b_discard != VLC_TRUE && eol_tok == '\n' )
{
psz_line[i_linepos] = '\0';
i_linepos = 0;
ProcessLine ( p_input, p_m3u , p_playlist , psz_line );
}
vlc_object_release( p_playlist );
return 0;
......
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