]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/asx.c
demux/playlist: Don't use playlist_t.
[vlc] / modules / demux / playlist / asx.c
index 6618beec77cdf5e7fb224e2dda651a6fc8f528c8..49e1dc4c01ce1083fa91d9d788f1c2b6cefb8480 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#define _GNU_SOURCE
-#include <ctype.h>                                              /* isspace() */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_demux.h>
 
-#include <errno.h>                                                 /* ENOMEM */
+#include <ctype.h>
 #include <vlc_charset.h>
 #include "playlist.h"
 #include "vlc_meta.h"
@@ -43,8 +44,8 @@ struct demux_sys_t
     char    *psz_prefix;
     char    *psz_data;
     int64_t i_data_len;
-    vlc_bool_t b_utf8;
-    vlc_bool_t b_skip_ads;
+    bool b_utf8;
+    bool b_skip_ads;
 };
 
 /*****************************************************************************
@@ -60,7 +61,7 @@ static int StoreString( demux_t *p_demux, char **ppsz_string,
     demux_sys_t *p_sys = p_demux->p_sys;
     unsigned len = psz_source_end - psz_source_start;
 
-    if( *ppsz_string ) free( *ppsz_string );
+    free( *ppsz_string );
 
     char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1);
     if (buf == NULL)
@@ -184,18 +185,18 @@ static int ParseTime(char *s, size_t i_strlen)
 /*****************************************************************************
  * Import_ASX: main import function
  *****************************************************************************/
-int E_(Import_ASX)( vlc_object_t *p_this )
+int Import_ASX( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    uint8_t *p_peek;
+    const uint8_t *p_peek;
     CHECK_PEEK( p_peek, 10 );
 
     // skip over possible leading empty lines and empty spaces
     p_peek = (uint8_t *)SkipBlanks((char *)p_peek, 6);
 
-    if( POKE( p_peek, "<asx", 4 ) || demux2_IsPathExtension( p_demux, ".asx" ) ||
-        demux2_IsPathExtension( p_demux, ".wax" ) || demux2_IsPathExtension( p_demux, ".wvx" ) ||
-        demux2_IsForced( p_demux, "asx-open" ) )
+    if( POKE( p_peek, "<asx", 4 ) || demux_IsPathExtension( p_demux, ".asx" ) ||
+        demux_IsPathExtension( p_demux, ".wax" ) || demux_IsPathExtension( p_demux, ".wvx" ) ||
+        demux_IsForced( p_demux, "asx-open" ) )
     {
         ;
     }
@@ -203,10 +204,10 @@ int E_(Import_ASX)( vlc_object_t *p_this )
         return VLC_EGENERIC;
 
     STANDARD_DEMUX_INIT_MSG( "found valid ASX playlist" );
-    p_demux->p_sys->psz_prefix = E_(FindPrefix)( p_demux );
+    p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
     p_demux->p_sys->psz_data = NULL;
     p_demux->p_sys->i_data_len = -1;
-    p_demux->p_sys->b_utf8 = VLC_FALSE;
+    p_demux->p_sys->b_utf8 = false;
     p_demux->p_sys->b_skip_ads = config_GetInt( p_demux, "playlist-skip-ads" );
 
     return VLC_SUCCESS;
@@ -215,13 +216,13 @@ int E_(Import_ASX)( vlc_object_t *p_this )
 /*****************************************************************************
  * Deactivate: frees unused data
  *****************************************************************************/
-void E_(Close_ASX)( vlc_object_t *p_this )
+void Close_ASX( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
 
-    if( p_sys->psz_prefix ) free( p_sys->psz_prefix );
-    if( p_sys->psz_data ) free( p_sys->psz_data );
+    free( p_sys->psz_prefix );
+    free( p_sys->psz_data );
     free( p_sys );
 }
 
@@ -230,7 +231,7 @@ static int Demux( demux_t *p_demux )
     demux_sys_t *p_sys = p_demux->p_sys;
     char        *psz_parse = NULL;
     char        *psz_backup = NULL;
-    vlc_bool_t  b_entry = VLC_FALSE;
+    bool  b_entry = false;
     input_item_t *p_input;
     INIT_PLAYLIST_STUFF;
 
@@ -254,7 +255,7 @@ static int Demux( demux_t *p_demux )
             p_sys->i_data_len += 1024;
             p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) +1 );
         }
-        if( p_sys->i_data_len <= 0 ) return VLC_EGENERIC;
+        if( p_sys->i_data_len <= 0 ) return -1;
     }
 
     psz_parse = p_sys->psz_data;
@@ -279,7 +280,7 @@ static int Demux( demux_t *p_demux )
         char *psz_moreinfo_entry = NULL;
         char *psz_abstract_entry = NULL;
         int i_entry_count = 0;
