]> git.sesse.net Git - vlc/blob - modules/demux/playlist/old.c
* Stringreview !!!
[vlc] / modules / demux / playlist / old.c
1 /*****************************************************************************
2  * old.c : Old playlist format import
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: old.c,v 1.2 2004/01/25 20:05:29 hartman Exp $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31
32 #include <errno.h>                                                 /* ENOMEM */
33
34 #define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 int Import_Old ( vlc_object_t * );
40 static int Demux( demux_t *p_demux);
41 static int Control( demux_t *p_demux, int i_query, va_list args );
42
43 /*****************************************************************************
44  * Import_Old : main import function
45  *****************************************************************************/
46 int Import_Old( vlc_object_t *p_this )
47 {
48     demux_t *p_demux = (demux_t *)p_this;
49     uint8_t *p_peek;
50
51     if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 )
52     {
53         msg_Err( p_demux, "cannot peek" );
54         return VLC_EGENERIC;
55     }
56
57     if( strncmp( p_peek, PLAYLIST_FILE_HEADER , 31 ) )
58     {
59         msg_Warn(p_demux, "old import module discarded: invalid file");
60         return VLC_EGENERIC;
61     }
62     msg_Dbg( p_demux, "found valid old playlist file");
63
64     p_demux->pf_control = Control;
65     p_demux->pf_demux = Demux;
66
67     return VLC_SUCCESS;
68 }
69
70 static int Demux( demux_t *p_demux)
71 {
72     char *psz_line;
73     /* Attach playlist and start reading data */
74     playlist_t *p_playlist;
75
76     p_playlist = (playlist_t*)vlc_object_find( p_demux,
77                          VLC_OBJECT_PLAYLIST, FIND_PARENT );
78     if( !p_playlist )
79     {
80         msg_Err( p_demux, "cannot attach playlist" );
81         return VLC_EGENERIC;
82     }
83
84     p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
85     while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
86     {
87         if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
88             ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
89         {
90             continue;
91         }
92         /* Remove end of line */
93         if( psz_line[strlen(psz_line) -1 ] == '\n' ||
94             psz_line[strlen(psz_line) -1 ] == '\r' )
95         {
96             psz_line[ strlen(psz_line) -1 ] = (char)0;
97             if( psz_line[strlen(psz_line) - 1 ] == '\r' )
98                 psz_line[strlen(psz_line) - 1 ] = (char)0;
99         }
100         playlist_Add( p_playlist, psz_line, psz_line, PLAYLIST_APPEND,
101                       PLAYLIST_END );
102
103         free( psz_line );
104     }
105
106     p_demux->b_die = VLC_TRUE;
107     vlc_object_release( p_playlist );
108     return VLC_SUCCESS;
109 }
110
111 static int Control( demux_t *p_demux, int i_query, va_list args )
112 {
113     return VLC_EGENERIC;
114 }