]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/ram.c
various modules: adjust to new playlist design
[vlc] / modules / demux / playlist / ram.c
index d640c7ac22dcd7fd7abcf317637f36ef4a46eaea..ce7cc822be212a969ab6a07ca6d9635ea80c8044 100644 (file)
@@ -49,7 +49,7 @@ http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ram
 
 #include <vlc_common.h>
 #include <vlc_demux.h>
-#include <vlc_charset.h>
+#include <vlc_url.h>
 
 #include "playlist.h"
 
@@ -63,8 +63,7 @@ struct demux_sys_t
  *****************************************************************************/
 static int Demux( demux_t *p_demux);
 static int Control( demux_t *p_demux, int i_query, va_list args );
-static bool ContainsURL( demux_t *p_demux );
-static void ParseClipInfo( char * psz_clipinfo, char **ppsz_artist, char **ppsz_title,
+static void ParseClipInfo( const char * psz_clipinfo, char **ppsz_artist, char **ppsz_title,
                            char **ppsz_album, char **ppsz_genre, char **ppsz_year,
                            char **ppsz_cdnum, char **ppsz_comments );
 
@@ -76,8 +75,7 @@ static void ParseClipInfo( char * psz_clipinfo, char **ppsz_artist, char **ppsz_
 int Import_RAM( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    const uint8_t *p_peek;
-    CHECK_PEEK( p_peek, 8 );
+
     if(! demux_IsPathExtension( p_demux, ".ram" ) ||
          demux_IsPathExtension( p_demux, ".rm" ) )
         return VLC_EGENERIC;
@@ -99,40 +97,12 @@ void Close_RAM( vlc_object_t *p_this )
     free( p_demux->p_sys );
 }
 
-/**
- * Returns a UTF8 encoded version of the string
- * @param str: input string
- * @return pointer to UTF8 string
- */
-static inline char *MaybeFromLocaleDup (const char *str)
-{
-    if (str == NULL)
-        return NULL;
-
-    return IsUTF8 (str) ? strdup (str) : FromLocaleDup (str);
-}
-
-/**
- * Converts a string to UTF8 encoding
- * @param str: input string
- */
-static inline void MaybeFromLocaleRep (char **str)
-{
-    char *const orig_str = *str;
-
-    if ((orig_str != NULL) && !IsUTF8 (orig_str))
-    {
-        *str = FromLocaleDup (orig_str);
-        free (orig_str);
-    }
-}
-
 /**
  * Skips blanks in a given buffer
  * @param s: input string
  * @param i_strlen: length of the buffer
  */
-static char *SkipBlanks(char *s, size_t i_strlen )
+static const char *SkipBlanks( const char *s, size_t i_strlen )
 {
     while( i_strlen > 0 ) {
         switch( *s )
@@ -157,7 +127,7 @@ static char *SkipBlanks(char *s, size_t i_strlen )
  * @param i_strlen: length of the buffer
  * @return time in seconds
  */
-static int ParseTime(char *s, size_t i_strlen)
+static int ParseTime( const char *s, size_t i_strlen)
 {
     // need to parse hour:minutes:sec.fraction string
     int result = 0;
@@ -233,7 +203,6 @@ static int ParseTime(char *s, size_t i_strlen)
 static int Demux( demux_t *p_demux )
 {
     char       *psz_line;
-    char       *psz_name = NULL;
     char       *psz_artist = NULL, *psz_album = NULL, *psz_genre = NULL, *psz_year = NULL;
     char       *psz_author = NULL, *psz_title = NULL, *psz_copyright = NULL, *psz_cdnum = NULL, *psz_comments = NULL;
     int        i_parsed_duration = 0;
@@ -243,7 +212,9 @@ static int Demux( demux_t *p_demux )
     bool b_cleanup = false;
     input_item_t *p_input;
 
-    INIT_PLAYLIST_STUFF;
+    input_item_t *p_current_input = GetCurrentItem(p_demux);
+
+    input_item_node_t *p_subitems = input_item_node_Create( p_current_input );
 
     psz_line = stream_ReadLine( p_demux->s );
     while( psz_line )
@@ -260,58 +231,47 @@ static int Demux( demux_t *p_demux )
         }
         else if( *psz_parse )
         {
-            char *psz_mrl, *psz_option_start, *psz_option_next, *psz_temp_mrl, *psz_option;
+            char *psz_mrl, *psz_option_next, *psz_option;
             char *psz_param, *psz_value;
-            if( !psz_name || !*psz_name )
-            {
-                /* Default filename as name for relative entries
-                   TODO: Currently not used. Either remove or use */
-                psz_name = MaybeFromLocaleDup( psz_parse );
-            }
 
             /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1&param2=value2 in a RAM file */
             psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix );
-            MaybeFromLocaleRep( &psz_mrl );
 
             b_cleanup = true;
             if ( !psz_mrl ) goto error;
 
             /* We have the MRL, now we have to check for options and parse them from MRL */
-            psz_temp_mrl = strdup( psz_mrl );
-            psz_option_start = strchr( psz_temp_mrl, '?' ); /* Look for start of options */
-            if( psz_option_start )
+            psz_option = strchr( psz_mrl, '?' ); /* Look for start of options */
+            if( psz_option )
             {
-                psz_option_start++;
-                psz_option_next = psz_option_start;
+                /* Remove options from MRL
+                   because VLC can't get the file otherwise */
+                *psz_option = '\0';
+                psz_option++;
+                psz_option_next = psz_option;
                 while( 1 ) /* Process each option */
                 {
                     /* Look for end of first option which maybe a & or \0 */
-                    psz_option_start = psz_option_next;
-                    psz_option_next = strchr( psz_option_start, '&' );
+                    psz_option = psz_option_next;
+                    psz_option_next = strchr( psz_option, '&' );
                     if( psz_option_next )
                     {
                         *psz_option_next = '\0';
                         psz_option_next++;
                     }
                     else
-                        psz_option_next = strchr( psz_option_start, '\0' );
+                        psz_option_next = strchr( psz_option, '\0' );
                     /* Quit if options are over */
-                    if( psz_option_next == psz_option_start )
+                    if( psz_option_next == psz_option )
                         break;
-                    psz_option = MaybeFromLocaleDup( psz_option_start );
-                    /* If this option is screwed up, try the next one */
-                    if( !psz_option )
-                        continue;
 
                     /* Parse out param and value */
                     psz_param = psz_option;
-                    if( strchr( psz_option, '=' ) )
-                    {
-                        psz_value = strchr( psz_option, '=' ) + 1;
-                        *(strchr( psz_option, '=' )) = '\0';
-                    }
-                    else
+                    psz_value = strchr( psz_option, '=' );
+                    if( psz_value == NULL )
                         break;
+                    *psz_value = '\0';
+                    psz_value++;
 
                     /* Take action based on parameter value in the below if else structure */
                     /* TODO: Remove any quotes surrounding values if required */
@@ -322,62 +282,53 @@ static int Demux( demux_t *p_demux )
                            &psz_cdnum, &psz_comments ); /* clipinfo has various sub parameters, which is parsed by this function */
                     }
                     else if( !strcmp( psz_param, "author" ) )
-                        psz_author = strdup(psz_value);
+                        psz_author = decode_URI_duplicate(psz_value);
                     else if( !strcmp( psz_param, "start" ) )
                     {
-                        i_start = ParseTime( strdup( psz_value ),strlen( psz_value ) );
-                        char * temp = NULL;
+                        i_start = ParseTime( psz_value, strlen( psz_value ) );
+                        char *temp;
                         if( i_start )
                         {
-                            if( asprintf( &temp, ":start-time=%d", i_start ) == -1 )
-                                *(temp) = NULL;
-                            if( temp && *temp )
+                            if( asprintf( &temp, ":start-time=%d", i_start ) != -1 )
                                 INSERT_ELEM( ppsz_options, i_options, i_options, temp );
                         }
                     }
                     else if( !strcmp( psz_param, "end" ) )
                     {
-                        i_stop = ParseTime( strdup( psz_value ), strlen( psz_value ) );
-                        char * temp = NULL;
+                        i_stop = ParseTime( psz_value, strlen( psz_value ) );
+                        char *temp;
                         if( i_stop )
                         {
-                            if( asprintf( &temp, ":stop-time=%d", i_stop ) == -1 )
-                                *(temp) = NULL;
-                            if( temp && *temp )
+                            if( asprintf( &temp, ":stop-time=%d", i_stop ) != -1 )
                                 INSERT_ELEM( ppsz_options, i_options, i_options, temp );
                         }
                     }
                     else if( !strcmp( psz_param, "title" ) )
-                        psz_title = strdup(psz_value);
+                        psz_title = decode_URI_duplicate(psz_value);
                     else if( !strcmp( psz_param, "copyright" ) )
-                        psz_copyright = strdup(psz_value);
+                        psz_copyright = decode_URI_duplicate(psz_value);
                     else
                     {   /* TODO: insert option anyway? Currently ignores*/
                         /* INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); */
                     }
-
-                    free( psz_option );
                 }
-
-                *(strchr( psz_mrl, '?' )) = '\0'; /* Remove options from MRL because VLC can't get the file otherwise */
             }
 
-            free( psz_temp_mrl );
-
             /* Create the input item and pump in all the options into playlist item */
             p_input = input_item_NewExt( p_demux, psz_mrl, psz_title, i_options, ppsz_options, 0, i_duration );
 
-            if( psz_artist && *psz_artist ) input_item_SetArtist( p_input, psz_artist );
-            if( psz_author && *psz_author ) input_item_SetPublisher( p_input, psz_author );
-            if( psz_title && *psz_title ) input_item_SetTitle( p_input, psz_title );
-            if( psz_copyright && *psz_copyright ) input_item_SetCopyright( p_input, psz_copyright );
-            if( psz_album && *psz_album ) input_item_SetAlbum( p_input, psz_album );
-            if( psz_genre && *psz_genre ) input_item_SetGenre( p_input, psz_genre );
-            if( psz_year && *psz_year ) input_item_SetDate( p_input, psz_copyright );
-            if( psz_cdnum && *psz_cdnum ) input_item_SetTrackNum( p_input, psz_cdnum );
-            if( psz_comments && *psz_comments ) input_item_SetDescription( p_input, psz_comments );
+            if( !EMPTY_STR( psz_artist ) ) input_item_SetArtist( p_input, psz_artist );
+            if( !EMPTY_STR( psz_author ) ) input_item_SetPublisher( p_input, psz_author );
+            if( !EMPTY_STR( psz_title ) ) input_item_SetTitle( p_input, psz_title );
+            if( !EMPTY_STR( psz_copyright ) ) input_item_SetCopyright( p_input, psz_copyright );
+            if( !EMPTY_STR( psz_album ) ) input_item_SetAlbum( p_input, psz_album );
+            if( !EMPTY_STR( psz_genre ) ) input_item_SetGenre( p_input, psz_genre );
+            if( !EMPTY_STR( psz_year ) ) input_item_SetDate( p_input, psz_copyright );
+            if( !EMPTY_STR( psz_cdnum ) ) input_item_SetTrackNum( p_input, psz_cdnum );
+            if( !EMPTY_STR( psz_comments ) ) input_item_SetDescription( p_input, psz_comments );
 
             input_item_AddSubItem( p_current_input, p_input );
+            input_item_node_AppendItem( p_subitems, p_input );
             vlc_gc_decref( p_input );
             free( psz_mrl );
         }
@@ -393,7 +344,6 @@ static int Demux( demux_t *p_demux )
             /* Cleanup state */
             while( i_options-- ) free( (char*)ppsz_options[i_options] );
             FREENULL( ppsz_options );
-            FREENULL( psz_name );
             FREENULL( psz_artist );
             FREENULL( psz_title );
             FREENULL( psz_author );
@@ -411,7 +361,9 @@ static int Demux( demux_t *p_demux )
             b_cleanup = false;
         }
     }
