]> git.sesse.net Git - vlc/blob - modules/demux/playlist/qtl.c
m3u8: validate UTF-8 input
[vlc] / modules / demux / playlist / qtl.c
1 /*****************************************************************************
2  * qtl.c: QuickTime Media Link Importer
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*
25 See
26 http://developer.apple.com/documentation/QuickTime/QT6WhatsNew/Chap1/chapter_1_section_54.html
27 and
28 http://developer.apple.com/documentation/QuickTime/WhatsNewQT5/QT5NewChapt1/chapter_1_section_39.html
29
30 autoplay - true/false
31 controller - true/false
32 fullscreen - normal/double/half/current/full
33 href - url
34 kioskmode - true/false
35 loop - true/false/palindrome
36 movieid - integer
37 moviename - string
38 playeveryframe - true/false
39 qtnext - url
40 quitwhendone - true/false
41 src - url (required)
42 type - mime type
43 volume - 0 (mute) - 100 (max)
44
45 */
46
47 /*****************************************************************************
48  * Preamble
49  *****************************************************************************/
50
51 #ifdef HAVE_CONFIG_H
52 # include "config.h"
53 #endif
54
55 #include <vlc_common.h>
56 #include <vlc_demux.h>
57
58 #include "playlist.h"
59 #include <vlc_xml.h>
60
61 typedef enum { FULLSCREEN_NORMAL,
62                FULLSCREEN_DOUBLE,
63                FULLSCREEN_HALF,
64                FULLSCREEN_CURRENT,
65                FULLSCREEN_FULL } qtl_fullscreen_t;
66 const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
67 typedef enum { LOOP_TRUE,
68                LOOP_FALSE,
69                LOOP_PALINDROME } qtl_loop_t;
70 const char* ppsz_loop[] = { "true", "false", "palindrome" };
71
72 /*****************************************************************************
73  * Local prototypes
74  *****************************************************************************/
75 static int Demux( demux_t *p_demux);
76 static int Control( demux_t *p_demux, int i_query, va_list args );
77
78 /*****************************************************************************
79  * Import_QTL: main import function
80  *****************************************************************************/
81 int Import_QTL( vlc_object_t *p_this )
82 {
83     demux_t *p_demux = (demux_t *)p_this;
84
85     if( !demux_IsPathExtension( p_demux, ".qtl" ) )
86         return VLC_EGENERIC;
87
88     p_demux->pf_demux = Demux;
89     p_demux->pf_control = Control;
90     msg_Dbg( p_demux, "using QuickTime Media Link reader" );
91
92     return VLC_SUCCESS;
93 }
94
95 /*****************************************************************************
96  * Deactivate: frees unused data
97  *****************************************************************************/
98 void Close_QTL( vlc_object_t *p_this )
99 {
100     (void)p_this;
101 }
102
103 static int Demux( demux_t *p_demux )
104 {
105     xml_reader_t *p_xml_reader;
106     const char *node;
107     input_item_t *p_input;
108     int i_ret = -1;
109
110     /* List of all possible attributes. The only required one is "src" */
111     bool b_autoplay = false;
112     bool b_controler = true;
113     qtl_fullscreen_t fullscreen = false;
114     char *psz_href = NULL;
115     bool b_kioskmode = false;
116     qtl_loop_t loop = LOOP_FALSE;
117     int i_movieid = -1;
118     char *psz_moviename = NULL;
119     bool b_playeveryframe = false;
120     char *psz_qtnext = NULL;
121     bool b_quitwhendone = false;
122     char *psz_src = NULL;
123     char *psz_mimetype = NULL;
124     int i_volume = 100;
125
126     input_item_t *p_current_input = GetCurrentItem(p_demux);
127
128     p_xml_reader = xml_ReaderCreate( p_demux, p_demux->s );
129     if( !p_xml_reader )
130         goto error;
131
132     /* check root node */
133     if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
134      || strcmp( node, "embed" ) )
135     {
136         msg_Err( p_demux, "invalid root node <%s>", node );
137
138         /* second line has <?quicktime tag ... so we try to skip it */
139         msg_Dbg( p_demux, "trying to read one more node" );
140         if( xml_ReaderNextNode( p_xml_reader, &node ) != XML_READER_STARTELEM
141          || strcmp( node, "embed" ) )
142         {
143             msg_Err( p_demux, "invalid root node <%s>", node );
144             goto error;
145         }
146     }
147
148     const char *attrname, *value;
149     while( (attrname = xml_ReaderNextAttr( p_xml_reader, &value )) != NULL )
150     {
151         if( !strcmp( attrname, "autoplay" ) )
152             b_autoplay = !strcmp( value, "true" );
153         else if( !strcmp( attrname, "controler" ) )
154             b_controler = !strcmp( attrname, "false" );
155         else if( !strcmp( attrname, "fullscreen" ) )
156         {
157             if( !strcmp( value, "double" ) )
158                 fullscreen = FULLSCREEN_DOUBLE;
159             else if( !strcmp( value, "half" ) )
160                 fullscreen = FULLSCREEN_HALF;
161             else if( !strcmp( value, "current" ) )
162                 fullscreen = FULLSCREEN_CURRENT;
163             else if( !strcmp( value, "full" ) )
164                 fullscreen = FULLSCREEN_FULL;
165             else
166                 fullscreen = FULLSCREEN_NORMAL;
167         }
168         else if( !strcmp( attrname, "href" ) )
169         {
170             free( psz_href );
171             psz_href = strdup( value );
172         }
173         else if( !strcmp( attrname, "kioskmode" ) )
174             b_kioskmode = !strcmp( value, "true" );
175         else if( !strcmp( attrname, "loop" ) )
176         {
177             if( !strcmp( value, "true" ) )
178                 loop = LOOP_TRUE;
179             else if( !strcmp( value, "palindrome" ) )
180                 loop = LOOP_PALINDROME;
181             else
182                 loop = LOOP_FALSE;
183         }
184         else if( !strcmp( attrname, "movieid" ) )
185             i_movieid = atoi( value );
186         else if( !strcmp( attrname, "moviename" ) )
187         {
188             free( psz_moviename );
189             psz_moviename = strdup( value );
190         }
191         else if( !strcmp( attrname, "playeveryframe" ) )
192             b_playeveryframe = !strcmp( value, "true" );
193         else if( !strcmp( attrname, "qtnext" ) )
194         {
195             free( psz_qtnext );
196             psz_qtnext = strdup( value );
197         }
198         else if( !strcmp( attrname, "quitwhendone" ) )
199             b_quitwhendone = !strcmp( value, "true" );
200         else if( !strcmp( attrname, "src" ) )
201         {
202             free( psz_src );
203             psz_src = strdup( value );
204         }
205         else if( !strcmp( attrname, "mimetype" ) )
206         {
207             free( psz_mimetype );
208             psz_mimetype = strdup( value );
209         }
210         else if( !strcmp( attrname, "volume" ) )
211             i_volume = atoi( value );
212         else
213             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
214                      attrname, value );
215     }
216
217     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
218              b_autoplay ? "true": "false" );
219     msg_Dbg( p_demux, "controler: %s (unused by VLC)",
220              b_controler ? "true": "false" );
221     msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
222              ppsz_fullscreen[fullscreen] );
223     msg_Dbg( p_demux, "href: %s", psz_href );
224     msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
225              b_kioskmode ? "true":"false" );
226     msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
227     msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
228     msg_Dbg( p_demux, "moviename: %s", psz_moviename );
229     msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
230              b_playeveryframe ? "true":"false" );
231     msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
232     msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
233              b_quitwhendone ? "true":"false" );
234     msg_Dbg( p_demux, "src: %s", psz_src );
235     msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
236     msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
237
238
239     if( !psz_src )
240     {
241         msg_Err( p_demux, "Mandatory attribute 'src' not found" );
242     }
243     else
244     {
245         input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
246         p_input = input_item_New( psz_src, psz_moviename );
247 #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
248                     p_input, "QuickTime Media Link", type, "%s", field ) ; }
249         SADD_INFO( "href", psz_href );
250         SADD_INFO( _("Mime"), psz_mimetype );
251         input_item_node_AppendItem( p_subitems, p_input );
252         vlc_gc_decref( p_input );
253         if( psz_qtnext )
254         {
255             p_input = input_item_New( psz_qtnext, NULL );
256             input_item_node_AppendItem( p_subitems, p_input );
257             vlc_gc_decref( p_input );
258         }
259         input_item_node_PostAndDelete( p_subitems );
260     }
261
262     i_ret = 0; /* Needed for correct operation of go back */
263
264 error:
265     if( p_xml_reader )
266         xml_ReaderDelete( p_xml_reader );
267
268     vlc_gc_decref(p_current_input);
269
270     free( psz_href );
271     free( psz_moviename );
272     free( psz_qtnext );
273     free( psz_src );
274     free( psz_mimetype );
275     return i_ret;
276 }
277
278 static int Control( demux_t *p_demux, int i_query, va_list args )
279 {
280     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
281     return VLC_EGENERIC;
282 }