]> git.sesse.net Git - vlc/blob - modules/demux/playlist/asx.c
06810f66b2cc651cc622831e0b0598d5166ef4ca
[vlc] / modules / demux / playlist / asx.c
1 /*****************************************************************************
2  * asx.c : ASX playlist format import
3  *****************************************************************************
4  * Copyright (C) 2005-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <hartman at 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 /* See also: http://msdn.microsoft.com/library/en-us/wmplay10/mmp_sdk/windowsmediametafilereference.asp
25  */
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_common.h>
35 #include <vlc_demux.h>
36
37 #include <ctype.h>
38 #include <vlc_charset.h>
39 #include "playlist.h"
40 #include <vlc_meta.h>
41
42 struct demux_sys_t
43 {
44     char    *psz_prefix;
45     char    *psz_data;
46     int64_t i_data_len;
47     bool b_utf8;
48     bool b_skip_ads;
49 };
50
51 /*****************************************************************************
52  * Local prototypes
53  *****************************************************************************/
54 static int Demux( demux_t *p_demux);
55 static int Control( demux_t *p_demux, int i_query, va_list args );
56
57 static int StoreString( demux_t *p_demux, char **ppsz_string,
58                         const char *psz_source_start,
59                         const char *psz_source_end )
60 {
61     demux_sys_t *p_sys = p_demux->p_sys;
62     unsigned len = psz_source_end - psz_source_start;
63
64     free( *ppsz_string );
65
66     char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1);
67     if (buf == NULL)
68         return VLC_ENOMEM;
69
70     if( p_sys->b_utf8 )
71     {
72         memcpy (buf, psz_source_start, len);
73         (*ppsz_string)[len] = '\0';
74         EnsureUTF8 (*ppsz_string);
75     }
76     else
77     {
78         /* Latin-1 -> UTF-8 */
79         for (unsigned i = 0; i < len; i++)
80         {
81             unsigned char c = psz_source_start[i];
82             if (c & 0x80)
83             {
84                 *buf++ = 0xc0 | (c >> 6);
85                 *buf++ = 0x80 | (c & 0x3f);
86             }
87             else
88                 *buf++ = c;
89         }
90         *buf++ = '\0';
91
92         buf = realloc (*ppsz_string, buf - *ppsz_string);
93         if( buf )
94             *ppsz_string = buf;
95     }
96     return VLC_SUCCESS;
97 }
98
99 static char *SkipBlanks(char *s, size_t i_strlen )
100 {
101     while( i_strlen > 0 ) {
102         switch( *s )
103         {
104             case ' ':
105             case '\t':
106             case '\r':
107             case '\n':
108                 --i_strlen;
109                 ++s;
110                 break;
111             default:
112                 i_strlen = 0;
113         }
114     }
115     return s;
116 }
117
118 static int ParseTime(char *s, size_t i_strlen)
119 {
120     // need to parse hour:minutes:sec.fraction string
121     int result = 0;
122     int val;
123     const char *end = s + i_strlen;
124     // skip leading spaces if any
125     s = SkipBlanks(s, i_strlen);
126
127     val = 0;
128     while( (s < end) && isdigit(*s) )
129     {
130         int newval = val*10 + (*s - '0');
131         if( newval < val )
132         {
133             // overflow
134             val = 0;
135             break;
136         }
137         val = newval;
138         ++s;
139     }
140     result = val;
141     s = SkipBlanks(s, end-s);
142     if( *s == ':' )
143     {
144         ++s;
145         s = SkipBlanks(s, end-s);
146         result = result * 60;
147         val = 0;
148         while( (s < end) && isdigit(*s) )
149         {
150             int newval = val*10 + (*s - '0');
151             if( newval < val )
152             {
153                 // overflow
154                 val = 0;
155                 break;
156             }
157             val = newval;
158             ++s;
159         }
160         result += val;
161         s = SkipBlanks(s, end-s);
162         if( *s == ':' )
163         {
164             ++s;
165             s = SkipBlanks(s, end-s);
166             result = result * 60;
167             val = 0;
168             while( (s < end) && isdigit(*s) )
169             {
170                 int newval = val*10 + (*s - '0');
171                 if( newval < val )
172                 {
173                     // overflow
174                     val = 0;
175                     break;
176                 }
177                 val = newval;
178                 ++s;
179             }
180             result += val;
181             // TODO: one day, we may need to parse fraction for sub-second resolution
182         }
183     }
184     return result;
185 }
186
187 /*****************************************************************************
188  * Import_ASX: main import function
189  *****************************************************************************/
190 int Import_ASX( vlc_object_t *p_this )
191 {
192     demux_t *p_demux = (demux_t *)p_this;
193     const uint8_t *p_peek;
194     CHECK_PEEK( p_peek, 10 );
195
196     // skip over possible leading empty lines and empty spaces
197     p_peek = (uint8_t *)SkipBlanks((char *)p_peek, 6);
198
199     if( POKE( p_peek, "<asx", 4 ) || demux_IsPathExtension( p_demux, ".asx" ) ||
200         demux_IsPathExtension( p_demux, ".wax" ) || demux_IsPathExtension( p_demux, ".wvx" ) ||
201         demux_IsForced( p_demux, "asx-open" ) )
202     {
203         ;
204     }
205     else
206         return VLC_EGENERIC;
207
208     STANDARD_DEMUX_INIT_MSG( "found valid ASX playlist" );
209     p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
210     p_demux->p_sys->psz_data = NULL;
211     p_demux->p_sys->i_data_len = -1;
212     p_demux->p_sys->b_utf8 = false;
213     p_demux->p_sys->b_skip_ads =
214         var_InheritInteger( p_demux, "playlist-skip-ads" );
215
216     return VLC_SUCCESS;
217 }
218
219 /*****************************************************************************
220  * Deactivate: frees unused data
221  *****************************************************************************/
222 void Close_ASX( vlc_object_t *p_this )
223 {
224     demux_t *p_demux = (demux_t *)p_this;
225     demux_sys_t *p_sys = p_demux->p_sys;
226
227     free( p_sys->psz_prefix );
228     free( p_sys->psz_data );
229     free( p_sys );
230 }
231
232 static int Demux( demux_t *p_demux )
233 {
234     demux_sys_t *p_sys = p_demux->p_sys;
235     char        *psz_parse = NULL;
236     char        *psz_backup = NULL;
237     bool  b_entry = false;
238     input_item_t *p_current_input = GetCurrentItem(p_demux);
239
240     /* init txt */
241     if( p_sys->i_data_len < 0 )
242     {
243         int64_t i_pos = 0;
244         p_sys->i_data_len = stream_Size( p_demux->s ) + 1; /* This is a cheat to prevent unnecessary realloc */
245         if( p_sys->i_data_len <= 0 || p_sys->i_data_len > 16384 ) p_sys->i_data_len = 1024;
246         p_sys->psz_data = xmalloc( p_sys->i_data_len +1);
247
248         /* load the complete file */
249         for( ;; )
250         {
251             int i_read = stream_Read( p_demux->s, &p_sys->psz_data[i_pos], p_sys->i_data_len - i_pos );
252             p_sys->psz_data[i_pos + i_read] = '\0';
253
254             if( i_read < p_sys->i_data_len - i_pos ) break; /* Done */
255
256             i_pos += i_read;
257             p_sys->i_data_len <<= 1 ;
258             p_sys->psz_data = xrealloc( p_sys->psz_data,
259                                    p_sys->i_data_len * sizeof( char * ) + 1 );
260         }
261         if( p_sys->i_data_len <= 0 ) return -1;
262     }
263
264     psz_parse = p_sys->psz_data;
265     /* Find first element */
266     if( ( psz_parse = strcasestr( psz_parse, "<ASX" ) ) )
267     {
268         /* ASX element */
269         char *psz_string = NULL;
270         int i_strlen = 0;
271
272         char *psz_base_asx = NULL;
273         char *psz_title_asx = NULL;
274         char *psz_artist_asx = NULL;
275         char *psz_copyright_asx = NULL;
276         char *psz_moreinfo_asx = NULL;
277         char *psz_abstract_asx = NULL;
278
279         char *psz_base_entry = NULL;
280         char *psz_title_entry = NULL;
281         char *psz_artist_entry = NULL;
282         char *psz_copyright_entry = NULL;
283         char *psz_moreinfo_entry = NULL;
284         char *psz_abstract_entry = NULL;
285         int i_entry_count = 0;
286         bool b_skip_entry = false;
287
288         char *psz_href = NULL;
289         int i_starttime = 0;
290         int i_duration = 0;
291
292         psz_parse = strcasestr( psz_parse, ">" );
293
294         /* counter for single ad item */
295         input_item_t *uniq_entry_ad_backup = NULL;
296         int i_inserted_entries = 0;
297
298         while( psz_parse && ( psz_parse = strcasestr( psz_parse, "<" ) ) )
299         {
300             if( !strncasecmp( psz_parse, "<!--", 4 ) )
301             {
302                 /* this is a comment */
303                 if( ( psz_parse = strcasestr( psz_parse, "-->" ) ) )
304                     psz_parse+=3;
305                 else continue;
306             }
307             else if( !strncasecmp( psz_parse, "<PARAM ", 7 ) )
308             {
309                 bool b_encoding_flag = false;
310                 psz_parse = SkipBlanks(psz_parse+7, (unsigned)-1);
311                 if( !strncasecmp( psz_parse, "name", 4 ) )
312                 {
313                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
314                     {
315                         psz_backup = ++psz_parse;
316                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
317                         {
318                             i_strlen = psz_parse-psz_backup;
319                             if( i_strlen < 1 ) continue;
320                             msg_Dbg( p_demux, "param name strlen: %d", i_strlen);
321                             psz_string = xmalloc( i_strlen + 1);
322                             memcpy( psz_string, psz_backup, i_strlen );
323                             psz_string[i_strlen] = '\0';
324                             msg_Dbg( p_demux, "param name: %s", psz_string);
325                             b_encoding_flag = !strcasecmp( psz_string, "encoding" );
326                             free( psz_string );
327                         }
328                         else continue;
329                     }
330                     else continue;
331                 }
332                 psz_parse++;
333                 if( !strncasecmp( psz_parse, "value", 5 ) )
334                 {
335                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
336                     {
337                         psz_backup = ++psz_parse;
338                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
339                         {
340                             i_strlen = psz_parse-psz_backup;
341                             if( i_strlen < 1 ) continue;
342                             msg_Dbg( p_demux, "param value strlen: %d", i_strlen);
343                             psz_string = xmalloc( i_strlen +1);
344                             memcpy( psz_string, psz_backup, i_strlen );
345                             psz_string[i_strlen] = '\0';
346                             msg_Dbg( p_demux, "param value: %s", psz_string);
347                             if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = true;
348                             free( psz_string );
349                         }
350                         else continue;
351                     }
352                     else continue;
353                 }
354                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
355                     psz_parse += 2;
356                 else continue;
357             }
358             else if( !strncasecmp( psz_parse, "<BANNER", 7 ) )
359             {
360                 /* We skip this element */
361                 if( ( psz_parse = strcasestr( psz_parse, "</BANNER>" ) ) )
362                     psz_parse += 9;
363                 else continue;
364             }
365             else if( !strncasecmp( psz_parse, "<PREVIEWDURATION", 16 ) ||
366                      !strncasecmp( psz_parse, "<LOGURL", 7 ) ||
367                      !strncasecmp( psz_parse, "<Skin", 5 ) )
368             {
369                 /* We skip this element */
370                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
371                     psz_parse += 2;
372                 else continue;
373             }
374             else if( !strncasecmp( psz_parse, "<BASE ", 6 ) )
375             {
376                 psz_parse = SkipBlanks(psz_parse+6, (unsigned)-1);
377                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
378                 {
379                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
380                     {
381                         psz_backup = ++psz_parse;
382                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
383                         {
384                             StoreString( p_demux, (b_entry ? &psz_base_entry : &psz_base_asx), psz_backup, psz_parse );
385                         }
386                         else continue;
387                     }
388                     else continue;
389                 }
390                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
391                     psz_parse += 2;
392                 else continue;
393             }
394             else if( !strncasecmp( psz_parse, "<TITLE>", 7 ) )
395             {
396                 psz_backup = psz_parse+=7;
397                 if( ( psz_parse = strcasestr( psz_parse, "</TITLE>" ) ) )
398                 {
399                     StoreString( p_demux, (b_entry ? &psz_title_entry : &psz_title_asx), psz_backup, psz_parse );
400                     psz_parse += 8;
401                 }
402                 else continue;
403             }
404             else if( !strncasecmp( psz_parse, "<Author>", 8 ) )
405             {
406                 psz_backup = psz_parse+=8;
407                 if( ( psz_parse = strcasestr( psz_parse, "</Author>" ) ) )
408                 {
409                     StoreString( p_demux, (b_entry ? &psz_artist_entry : &psz_artist_asx), psz_backup, psz_parse );
410                     psz_parse += 9;
411                 }
412                 else continue;
413             }
414             else if( !strncasecmp( psz_parse, "<Copyright", 10 ) )
415             {
416                 psz_backup = psz_parse+=11;
417                 if( ( psz_parse = strcasestr( psz_parse, "</Copyright>" ) ) )
418                 {
419                     StoreString( p_demux, (b_entry ? &psz_copyright_entry : &psz_copyright_asx), psz_backup, psz_parse );
420                     psz_parse += 12;
421                 }
422                 else continue;
423             }
424             else if( !strncasecmp( psz_parse, "<MoreInfo ", 10 ) )
425             {
426                 psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1);
427                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
428                 {
429                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
430                     {
431                         psz_backup = ++psz_parse;
432                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
433                         {
434                             StoreString( p_demux, (b_entry ? &psz_moreinfo_entry : &psz_moreinfo_asx), psz_backup, psz_parse );
435                         }
436                         else continue;
437                     }
438                     else continue;
439                 }
440                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
441                     psz_parse += 2;
442                 else if( ( psz_parse = strcasestr( psz_parse, "</MoreInfo>") ) )
443                     psz_parse += 11;
444                 else continue;
445             }
446             else if( !strncasecmp( psz_parse, "<ABSTRACT>", 10 ) )
447             {
448                 psz_backup = psz_parse+=10;
449                 if( ( psz_parse = strcasestr( psz_parse, "</ABSTRACT>" ) ) )
450                 {
451                     StoreString( p_demux, (b_entry ? &psz_abstract_entry : &psz_abstract_asx), psz_backup, psz_parse );
452                     psz_parse += 11;
453                 }
454                 else continue;
455             }
456             else if( !strncasecmp( psz_parse, "<EntryRef ", 10 ) )
457             {
458                 psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1);
459                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
460                 {
461                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
462                     {
463                         psz_backup = ++psz_parse;
464                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
465                         {
466                             i_strlen = psz_parse-psz_backup;
467                             if( i_strlen < 1 ) continue;
468                             psz_string = xmalloc( i_strlen +1);
469                             memcpy( psz_string, psz_backup, i_strlen );
470                             psz_string[i_strlen] = '\0';
471                             input_item_t *p_input;
472                             p_input = input_item_New( p_demux, psz_string, psz_title_asx );
473                             input_item_CopyOptions( p_current_input, p_input );
474                             input_item_AddSubItem( p_current_input, p_input );
475                             vlc_gc_decref( p_input );
476                             free( psz_string );
477                         }
478                         else continue;
479                     }
480                     else continue;
481                 }
482                 if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) )
483                     psz_parse += 2;
484                 else continue;
485             }
486             else if( !strncasecmp( psz_parse, "</Entry>", 8 ) )
487             {
488                 input_item_t *p_entry = NULL;
489                 char *psz_name = NULL;
490
491                 char * ppsz_options[2];
492                 int i_options = 0;
493
494                 /* add a new entry */
495                 psz_parse+=8;
496                 if( !b_entry )
497                 {
498                     msg_Err( p_demux, "end of entry without start?" );
499                     continue;
500                 }
501
502                 if( !psz_href )
503                 {
504                     msg_Err( p_demux, "entry without href?" );
505                     continue;
506                 }
507                 /* An skip entry is an ad only if other entries exist without skip */
508                 if( p_sys->b_skip_ads && b_skip_entry && i_inserted_entries != 0 )
509                 {
510                     char *psz_current_input_name = input_item_GetName( p_current_input );
511                     msg_Dbg( p_demux, "skipped entry %d %s (%s)",
512                              i_entry_count,
513                              ( psz_title_entry ? psz_title_entry : psz_current_input_name ), psz_href );
514                     free( psz_current_input_name );
515                 }
516                 else
517                 {
518                     if( i_starttime || i_duration )
519                     {
520                         if( i_starttime )
521                         {
522                             if( asprintf(ppsz_options+i_options, ":start-time=%d", i_starttime) == -1 )
523                                 *(ppsz_options+i_options) = NULL;
524                             else
525                                 ++i_options;
526                         }
527                         if( i_duration )
528                         {
529                             if( asprintf(ppsz_options+i_options, ":stop-time=%d", i_starttime + i_duration) == -1 )
530                                 *(ppsz_options+i_options) = NULL;
531                             else
532                                 ++i_options;
533                         }
534                     }
535
536                     /* create the new entry */
537                     char *psz_current_input_name = input_item_GetName( p_current_input );
538                     if( asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : psz_current_input_name ) ) != -1 )
539                     {
540                         char *psz_mrl = ProcessMRL( psz_href, p_demux->p_sys->psz_prefix );
541                         p_entry = input_item_NewExt( p_demux, psz_mrl, psz_name,
542                                                      i_options, (const char * const *)ppsz_options, VLC_INPUT_OPTION_TRUSTED, -1 );
543                         free( psz_name );
544                         free( psz_mrl );
545                         input_item_CopyOptions( p_current_input, p_entry );
546                         while( i_options )
547                         {
548                             psz_name = ppsz_options[--i_options];
549                             free( psz_name );
550                         }
551                         psz_name = NULL;
552
553                         if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry );
554                         if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry );
555                         if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry );
556                         if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry );
557                         if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry );
558
559                         i_inserted_entries++;
560                         if( p_sys->b_skip_ads && b_skip_entry )
561                         {
562                             // We put the entry as a backup for unique ad case
563                             uniq_entry_ad_backup = p_entry;
564                         }
565                         else
566                         {
567                             if( uniq_entry_ad_backup != NULL )
568                             {
569                                 uniq_entry_ad_backup = NULL;
570                                 vlc_gc_decref( uniq_entry_ad_backup );
571                             }
572                             input_item_AddSubItem( p_current_input, p_entry );
573                             vlc_gc_decref( p_entry );
574                         }
575                     }
576                     free( psz_current_input_name );
577                 }
578
579                 /* cleanup entry */;
580                 FREENULL( psz_href );
581                 FREENULL( psz_title_entry );
582                 FREENULL( psz_base_entry );
583                 FREENULL( psz_artist_entry );
584                 FREENULL( psz_copyright_entry );
585                 FREENULL( psz_moreinfo_entry );
586                 FREENULL( psz_abstract_entry );
587                 b_entry = false;
588             }
589             else if( !strncasecmp( psz_parse, "<Entry", 6 ) )
590             {
591                 char *psz_clientskip;
592                 psz_parse+=6;
593                 if( b_entry )
594                 {
595                     msg_Err( p_demux, "We already are in an entry section" );
596                     continue;
597                 }
598                 i_entry_count += 1;
599                 b_entry = true;
600                 psz_clientskip = strcasestr( psz_parse, "clientskip=\"no\"" );
601                 psz_parse = strcasestr( psz_parse, ">" );
602
603                 /* If clientskip was enabled ... this is an ad */
604                 b_skip_entry = (NULL != psz_clientskip) && (psz_clientskip < psz_parse);
605
606                 // init entry details
607                 FREENULL(psz_href);
608                 i_starttime = 0;
609                 i_duration = 0;
610             }
611             else if( !strncasecmp( psz_parse, "<Ref ", 5 ) )
612             {
613                 psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1);
614                 if( !b_entry )
615                 {
616                     msg_Err( p_demux, "A ref outside an entry section" );
617                     continue;
618                 }
619
620                 if( !strncasecmp( psz_parse, "HREF", 4 ) )
621                 {
622                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
623                     {
624                         psz_backup = ++psz_parse;
625                         psz_backup = SkipBlanks(psz_backup, (unsigned)-1);
626                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
627                         {
628                             char *psz_tmp;
629                             i_strlen = psz_parse-psz_backup;
630                             if( i_strlen < 1 ) continue;
631
632                             if( psz_href )
633                             {
634                                 /* we have allready one href in this entry, lets make new input from it and
635                                 continue with new href, don't free meta/options*/
636                                 input_item_t *p_entry = NULL;
637                                 char *psz_name = input_item_GetName( p_current_input );
638
639                                 char *psz_mrl = ProcessMRL( psz_href, p_demux->p_sys->psz_prefix );
640                                 p_entry = input_item_NewExt( p_demux, psz_mrl, psz_name,
641                                                      0, NULL, VLC_INPUT_OPTION_TRUSTED, -1 );
642                                 free( psz_mrl );
643                                 input_item_CopyOptions( p_current_input, p_entry );
644                                 if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry );
645                                 if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry );
646                                 if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry );
647                                 if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry );
648                                 if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry );
649                                 input_item_AddSubItem( p_current_input, p_entry );
650                                 vlc_gc_decref( p_entry );
651                             }
652
653                             free( psz_href );
654                             psz_href = xmalloc( i_strlen +1);
655                             memcpy( psz_href, psz_backup, i_strlen );
656                             psz_href[i_strlen] = '\0';
657                             psz_tmp = psz_href + (i_strlen-1);
658                             while( psz_tmp >= psz_href &&
659                                  ( *psz_tmp == '\r' || *psz_tmp == '\n' ) )
660                             {
661                                 *psz_tmp = '\0';
662                                 psz_tmp++;
663                             }
664                         }
665                         else continue;
666                     }
667                     else continue;
668                 }
669                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
670                     psz_parse++;
671                 else continue;
672             }
673             else if( !strncasecmp( psz_parse, "<starttime ", 11 ) )
674             {
675                 psz_parse = SkipBlanks(psz_parse+11, (unsigned)-1);
676                 if( !b_entry )
677                 {
678                     msg_Err( p_demux, "starttime outside an entry section" );
679                     continue;
680                 }
681
682                 if( !strncasecmp( psz_parse, "value", 5 ) )
683                 {
684                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
685                     {
686                         psz_backup = ++psz_parse;
687                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
688                         {
689                             i_strlen = psz_parse-psz_backup;
690                             if( i_strlen < 1 ) continue;
691
692                             i_starttime = ParseTime(psz_backup, i_strlen);
693                         }
694                         else continue;
695                     }
696                     else continue;
697                 }
698                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
699                     psz_parse++;
700                 else continue;
701             }
702             else if( !strncasecmp( psz_parse, "<duration ", 11 ) )
703             {
704                 psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1);
705                 if( !b_entry )
706                 {
707                     msg_Err( p_demux, "duration outside an entry section" );
708                     continue;
709                 }
710
711                 if( !strncasecmp( psz_parse, "value", 5 ) )
712                 {
713                     if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
714                     {
715                         psz_backup = ++psz_parse;
716                         if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) )
717                         {
718                             i_strlen = psz_parse-psz_backup;
719                             if( i_strlen < 1 ) continue;
720
721                             i_duration = ParseTime(psz_backup, i_strlen);
722                         }
723                         else continue;
724                     }
725                     else continue;
726                 }
727                 if( ( psz_parse = strcasestr( psz_parse, ">" ) ) )
728                     psz_parse++;
729                 else continue;
730             }
731             else if( !strncasecmp( psz_parse, "</ASX", 5 ) )
732             {
733                 if( psz_title_asx ) input_item_SetTitle( p_current_input, psz_title_asx );
734                 if( psz_artist_asx ) input_item_SetArtist( p_current_input, psz_artist_asx );
735                 if( psz_copyright_asx ) input_item_SetCopyright( p_current_input, psz_copyright_asx );
736                 if( psz_moreinfo_asx ) input_item_SetURL( p_current_input, psz_moreinfo_asx );
737                 if( psz_abstract_asx ) input_item_SetDescription( p_current_input, psz_abstract_asx );
738                 FREENULL( psz_base_asx );
739                 FREENULL( psz_title_asx );
740                 FREENULL( psz_artist_asx );
741                 FREENULL( psz_copyright_asx );
742                 FREENULL( psz_moreinfo_asx );
743                 FREENULL( psz_abstract_asx );
744                 psz_parse++;
745             }
746             else psz_parse++;
747         }
748         if ( uniq_entry_ad_backup != NULL )
749         {
750             msg_Dbg( p_demux, "added unique entry even if ad");
751             /* If ASX contains a unique entry, we add it, it is probably not an ad */
752             input_item_AddSubItem( p_current_input, uniq_entry_ad_backup );
753             vlc_gc_decref( uniq_entry_ad_backup);
754         }
755 #if 0
756 /* FIXME Unsupported elements */
757             PARAM
758             EVENT
759             REPEAT
760             ENDMARK
761             STARTMARK
762 #endif
763     }
764     vlc_gc_decref(p_current_input);
765     return 0; /* Needed for correct operation of go back */
766 }
767
768 static int Control( demux_t *p_demux, int i_query, va_list args )
769 {
770     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
771     return VLC_EGENERIC;
772 }