-        vlc_bool_t b_skip_entry = VLC_FALSE;
+        bool b_skip_entry = false;
 
         char *psz_href = NULL;
         int i_starttime = 0;
@@ -298,7 +299,7 @@ static int Demux( demux_t *p_demux )
             }
             else if( !strncasecmp( psz_parse, "<PARAM ", 7 ) )
             {
-                vlc_bool_t b_encoding_flag = VLC_FALSE;
+                bool b_encoding_flag = false;
                 psz_parse = SkipBlanks(psz_parse+7, (unsigned)-1);
                 if( !strncasecmp( psz_parse, "name", 4 ) )
                 {
@@ -336,7 +337,7 @@ static int Demux( demux_t *p_demux )
                             memcpy( psz_string, psz_backup, i_strlen );
                             psz_string[i_strlen] = '\0';
                             msg_Dbg( p_demux, "param value: %s", psz_string);
-                            if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = VLC_TRUE;
+                            if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = true;
                             free( psz_string );
                         }
                         else continue;
@@ -458,7 +459,7 @@ static int Demux( demux_t *p_demux )
                             psz_string = malloc( i_strlen*sizeof( char ) +1);
                             memcpy( psz_string, psz_backup, i_strlen );
                             psz_string[i_strlen] = '\0';
-                            p_input = input_ItemNew( p_playlist, psz_string, psz_title_asx );
+                            p_input = input_ItemNew( p_demux, psz_string, psz_title_asx );
                             input_ItemCopyOptions( p_current_input, p_input );
                             input_ItemAddSubItem( p_current_input, p_input );
                             free( psz_string );
@@ -515,7 +516,7 @@ static int Demux( demux_t *p_demux )
                     /* create the new entry */
                     asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : p_current_input->psz_name ) );
 
-                    p_entry = input_ItemNewExt( p_playlist, psz_href, psz_name, i_options, (const char * const *)ppsz_options, -1 );
+                    p_entry = input_ItemNewExt( p_demux, psz_href, psz_name, i_options, (const char * const *)ppsz_options, -1 );
                     FREENULL( psz_name );
                     input_ItemCopyOptions( p_current_input, p_entry );
                     while( i_options )
@@ -530,17 +531,18 @@ static int Demux( demux_t *p_demux )
                     if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry );
                     if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry );
                     input_ItemAddSubItem( p_current_input, p_entry );
+                    vlc_gc_decref( p_entry );
                 }
 
-                /* cleanup entry */
-                FREENULL( psz_href )
-                FREENULL( psz_title_entry )
-                FREENULL( psz_base_entry )
-                FREENULL( psz_artist_entry )
-                FREENULL( psz_copyright_entry )
-                FREENULL( psz_moreinfo_entry )
-                FREENULL( psz_abstract_entry )
-                b_entry = VLC_FALSE;
+                /* cleanup entry */;
+                FREENULL( psz_href );
+                FREENULL( psz_title_entry );
+                FREENULL( psz_base_entry );
+                FREENULL( psz_artist_entry );
+                FREENULL( psz_copyright_entry );
+                FREENULL( psz_moreinfo_entry );
+                FREENULL( psz_abstract_entry );
+                b_entry = false;
             }
             else if( !strncasecmp( psz_parse, "<Entry", 6 ) )
             {
@@ -552,7 +554,7 @@ static int Demux( demux_t *p_demux )
                     continue;
                 }
                 i_entry_count += 1;
-                b_entry = VLC_TRUE;
+                b_entry = true;
                 psz_clientskip = strcasestr( psz_parse, "clientskip=\"no\"" );
                 psz_parse = strcasestr( psz_parse, ">" );
 
@@ -666,13 +668,11 @@ static int Demux( demux_t *p_demux )
             }
             else if( !strncasecmp( psz_parse, "</ASX", 5 ) )
             {
-                vlc_mutex_lock( &p_current_input->lock );
                 if( psz_title_asx ) input_item_SetTitle( p_current_input, psz_title_asx );
                 if( psz_artist_asx ) input_item_SetArtist( p_current_input, psz_artist_asx );
                 if( psz_copyright_asx ) input_item_SetCopyright( p_current_input, psz_copyright_asx );
                 if( psz_moreinfo_asx ) input_item_SetURL( p_current_input, psz_moreinfo_asx );
                 if( psz_abstract_asx ) input_item_SetDescription( p_current_input, psz_abstract_asx );
-                vlc_mutex_unlock( &p_current_input->lock );
                 FREENULL( psz_base_asx );
                 FREENULL( psz_title_asx );
                 FREENULL( psz_artist_asx );
@@ -693,10 +693,11 @@ static int Demux( demux_t *p_demux )
 #endif
     }
     HANDLE_PLAY_AND_RELEASE;
-    return -1; /* Needed for correct operation of go back */
+    return 0; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
+    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
     return VLC_EGENERIC;
 }