-    HANDLE_PLAY_AND_RELEASE;
+    input_item_AddSubItemTree( p_subitems );
+    input_item_node_Delete( p_subitems );
+    vlc_gc_decref(p_current_input);
     var_Destroy( p_demux, "m3u-extvlcopt" );
     return 0; /* Needed for correct operation of go back */
 }
@@ -438,16 +390,18 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
  * @param ppsz_cdnum: Buffer to store cdnum
  * @param ppsz_comments: Buffer to store comments
  */
-static void ParseClipInfo( char *psz_clipinfo, char **ppsz_artist, char **ppsz_title,
+static void ParseClipInfo( const char *psz_clipinfo, char **ppsz_artist, char **ppsz_title,
                            char **ppsz_album, char **ppsz_genre, char **ppsz_year,
                            char **ppsz_cdnum, char **ppsz_comments )
 {
     char *psz_option_next, *psz_option_start, *psz_param, *psz_value, *psz_suboption;
     char *psz_temp_clipinfo = strdup( psz_clipinfo );
-    psz_option_start = psz_clipinfo;
     psz_option_start = strchr( psz_temp_clipinfo, '"' );
     if( !psz_option_start )
+    {
+        free( psz_temp_clipinfo );
         return;
+    }
 
     psz_option_start++;
     psz_option_next = psz_option_start;
@@ -467,7 +421,7 @@ static void ParseClipInfo( char *psz_clipinfo, char **ppsz_artist, char **ppsz_t
         if( psz_option_next == psz_option_start )
             break;
 
-        psz_suboption = MaybeFromLocaleDup( psz_option_start );
+        psz_suboption = strdup( psz_option_start );
         if( !psz_suboption )
             break;
 
@@ -482,19 +436,19 @@ static void ParseClipInfo( char *psz_clipinfo, char **ppsz_artist, char **ppsz_t
             break;
         /* Put into args */
         if( !strcmp( psz_param, "artist name" ) )
-            *ppsz_artist = strdup( psz_value );
+            *ppsz_artist = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "title" ) )
-            *ppsz_title = strdup( psz_value );
+            *ppsz_title = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "album name" ) )
-            *ppsz_album = strdup( psz_value );
+            *ppsz_album = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "genre" ) )
-            *ppsz_genre = strdup( psz_value );
+            *ppsz_genre = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "year" ) )
-            *ppsz_year = strdup( psz_value );
+            *ppsz_year = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "cdnum" ) )
-            *ppsz_cdnum = strdup( psz_value );
+            *ppsz_cdnum = decode_URI_duplicate( psz_value );
         else if( !strcmp( psz_param, "comments" ) )
-            *ppsz_comments = strdup( psz_value );
+            *ppsz_comments = decode_URI_duplicate( psz_value );
 
         free( psz_suboption );
         psz_option_next++;