]> git.sesse.net Git - vlc/blobdiff - modules/misc/playlist/xspf.c
Fix memleaks.
[vlc] / modules / misc / playlist / xspf.c
index d2bbc8e594992488a230a93f68470fded0d5f285..e1178b2f94bc90cdf9332e4e63132a5b6a2a2548 100644 (file)
  * \file modules/misc/playlist/xspf.c
  * \brief XSPF playlist export functions
  */
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_input.h>
 #include <vlc_meta.h>
 #include <vlc_strings.h>
+#include <vlc_url.h>
 #include <vlc_charset.h>
 #include "xspf.h"
 
+#include <assert.h>
+
 /**
  * \brief Prints the XSPF header to file, writes each item by xspf_export_item()
  * and closes the open xml elements
  * \param p_this the VLC playlist object
  * \return VLC_SUCCESS if some memory is available, otherwise VLC_ENONMEM
  */
-int E_(xspf_export_playlist)( vlc_object_t *p_this )
+int xspf_export_playlist( vlc_object_t *p_this )
 {
     const playlist_t *p_playlist = (playlist_t *)p_this;
     const playlist_export_t *p_export =
@@ -70,8 +77,8 @@ int E_(xspf_export_playlist)( vlc_object_t *p_this )
     if( psz_temp && *psz_temp )
     {
         fprintf( p_export->p_file, "\t<location>%s</location>\n", psz_temp );
-        free( psz_temp );
     }
+    free( psz_temp );
 
     /* export all items in a flat format */
     fprintf( p_export->p_file, "\t<trackList>\n" );
@@ -110,6 +117,7 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
 {
     char *psz;
     char *psz_temp;
+    int i;
     mtime_t i_duration;
 
     if( !p_item ) return;
@@ -220,6 +228,17 @@ static void xspf_export_item( playlist_item_t *p_item, FILE *p_file,
     }
     free( psz );
 
+    /* export the input's options (bookmarks, ...) in <extension> */
+    fprintf( p_file, "\t\t\t<extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" );
+    for( i = 0; i < p_item->p_input->i_options; i++ )
+    {
+        fprintf( p_file, "\t\t\t\t<option>%s</option>\n",
+                 p_item->p_input->ppsz_options[i][0] == ':' ?
+                 p_item->p_input->ppsz_options[i] + 1 :
+                 p_item->p_input->ppsz_options[i] );
+    }
+    fprintf( p_file, "\t\t\t</extension>\n" );
+
 xspfexportitem_end:
     /* -> the duration */
     i_duration = input_item_GetDuration( p_item->p_input );
@@ -283,7 +302,7 @@ static char *assertUTF8URI( char *psz_name )
 {
     char *psz_ret = NULL;              /**< the new result buffer to return */
     char *psz_s = NULL, *psz_d = NULL; /**< src & dest pointers for URI conversion */
-    vlc_bool_t b_uri_is_file = VLC_FALSE; /**< we do additional %-encoding if the URI is a file:// one */
+    bool b_uri_is_file = false; /**< we do additional %-encoding if the URI is a file:// one */
 
     if( !psz_name || !*psz_name )
         return NULL;
@@ -306,17 +325,18 @@ static char *assertUTF8URI( char *psz_name )
         i_delim++; /* skip the ':' */
         strncpy( psz_ret, psz_s, i_delim );
         psz_d = psz_ret + i_delim;
-        psz_s += i_delim;
 
         if( !strncmp( psz_s, "file://", 7 ) )
-            b_uri_is_file = VLC_TRUE;
+            b_uri_is_file = true;
+
+        psz_s += i_delim;
     }
     /* assume "file" scheme if no scheme-part is included */
     else
     {
         strcpy( psz_ret, "file://" );
         psz_d = psz_ret + 7;
-        b_uri_is_file = VLC_TRUE;
+        b_uri_is_file = true;
     }
 
     while( *psz_s )
@@ -327,6 +347,8 @@ static char *assertUTF8URI( char *psz_name )
             *psz_s == '>' ||
             *psz_s == '&' ||
             *psz_s == ' ' ||
+            *psz_s == '+' ||
+            *psz_s == '%' ||
             ( b_uri_is_file && (
             *psz_s == ':' ||
             *psz_s == '"' ||
@@ -334,8 +356,7 @@ static char *assertUTF8URI( char *psz_name )
             *psz_s == '#' ||
             *psz_s == '[' ||
             *psz_s == ']' ||
-            *psz_s == '@' ||
-            *psz_s == '%' )
+            *psz_s == '@' )
             )
           )
         {