]> git.sesse.net Git - vlc/blob - modules/demux/m3u.c
Merge back branch 0.8.6-playlist-vlm to trunk.
[vlc] / modules / demux / m3u.c
1 /*****************************************************************************
2  * m3u.c: a meta demux to parse pls, m3u, asx et b4s playlists
3  *****************************************************************************
4  * Copyright (C) 2001-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *          ClĂ©ment Stenac <zorglub@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30
31 #include <vlc/vlc.h>
32 #include <vlc/input.h>
33 #include <vlc_playlist.h>
34
35 /*****************************************************************************
36  * Constants and structures
37  *****************************************************************************/
38 #define MAX_LINE 8192
39
40 #define TYPE_UNKNOWN 0
41 #define TYPE_M3U 1
42 #define TYPE_ASX 2
43 #define TYPE_HTML 3
44 #define TYPE_PLS 4
45 #define TYPE_B4S 5
46 #define TYPE_WMP 6
47 #define TYPE_RTSP 7
48
49 struct demux_sys_t
50 {
51     int i_type;                                   /* playlist type (m3u/asx) */
52 };
53
54 /*****************************************************************************
55  * Local prototypes
56  *****************************************************************************/
57 static int  Activate  ( vlc_object_t * );
58 static void Deactivate( vlc_object_t * );
59 static int  Demux     ( demux_t * );
60 static int  Control   ( demux_t *, int, va_list );
61
62 /*****************************************************************************
63  * Module descriptor
64  *****************************************************************************/
65 vlc_module_begin();
66     set_category( CAT_INPUT );
67     set_subcategory( SUBCAT_INPUT_DEMUX );
68     set_description( _("Playlist metademux") );
69     set_capability( "demux2", 5 );
70     set_callbacks( Activate, Deactivate );
71     add_shortcut( "asx" );
72     add_shortcut( "html" );
73     add_shortcut( "b4s" );
74 vlc_module_end();
75
76 /*****************************************************************************
77  * Activate: initializes m3u demux structures
78  *****************************************************************************/
79 static int Activate( vlc_object_t * p_this )
80 {
81     demux_t *p_demux = (demux_t *)p_this;
82     char    *psz_ext;
83     int     i_type  = TYPE_UNKNOWN;
84     int     i_type2 = TYPE_UNKNOWN;
85
86     p_demux->pf_control = Control;
87     p_demux->pf_demux = Demux;
88
89     /* Check for m3u/asx file extension or if the demux has been forced */
90     psz_ext = strrchr ( p_demux->psz_path, '.' );
91
92     if(( psz_ext && !strcasecmp( psz_ext, ".ram") ) )
93     {
94         i_type = TYPE_M3U;
95     }
96     else if( ( psz_ext && !strcasecmp( psz_ext, ".asx") ) ||
97              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "asx") ) )
98     {
99         i_type = TYPE_ASX;
100     }
101     else if( ( psz_ext && !strcasecmp( psz_ext, ".html") ) ||
102              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "html") ) )
103     {
104         i_type = TYPE_HTML;
105     }
106     else if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) ||
107              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s") ) )
108     {
109         i_type = TYPE_B4S;
110     }
111
112     /* we had no luck looking at the file extension, so we have a look
113      * at the content. This is useful for .asp, .php and similar files
114      * that are actually html. Also useful for some asx files that have
115      * another extension */
116     /* We double check for file != m3u as some asx are just m3u file */
117     if( i_type != TYPE_M3U )
118     {
119         char *p_peek;
120         int i_size = stream_Peek( p_demux->s, (uint8_t **)&p_peek, MAX_LINE );
121         i_size -= sizeof("[Reference]") - 1;
122
123         if( i_size > 0 )
124         {
125             while( i_size &&
126                    strncasecmp(p_peek, "[playlist]", sizeof("[playlist]") - 1)
127                    && strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") - 1 )
128                    && strncasecmp( p_peek, "<html>", sizeof("<html>") - 1 )
129                    && strncasecmp( p_peek, "<asx", sizeof("<asx") - 1 )
130                    && strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") - 1 )
131                    && strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
132             {
133                 p_peek++;
134                 i_size--;
135             }
136             if( !i_size )
137             {
138                 ;
139             }
140             else if( !strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") -1 ) )
141             {
142                 i_type2 = TYPE_PLS;
143             }
144             else if( !strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") -1 ) )
145             {
146                 i_type2 = TYPE_WMP;
147             }
148             else if( !strncasecmp( p_peek, "<html>", sizeof("<html>") -1 ) )
149             {
150                 i_type2 = TYPE_HTML;
151             }
152             else if( !strncasecmp( p_peek, "<asx", sizeof("<asx") -1 ) )
153             {
154                 i_type2 = TYPE_ASX;
155             }
156             else if( !strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") -1 ) )
157             {
158                 i_type2 = TYPE_RTSP;
159             }
160 #if 0
161             else if( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
162             {
163                 i_type2 = TYPE_B4S;
164             }
165 #endif
166         }
167     }
168     if( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN)
169     {
170         return VLC_EGENERIC;
171     }
172     if( i_type  != TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN )
173     {
174         i_type = TYPE_M3U;
175     }
176     else
177     {
178         i_type = i_type2;
179     }
180
181     /* Allocate p_m3u */
182     p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
183     p_demux->p_sys->i_type = i_type;
184     msg_Dbg( p_this, "playlist type: %d - %d", i_type, i_type2 );
185
186     return VLC_SUCCESS;
187 }
188
189 /*****************************************************************************
190  * Deactivate: frees unused data
191  *****************************************************************************/
192 static void Deactivate( vlc_object_t *p_this )
193 {
194     demux_t *p_demux = (demux_t *)p_this;
195     free( p_demux->p_sys );
196 }
197
198 /*****************************************************************************
199  * XMLSpecialChars: Handle the special chars in a XML file.
200  * ***************************************************************************/
201 static void XMLSpecialChars ( char *str )
202 {
203     char *src = str;
204     char *dst = str;
205
206     while( *src )
207     {
208         if( *src == '&' )
209         {
210             /* FIXME:
211              * - should probably accept any sequence, rather than only those
212              *   commonly found in French.
213              * - output may have to be UTF-8 encoded (cannot assume Latin-1)
214              */
215             if( !strncasecmp( src, "&#xe0;", 6 ) ) *dst++ = '\xe0';
216             else if( !strncasecmp( src, "&#xee;", 6 ) ) *dst++ = '\xee';
217             else if( !strncasecmp( src, "&apos;", 6 ) ) *dst++ = '\'';
218             else if( !strncasecmp( src, "&#xe8;", 6 ) ) *dst++ = '\xe8';
219             else if( !strncasecmp( src, "&#xe9;", 6 ) ) *dst++ = '\xe9';
220             else if( !strncasecmp( src, "&#xea;", 6 ) ) *dst++ = '\xea';
221             else
222             {
223                 *dst++ = '?';
224             }
225             src += 6;
226         }
227         else
228         {
229             *dst++ = *src++;
230         }
231     }
232
233     *dst = '\0';
234 }
235
236 /*****************************************************************************
237  * ParseLine: read a "line" from the file and add any entries found
238  * to the playlist. Returns:
239  * 0 if nothing was found
240  * 1 if a URI was found (it is then copied in psz_data)
241  * 2 if a name was found (  "  )
242  *
243  * XXX psz_data has the same length that psz_line so no problem if you don't
244  * expand it
245  *    psz_line is \0 terminated
246  *****************************************************************************/
247 static int ParseLine( demux_t *p_demux, char *psz_line, char *psz_data,
248                       vlc_bool_t *pb_done )
249 {
250     demux_sys_t *p_m3u = p_demux->p_sys;
251     char        *psz_bol, *psz_name;
252
253     psz_bol = psz_line;
254     *pb_done = VLC_FALSE;
255
256     /* Remove unnecessary tabs or spaces at the beginning of line */
257     while( *psz_bol == ' ' || *psz_bol == '\t' ||
258            *psz_bol == '\n' || *psz_bol == '\r' )
259     {
260         psz_bol++;
261     }
262
263     if( p_m3u->i_type == TYPE_M3U )
264     {
265         /* Check for comment line */
266         if( *psz_bol == '#' )
267         {
268             while( *psz_bol &&
269                    strncasecmp( psz_bol, "EXTINF:",
270                                 sizeof("EXTINF:") - 1 ) &&
271                    strncasecmp( psz_bol, "EXTVLCOPT:",
272                                 sizeof("EXTVLCOPT:") - 1 ) ) psz_bol++;
273
274             if( !*psz_bol ) return 0;
275
276             if( !strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
277             {
278                 psz_bol = strchr( psz_bol, ',' );
279                 if ( !psz_bol ) return 0;
280                 psz_bol++;
281
282                 /* From now, we have a name line */
283                 strcpy( psz_data , psz_bol );
284                 return 2;
285             }
286             else
287             {
288                 psz_bol = strchr( psz_bol, ':' );
289                 if ( !psz_bol ) return 0;
290                 psz_bol++;
291
292                 strcpy( psz_data , psz_bol );
293                 return 3;
294             }
295         }
296         /* If we don't have a comment, the line is directly the URI */
297     }
298     else if( p_m3u->i_type == TYPE_PLS )
299     {
300         /* We are dealing with .pls files from shoutcast
301          * We are looking for lines like "File1=http://..." */
302         if( !strncasecmp( psz_bol, "File", sizeof("File") - 1 ) )
303         {
304             psz_bol += sizeof("File") - 1;
305             psz_bol = strchr( psz_bol, '=' );
306             if ( !psz_bol ) return 0;
307             psz_bol++;
308         }
309         else
310         {
311             return 0;
312         }
313     }
314     else if( p_m3u->i_type == TYPE_WMP )
315     {
316         /* We are dealing with some weird WMP stream playlist format
317          * Hurray for idiotic M$. Lines look like: "Ref1=http://..." */
318         if( !strncasecmp( psz_bol, "Ref", sizeof("Ref") - 1 ) )
319         {
320             psz_bol += sizeof("Ref") - 1;
321             psz_bol = strchr( psz_bol, '=' );
322             if ( !psz_bol ) return 0;
323             psz_bol++;
324             if( !strncasecmp( psz_bol, "http://", sizeof("http://") -1 ) )
325             {
326                 psz_bol++;
327                 psz_bol[0] = 'm'; psz_bol[1] = 'm'; psz_bol[2] = 's';
328             }
329         }
330         else
331         {
332             return 0;
333         }
334     }
335     else if( p_m3u->i_type == TYPE_ASX )
336     {
337         /* We are dealing with ASX files.
338          * We are looking for "<ref href=" xml markups that
339          * begins with "mms://", "http://" or "file://" */
340         char *psz_eol;
341
342         while( *psz_bol &&
343                strncasecmp( psz_bol, "ref", sizeof("ref") - 1 ) )
344             psz_bol++;
345
346         if( !*psz_bol ) return 0;
347
348         while( *psz_bol &&
349                strncasecmp( psz_bol, "href", sizeof("href") - 1 ) )
350             psz_bol++;
351
352         if( !*psz_bol ) return 0;
353
354         while( *psz_bol &&
355                strncasecmp( psz_bol, "mms://",
356                             sizeof("mms://") - 1 ) &&
357                strncasecmp( psz_bol, "mmsu://",
358                             sizeof("mmsu://") - 1 ) &&
359                strncasecmp( psz_bol, "mmst://",
360                             sizeof("mmst://") - 1 ) &&
361                strncasecmp( psz_bol, "http://",
362                             sizeof("http://") - 1 ) &&
363                strncasecmp( psz_bol, "file://",
364                             sizeof("file://") - 1 ) )
365             psz_bol++;
366
367         if( !*psz_bol ) return 0;
368
369         psz_eol = strchr( psz_bol, '"');
370         if( !psz_eol )
371           return 0;
372
373         *psz_eol = '\0';
374     }
375     else if( p_m3u->i_type == TYPE_HTML )
376     {
377         /* We are dealing with a html file with embedded
378          * video.  We are looking for "<param name="filename"
379          * value=" html markups that begin with "http://" */
380         char *psz_eol;
381
382         while( *psz_bol &&
383                strncasecmp( psz_bol, "param", sizeof("param") - 1 ) )
384             psz_bol++;
385
386         if( !*psz_bol ) return 0;
387
388         while( *psz_bol &&
389                strncasecmp( psz_bol, "filename", sizeof("filename") - 1 ) )
390             psz_bol++;
391
392         if( !*psz_bol ) return 0;
393
394         while( *psz_bol &&
395                strncasecmp( psz_bol, "http://",
396                             sizeof("http://") - 1 ) )
397             psz_bol++;
398
399         if( !*psz_bol ) return 0;
400
401         psz_eol = strchr( psz_bol, '"');
402         if( !psz_eol )
403           return 0;
404
405         *psz_eol = '\0';
406
407     }
408     else if( p_m3u->i_type == TYPE_B4S )
409     {
410
411         char *psz_eol;
412
413         msg_Dbg( p_demux, "b4s line=%s", psz_line );
414         /* We are dealing with a B4S file from Winamp 3 */
415
416         /* First, search for name *
417          * <Name>Blabla</Name> */
418
419         if( strstr ( psz_bol, "<Name>" ) )
420         {
421             /* We have a name */
422             while ( *psz_bol &&
423                     strncasecmp( psz_bol,"Name",sizeof("Name") -1 ) )
424                 psz_bol++;
425
426             if( !*psz_bol ) return 0;
427
428             psz_bol = psz_bol + 5 ;
429             /* We are now at the beginning of the name */
430
431             if( !psz_bol ) return 0;
432
433
434             psz_eol = strchr(psz_bol, '<' );
435             if( !psz_eol) return 0;
436
437             *psz_eol='\0';
438
439             XMLSpecialChars( psz_bol );
440
441             strcpy( psz_data, psz_bol );
442             return 2;
443         }
444         else if( strstr( psz_bol, "</entry>" ) || strstr( psz_bol, "</Entry>" ))
445         {
446             *pb_done = VLC_TRUE;
447             return 0;
448         }
449
450         /* We are looking for <entry Playstring="blabla"> */
451
452         while( *psz_bol &&
453                strncasecmp( psz_bol,"Playstring",sizeof("Playstring") -1 ) )
454             psz_bol++;
455
456         if( !*psz_bol ) return 0;
457
458         psz_bol = strchr( psz_bol, '=' );
459         if ( !psz_bol ) return 0;
460
461         psz_bol += 2;
462
463         psz_eol= strchr(psz_bol, '"');
464         if( !psz_eol ) return 0;
465
466         *psz_eol= '\0';
467
468         /* Handle the XML special characters */
469         XMLSpecialChars( psz_bol );
470     }
471     else if( p_m3u->i_type == TYPE_RTSP )
472     {
473         /* We are dealing with rtsptext reference files
474          * Ignore anthying that doesn't start with rtsp://..." */
475         if( strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) )
476         /* ignore */ return 0;
477     }
478     else
479     {
480         msg_Warn( p_demux, "unknown file type" );
481         return 0;
482     }
483
484     /* empty line */
485     if ( !*psz_bol ) return 0;
486
487     /*
488      * From now on, we know we've got a meaningful line
489      */
490
491     /* check for a protocol name */
492     /* for URL, we should look for "://"
493      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
494      * we should look for ":"
495      * so we end up looking simply for ":"*/
496     /* PB: on some file systems, ':' are valid characters though*/
497     psz_name = psz_bol;
498     while( *psz_name && *psz_name!=':' )
499     {
500         psz_name++;
501     }
502 #ifdef WIN32
503     if ( *psz_name && ( psz_name == psz_bol + 1 ) )
504     {
505         /* if it is not an URL,
506          * as it is unlikely to be an MRL (PB: if it is ?)
507          * it should be an absolute file name with the drive letter */
508         if ( *(psz_name+1) == '/' )/* "*:/" */
509         {
510             if ( *(psz_name+2) != '/' )/* not "*://" */
511                 while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
512         }
513         else while ( *psz_name ) *psz_name++;/* "*:*"*/
514     }
515 #endif
516
517     /* if the line doesn't specify a protocol name,
518      * check if the line has an absolute or relative path */
519 #ifndef WIN32
520     if( !*psz_name && *psz_bol != '/' )
521          /* If this line doesn't begin with a '/' */
522 #else
523     if( !*psz_name
524             && *psz_bol!='/'
525             && *psz_bol!='\\'
526             && *(psz_bol+1)!=':' )
527          /* if this line doesn't begin with
528           *  "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
529 #endif
530     {
531         /* assume the path is relative to the path of the m3u file. */
532         char *psz_path = strdup( p_demux->psz_path );
533
534 #ifndef WIN32
535         psz_name = strrchr( psz_path, '/' );
536 #else
537         psz_name = strrchr( psz_path, '\\' );
538         if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
539 #endif
540         if( psz_name ) *psz_name = '\0';
541         else *psz_path = '\0';
542 #ifndef WIN32
543         psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
544         sprintf( psz_name, "%s/%s", psz_path, psz_bol );
545 #else
546         if ( *psz_path != '\0' )
547         {
548             psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
549             sprintf( psz_name, "%s\\%s", psz_path, psz_bol );
550         }
551         else psz_name = strdup( psz_bol );
552 #endif
553         free( psz_path );
554     }
555     else
556     {
557         psz_name = strdup( psz_bol );
558     }
559
560     strcpy(psz_data, psz_name ) ;
561
562     free( psz_name );
563
564     if( p_m3u->i_type != TYPE_B4S )
565     {
566        *pb_done = VLC_TRUE;
567     }
568
569     return 1;
570 }
571
572 static void ProcessLine ( demux_t *p_demux, playlist_t *p_playlist,
573                           playlist_item_t *p_parent,
574                           char *psz_line, char **ppsz_uri, char **ppsz_name,
575                           int *pi_options, char ***pppsz_options,
576                           vlc_bool_t b_flush )
577 {
578     char psz_data[MAX_LINE];
579     vlc_bool_t b_done;
580
581     switch( ParseLine( p_demux, psz_line, psz_data, &b_done ) )
582     {
583         case 1:
584             if( *ppsz_uri ) free( *ppsz_uri );
585             *ppsz_uri = strdup( psz_data );
586             break;
587         case 2:
588             if( *ppsz_name ) free( *ppsz_name );
589             *ppsz_name = strdup( psz_data );
590             break;
591         case 3:
592             (*pi_options)++;
593             *pppsz_options = realloc( *pppsz_options,
594                                       sizeof(char *) * *pi_options );
595             (*pppsz_options)[*pi_options - 1] = strdup( psz_data );
596             break;
597         case 0:
598         default:
599             break;
600     }
601
602     if( (b_done || b_flush) && *ppsz_uri )
603     {
604         playlist_item_t *p_item =
605             playlist_ItemNew( p_playlist, *ppsz_uri, *ppsz_name );
606         int i;
607
608         for( i = 0; i < *pi_options; i++ )
609         {
610             playlist_ItemAddOption( p_item, *pppsz_options[i] );
611         }
612
613         playlist_NodeAddItem( p_playlist, p_item,
614                               p_parent->pp_parents[0]->i_view,
615                               p_parent, PLAYLIST_APPEND, PLAYLIST_END );
616
617         /* We need to declare the parents of the node as the
618          * same of the parent's ones */
619         playlist_CopyParents( p_parent, p_item );
620
621         vlc_input_item_CopyOptions( &p_parent->input, &p_item->input );
622
623         if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL;
624         free( *ppsz_uri ); *ppsz_uri  = NULL;
625
626         for( ; *pi_options; (*pi_options)-- )
627         {
628             free( (*pppsz_options)[*pi_options - 1] );
629             if( *pi_options == 1 ) free( *pppsz_options );
630         }
631         *pppsz_options = NULL;
632     }
633 }
634
635 static vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist,
636                             playlist_item_t **pp_item )
637 {
638      vlc_bool_t b_play;
639
640      if( &p_playlist->status.p_item->input ==
641          ((input_thread_t *)p_demux->p_parent)->input.p_item )
642      {
643          msg_Dbg( p_playlist, "starting playlist playback" );
644          *pp_item = p_playlist->status.p_item;
645          b_play = VLC_TRUE;
646      }
647      else
648      {
649          input_item_t *p_current =
650              ((input_thread_t*)p_demux->p_parent)->input.p_item;
651          *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
652
653          if( !*pp_item )
654              msg_Dbg( p_playlist, "unable to find item in playlist");
655
656          b_play = VLC_FALSE;
657      }
658
659      return b_play;
660 }
661
662 /*****************************************************************************
663  * Demux: reads and demuxes data packets
664  *****************************************************************************
665  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
666  *****************************************************************************/
667 static int Demux( demux_t *p_demux )
668 {
669     demux_sys_t   *p_m3u = p_demux->p_sys;
670
671     char          psz_line[MAX_LINE];
672     char          p_buf[MAX_LINE], eol_tok;
673     int           i_size, i_bufpos, i_linepos = 0;
674     vlc_bool_t    b_discard = VLC_FALSE;
675
676     char          *psz_name = NULL;
677     char          *psz_uri  = NULL;
678     int           i_options = 0;
679     char          **ppsz_options = NULL;
680
681     playlist_t      *p_playlist;
682     playlist_item_t *p_parent;
683     vlc_bool_t      b_play;
684
685     p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
686                                                  FIND_ANYWHERE );
687     if( !p_playlist )
688     {
689         msg_Err( p_demux, "can't find playlist" );
690         return -1;
691     }
692
693     b_play = FindItem( p_demux, p_playlist, &p_parent );
694     playlist_ItemToNode( p_playlist, p_parent );
695     p_parent->input.i_type = ITEM_TYPE_PLAYLIST;
696
697     /* Depending on wether we are dealing with an m3u/asf file, the end of
698      * line token will be different */
699     if( p_m3u->i_type == TYPE_ASX || p_m3u->i_type == TYPE_HTML )
700         eol_tok = '>';
701     else
702         eol_tok = '\n';
703
704     while( ( i_size = stream_Read( p_demux->s, p_buf, MAX_LINE ) ) )
705     {
706         i_bufpos = 0;
707
708         while( i_size )
709         {
710             /* Build a line < MAX_LINE */
711             while( p_buf[i_bufpos] != eol_tok && i_size )
712             {
713                 if( i_linepos == MAX_LINE || b_discard == VLC_TRUE )
714                 {
715                     /* line is bigger than MAX_LINE, discard it */
716                     i_linepos = 0;
717                     b_discard = VLC_TRUE;
718                 }
719                 else
720                 {
721                     if ( eol_tok != '\n' || p_buf[i_bufpos] != '\r' )
722                     {
723                         psz_line[i_linepos] = p_buf[i_bufpos];
724                         i_linepos++;
725                     }
726                 }
727
728                 i_size--; i_bufpos++;
729             }
730
731             /* Check if we need more data */
732             if( !i_size ) continue;
733
734             i_size--; i_bufpos++;
735             b_discard = VLC_FALSE;
736
737             /* Check for empty line */
738             if( !i_linepos ) continue;
739
740             psz_line[i_linepos] = '\0';
741             i_linepos = 0;
742
743             ProcessLine( p_demux, p_playlist, p_parent,
744                          psz_line, &psz_uri, &psz_name,
745                          &i_options, &ppsz_options, VLC_FALSE );
746         }
747     }
748
749     if( i_linepos && b_discard != VLC_TRUE && eol_tok == '\n' )
750     {
751         psz_line[i_linepos] = '\0';
752
753         ProcessLine( p_demux, p_playlist, p_parent,
754                      psz_line, &psz_uri, &psz_name,
755                      &i_options, &ppsz_options, VLC_TRUE );
756     }
757
758     if( psz_uri ) free( psz_uri );
759     if( psz_name ) free( psz_name );
760     for( ; i_options; i_options-- )
761     {
762         free( ppsz_options[i_options - 1] );
763         if( i_options == 1 ) free( ppsz_options );
764     }
765
766     /* Go back and play the playlist */
767     if( b_play )
768     {
769         playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
770                           p_playlist->status.i_view,
771                           p_playlist->status.p_item, NULL );
772     }
773
774     vlc_object_release( p_playlist );
775
776     return 0;
777 }
778
779 static int Control( demux_t *p_demux, int i_query, va_list args )
780 {
781     return VLC_EGENERIC;
782 }