]> git.sesse.net Git - vlc/blobdiff - modules/control/http.c
* modules/control/http.c: Added an id="include" macro to include
[vlc] / modules / control / http.c
index d11e01169423b4c2a019204fd8767b3fedb5285c..82842c646339eef2a4a77b574199acf74fdd1f8f 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
  * http.c :  http mini-server ;)
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.38 2003/11/23 16:24:20 garf Exp $
+ * Copyright (C) 2001-2005 the VideoLAN team
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
+ *          Christophe Massiot <massiot@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-/*
- * TODO:
- *
- * - clean up ?
- * - doc ! (mouarf ;)
- *
- */
-
 #include <stdlib.h>
+#include <ctype.h>
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 
 #include <vlc/aout.h>
 #include <vlc/vout.h> /* for fullscreen */
 
-#include "httpd.h"
+#include "vlc_httpd.h"
+#include "vlc_vlm.h"
+#include "vlc_tls.h"
+#include "vlc_acl.h"
+#include "charset.h"
 
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 #   include <io.h>
 #endif
 
-#if (!defined( WIN32 ) || defined(__MINGW32__))
-/* Mingw has its own version of dirent */
+#ifdef HAVE_DIRENT_H
 #   include <dirent.h>
 #endif
 
+/* stat() support for large files on win32 */
+#if defined( WIN32 ) && !defined( UNDER_CE )
+#   define stat _stati64
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-static int  Activate     ( vlc_object_t * );
-static void Close        ( vlc_object_t * );
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
 
 #define HOST_TEXT N_( "Host address" )
 #define HOST_LONGTEXT N_( \
-    "You can set the address and port on which the http interface will bind" )
+    "You can set the address and port the http interface will bind to." )
 #define SRC_TEXT N_( "Source directory" )
 #define SRC_LONGTEXT N_( "Source directory" )
+#define CHARSET_TEXT N_( "Charset" )
+#define CHARSET_LONGTEXT N_( \
+        "Charset declared in Content-Type header (default UTF-8)." )
+#define CERT_TEXT N_( "Certificate file" )
+#define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
+                          "(enables SSL)" )
+#define KEY_TEXT N_( "Private key file" )
+#define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file" )
+#define CA_TEXT N_( "Root CA file" )
+#define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
+                        "certificates file" )
+#define CRL_TEXT N_( "CRL file" )
+#define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file" )
 
 vlc_module_begin();
+    set_shortname( _("HTTP"));
     set_description( _("HTTP remote control interface") );
-    add_category_hint( N_("HTTP remote control"), NULL, VLC_TRUE );
+    set_category( CAT_INTERFACE );
+    set_subcategory( SUBCAT_INTERFACE_GENERAL );
         add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
         add_string ( "http-src",  NULL, NULL, SRC_TEXT,  SRC_LONGTEXT,  VLC_TRUE );
+        add_string ( "http-charset", "UTF-8", NULL, CHARSET_TEXT, CHARSET_LONGTEXT, VLC_TRUE );
+        set_section( N_("HTTP SSL" ), 0 );
+        add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
+        add_string ( "http-intf-key",  NULL, NULL, KEY_TEXT,  KEY_LONGTEXT,  VLC_TRUE );
+        add_string ( "http-intf-ca",   NULL, NULL, CA_TEXT,   CA_LONGTEXT,   VLC_TRUE );
+        add_string ( "http-intf-crl",  NULL, NULL, CRL_TEXT,  CRL_LONGTEXT,  VLC_TRUE );
     set_capability( "interface", 0 );
-    set_callbacks( Activate, Close );
+    set_callbacks( Open, Close );
 vlc_module_end();
 
 
@@ -93,6 +116,7 @@ static void Run          ( intf_thread_t *p_intf );
 static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
                            char *psz_dir );
 
+#if !defined(SYS_DARWIN) && !defined(SYS_BEOS) && !defined(WIN32)
 static int DirectoryCheck( char *psz_dir )
 {
     DIR           *p_dir;
@@ -114,19 +138,20 @@ static int DirectoryCheck( char *psz_dir )
 
     return VLC_SUCCESS;
 }
+#endif
 
+static int  HttpCallback( httpd_file_sys_t *p_args,
+                          httpd_file_t *,
+                          uint8_t *p_request,
+                          uint8_t **pp_data, int *pi_data );
 
-static int  http_get( httpd_file_callback_args_t *p_args,
-                      uint8_t *p_request, int i_request,
-                      uint8_t **pp_data, int *pi_data );
-
-static char *uri_extract_value( char *psz_uri, char *psz_name,
+static char *uri_extract_value( char *psz_uri, const char *psz_name,
                                 char *psz_value, int i_value_max );
-static void uri_decode_url_encoded( char *psz );
+static int uri_test_param( char *psz_uri, const char *psz_name );
 
-static char *Find_end_MRL( char *psz );
+static void uri_decode_url_encoded( char *psz );
 
-static playlist_item_t * parse_MRL( char *psz );
+static playlist_item_t *parse_MRL( intf_thread_t *, char *psz, char *psz_name );
 
 /*****************************************************************************
  *
@@ -147,30 +172,35 @@ typedef struct
     int  i_stack;
 } rpn_stack_t;
 
-struct httpd_file_callback_args_t
+struct httpd_file_sys_t
 {
-    intf_thread_t *p_intf;
-    httpd_file_t  *p_file;
+    intf_thread_t    *p_intf;
+    httpd_file_t     *p_file;
+    httpd_redirect_t *p_redir;
+    httpd_redirect_t *p_redir2;
 
     char          *file;
     char          *name;
-    char          *mime;
+
+    vlc_bool_t    b_html;
 
     /* inited for each access */
-    rpn_stack_t       stack;
+    rpn_stack_t   stack;
     mvar_t        *vars;
 };
 
 struct intf_sys_t
 {
-    httpd_t             *p_httpd;
     httpd_host_t        *p_httpd_host;
 
-    int                         i_files;
-    httpd_file_callback_args_t  **pp_files;
+    int                 i_files;
+    httpd_file_sys_t    **pp_files;
 
     playlist_t          *p_playlist;
     input_thread_t      *p_input;
+    vlm_t               *p_vlm;
+    char                *psz_html_type;
+    vlc_iconv_t         iconv_from_utf8, iconv_to_utf8;
 };
 
 
@@ -178,12 +208,14 @@ struct intf_sys_t
 /*****************************************************************************
  * Activate: initialize and create stuff
  *****************************************************************************/
-static int Activate( vlc_object_t *p_this )
+static int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
     intf_sys_t    *p_sys;
     char          *psz_host;
     char          *psz_address = "";
+    const char    *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
+                  *psz_crl = NULL;
     int           i_port       = 0;
     char          *psz_src;
 
@@ -200,12 +232,7 @@ static int Activate( vlc_object_t *p_this )
             i_port = atoi( psz_parser );
         }
     }
-    if( i_port <= 0 )
-    {
-        i_port= 8080;
-    }
 
-    msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
     p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
     if( !p_intf->p_sys )
     {
@@ -213,20 +240,76 @@ static int Activate( vlc_object_t *p_this )
     }
     p_sys->p_playlist = NULL;
     p_sys->p_input    = NULL;
+    p_sys->p_vlm      = NULL;
+
+    /* determine Content-Type value for HTML pages */
+    psz_src = config_GetPsz( p_intf, "http-charset" );
+    if( psz_src == NULL || !*psz_src )
+    {
+        if( psz_src != NULL ) free( psz_src );
+        psz_src = strdup("UTF-8");
+    }
 
-    if( ( p_sys->p_httpd = httpd_Find( VLC_OBJECT(p_intf), VLC_TRUE ) ) == NULL )
+    p_sys->psz_html_type = malloc( 20 + strlen( psz_src ) );
+    if( p_sys->psz_html_type == NULL )
     {
-        msg_Err( p_intf, "cannot create/find httpd" );
         free( p_sys );
-        return VLC_EGENERIC;
+        free( psz_src );
+        return VLC_ENOMEM ;
+    }
+    sprintf( p_sys->psz_html_type, "text/html; charset=%s", psz_src );
+    msg_Dbg( p_intf, "using charset=%s", psz_src );
+
+    if( strcmp( psz_src, "UTF-8" ) )
+    {
+        p_sys->iconv_from_utf8 = vlc_iconv_open( psz_src, "UTF-8" );
+        if( p_sys->iconv_from_utf8 == (vlc_iconv_t)-1 )
+            msg_Warn( p_intf, "unable to perform charset conversion to %s",
+                      psz_src );
+        else
+        {
+            p_sys->iconv_to_utf8 = vlc_iconv_open( "UTF-8", psz_src );
+            if( p_sys->iconv_to_utf8 == (vlc_iconv_t)-1 )
+                msg_Warn( p_intf,
+                          "unable to perform charset conversion from %s",
+                          psz_src );
+        }
+    }
+    else
+    {
+        p_sys->iconv_from_utf8 = p_sys->iconv_to_utf8 = (vlc_iconv_t)-1;
+    }
+
+    free( psz_src );
+
+    /* determine SSL configuration */
+    psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
+    if ( psz_cert != NULL )
+    {
+        msg_Dbg( p_intf, "enabling TLS for HTTP interface (cert file: %s)",
+                 psz_cert );
+        psz_key = config_GetPsz( p_intf, "http-intf-key" );
+        psz_ca = config_GetPsz( p_intf, "http-intf-ca" );
+        psz_crl = config_GetPsz( p_intf, "http-intf-crl" );
+
+        if( i_port <= 0 )
+            i_port = 8443;
+    }
+    else
+    {
+        if( i_port <= 0 )
+            i_port= 8080;
     }
 
-    if( ( p_sys->p_httpd_host =
-                p_sys->p_httpd->pf_register_host( p_sys->p_httpd,
-                                                  psz_address, i_port ) ) == NULL )
+    msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
+
+    p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
+                                            i_port, psz_cert, psz_key, psz_ca,
+                                            psz_crl );
+    if( p_sys->p_httpd_host == NULL )
     {
         msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
-        httpd_Release( p_sys->p_httpd );
+        free( p_sys->psz_html_type );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -236,23 +319,15 @@ static int Activate( vlc_object_t *p_this )
         free( psz_host );
     }
 
-    p_sys->i_files = 0;
-    p_sys->pp_files = malloc( sizeof( httpd_file_callback_args_t *) );
-    if( !p_sys->pp_files )
-    {
-        return( VLC_ENOMEM );
-    }
+    p_sys->i_files  = 0;
+    p_sys->pp_files = NULL;
 
-#if defined(SYS_DARWIN) || defined(SYS_BEOS) || \
-        ( defined(WIN32) && !defined(UNDER_CE ) )
+#if defined(SYS_DARWIN) || defined(SYS_BEOS) || defined(WIN32)
     if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
     {
         char * psz_vlcpath = p_intf->p_libvlc->psz_vlcpath;
         psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
-        if( !psz_src )
-        {
-            return( VLC_ENOMEM );
-        }
+        if( !psz_src ) return VLC_ENOMEM;
 #if defined(WIN32)
         sprintf( psz_src, "%s/http", psz_vlcpath);
 #else
@@ -297,41 +372,63 @@ static int Activate( vlc_object_t *p_this )
         goto failed;
     }
     p_intf->pf_run = Run;
+    free( psz_src );
 
     return VLC_SUCCESS;
 
 failed:
-    free( p_sys->pp_files );
-    p_sys->p_httpd->pf_unregister_host( p_sys->p_httpd,
-                                        p_sys->p_httpd_host );
-    httpd_Release( p_sys->p_httpd );
+    if( psz_src ) free( psz_src );
+    if( p_sys->pp_files )
+    {
+        free( p_sys->pp_files );
+    }
+    httpd_HostDelete( p_sys->p_httpd_host );
+    free( p_sys->psz_html_type ); 
+    if( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
+        vlc_iconv_close( p_sys->iconv_from_utf8 );
+    if( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
+        vlc_iconv_close( p_sys->iconv_to_utf8 );
     free( p_sys );
     return VLC_EGENERIC;
 }
 
 /*****************************************************************************
- * CloseIntf: destroy interface
+ * Close: destroy interface
  *****************************************************************************/
-void Close ( vlc_object_t *p_this )
+static void Close ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     intf_sys_t    *p_sys = p_intf->p_sys;
 
     int i;
 
+    if( p_sys->p_vlm )
+    {
+        vlm_Delete( p_sys->p_vlm );
+    }
     for( i = 0; i < p_sys->i_files; i++ )
     {
-       p_sys->p_httpd->pf_unregister_file( p_sys->p_httpd,
-                                           p_sys->pp_files[i]->p_file );
-       /* do not free mime */
+       httpd_FileDelete( p_sys->pp_files[i]->p_file );
+       if( p_sys->pp_files[i]->p_redir )
+           httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
+       if( p_sys->pp_files[i]->p_redir2 )
+           httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
+
        free( p_sys->pp_files[i]->file );
        free( p_sys->pp_files[i]->name );
        free( p_sys->pp_files[i] );
     }
-    free( p_sys->pp_files );
-    p_sys->p_httpd->pf_unregister_host( p_sys->p_httpd,
-                                        p_sys->p_httpd_host );
-    httpd_Release( p_sys->p_httpd );
+    if( p_sys->pp_files )
+    {
+        free( p_sys->pp_files );
+    }
+    httpd_HostDelete( p_sys->p_httpd_host );
+    free( p_sys->psz_html_type );
+
+    if( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
+        vlc_iconv_close( p_sys->iconv_from_utf8 );
+    if( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
+        vlc_iconv_close( p_sys->iconv_to_utf8 );
     free( p_sys );
 }
 
@@ -389,17 +486,18 @@ static void Run( intf_thread_t *p_intf )
 /*****************************************************************************
  * Local functions
  *****************************************************************************/
-#define MAX_DIR_SIZE 10240
+#define MAX_DIR_SIZE 2560
 
 /****************************************************************************
  * FileToUrl: create a good name for an url from filename
  ****************************************************************************/
-static char *FileToUrl( char *name )
+static char *FileToUrl( char *name, vlc_bool_t *pb_index )
 {
     char *url, *p;
 
     url = p = malloc( strlen( name ) + 1 );
 
+    *pb_index = VLC_FALSE;
     if( !url || !p )
     {
         return NULL;
@@ -436,66 +534,70 @@ static char *FileToUrl( char *name )
         if( !strncmp( p, "/index.", 7 ) )
         {
             p[1] = '\0';
+            *pb_index = VLC_TRUE;
         }
     }
     return url;
 }
 
-/****************************************************************************
- * FileToMime: XXX duplicated with modules/access_out/http.c
- ****************************************************************************/
-static struct
+static char *FromUTF8( intf_thread_t *p_intf, char *psz_utf8 )
 {
-    char *psz_ext;
-    char *psz_mime;
-} http_mime[] =
-{
-    { ".htm",   "text/html" },
-    { ".html",  "text/html" },
-
-    { ".css",   "text/css" },
-
-    /* media mime */
-    { ".avi",   "video/avi" },
-    { ".asf",   "video/x-ms-asf" },
-    { ".m1a",   "audio/mpeg" },
-    { ".m2a",   "audio/mpeg" },
-    { ".m1v",   "video/mpeg" },
-    { ".m2v",   "video/mpeg" },
-    { ".mp2",   "audio/mpeg" },
-    { ".mp3",   "audio/mpeg" },
-    { ".mpa",   "audio/mpeg" },
-    { ".mpg",   "video/mpeg" },
-    { ".mpeg",  "video/mpeg" },
-    { ".mpe",   "video/mpeg" },
-    { ".mov",   "video/quicktime" },
-    { ".moov",  "video/quicktime" },
-    { ".ogg",   "application/ogg" },
-    { ".ogm",   "application/ogg" },
-    { ".wav",   "audio/wav" },
+    intf_sys_t    *p_sys = p_intf->p_sys;
 
-    /* end */
-    { NULL,     NULL }
-};
+    if ( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
+    {
+        char *psz_in = psz_utf8;
+        size_t i_in = strlen(psz_in);
+        size_t i_out = i_in * 2;
+        char *psz_local = malloc(i_out + 1);
+        char *psz_out = psz_local;
+
+        size_t i_ret = vlc_iconv( p_sys->iconv_from_utf8, &psz_in, &i_in,
+                                  &psz_out, &i_out );
+        if( i_ret == (size_t)-1 || i_in )
+        {
+            msg_Warn( p_intf,
+                      "failed to convert \"%s\" to desired charset (%s)",
+                      psz_utf8, strerror(errno) );
+            free( psz_local );
+            return strdup( psz_utf8 );
+        }
+
+        *psz_out = '\0';
+        return psz_local;
+    }
+    else
+        return strdup( psz_utf8 );
+}
 
-static char *FileToMime( char *psz_name )
+static char *ToUTF8( intf_thread_t *p_intf, char *psz_local )
 {
-    char *psz_ext;
+    intf_sys_t    *p_sys = p_intf->p_sys;
 
-    psz_ext = strrchr( psz_name, '.' );
-    if( psz_ext )
+    if ( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
     {
-        int i;
+        char *psz_in = psz_local;
+        size_t i_in = strlen(psz_in);
+        size_t i_out = i_in * 6;
+        char *psz_utf8 = malloc(i_out + 1);
+        char *psz_out = psz_utf8;
 
-        for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
+        size_t i_ret = vlc_iconv( p_sys->iconv_to_utf8, &psz_in, &i_in,
+                                  &psz_out, &i_out );
+        if( i_ret == (size_t)-1 || i_in )
         {
-            if( !strcmp( http_mime[i].psz_ext, psz_ext ) )
-            {
-                return( http_mime[i].psz_mime );
-            }
+            msg_Warn( p_intf,
+                      "failed to convert \"%s\" to desired charset (%s)",
+                      psz_local, strerror(errno) );
+            free( psz_utf8 );
+            return strdup( psz_local );
         }
+
+        *psz_out = '\0';
+        return psz_utf8;
     }
-    return( "application/octet-stream" );
+    else
+        return strdup( psz_local );
 }
 
 /****************************************************************************
@@ -511,11 +613,14 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
 #endif
     DIR           *p_dir;
     struct dirent *p_dir_content;
+    vlc_acl_t     *p_acl;
     FILE          *file;
 
     char          *user = NULL;
     char          *password = NULL;
 
+    int           i_dirlen;
+
 #ifdef HAVE_SYS_STAT_H
     if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
     {
@@ -529,6 +634,13 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
         return VLC_EGENERIC;
     }
 
+    i_dirlen = strlen( psz_dir );
+    if( i_dirlen + 10 > MAX_DIR_SIZE )
+    {
+        msg_Warn( p_intf, "skipping too deep dir (%s)", psz_dir );
+        return 0;
+    }
+
     msg_Dbg( p_intf, "dir=%s", psz_dir );
 
     sprintf( dir, "%s/.access", psz_dir );
@@ -565,6 +677,14 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
         fclose( file );
     }
 
+    sprintf( dir, "%s/.hosts", psz_dir );
+    p_acl = ACL_Create( p_intf, VLC_FALSE );
+    if( ACL_LoadFile( p_acl, dir ) )
+    {
+        ACL_Destroy( p_acl );
+        p_acl = NULL;
+    }
+
     for( ;; )
     {
         /* parse psz_src dir */
@@ -573,81 +693,74 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
             break;
         }
 
-        if( p_dir_content->d_name[0] == '.' )
-        {
+        if( p_dir_content->d_name[0] == '.' )
+         || ( i_dirlen + strlen( p_dir_content->d_name ) > MAX_DIR_SIZE ) )
             continue;
-        }
+
         sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
         if( ParseDirectory( p_intf, psz_root, dir ) )
         {
-#define f p_sys->pp_files[p_sys->i_files]
-            f = malloc( sizeof( httpd_file_callback_args_t ) );
-            if( !f )
-            {
-                msg_Err( p_intf, "Out of memory" );
-                return( VLC_ENOMEM );
-            }
-            f->p_intf  = p_intf;
-            f->file = strdup( dir );
-            f->name = FileToUrl( &dir[strlen( psz_root )] );
-            f->mime = FileToMime( &dir[strlen( psz_root )] );
+            httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
+            vlc_bool_t b_index;
+            char *psz_tmp;
 
-            if( !f->name || !f->mime )
+            f->p_intf  = p_intf;
+            f->p_file = NULL;
+            f->p_redir = NULL;
+            f->p_redir2 = NULL;
+            psz_tmp = vlc_fix_readdir_charset( p_intf, dir );
+            f->file = FromUTF8( p_intf, psz_tmp );
+            free( psz_tmp );
+            psz_tmp = vlc_fix_readdir_charset( p_intf,
+                                               &dir[strlen( psz_root )] );
+            f->name = FileToUrl( psz_tmp, &b_index );
+            free( psz_tmp );
+            f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
+
+            if( !f->name )
             {
-                msg_Err( p_intf , "Unable to parse directory" );
+                msg_Err( p_intf , "unable to parse directory" );
+                closedir( p_dir );
+                free( f );
                 return( VLC_ENOMEM );
             }
-            msg_Dbg( p_intf, "file=%s (url=%s mime=%s)",
-                     f->file, f->name, f->mime );
-
-            f->p_file =
-                p_sys->p_httpd->pf_register_file( p_sys->p_httpd,
-                                                  f->name, f->mime,
-                                                  user, password,
-                                                  http_get, http_get,
-                                                  f );
+            msg_Dbg( p_intf, "file=%s (url=%s)",
+                     f->file, f->name );
+
+            f->p_file = httpd_FileNew( p_sys->p_httpd_host,
+                                       f->name,
+                                       f->b_html ? p_sys->psz_html_type : NULL,
+                                       user, password, p_acl,
+                                       HttpCallback, f );
+
             if( f->p_file )
             {
-                p_sys->i_files++;
-                p_sys->pp_files = realloc( p_sys->pp_files,
-                  (p_sys->i_files+1) * sizeof( httpd_file_callback_args_t ) );
+                TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
             }
-#define fold p_sys->pp_files[p_sys->i_files-1]
-
-            /* FIXME for rep/ add rep (it would be better to do a redirection) */
-            if( p_sys->i_files && strlen(fold->name) > 1 &&
-                fold->name[strlen(fold->name) - 1] == '/' )
+            /* for url that ends by / add
+             *  - a redirect from rep to rep/
+             *  - in case of index.* rep/index.html to rep/ */
+            if( f && f->name[strlen(f->name) - 1] == '/' )
             {
-                f = malloc( sizeof( httpd_file_callback_args_t ) );
-                if( !f )
-                {
-                    msg_Err( p_intf, "Out of memory" );
-                    return( VLC_ENOMEM );
-                }
-                f->p_intf  = p_intf;
-                f->file = strdup( fold->file );
-                f->name = strdup( fold->name );
-                f->mime = fold->mime;
-
-                f->name[strlen(f->name) - 1] = '\0';
-                msg_Dbg( p_intf, "file=%s (url=%s mime=%s)", f->file, f->name,
-                         f->mime );
-                f->p_file =
-                    p_sys->p_httpd->pf_register_file( p_sys->p_httpd,
-                                                      f->name, f->mime,
-                                                      user, password,
-                                                      http_get, http_get,
-                                                      f );
-                if( f->p_file )
+                char *psz_redir = strdup( f->name );
+                char *p;
+                psz_redir[strlen( psz_redir ) - 1] = '\0';
+
+                msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
+                f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
+                free( psz_redir );
+
+                if( b_index && ( p = strstr( f->file, "index." ) ) )
                 {
-                    p_sys->i_files++;
-                    p_sys->pp_files =
-                        realloc( p_sys->pp_files, (p_sys->i_files+1) *
-                                 sizeof( httpd_file_callback_args_t ) );
+                    asprintf( &psz_redir, "%s%s", f->name, p );
+
+                    msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
+                    f->p_redir2 = httpd_RedirectNew( p_sys->p_httpd_host,
+                                                     f->name, psz_redir );
+
+                    free( psz_redir );
                 }
             }
-#undef fold
-#undef f
         }
     }
 
@@ -659,6 +772,10 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
     {
         free( password );
     }
+
+    ACL_Destroy( p_acl );
+    closedir( p_dir );
+
     return VLC_SUCCESS;
 }
 
@@ -666,7 +783,7 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
  * var and set handling
  ****************************************************************************/
 
-static mvar_t *mvar_New( char *name, char *value )
+static mvar_t *mvar_New( const char *name, const char *value )
 {
     mvar_t *v = malloc( sizeof( mvar_t ) );
 
@@ -703,7 +820,7 @@ static void mvar_AppendVar( mvar_t *v, mvar_t *f )
     v->i_field++;
 }
 
-static mvar_t *mvar_Duplicate( mvar_t *v )
+static mvar_t *mvar_Duplicate( const mvar_t *v )
 {
     int i;
     mvar_t *n;
@@ -751,7 +868,7 @@ static void mvar_RemoveVar( mvar_t *v, mvar_t *f )
     /* FIXME should do a realloc */
 }
 
-static mvar_t *mvar_GetVar( mvar_t *s, char *name )
+static mvar_t *mvar_GetVar( mvar_t *s, const char *name )
 {
     int i;
     char base[512], *field, *p;
@@ -832,13 +949,15 @@ static char *mvar_GetValue( mvar_t *v, char *field )
     }
 }
 
-static void mvar_PushNewVar( mvar_t *vars, char *name, char *value )
+static void mvar_PushNewVar( mvar_t *vars, const char *name,
+                             const char *value )
 {
     mvar_t *f = mvar_New( name, value );
     mvar_PushVar( vars, f );
 }
 
-static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
+static void mvar_AppendNewVar( mvar_t *vars, const char *name,
+                               const char *value )
 {
     mvar_t *f = mvar_New( name, value );
     mvar_AppendVar( vars, f );
@@ -846,13 +965,12 @@ static void mvar_AppendNewVar( mvar_t *vars, char *name, char *value )
 
 
 /* arg= start[:stop[:step]],.. */
-static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
+static mvar_t *mvar_IntegerSetNew( const char *name, const char *arg )
 {
     char *dup = strdup( arg );
     char *str = dup;
     mvar_t *s = mvar_New( name, "set" );
 
-    fprintf( stderr," mvar_IntegerSetNew: name=`%s' arg=`%s'\n", name, str );
 
     while( str )
     {
@@ -868,7 +986,6 @@ static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
 
         i_step = 0;
         i_match = sscanf( str, "%d:%d:%d", &i_start, &i_stop, &i_step );
-        fprintf( stderr," mvar_IntegerSetNew: m=%d start=%d stop=%d step=%d\n", i_match, i_start, i_stop, i_step );
 
         if( i_match == 1 )
         {
@@ -884,12 +1001,12 @@ static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
         {
             int i;
 
-            if( ( i_start < i_stop && i_step > 0 ) ||
-                ( i_start > i_stop && i_step < 0 ) )
+            if( ( i_start <= i_stop && i_step > 0 ) ||
+                ( i_start >= i_stop && i_step < 0 ) )
             {
                 for( i = i_start; ; i += i_step )
                 {
-                    char   value[512];
+                    char   value[79];
 
                     if( ( i_step > 0 && i > i_stop ) ||
                         ( i_step < 0 && i < i_stop ) )
@@ -897,7 +1014,6 @@ static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
                         break;
                     }
 
-                    fprintf( stderr," mvar_IntegerSetNew: adding %d\n", i );
                     sprintf( value, "%d", i );
 
                     mvar_PushNewVar( s, name, value );
@@ -911,86 +1027,250 @@ static mvar_t *mvar_IntegerSetNew( char *name, char *arg )
     return s;
 }
 
-static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
+static void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl,
+                              playlist_item_t *p_node, char *name, mvar_t *s,
+                              int i_depth )
 {
-    mvar_t *s = mvar_New( name, "set" );
-    int    i;
+    if( p_node != NULL )
+    {
+        if( p_node->i_children == -1 )
+        {
+            char value[512];
+            char *psz;
+            mvar_t *itm = mvar_New( name, "set" );
 
-    fprintf( stderr," mvar_PlaylistSetNew: name=`%s'\n", name );
+            sprintf( value, "%d", ( p_pl->status.p_item == p_node )? 1 : 0 );
+            mvar_AppendNewVar( itm, "current", value );
 
-    vlc_mutex_lock( &p_pl->object_lock );
-    for( i = 0; i < p_pl->i_size; i++ )
-    {
-        mvar_t *itm = mvar_New( name, "set" );
-        char   value[512];
+            sprintf( value, "%d", p_node->input.i_id );
+            mvar_AppendNewVar( itm, "index", value );
+
+            psz = FromUTF8( p_intf, p_node->input.psz_name );
+            mvar_AppendNewVar( itm, "name", psz );
+            free( psz );
+
+            psz = FromUTF8( p_intf, p_node->input.psz_uri );
+            mvar_AppendNewVar( itm, "uri", psz );
+            free( psz );
+
+            sprintf( value, "Item");
+            mvar_AppendNewVar( itm, "type", value );
+
+            sprintf( value, "%d", i_depth );
+            mvar_AppendNewVar( itm, "depth", value );
+
+            mvar_AppendVar( s, itm );
+        }
+        else
+        {
+            char value[512];
+            char *psz;
+            int i_child;
+            mvar_t *itm = mvar_New( name, "set" );
 
-        sprintf( value, "%d", i == p_pl->i_index ? 1 : 0 );
-        mvar_AppendNewVar( itm, "current", value );
+            psz = FromUTF8( p_intf, p_node->input.psz_name );
+            mvar_AppendNewVar( itm, "name", psz );
+            mvar_AppendNewVar( itm, "uri", psz );
+            free( psz );
 
-        sprintf( value, "%d", i );
-        mvar_AppendNewVar( itm, "index", value );
+            sprintf( value, "Node" );
+            mvar_AppendNewVar( itm, "type", value );
 
-        mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->psz_name );
+            sprintf( value, "%d", p_node->input.i_id );
+            mvar_AppendNewVar( itm, "index", value );
 
-        sprintf( value, "%d", p_pl->pp_items[i]->i_group );
-        mvar_AppendNewVar( itm, "group", value );
+            sprintf( value, "%d", p_node->i_children);
+            mvar_AppendNewVar( itm, "i_children", value );
 
-        mvar_AppendVar( s, itm );
+            sprintf( value, "%d", i_depth );
+            mvar_AppendNewVar( itm, "depth", value );
+
+            mvar_AppendVar( s, itm );
+
+            for (i_child = 0 ; i_child < p_node->i_children ; i_child++)
+                PlaylistListNode( p_intf, p_pl, p_node->pp_children[i_child],
+                                  name, s, i_depth + 1);
+
+        }
     }
+}
+
+static mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,
+                                    playlist_t *p_pl )
+{
+    playlist_view_t *p_view;
+    mvar_t *s = mvar_New( name, "set" );
+
+
+    vlc_mutex_lock( &p_pl->object_lock );
+
+    p_view = playlist_ViewFind( p_pl, VIEW_CATEGORY ); /* FIXME */
+
+    if( p_view != NULL )
+        PlaylistListNode( p_intf, p_pl, p_view->p_root, name, s, 0 );
+
     vlc_mutex_unlock( &p_pl->object_lock );
 
     return s;
 }
 
-static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
+static mvar_t *mvar_InfoSetNew( intf_thread_t *p_intf, char *name,
+                                input_thread_t *p_input )
 {
     mvar_t *s = mvar_New( name, "set" );
+    int i, j;
 
-    input_info_category_t * p_category;
-    input_info_t * p_info;
-
-    fprintf( stderr," mvar_InfoSetNew: name=`%s'\n", name );
     if( p_input == NULL )
     {
         return s;
     }
 
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    p_category = p_input->stream.p_info;
-    while ( p_category )
+    vlc_mutex_lock( &p_input->input.p_item->lock );
+    for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
     {
+        info_category_t *p_category = p_input->input.p_item->pp_categories[i];
+        char *psz;
+
         mvar_t *cat  = mvar_New( name, "set" );
         mvar_t *iset = mvar_New( "info", "set" );
 
-        mvar_AppendNewVar( cat, "name", p_category->psz_name );
+        psz = FromUTF8( p_intf, p_category->psz_name );
+        mvar_AppendNewVar( cat, "name", psz );
+        free( psz );
         mvar_AppendVar( cat, iset );
 
-        p_info = p_category->p_info;
-        while ( p_info )
+        for ( j = 0; j < p_category->i_infos; j++ )
         {
+            info_t *p_info = p_category->pp_infos[j];
             mvar_t *info = mvar_New( "info", "" );
-
-            msg_Dbg( p_input, "adding info name=%s value=%s", p_info->psz_name, p_info->psz_value );
-            mvar_AppendNewVar( info, "name",  p_info->psz_name );
-            mvar_AppendNewVar( info, "value", p_info->psz_value );
+            char *psz_name = FromUTF8( p_intf, p_info->psz_name );
+            char *psz_value = FromUTF8( p_intf, p_info->psz_value );
+
+            msg_Dbg( p_input, "adding info name=%s value=%s",
+                     psz_name, psz_value );
+            mvar_AppendNewVar( info, "name",  psz_name );
+            mvar_AppendNewVar( info, "value", psz_value );
+            free( psz_name );
+            free( psz_value );
             mvar_AppendVar( iset, info );
-            p_info = p_info->p_next;
         }
         mvar_AppendVar( s, cat );
-        p_category = p_category->p_next;
     }
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
+    vlc_mutex_unlock( &p_input->input.p_item->lock );
+
+    return s;
+}
+
+static mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
+                                    input_thread_t *p_input,
+                                    const char *psz_variable )
+{
+    intf_sys_t     *p_sys = p_intf->p_sys;
+    mvar_t *s = mvar_New( name, "set" );
+    vlc_value_t val, val_list, text_list;
+    int i_type, i;
+
+    if( p_input == NULL )
+    {
+        return s;
+    }
+
+    /* Check the type of the object variable */
+    i_type = var_Type( p_sys->p_input, psz_variable );
+
+    /* Make sure we want to display the variable */
+    if( i_type & VLC_VAR_HASCHOICE )
+    {
+        var_Change( p_sys->p_input, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
+        if( val.i_int == 0 ) return s;
+        if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
+            return s;
+    }
+    else
+    {
+        return s;
+    }
+
+    switch( i_type & VLC_VAR_TYPE )
+    {
+    case VLC_VAR_VOID:
+    case VLC_VAR_BOOL:
+    case VLC_VAR_VARIABLE:
+    case VLC_VAR_STRING:
+    case VLC_VAR_INTEGER:
+        break;
+    default:
+        /* Variable doesn't exist or isn't handled */
+        return s;
+    }
+
+    if( var_Get( p_sys->p_input, psz_variable, &val ) < 0 )
+    {
+        return s;
+    }
+
+    if( var_Change( p_sys->p_input, psz_variable, VLC_VAR_GETLIST,
+                    &val_list, &text_list ) < 0 )
+    {
+        if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
+        return s;
+    }
+
+    for( i = 0; i < val_list.p_list->i_count; i++ )
+    {
+        char *psz, psz_int[16];
+        mvar_t *itm;
+
+        switch( i_type & VLC_VAR_TYPE )
+        {
+        case VLC_VAR_STRING:
+            itm = mvar_New( name, "set" );
+            psz = FromUTF8( p_intf, text_list.p_list->p_values[i].psz_string );
+            mvar_AppendNewVar( itm, "name", psz );
+            psz = FromUTF8( p_intf, val_list.p_list->p_values[i].psz_string );
+            mvar_AppendNewVar( itm, "id", psz );
+            free( psz );
+            snprintf( psz_int, sizeof(psz_int), "%d",
+                      ( !strcmp( val.psz_string,
+                                   val_list.p_list->p_values[i].psz_string )
+                           && !( i_type & VLC_VAR_ISCOMMAND ) ) );
+            mvar_AppendNewVar( itm, "selected", psz_int );
+            mvar_AppendVar( s, itm );
+            break;
+
+        case VLC_VAR_INTEGER:
+            itm = mvar_New( name, "set" );
+            psz = FromUTF8( p_intf, text_list.p_list->p_values[i].psz_string );
+            mvar_AppendNewVar( itm, "name", psz );
+            snprintf( psz_int, sizeof(psz_int), "%d",
+                      val_list.p_list->p_values[i].i_int );
+            mvar_AppendNewVar( itm, "id", psz_int );
+            snprintf( psz_int, sizeof(psz_int), "%d",
+                      ( val.i_int == val_list.p_list->p_values[i].i_int )
+                         && !( i_type & VLC_VAR_ISCOMMAND ) );
+            mvar_AppendNewVar( itm, "selected", psz_int );
+            mvar_AppendVar( s, itm );
+            break;
 
+        default:
+            break;
+        }
+    }
+    
+    /* clean up everything */
+    if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
+    var_Change( p_sys->p_input, psz_variable, VLC_VAR_FREELIST, &val_list,
+                &text_list );
     return s;
 }
 
+#if 0
 static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
 {
     mvar_t       *s = mvar_New( name, "set" );
     httpd_info_t info;
     int          i;
 
-    fprintf( stderr," mvar_HttpdInfoSetNew: name=`%s'\n", name );
     if( !p_httpd->pf_control( p_httpd, i_type, &info, NULL ) )
     {
         for( i= 0; i < info.i_count; )
@@ -1017,18 +1297,37 @@ static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
         free( info.info[i].psz_name );
         free( info.info[i].psz_value );
     }
+    if( info.i_count > 0 )
+    {
+        free( info.info );
+    }
 
     return s;
 }
-static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
+#endif
+
+/* Utility function for scandir */
+static int Filter( const struct dirent *foo )
+{
+    return VLC_TRUE;
+}
+
+static int InsensitiveAlphasort( const struct dirent **foo1,
+                                 const struct dirent **foo2 )
+{
+    return strcasecmp( (*foo1)->d_name, (*foo2)->d_name );
+}
+
+static mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
+                                char *psz_dir )
 {
     mvar_t *s = mvar_New( name, "set" );
-    char           tmp[MAX_DIR_SIZE], *p, *src;
+    char          tmp[MAX_DIR_SIZE], dir[MAX_DIR_SIZE], *p, *src;
 #ifdef HAVE_SYS_STAT_H
     struct stat   stat_info;
 #endif
-    DIR           *p_dir;
-    struct dirent *p_dir_content;
+    struct dirent **pp_dir_content;
+    int           i_dir_content, i;
     char          sep;
 
     /* convert all / to native separator */
@@ -1066,6 +1365,15 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
     {
         return s;
     }
+
+    if( *psz_dir == '~' )
+    {
+        /* This is incomplete : we should also support the ~cmassiot/ syntax. */
+        snprintf( dir, sizeof(dir), "%s/%s", p_intf->p_vlc->psz_homedir,
+                  psz_dir + 1 );
+        psz_dir = dir;
+    }
+
     /* first fix all .. dir */
     p = src = psz_dir;
     while( *src )
@@ -1106,8 +1414,6 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
     }
     *p = '\0';
 
-    fprintf( stderr," mvar_FileSetNew: name=`%s' dir=`%s'\n", name, psz_dir );
-
 #ifdef HAVE_SYS_STAT_H
     if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
     {
@@ -1115,37 +1421,35 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
     }
 #endif
 
-    if( ( p_dir = opendir( psz_dir ) ) == NULL )
+    /* parse psz_src dir */
+    if( ( i_dir_content = scandir( psz_dir, &pp_dir_content, Filter,
+                                   InsensitiveAlphasort ) ) == -1 )
     {
-        fprintf( stderr, "cannot open dir (%s)", psz_dir );
+        msg_Warn( p_intf, "scandir error on %s (%s)", psz_dir,
+                  strerror(errno) );
         return s;
     }
 
-    /* remove traling / or \ */
-    for( p = &psz_dir[strlen( psz_dir) - 1]; p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
+    /* remove trailing / or \ */
+    for( p = &psz_dir[strlen( psz_dir) - 1];
+         p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
     {
         *p = '\0';
     }
 
-    for( ;; )
+    for( i = 0; i < i_dir_content; i++ )
     {
+        struct dirent *p_dir_content = pp_dir_content[i];
         mvar_t *f;
+        const char *psz_ext;
+        char *psz_name, *psz_tmp;
 
-        /* parse psz_src dir */
-        if( ( p_dir_content = readdir( p_dir ) ) == NULL )
-        {
-            break;
-        }
         if( !strcmp( p_dir_content->d_name, "." ) )
         {
             continue;
         }
 
-#if defined( WIN32 )
-        sprintf( tmp, "%s\\%s", psz_dir, p_dir_content->d_name );
-#else
-        sprintf( tmp, "%s/%s", psz_dir, p_dir_content->d_name );
-#endif
+        snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, p_dir_content->d_name );
 
 #ifdef HAVE_SYS_STAT_H
         if( stat( tmp, &stat_info ) == -1 )
@@ -1154,7 +1458,20 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
         }
 #endif
         f = mvar_New( name, "set" );
+
+        psz_tmp = vlc_fix_readdir_charset( p_intf, p_dir_content->d_name );
+        psz_name = FromUTF8( p_intf, psz_tmp );
+        free( psz_tmp );
+        snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, psz_name );
         mvar_AppendNewVar( f, "name", tmp );
+        mvar_AppendNewVar( f, "basename", psz_name );
+
+        /* put file extension in 'ext' */
+        psz_ext = strrchr( psz_name, '.' );
+        mvar_AppendNewVar( f, "ext", psz_ext != NULL ? psz_ext + 1 : "" );
+
+        free( psz_name );
+
 #ifdef HAVE_SYS_STAT_H
         if( S_ISDIR( stat_info.st_mode ) )
         {
@@ -1169,7 +1486,7 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
             mvar_AppendNewVar( f, "type", "unknown" );
         }
 
-        sprintf( tmp, "%lld", stat_info.st_size );
+        sprintf( tmp, I64Fd, (int64_t)stat_info.st_size );
         mvar_AppendNewVar( f, "size", tmp );
 
         /* FIXME memory leak FIXME */
@@ -1191,9 +1508,85 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
     return s;
 }
 
+static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
+{
+    mvar_t        *s = mvar_New( name, "set" );
+    vlm_message_t *msg;
+    int    i;
+
+    if( vlm == NULL ) return s;
+
+    if( vlm_ExecuteCommand( vlm, "show", &msg ) )
+    {
+        return s;
+    }
+
+    for( i = 0; i < msg->i_child; i++ )
+    {
+        /* Over media, schedule */
+        vlm_message_t *ch = msg->child[i];
+        int j;
+
+        for( j = 0; j < ch->i_child; j++ )
+        {
+            /* Over name */
+            vlm_message_t *el = ch->child[j];
+            vlm_message_t *inf, *desc;
+            mvar_t        *set;
+            char          psz[500];
+            int k;
+
+            sprintf( psz, "show %s", el->psz_name );
+            if( vlm_ExecuteCommand( vlm, psz, &inf ) )
+                continue;
+            desc = inf->child[0];
+
+            /* Add a node with name and info */
+            set = mvar_New( name, "set" );
+            mvar_AppendNewVar( set, "name", el->psz_name );
+
+            for( k = 0; k < desc->i_child; k++ )
+            {
+                vlm_message_t *ch = desc->child[k];
+                if( ch->i_child > 0 )
+                {
+                    int c;
+                    mvar_t *n = mvar_New( ch->psz_name, "set" );
+
+                    for( c = 0; c < ch->i_child; c++ )
+                    {
+                        if( ch->child[c]->psz_value )
+                        {
+                            mvar_AppendNewVar( n, ch->child[c]->psz_name, ch->child[c]->psz_value );
+                        }
+                        else
+                        {
+                            mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
+                            mvar_AppendVar( n, in );
+                        }
+                    }
+                    mvar_AppendVar( set, n );
+                }
+                else
+                {
+                    mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
+                }
+            }
+            vlm_MessageDelete( inf );
+
+            mvar_AppendVar( s, set );
+        }
+    }
+    vlm_MessageDelete( msg );
+
+    return s;
+}
+
+
 static void SSInit( rpn_stack_t * );
 static void SSClean( rpn_stack_t * );
-static void EvaluateRPN( mvar_t  *, rpn_stack_t *, char * );
+static void EvaluateRPN( intf_thread_t *p_intf, mvar_t  *, rpn_stack_t *,
+                         char * );
 
 static void SSPush  ( rpn_stack_t *, char * );
 static char *SSPop  ( rpn_stack_t * );
@@ -1212,19 +1605,197 @@ typedef struct
     char *param2;
 } macro_t;
 
-static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
+static void Seek( intf_thread_t *p_intf, char *p_value )
 {
-    int i_read;
-
-    /* just load the file */
-    *pi_data = 0;
-    *pp_data = malloc( 1025 );  /* +1 for \0 */
-    while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
+    intf_sys_t     *p_sys = p_intf->p_sys;
+    vlc_value_t val;
+    int i_stock = 0;
+    uint64_t i_length;
+    int i_value = 0;
+    int i_relative = 0;
+#define POSITION_ABSOLUTE 12
+#define POSITION_REL_FOR 13
+#define POSITION_REL_BACK 11
+#define VL_TIME_ABSOLUTE 0
+#define VL_TIME_REL_FOR 1
+#define VL_TIME_REL_BACK -1
+    if( p_sys->p_input )
     {
-        *pi_data += 1024;
-        *pp_data = realloc( *pp_data, *pi_data  + 1025 );
-    }
-    if( i_read > 0 )
+        var_Get( p_sys->p_input, "length", &val );
+        i_length = val.i_time;
+
+        while( p_value[0] != '\0' )
+        {
+            switch(p_value[0])
+            {
+                case '+':
+                {
+                    i_relative = VL_TIME_REL_FOR;
+                    p_value++;
+                    break;
+                }
+                case '-':
+                {
+                    i_relative = VL_TIME_REL_BACK;
+                    p_value++;
+                    break;
+                }
+                case '0': case '1': case '2': case '3': case '4':
+                case '5': case '6': case '7': case '8': case '9':
+                {
+                    i_stock = strtol( p_value , &p_value , 10 );
+                    break;
+                }
+                case '%': /* for percentage ie position */
+                {
+                    i_relative += POSITION_ABSOLUTE;
+                    i_value = i_stock;
+                    i_stock = 0;
+                    p_value[0] = '\0';
+                    break;
+                }
+                case ':':
+                {
+                    i_value = 60 * (i_value + i_stock) ;
+                    i_stock = 0;
+                    p_value++;
+                    break;
+                }
+                case 'h': case 'H': /* hours */
+                {
+                    i_value += 3600 * i_stock;
+                    i_stock = 0;
+                    /* other characters which are not numbers are not important */
+                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    {
+                        p_value++;
+                    }
+                    break;
+                }
+                case 'm': case 'M': case '\'': /* minutes */
+                {
+                    i_value += 60 * i_stock;
+                    i_stock = 0;
+                    p_value++;
+                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    {
+                        p_value++;
+                    }
+                    break;
+                }
+                case 's': case 'S': case '"':  /* seconds */
+                {
+                    i_value += i_stock;
+                    i_stock = 0;
+                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    {
+                        p_value++;
+                    }
+                    break;
+                }
+                default:
+                {
+                    p_value++;
+                    break;
+                }
+            }
+        }
+
+        /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
+        i_value += i_stock;
+
+        switch(i_relative)
+        {
+            case VL_TIME_ABSOLUTE:
+            {
+                if( (uint64_t)( i_value ) * 1000000 <= i_length )
+                    val.i_time = (uint64_t)( i_value ) * 1000000;
+                else
+                    val.i_time = i_length;
+
+                var_Set( p_sys->p_input, "time", val );
+                msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
+                break;
+            }
+            case VL_TIME_REL_FOR:
+            {
+                var_Get( p_sys->p_input, "time", &val );
+                if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
+                {
+                    val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
+                } else
+                {
+                    val.i_time = i_length;
+                }
+                var_Set( p_sys->p_input, "time", val );
+                msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
+                break;
+            }
+            case VL_TIME_REL_BACK:
+            {
+                var_Get( p_sys->p_input, "time", &val );
+                if( (int64_t)( i_value ) * 1000000 > val.i_time )
+                {
+                    val.i_time = 0;
+                } else
+                {
+                    val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
+                }
+                var_Set( p_sys->p_input, "time", val );
+                msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
+                break;
+            }
+            case POSITION_ABSOLUTE:
+            {
+                val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                var_Set( p_sys->p_input, "position", val );
+                msg_Dbg( p_intf, "requested seek percent: %d", i_value );
+                break;
+            }
+            case POSITION_REL_FOR:
+            {
+                var_Get( p_sys->p_input, "position", &val );
+                val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                var_Set( p_sys->p_input, "position", val );
+                msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
+                break;
+            }
+            case POSITION_REL_BACK:
+            {
+                var_Get( p_sys->p_input, "position", &val );
+                val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                var_Set( p_sys->p_input, "position", val );
+                msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
+                break;
+            }
+            default:
+            {
+                msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
+                break;
+            }
+        }
+    }
+#undef POSITION_ABSOLUTE
+#undef POSITION_REL_FOR
+#undef POSITION_REL_BACK
+#undef VL_TIME_ABSOLUTE
+#undef VL_TIME_REL_FOR
+#undef VL_TIME_REL_BACK
+}
+
+static int FileLoad( FILE *f, char **pp_data, int *pi_data )
+{
+    int i_read;
+
+    /* just load the file */
+    *pi_data = 0;
+    *pp_data = malloc( 1025 );  /* +1 for \0 */
+    while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 )
+    {
+        *pi_data += 1024;
+        *pp_data = realloc( *pp_data, *pi_data  + 1025 );
+    }
+    if( i_read > 0 )
     {
         *pi_data += i_read;
     }
@@ -1233,11 +1804,11 @@ static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data )
     return VLC_SUCCESS;
 }
 
-static int MacroParse( macro_t *m, uint8_t *psz_src )
+static int MacroParse( macro_t *m, char *psz_src )
 {
-    uint8_t *dup = strdup( psz_src );
-    uint8_t *src = dup;
-    uint8_t *p;
+    char *dup = strdup( (char *)psz_src );
+    char *src = dup;
+    char *p;
     int     i_skip;
 
 #define EXTRACT( name, l ) \
@@ -1335,14 +1906,28 @@ enum macroType
         MVLC_SEEK,
         MVLC_KEEP,
         MVLC_SORT,
+        MVLC_MOVE,
         MVLC_VOLUME,
         MVLC_FULLSCREEN,
 
         MVLC_CLOSE,
         MVLC_SHUTDOWN,
+
+        MVLC_VLM_NEW,
+        MVLC_VLM_SETUP,
+        MVLC_VLM_DEL,
+        MVLC_VLM_PLAY,
+        MVLC_VLM_PAUSE,
+        MVLC_VLM_STOP,
+        MVLC_VLM_SEEK,
+        MVLC_VLM_LOAD,
+        MVLC_VLM_SAVE,
+
+    MVLC_INCLUDE,
     MVLC_FOREACH,
     MVLC_IF,
     MVLC_RPN,
+    MVLC_STACK,
     MVLC_ELSE,
     MVLC_END,
     MVLC_GET,
@@ -1378,21 +1963,35 @@ StrToMacroTypeTab [] =
         { "delete",         MVLC_DEL },
         { "empty",          MVLC_EMPTY },
         { "sort",           MVLC_SORT },
+        { "move",           MVLC_MOVE },
 
         /* admin control */
         { "close",          MVLC_CLOSE },
         { "shutdown",       MVLC_SHUTDOWN },
 
+        /* vlm control */
+        { "vlm_new",        MVLC_VLM_NEW },
+        { "vlm_setup",      MVLC_VLM_SETUP },
+        { "vlm_del",        MVLC_VLM_DEL },
+        { "vlm_play",       MVLC_VLM_PLAY },
+        { "vlm_pause",      MVLC_VLM_PAUSE },
+        { "vlm_stop",       MVLC_VLM_STOP },
+        { "vlm_seek",       MVLC_VLM_SEEK },
+        { "vlm_load",       MVLC_VLM_LOAD },
+        { "vlm_save",       MVLC_VLM_SAVE },
+
     { "rpn",        MVLC_RPN },
+    { "stack",      MVLC_STACK },
 
+    { "include",    MVLC_INCLUDE },
     { "foreach",    MVLC_FOREACH },
     { "value",      MVLC_VALUE },
 
     { "if",         MVLC_IF },
     { "else",       MVLC_ELSE },
     { "end",        MVLC_END },
-    { "get",         MVLC_GET },
-    { "set",         MVLC_SET },
+    { "get",        MVLC_GET },
+    { "set",        MVLC_SET },
         { "int",            MVLC_INT },
         { "float",          MVLC_FLOAT },
         { "string",         MVLC_STRING },
@@ -1419,11 +2018,11 @@ static int StrToMacroType( char *name )
     return MVLC_UNKNOWN;
 }
 
-static void MacroDo( httpd_file_callback_args_t *p_args,
+static void MacroDo( httpd_file_sys_t *p_args,
                      macro_t *m,
-                     uint8_t *p_request, int i_request,
-                     uint8_t **pp_data,  int *pi_data,
-                     uint8_t **pp_dst )
+                     char *p_request, int i_request,
+                     char **pp_data,  int *pi_data,
+                     char **pp_dst )
 {
     intf_thread_t  *p_intf = p_args->p_intf;
     intf_sys_t     *p_sys = p_args->p_intf->p_sys;
@@ -1476,30 +2075,29 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
 
                     uri_extract_value( p_request, "item", item, 512 );
                     i_item = atoi( item );
-                    playlist_Command( p_sys->p_playlist, PLAYLIST_GOTO, i_item );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
+                                      playlist_ItemGetById( p_sys->p_playlist,
+                                      i_item ) );
                     msg_Dbg( p_intf, "requested playlist item: %i", i_item );
                     break;
                 }
                 case MVLC_STOP:
-                    playlist_Command( p_sys->p_playlist, PLAYLIST_STOP, 0 );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
                     msg_Dbg( p_intf, "requested playlist stop" );
                     break;
                 case MVLC_PAUSE:
-                    playlist_Command( p_sys->p_playlist, PLAYLIST_PAUSE, 0 );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
                     msg_Dbg( p_intf, "requested playlist pause" );
                     break;
                 case MVLC_NEXT:
-                    playlist_Command( p_sys->p_playlist, PLAYLIST_GOTO,
-                                      p_sys->p_playlist->i_index + 1 );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
                     msg_Dbg( p_intf, "requested playlist next" );
                     break;
                 case MVLC_PREVIOUS:
-                    playlist_Command( p_sys->p_playlist, PLAYLIST_GOTO,
-                                      p_sys->p_playlist->i_index - 1 );
-                    msg_Dbg( p_intf, "requested playlist next" );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
+                    msg_Dbg( p_intf, "requested playlist previous" );
                     break;
                 case MVLC_FULLSCREEN:
-                {
                     if( p_sys->p_input )
                     {
                         vout_thread_t *p_vout;
@@ -1513,188 +2111,13 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                             msg_Dbg( p_intf, "requested fullscreen toggle" );
                         }
                     }
-                }
-                break;
+                    break;
                 case MVLC_SEEK:
                 {
-                    vlc_value_t val;
                     char value[30];
-                    char * p_value;
-                    int i_stock = 0;
-                    uint64_t i_length;
-                    int i_value = 0;
-                    int i_relative = 0;
-#define POSITION_ABSOLUTE 12
-#define POSITION_REL_FOR 13
-#define POSITION_REL_BACK 11
-#define TIME_ABSOLUTE 0
-#define TIME_REL_FOR 1
-#define TIME_REL_BACK -1
-                    if( p_sys->p_input )
-                    {
-                        uri_extract_value( p_request, "seek_value", value, 20 );
-                        uri_decode_url_encoded( value );
-                        p_value = value;
-                        var_Get( p_sys->p_input, "length", &val);
-                        i_length = val.i_time;
-
-                        while( p_value[0] != '\0' )
-                        {
-                            switch(p_value[0])
-                            {
-                                case '+':
-                                {
-                                    i_relative = TIME_REL_FOR;
-                                    p_value++;
-                                    break;
-                                }
-                                case '-':
-                                {
-                                    i_relative = TIME_REL_BACK;
-                                    p_value++;
-                                    break;
-                                }
-                                case '0': case '1': case '2': case '3': case '4':
-                                case '5': case '6': case '7': case '8': case '9':
-                                {
-                                    i_stock = strtol( p_value , &p_value , 10 );
-                                    break;
-                                }
-                                case '%': /* for percentage ie position */
-                                {
-                                    i_relative += POSITION_ABSOLUTE;
-                                    i_value = i_stock;
-                                    i_stock = 0;
-                                    p_value[0] = '\0';
-                                    break;
-                                }
-                                case ':':
-                                {
-                                    i_value = 60 * (i_value + i_stock) ;
-                                    i_stock = 0;
-                                    p_value++;
-                                    break;
-                                }
-                                case 'h': case 'H': /* hours */
-                                {
-                                    i_value += 3600 * i_stock;
-                                    i_stock = 0;
-                                    /* other characters which are not numbers are not important */
-                                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
-                                    {
-                                        p_value++;
-                                    }
-                                    break;
-                                }
-                                case 'm': case 'M': case '\'': /* minutes */
-                                {
-                                    i_value += 60 * i_stock;
-                                    i_stock = 0;
-                                    p_value++;
-                                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
-                                    {
-                                        p_value++;
-                                    }
-                                    break;
-                                }
-                                case 's': case 'S': case '"':  /* seconds */
-                                {
-                                    i_value += i_stock;
-                                    i_stock = 0;
-                                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
-                                    {
-                                        p_value++;
-                                    }
-                                    break;
-                                }
-                                default:
-                                {
-                                    p_value++;
-                                    break;
-                                }
-                            }
-                        }
-
-                        /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
-                        i_value += i_stock;
-
-                        switch(i_relative)
-                        {
-                            case TIME_ABSOLUTE:
-                            {
-                                if( (uint64_t)( i_value ) * 1000000 <= i_length )
-                                    val.i_time = (uint64_t)( i_value ) * 1000000;
-                                else
-                                    val.i_time = i_length;
-
-                                var_Set( p_sys->p_input, "time", val );
-                                msg_Dbg( p_intf, "requested seek position: %dsec", i_value );
-                                break;
-                            }
-                            case TIME_REL_FOR:
-                            {
-                                var_Get( p_sys->p_input, "time", &val );
-                                if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
-                                {
-                                    val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
-                                } else
-                                {
-                                    val.i_time = i_length;
-                                }
-                                var_Set( p_sys->p_input, "time", val );
-                                msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );
-                                break;
-                            }
-                            case TIME_REL_BACK:
-                            {
-                                var_Get( p_sys->p_input, "time", &val );
-                                if( (int64_t)( i_value ) * 1000000 > val.i_time )
-                                {
-                                    val.i_time = 0;
-                                } else
-                                {
-                                    val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);
-                                }
-                                var_Set( p_sys->p_input, "time", val );
-                                msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );
-                                break;
-                            }
-                            case POSITION_ABSOLUTE:
-                            {
-                                val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
-                                var_Set( p_sys->p_input, "position", val );
-                                msg_Dbg( p_intf, "requested seek percent: %d", i_value );
-                                break;
-                            }
-                            case POSITION_REL_FOR:
-                            {
-                                var_Get( p_sys->p_input, "position", &val );
-                                val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
-                                var_Set( p_sys->p_input, "position", val );
-                                msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
-                                break;
-                            }
-                            case POSITION_REL_BACK:
-                            {
-                                var_Get( p_sys->p_input, "position", &val );
-                                val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
-                                var_Set( p_sys->p_input, "position", val );
-                                msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
-                                break;
-                            }
-                            default:
-                            {
-                                msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
-                                break;
-                            }
-                        }
-                    }
-#undef POSITION_ABSOLUTE
-#undef POSITION_REL_FOR
-#undef POSITION_REL_BACK
-#undef TIME_ABSOLUTE
-#undef TIME_REL_FOR
-#undef TIME_REL_BACK
+                    uri_extract_value( p_request, "seek_value", value, 30 );
+                    uri_decode_url_encoded( value );
+                    Seek( p_intf, value );
                     break;
                 }
                 case MVLC_VOLUME:
@@ -1714,25 +2137,36 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                         {
                             aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
                             msg_Dbg( p_intf, "requested volume set: max" );
-                        } else
+                        }
+                        else
                         {
                             aout_VolumeSet( p_intf , (i_volume + i_value) );
                             msg_Dbg( p_intf, "requested volume set: +%i", (i_volume + i_value) );
                         }
-                    } else
-                    if( vol[0] == '-' )
+                    }
+                    else if( vol[0] == '-' )
                     {
                         i_value = atoi( vol + 1 );
                         if( (i_volume - i_value) < AOUT_VOLUME_MIN )
                         {
                             aout_VolumeSet( p_intf , AOUT_VOLUME_MIN );
                             msg_Dbg( p_intf, "requested volume set: min" );
-                        } else
+                        }
+                        else
                         {
                             aout_VolumeSet( p_intf , (i_volume - i_value) );
                             msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
                         }
-                    } else
+                    }
+                    else if( strstr(vol, "%") != NULL )
+                    {
+                        i_value = atoi( vol );
+                        if( (i_value <= 400) && (i_value>=0) ){
+                            aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);
+                            msg_Dbg( p_intf, "requested volume set: %i%%", atoi( vol ));
+                        }
+                    }
+                    else
                     {
                         i_value = atoi( vol );
                         if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
@@ -1747,19 +2181,27 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 /* playlist management */
                 case MVLC_ADD:
                 {
-                    char mrl[512];
-                    playlist_item_t * p_item;
+                    char mrl[1024], psz_name[1024];
+                    playlist_item_t *p_item;
 
-                    uri_extract_value( p_request, "mrl", mrl, 512 );
+                    uri_extract_value( p_request, "mrl", mrl, 1024 );
                     uri_decode_url_encoded( mrl );
-                    p_item = parse_MRL( mrl );
+                    uri_extract_value( p_request, "name", psz_name, 1024 );
+                    uri_decode_url_encoded( psz_name );
+                    if( !*psz_name )
+                    {
+                        memcpy( psz_name, mrl, 1024 );
+                    }
+                    p_item = parse_MRL( p_intf, mrl, psz_name );
 
-                    if( p_item == NULL )
+                    if( !p_item || !p_item->input.psz_uri ||
+                        !*p_item->input.psz_uri )
                     {
                         msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
-                    } else
+                    }
+                    else
                     {
-                        playlist_AddItem( p_sys->p_playlist , p_item ,
+                        playlist_AddItem( p_sys->p_playlist, p_item,
                                           PLAYLIST_APPEND, PLAYLIST_END );
                         msg_Dbg( p_intf, "requested mrl add: %s", mrl );
                     }
@@ -1784,24 +2226,15 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                         i_nb_items++;
                     }
 
-                    /* The items need to be deleted from in reversed order */
                     if( i_nb_items )
                     {
                         int i;
                         for( i = 0; i < i_nb_items; i++ )
                         {
-                            int j, i_index = 0;
-                            for( j = 0; j < i_nb_items; j++ )
-                            {
-                                if( p_items[j] > p_items[i_index] )
-                                    i_index = j;
-                            }
-
-                            playlist_Delete( p_sys->p_playlist,
-                                             p_items[i_index] );
+                            playlist_LockDelete( p_sys->p_playlist, p_items[i] );
                             msg_Dbg( p_intf, "requested playlist delete: %d",
-                                     p_items[i_index] );
-                            p_items[i_index] = -1;
+                                     p_items[i] );
+                            p_items[i] = -1;
                         }
                     }
 
@@ -1810,10 +2243,9 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 }
                 case MVLC_KEEP:
                 {
-                    int i_item, *p_items = NULL, i_nb_items = 0, i_current = -1;
+                    int i_item, *p_items = NULL, i_nb_items = 0;
                     char item[512], *p_parser = p_request;
                     int i,j;
-                    vlc_value_t val;
 
                     /* Get the list of items to keep */
                     while( (p_parser =
@@ -1828,27 +2260,17 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                         i_nb_items++;
                     }
 
-                    /* we should not remove an item while it is played by VLC */
-                    var_Get( p_sys->p_input, "state", &val );
-                    if( val.i_int == PLAYING_S )
-                    {
-                        i_current = p_sys->p_playlist->i_index;
-                    } else
-                    {
-                        i_current = -1;
-                    }
-
-                    /* The items need to be deleted from in reversed order */
-                    for( i = p_sys->p_playlist->i_size - 1; i >= 0 ; i-- )
+                    for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
                     {
                         /* Check if the item is in the keep list */
                         for( j = 0 ; j < i_nb_items ; j++ )
                         {
-                            if( p_items[j] == i ) break;
+                            if( p_items[j] ==
+                                p_sys->p_playlist->pp_items[i]->input.i_id ) break;
                         }
-                        if( (j == i_nb_items) && (i != i_current ) )
+                        if( j == i_nb_items )
                         {
-                            playlist_Delete( p_sys->p_playlist, i );
+                            playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
                             msg_Dbg( p_intf, "requested playlist delete: %d",
                                      i );
                         }
@@ -1859,10 +2281,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 }
                 case MVLC_EMPTY:
                 {
-                    while( p_sys->p_playlist->i_size > 0 )
-                    {
-                        playlist_Delete( p_sys->p_playlist, 0 );
-                    }
+                    playlist_LockClear( p_sys->p_playlist );
                     msg_Dbg( p_intf, "requested playlist empty" );
                     break;
                 }
@@ -1870,30 +2289,66 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 {
                     char type[12];
                     char order[2];
+                    char item[512];
                     int i_order;
+                    int i_item;
 
                     uri_extract_value( p_request, "type", type, 12 );
                     uri_extract_value( p_request, "order", order, 2 );
+                    uri_extract_value( p_request, "item", item, 512 );
+                    i_item = atoi( item );
 
-                    if( order[0] == '0' ) i_order = SORT_NORMAL;
-                    else i_order = SORT_REVERSE;
+                    if( order[0] == '0' ) i_order = ORDER_NORMAL;
+                    else i_order = ORDER_REVERSE;
 
                     if( !strcmp( type , "title" ) )
                     {
-                        playlist_SortTitle( p_sys->p_playlist , i_order );
+                        playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
+                                                    p_sys->p_playlist->pp_views[0]->p_root,
+                                                    SORT_TITLE_NODES_FIRST,
+                                                    ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
-                    } else if( !strcmp( type , "group" ) )
-                    {
-                        playlist_SortGroup( p_sys->p_playlist , i_order );
-                        msg_Dbg( p_intf, "requested playlist sort by group (%d)" , i_order );
-                    } else if( !strcmp( type , "author" ) )
+                    }
+                    else if( !strcmp( type , "author" ) )
                     {
-                        playlist_SortAuthor( p_sys->p_playlist , i_order );
+                        playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
+                                                    p_sys->p_playlist->pp_views[0]->p_root,
+                                                    SORT_AUTHOR,
+                                                    ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
                     }
+                    else if( !strcmp( type , "shuffle" ) )
+                    {
+                        playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
+                                                    p_sys->p_playlist->pp_views[0]->p_root,
+                                                    SORT_RANDOM,
+                                                    ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
+                        msg_Dbg( p_intf, "requested playlist shuffle");
+                    }
 
                     break;
                 }
+                case MVLC_MOVE:
+                {
+                    char psz_pos[6];
+                    char psz_newpos[6];
+                    int i_pos;
+                    int i_newpos;
+                    uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
+                    uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
+                    i_pos = atoi( psz_pos );
+                    i_newpos = atoi( psz_newpos );
+                    if ( i_pos < i_newpos )
+                    {
+                        playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
+                    }
+                    else
+                    {
+                        playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
+                    }
+                    msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
+                    break;
+                }
 
                 /* admin function */
                 case MVLC_CLOSE:
@@ -1901,10 +2356,12 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     char id[512];
                     uri_extract_value( p_request, "id", id, 512 );
                     msg_Dbg( p_intf, "requested close id=%s", id );
+#if 0
                     if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
                     {
                         msg_Warn( p_intf, "close failed for id=%s", id );
                     }
+#endif
                     break;
                 }
                 case MVLC_SHUTDOWN:
@@ -1913,8 +2370,159 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     p_intf->p_vlc->b_die = VLC_TRUE;
                     break;
                 }
+                /* vlm */
+                case MVLC_VLM_NEW:
+                case MVLC_VLM_SETUP:
+                {
+                    static const char *vlm_properties[11] =
+                    {
+                        /* no args */
+                        "enabled", "disabled", "loop", "unloop",
+                        /* args required */
+                        "input", "output", "option", "date", "period", "repeat", "append",
+                    };
+                    vlm_message_t *vlm_answer;
+                    char name[512];
+                    char *psz = malloc( strlen( p_request ) + 1000 );
+                    char *p = psz;
+                    char *vlm_error;
+                    int i;
+
+                    if( p_intf->p_sys->p_vlm == NULL )
+                        p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+                    if( p_intf->p_sys->p_vlm == NULL ) break;
+
+                    uri_extract_value( p_request, "name", name, 512 );
+                    if( StrToMacroType( control ) == MVLC_VLM_NEW )
+                    {
+                        char type[20];
+                        uri_extract_value( p_request, "type", type, 20 );
+                        p += sprintf( psz, "new %s %s", name, type );
+                    }
+                    else
+                    {
+                        p += sprintf( psz, "setup %s", name );
+                    }
+                    /* Parse the request */
+                    for( i = 0; i < 11; i++ )
+                    {
+                        char val[512];
+                        uri_extract_value( p_request, vlm_properties[i], val, 512 );
+                        uri_decode_url_encoded( val );
+                        if( strlen( val ) > 0 && i >= 4 )
+                        {
+                            p += sprintf( p, " %s %s", vlm_properties[i], val );
+                        }
+                        else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
+                        {
+                            p += sprintf( p, " %s", vlm_properties[i] );
+                        }
+                    }
+                    vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+                    if( vlm_answer->psz_value == NULL ) /* there is no error */
+                    {
+                        vlm_error = strdup( "" );
+                    }
+                    else
+                    {
+                        vlm_error = malloc( strlen(vlm_answer->psz_name) +
+                                            strlen(vlm_answer->psz_value) +
+                                            strlen( " : ") + 1 );
+                        sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
+                                                         vlm_answer->psz_value );
+                    }
+
+                    mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
+
+                    vlm_MessageDelete( vlm_answer );
+                    free( vlm_error );
+                    free( psz );
+                    break;
+                }
+
+                case MVLC_VLM_DEL:
+                {
+                    vlm_message_t *vlm_answer;
+                    char name[512];
+                    char psz[512+10];
+                    if( p_intf->p_sys->p_vlm == NULL )
+                        p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+                    if( p_intf->p_sys->p_vlm == NULL ) break;
+
+                    uri_extract_value( p_request, "name", name, 512 );
+                    sprintf( psz, "del %s", name );
+
+                    vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+                    /* FIXME do a vlm_answer -> var stack conversion */
+                    vlm_MessageDelete( vlm_answer );
+                    break;
+                }
+
+                case MVLC_VLM_PLAY:
+                case MVLC_VLM_PAUSE:
+                case MVLC_VLM_STOP:
+                case MVLC_VLM_SEEK:
+                {
+                    vlm_message_t *vlm_answer;
+                    char name[512];
+                    char psz[512+10];
+                    if( p_intf->p_sys->p_vlm == NULL )
+                        p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+                    if( p_intf->p_sys->p_vlm == NULL ) break;
+
+                    uri_extract_value( p_request, "name", name, 512 );
+                    if( StrToMacroType( control ) == MVLC_VLM_PLAY )
+                        sprintf( psz, "control %s play", name );
+                    else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
+                        sprintf( psz, "control %s pause", name );
+                    else if( StrToMacroType( control ) == MVLC_VLM_STOP )
+                        sprintf( psz, "control %s stop", name );
+                    else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
+                    {
+                        char percent[20];
+                        uri_extract_value( p_request, "percent", percent, 512 );
+                        sprintf( psz, "control %s seek %s", name, percent );
+                    }
+
+                    vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+                    /* FIXME do a vlm_answer -> var stack conversion */
+                    vlm_MessageDelete( vlm_answer );
+                    break;
+                }
+                case MVLC_VLM_LOAD:
+                case MVLC_VLM_SAVE:
+                {
+                    vlm_message_t *vlm_answer;
+                    char file[512];
+                    char psz[512];
+
+                    if( p_intf->p_sys->p_vlm == NULL )
+                        p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+                    if( p_intf->p_sys->p_vlm == NULL ) break;
+
+                    uri_extract_value( p_request, "file", file, 512 );
+                    uri_decode_url_encoded( file );
+
+                    if( StrToMacroType( control ) == MVLC_VLM_LOAD )
+                        sprintf( psz, "load %s", file );
+                    else
+                        sprintf( psz, "save %s", file );
+
+                    vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+                    /* FIXME do a vlm_answer -> var stack conversion */
+                    vlm_MessageDelete( vlm_answer );
+                    break;
+                }
+
                 default:
-                    PRINTS( "<!-- control param(%s) unsuported -->", control );
+                    if( *control )
+                    {
+                        PRINTS( "<!-- control param(%s) unsupported -->", control );
+                    }
                     break;
             }
             break;
@@ -1968,7 +2576,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
             {
                 case MVLC_INT:
                     i = config_GetInt( p_intf, m->param1 );
-                    sprintf( value, "%i", i );
+                    sprintf( value, "%d", i );
                     break;
                 case MVLC_FLOAT:
                     f = config_GetFloat( p_intf, m->param1 );
@@ -1976,13 +2584,22 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     break;
                 case MVLC_STRING:
                     psz = config_GetPsz( p_intf, m->param1 );
-                    sprintf( value, "%s", psz ? psz : "" );
+                    if( psz != NULL )
+                    {
+                        strncpy( value, psz,sizeof( value ) );
+                        free( psz );
+                        value[sizeof( value ) - 1] = '\0';
+                    }
+                    else
+                        *value = '\0';
+                    msg_Dbg( p_intf, "%d: value = \"%s\"", __LINE__, value );
                     break;
                 default:
-                    sprintf( value, "invalid type(%s) in set", m->param2 );
+                    snprintf( value, sizeof( value ),
+                              "invalid type(%s) in set", m->param2 );
+                    value[sizeof( value ) - 1] = '\0';
                     break;
             }
-            msg_Dbg( p_intf, "get name=%s value=%s type=%s", m->param1, value, m->param2 );
             PRINTS( "%s", value );
             break;
         }
@@ -1992,7 +2609,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
 
             if( m->param1 )
             {
-                EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
+                EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m->param1 );
                 s = SSPop( &p_args->stack );
                 v = mvar_GetValue( p_args->vars, s );
             }
@@ -2006,8 +2623,19 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
             break;
         }
         case MVLC_RPN:
-            EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
+            EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m->param1 );
+            break;
+
+        /* Useful to learn stack management */
+        case MVLC_STACK:
+        {
+            int i;
+            msg_Dbg( p_intf, "stack" );
+            for (i=0;i<(&p_args->stack)->i_stack;i++)
+                msg_Dbg( p_intf, "%d -> %s", i, (&p_args->stack)->stack[i] );
             break;
+        }
+
         case MVLC_UNKNOWN:
         default:
             PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
@@ -2019,14 +2647,14 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
 #undef ALLOC
 }
 
-static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t b_after )
+static char *MacroSearch( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
 {
     int     i_id;
     int     i_level = 0;
 
     while( src < end )
     {
-        if( src + 4 < end  && !strncmp( src, "<vlc", 4 ) )
+        if( src + 4 < end  && !strncmp( (char *)src, "<vlc", 4 ) )
         {
             int i_skip;
             macro_t m;
@@ -2048,6 +2676,8 @@ static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t
                     break;
             }
 
+            MacroClean( &m );
+
             if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
                 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
             {
@@ -2069,16 +2699,16 @@ static uint8_t *MacroSearch( uint8_t *src, uint8_t *end, int i_mvlc, vlc_bool_t
     return NULL;
 }
 
-static void Execute( httpd_file_callback_args_t *p_args,
-                     uint8_t *p_request, int i_request,
-                     uint8_t **pp_data, int *pi_data,
-                     uint8_t **pp_dst,
-                     uint8_t *_src, uint8_t *_end )
+static void Execute( httpd_file_sys_t *p_args,
+                     char *p_request, int i_request,
+                     char **pp_data, int *pi_data,
+                     char **pp_dst,
+                     char *_src, char *_end )
 {
     intf_thread_t  *p_intf = p_args->p_intf;
 
-    uint8_t *src, *dup, *end;
-    uint8_t *dst = *pp_dst;
+    char *src, *dup, *end;
+    char *dst = *pp_dst;
 
     src = dup = malloc( _end - _src + 1 );
     end = src +( _end - _src );
@@ -2089,10 +2719,10 @@ static void Execute( httpd_file_callback_args_t *p_args,
     /* we parse searching <vlc */
     while( src < end )
     {
-        uint8_t *p;
+        char *p;
         int i_copy;
 
-        p = strstr( src, "<vlc" );
+        p = (char *)strstr( (char *)src, "<vlc" );
         if( p < end && p == src )
         {
             macro_t m;
@@ -2103,12 +2733,52 @@ static void Execute( httpd_file_callback_args_t *p_args,
 
             switch( StrToMacroType( m.id ) )
             {
+                case MVLC_INCLUDE:
+                {
+                    FILE *f;
+                    int  i_buffer;
+                    char *p_buffer;
+                    char psz_file[MAX_DIR_SIZE];
+                    char *p;
+
+                    if( m.param1[0] != '/' )
+                    {
+                        strcpy( psz_file, p_args->file );
+                        p = strrchr( psz_file, '/' );
+                        if( p != NULL )
+                            strcpy( p + 1, m.param1 );
+                        else
+                            strcpy( psz_file, m.param1 );
+                    }
+                    else
+                    {
+                        strcpy( psz_file, m.param1 );
+                    }
+
+                    if( ( f = fopen( psz_file, "r" ) ) == NULL )
+                    {
+                        msg_Warn( p_args->p_intf,
+                                  "unable to include file %s (%s)",
+                                  psz_file, strerror(errno) );
+                        break;
+                    }
+
+                    /* first we load in a temporary buffer */
+                    FileLoad( f, &p_buffer, &i_buffer );
+
+                    /* we parse executing all  <vlc /> macros */
+                    Execute( p_args, p_request, i_request, pp_data, pi_data,
+                             &dst, &p_buffer[0], &p_buffer[i_buffer] );
+                    free( p_buffer );
+                    fclose(f);
+                    break;
+                }
                 case MVLC_IF:
                 {
                     vlc_bool_t i_test;
-                    uint8_t    *endif;
+                    char    *endif;
 
-                    EvaluateRPN( p_args->vars, &p_args->stack, m.param1 );
+                    EvaluateRPN( p_intf, p_args->vars, &p_args->stack, m.param1 );
                     if( SSPopN( &p_args->stack, p_args->vars ) )
                     {
                         i_test = 1;
@@ -2121,27 +2791,29 @@ static void Execute( httpd_file_callback_args_t *p_args,
 
                     if( i_test == 0 )
                     {
-                        uint8_t *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
+                        char *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
 
                         if( start )
                         {
-                            uint8_t *stop  = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
+                            char *stop  = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
                             if( stop )
                             {
-                                Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
+                                Execute( p_args, p_request, i_request,
+                                         pp_data, pi_data, &dst, start, stop );
                             }
                         }
                     }
                     else if( i_test == 1 )
                     {
-                        uint8_t *stop;
+                        char *stop;
                         if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
                         {
                             stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
                         }
                         if( stop )
                         {
-                            Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, src, stop );
+                            Execute( p_args, p_request, i_request,
+                                     pp_data, pi_data, &dst, src, stop );
                         }
                     }
 
@@ -2150,9 +2822,9 @@ static void Execute( httpd_file_callback_args_t *p_args,
                 }
                 case MVLC_FOREACH:
                 {
-                    uint8_t *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
-                    uint8_t *start = src;
-                    uint8_t *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
+                    char *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
+                    char *start = src;
+                    char *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
 
                     if( stop )
                     {
@@ -2168,17 +2840,37 @@ static void Execute( httpd_file_callback_args_t *p_args,
                         else if( !strcmp( m.param2, "directory" ) )
                         {
                             char *arg = SSPop( &p_args->stack );
-                            index = mvar_FileSetNew( m.param1, arg );
+                            index = mvar_FileSetNew( p_intf, m.param1, arg );
                             free( arg );
                         }
                         else if( !strcmp( m.param2, "playlist" ) )
                         {
-                            index = mvar_PlaylistSetNew( m.param1, p_intf->p_sys->p_playlist );
+                            index = mvar_PlaylistSetNew( p_intf, m.param1,
+                                                    p_intf->p_sys->p_playlist );
+                        }
+                        else if( !strcmp( m.param2, "information" ) )
+                        {
+                            index = mvar_InfoSetNew( p_intf, m.param1,
+                                                     p_intf->p_sys->p_input );
+                        }
+                        else if( !strcmp( m.param2, "program" )
+                                  || !strcmp( m.param2, "title" )
+                                  || !strcmp( m.param2, "chapter" )
+                                  || !strcmp( m.param2, "audio-es" )
+                                  || !strcmp( m.param2, "video-es" )
+                                  || !strcmp( m.param2, "spu-es" ) )
+                        {
+                            index = mvar_InputVarSetNew( p_intf, m.param1,
+                                                         p_intf->p_sys->p_input,
+                                                         m.param2 );
                         }
-                        else if( !strcmp( m.param2, "informations" ) )
+                        else if( !strcmp( m.param2, "vlm" ) )
                         {
-                            index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
+                            if( p_intf->p_sys->p_vlm == NULL )
+                                p_intf->p_sys->p_vlm = vlm_New( p_intf );
+                            index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
                         }
+#if 0
                         else if( !strcmp( m.param2, "hosts" ) )
                         {
                             index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
@@ -2191,6 +2883,7 @@ static void Execute( httpd_file_callback_args_t *p_args,
                         {
                             index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
                         }
+#endif
                         else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
                         {
                             index = mvar_Duplicate( v );
@@ -2213,7 +2906,8 @@ static void Execute( httpd_file_callback_args_t *p_args,
 
 
                             mvar_PushVar( p_args->vars, f );
-                            Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, start, stop );
+                            Execute( p_args, p_request, i_request,
+                                     pp_data, pi_data, &dst, start, stop );
                             mvar_RemoveVar( p_args->vars, f );
 
                             mvar_Delete( f );
@@ -2225,7 +2919,8 @@ static void Execute( httpd_file_callback_args_t *p_args,
                     break;
                 }
                 default:
-                    MacroDo( p_args, &m, p_request, i_request, pp_data, pi_data, &dst );
+                    MacroDo( p_args, &m, p_request, i_request,
+                             pp_data, pi_data, &dst );
                     break;
             }
 
@@ -2253,17 +2948,21 @@ static void Execute( httpd_file_callback_args_t *p_args,
 }
 
 /****************************************************************************
- * http_get:
+ * HttpCallback:
  ****************************************************************************
- * a file with mime == text/html is parsed and all "macro" replaced
+ * a file with b_html is parsed and all "macro" replaced
  * <vlc id="macro name" [param1="" [param2=""]] />
  * valid id are
  *
  ****************************************************************************/
-static int  http_get( httpd_file_callback_args_t *p_args,
-                      uint8_t *p_request, int i_request,
-                      uint8_t **pp_data, int *pi_data )
+static int  HttpCallback( httpd_file_sys_t *p_args,
+                          httpd_file_t *p_file,
+                          uint8_t *_p_request,
+                          uint8_t **_pp_data, int *pi_data )
 {
+    char *p_request = (char *)_p_request;
+    char **pp_data = (char **)_pp_data;
+    int i_request = p_request ? strlen( p_request ) : 0;
     char *p;
     FILE *f;
 
@@ -2281,24 +2980,24 @@ static int  http_get( httpd_file_callback_args_t *p_args,
         p += sprintf( p, "<body>\n" );
         p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
         p += sprintf( p, "<hr />\n" );
-        p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
+        p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
         p += sprintf( p, "</body>\n" );
         p += sprintf( p, "</html>\n" );
 
-        *pi_data = strlen( *pp_data ) + 1;
+        *pi_data = strlen( *pp_data );
 
         return VLC_SUCCESS;
     }
 
-    if( strcmp( p_args->mime, "text/html" ) )
+    if( !p_args->b_html )
     {
         FileLoad( f, pp_data, pi_data );
     }
     else
     {
         int  i_buffer;
-        uint8_t *p_buffer;
-        uint8_t *dst;
+        char *p_buffer;
+        char *dst;
         vlc_value_t val;
         char position[4]; /* percentage */
         char time[12]; /* in seconds */
@@ -2321,14 +3020,17 @@ static int  http_get( httpd_file_callback_args_t *p_args,
             if( val.i_int == PLAYING_S )
             {
                 sprintf( state, "playing" );
-            } else if( val.i_int == PAUSE_S )
+            }
+            else if( val.i_int == PAUSE_S )
             {
                 sprintf( state, "paused" );
-            } else
+            }
+            else
             {
                 sprintf( state, "stop" );
             }
-        } else
+        }
+        else
         {
             sprintf( position, "%d", 0 );
             sprintf( time, "%d", 0 );
@@ -2361,13 +3063,15 @@ static int  http_get( httpd_file_callback_args_t *p_args,
         dst = *pp_data = malloc( *pi_data );
 
         /* we parse executing all  <vlc /> macros */
-        Execute( p_args, p_request, i_request, pp_data, pi_data, &dst, &p_buffer[0], &p_buffer[i_buffer] );
+        Execute( p_args, p_request, i_request, pp_data, pi_data, &dst,
+                 &p_buffer[0], &p_buffer[i_buffer] );
 
-        *dst++ = '\0';
+        *dst     = '\0';
         *pi_data = dst - *pp_data;
 
         SSClean( &p_args->stack );
         mvar_Delete( p_args->vars );
+        free( p_buffer );
     }
 
     fclose( f );
@@ -2378,12 +3082,37 @@ static int  http_get( httpd_file_callback_args_t *p_args,
 /****************************************************************************
  * uri parser
  ****************************************************************************/
-static char *uri_extract_value( char *psz_uri, char *psz_name,
+static int uri_test_param( char *psz_uri, const char *psz_name )
+{
+    char *p = psz_uri;
+
+    while( (p = strstr( p, psz_name )) )
+    {
+        /* Verify that we are dealing with a post/get argument */
+        if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')
+              && p[strlen(psz_name)] == '=' )
+        {
+            return VLC_TRUE;
+        }
+        p++;
+    }
+
+    return VLC_FALSE;
+}
+static char *uri_extract_value( char *psz_uri, const char *psz_name,
                                 char *psz_value, int i_value_max )
 {
-    char *p;
+    char *p = psz_uri;
+
+    while( (p = strstr( p, psz_name )) )
+    {
+        /* Verify that we are dealing with a post/get argument */
+        if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')
+              && p[strlen(psz_name)] == '=' )
+            break;
+        p++;
+    }
 
-    p = strstr( psz_uri, psz_name );
     if( p )
     {
         int i_len;
@@ -2460,10 +3189,50 @@ static void uri_decode_url_encoded( char *psz )
             *psz++ = *p++;
         }
     }
-    *psz++  ='\0';
+    *psz++ '\0';
     free( dup );
 }
 
+/* Since the resulting string is smaller we can work in place, so it is
+ * permitted to have psz == new. new points to the first word of the
+ * string, the function returns the remaining string. */
+static char *FirstWord( char *psz, char *new )
+{
+    vlc_bool_t b_end;
+
+    while( *psz == ' ' )
+        psz++;
+
+    while( *psz != '\0' && *psz != ' ' )
+    {
+        if( *psz == '\'' )
+        {
+            char c = *psz++;
+            while( *psz != '\0' && *psz != c )
+            {
+                if( *psz == '\\' && psz[1] != '\0' )
+                    psz++;
+                *new++ = *psz++;
+            }
+            if( *psz == c )
+                psz++;
+        }
+        else
+        {
+            if( *psz == '\\' && psz[1] != '\0' )
+                psz++;
+            *new++ = *psz++;
+        }
+    }
+    b_end = !*psz;
+
+    *new++ = '\0';
+    if( !b_end )
+        return psz + 1;
+    else
+        return NULL;
+}
+
 /****************************************************************************
  * Light RPN evaluator
  ****************************************************************************/
@@ -2528,13 +3297,16 @@ static void SSPushN( rpn_stack_t *st, int i )
     SSPush( st, v );
 }
 
-static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
+static void  EvaluateRPN( intf_thread_t *p_intf, mvar_t  *vars,
+                          rpn_stack_t *st, char *exp )
 {
-    for( ;; )
+    intf_sys_t    *p_sys = p_intf->p_sys;
+
+    while( exp != NULL && *exp != '\0' )
     {
-        char s[100], *p;
+        char *p, *s;
 
-        /* skip spcae */
+        /* skip space */
         while( *exp == ' ' )
         {
             exp++;
@@ -2543,33 +3315,22 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         if( *exp == '\'' )
         {
             /* extract string */
-            p = &s[0];
-            exp++;
-            while( *exp && *exp != '\'' )
-            {
-                *p++ = *exp++;
-            }
-            *p = '\0';
-            exp++;
-            SSPush( st, s );
+            p = FirstWord( exp, exp );
+            SSPush( st, exp );
+            exp = p;
             continue;
         }
 
         /* extract token */
-        p = strchr( exp, ' ' );
-        if( !p )
+        p = FirstWord( exp, exp );
+        s = exp;
+        if( p == NULL )
         {
-            strcpy( s, exp );
-
             exp += strlen( exp );
         }
         else
         {
-            int i = p -exp;
-            strncpy( s, exp, i );
-            s[i] = '\0';
-
-            exp = p + 1;
+            exp = p;
         }
 
         if( *s == '\0' )
@@ -2631,6 +3392,10 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         {
             SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
         }
+        else if( !strcmp( s, "!=" ) )
+        {
+            SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
+        }
         else if( !strcmp( s, "<" ) )
         {
             int j = SSPopN( st, vars );
@@ -2693,6 +3458,32 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
             free( s1 );
             free( s2 );
         }
+        else if( !strcmp( s, "strsub" ) )
+        {
+            int n = SSPopN( st, vars );
+            int m = SSPopN( st, vars );
+            int i_len;
+            char *s = SSPop( st );
+            char *str;
+
+            if( n >= m )
+            {
+                i_len = n - m + 1;
+            }
+            else
+            {
+                i_len = 0;
+            }
+
+            str = malloc( i_len + 1 );
+
+            memcpy( str, s + m - 1, i_len );
+            str[ i_len ] = '\0';
+
+            SSPush( st, str );
+            free( s );
+            free( str );
+        }
         else if( !strcmp( s, "strlen" ) )
         {
             char *str = SSPop( st );
@@ -2700,6 +3491,222 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
             SSPushN( st, strlen( str ) );
             free( str );
         }
+        else if( !strcmp( s, "str_replace" ) )
+        {
+            char *psz_to = SSPop( st );
+            char *psz_from = SSPop( st );
+            char *psz_in = SSPop( st );
+            char *psz_in_current = psz_in;
+            char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
+            char *psz_out_current = psz_out;
+
+            while( (p = strstr( psz_in_current, psz_from )) != NULL )
+            {
+                memcpy( psz_out_current, psz_in_current, p - psz_in_current );
+                psz_out_current += p - psz_in_current;
+                strcpy( psz_out_current, psz_to );
+                psz_out_current += strlen(psz_to);
+                psz_in_current = p + strlen(psz_from);
+            }
+            strcpy( psz_out_current, psz_in_current );
+            psz_out_current += strlen(psz_in_current);
+            *psz_out_current = '\0';
+
+            SSPush( st, psz_out );
+            free( psz_to );
+            free( psz_from );
+            free( psz_in );
+            free( psz_out );
+        }
+        else if( !strcmp( s, "url_extract" ) )
+        {
+            char *url = mvar_GetValue( vars, "url_value" );
+            char *name = SSPop( st );
+            char value[512];
+            char *tmp;
+
+            uri_extract_value( url, name, value, 512 );
+            uri_decode_url_encoded( value );
+            tmp = FromUTF8( p_intf, value );
+            SSPush( st, tmp );
+            free( tmp );
+            free( name );
+        }
+        else if( !strcmp( s, "url_encode" ) )
+        {
+            char *url = SSPop( st );
+            char *value;
+
+            value = ToUTF8( p_intf, url );
+            free( url );
+            url = value;
+            value = vlc_UrlEncode( url );
+            free( url );
+            SSPush( st, value );
+            free( value );
+        }
+        else if( !strcmp( s, "addslashes" ) )
+        {
+            char *psz_src = SSPop( st );
+            char *psz_dest;
+            char *str = psz_src;
+
+            p = psz_dest = malloc( strlen( str ) * 2 + 1 );
+
+            while( *str != '\0' )
+            {
+                if( *str == '"' || *str == '\'' )
+                {
+                    *p++ = '\\';
+                }
+                *p++ = *str;
+                str++;
+            }
+            *p = '\0';
+
+            SSPush( st, psz_dest );
+            free( psz_src );
+            free( psz_dest );
+        }
+        else if( !strcmp( s, "stripslashes" ) )
+        {
+            char *psz_src = SSPop( st );
+            char *psz_dest;
+
+            p = psz_dest = strdup( psz_src );
+
+            while( *psz_src != '\0' )
+            {
+                if( *psz_src == '\\' )
+                {
+                    *psz_src++;
+                }
+                *p++ = *psz_src;
+                psz_src++;
+            }
+            *p = '\0';
+
+            SSPush( st, psz_dest );
+            free( psz_src );
+            free( psz_dest );
+        }
+        else if( !strcmp( s, "htmlspecialchars" ) )
+        {
+            char *psz_src = SSPop( st );
+            char *psz_dest;
+            char *str = psz_src;
+
+            p = psz_dest = malloc( strlen( str ) * 6 + 1 );
+
+            while( *str != '\0' )
+            {
+                if( *str == '&' )
+                {
+                    strcpy( p, "&amp;" );
+                    p += 5;
+                }
+                else if( *str == '\"' )
+                {
+                    strcpy( p, "&quot;" );
+                    p += 6;
+                }
+                else if( *str == '\'' )
+                {
+                    strcpy( p, "&#039;" );
+                    p += 6;
+                }
+                else if( *str == '<' )
+                {
+                    strcpy( p, "&lt;" );
+                    p += 4;
+                }
+                else if( *str == '>' )
+                {
+                    strcpy( p, "&gt;" );
+                    p += 4;
+                }
+                else
+                {
+                    *p++ = *str;
+                }
+                str++;
+            }
+            *p = '\0';
+
+            SSPush( st, psz_dest );
+            free( psz_src );
+            free( psz_dest );
+        }
+        else if( !strcmp( s, "realpath" ) )
+        {
+            char dir[MAX_DIR_SIZE], *src;
+            char *psz_src = SSPop( st );
+            char *psz_dir = psz_src;
+            char sep;
+
+            /* convert all / to native separator */
+#if defined( WIN32 )
+            while( (p = strchr( psz_dir, '/' )) )
+            {
+                *p = '\\';
+            }
+            sep = '\\';
+#else
+            sep = '/';
+#endif
+
+            if( *psz_dir == '~' )
+            {
+                /* This is incomplete : we should also support the ~cmassiot/ syntax. */
+                snprintf( dir, sizeof(dir), "%s/%s", p_intf->p_vlc->psz_homedir,
+                          psz_dir + 1 );
+                psz_dir = dir;
+            }
+
+            /* first fix all .. dir */
+            p = src = psz_dir;
+            while( *src )
+            {
+                if( src[0] == '.' && src[1] == '.' )
+                {
+                    src += 2;
+                    if( p <= &psz_dir[1] )
+                    {
+                        continue;
+                    }
+
+                    p -= 2;
+
+                    while( p > &psz_dir[1] && *p != sep )
+                    {
+                        p--;
+                    }
+                }
+                else if( *src == sep )
+                {
+                    if( p > psz_dir && p[-1] == sep )
+                    {
+                        src++;
+                    }
+                    else
+                    {
+                        *p++ = *src++;
+                    }
+                }
+                else
+                {
+                    do
+                    {
+                        *p++ = *src++;
+                    } while( *src && *src != sep );
+                }
+            }
+            if( p != psz_dir + 1 && p[-1] == '/' ) p--;
+            *p = '\0';
+
+            SSPush( st, psz_dir );
+            free( psz_src );
+        }
         /* 4. stack functions */
         else if( !strcmp( s, "dup" ) )
         {
@@ -2746,235 +3753,171 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
 
             free( name );
         }
-        else if( !strcmp( s, "url_extract" ) )
+        /* 5. player control */
+        else if( !strcmp( s, "vlc_play" ) )
         {
-            char *url = mvar_GetValue( vars, "url_value" );
-            char *name = SSPop( st );
-            char value[512];
+            int i_id = SSPopN( st, vars );
+            int i_ret;
 
-            uri_extract_value( url, name, value, 512 );
-            uri_decode_url_encoded( value );
-            SSPush( st, value );
+            i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
+                                      playlist_ItemGetById( p_sys->p_playlist,
+                                      i_id ) );
+            msg_Dbg( p_intf, "requested playlist item: %i", i_id );
+            SSPushN( st, i_ret );
         }
-        else
+        else if( !strcmp( s, "vlc_stop" ) )
         {
-            SSPush( st, s );
+            playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
+            msg_Dbg( p_intf, "requested playlist stop" );
         }
-    }
-}
-
-/**********************************************************************
- * Find_end_MRL: Find the end of the sentence :
- * this function parses the string psz and find the end of the item
- * and/or option with detecting the " and ' problems.
- * returns NULL if an error is detected, otherwise, returns a pointer
- * of the end of the sentence (after the last character)
- **********************************************************************/
-static char *Find_end_MRL( char *psz )
-{
-    char *s_sent = psz;
-
-    switch( *s_sent )
-    {
-        case '\"':
+        else if( !strcmp( s, "vlc_pause" ) )
+        {
+            playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
+            msg_Dbg( p_intf, "requested playlist pause" );
+        }
+        else if( !strcmp( s, "vlc_next" ) )
+        {
+            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
+            msg_Dbg( p_intf, "requested playlist next" );
+        }
+        else if( !strcmp( s, "vlc_previous" ) )
         {
-            s_sent++;
+            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
+            msg_Dbg( p_intf, "requested playlist previous" );
+        }
+        else if( !strcmp( s, "vlc_seek" ) )
+        {
+            char *psz_value = SSPop( st );
+            Seek( p_intf, psz_value );
+            msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
+            free( psz_value );
+        }
+        else if( !strcmp( s, "vlc_set_var" ) )
+        {
+            char *psz_variable = SSPop( st );
+            char *psz_value = NULL;
+            vlc_value_t val;
+            int i_type;
 
-            while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
+            if( p_sys->p_input != NULL )
             {
-                if( *s_sent == '\'' )
-                {
-                    s_sent = Find_end_MRL( s_sent );
+                i_type = var_Type( p_sys->p_input, psz_variable );
 
-                    if( s_sent == NULL )
-                    {
-                        return NULL;
-                    }
-                } else
+                if( (i_type & VLC_VAR_TYPE) == VLC_VAR_INTEGER )
                 {
-                    s_sent++;
+                    int i_value = SSPopN( st, vars );
+                    val.i_int = i_value;
+                    msg_Dbg( p_intf, "requested input var change: %s->%d",
+                             psz_variable, i_value );
+                }
+                else
+                {
+                    psz_value = SSPop( st );
+                    val.psz_string = psz_value;
+                    msg_Dbg( p_intf, "requested input var change: %s->%s",
+                             psz_variable, psz_value );
                 }
-            }
 
-            if( *s_sent == '\"' )
-            {
-                s_sent++;
-                return s_sent;
-            } else  /* *s_sent == '\0' , which means the number of " is incorrect */
+                var_Set( p_sys->p_input, psz_variable, val );
+            }
+            if( psz_value != NULL )
+                free( psz_value );
+            free( psz_variable );
+        }
+        /* 6. playlist functions */
+        else if( !strcmp( s, "playlist_add" ) )
+        {
+            char *psz_name = SSPop( st );
+            char *mrl = SSPop( st );
+            char *tmp;
+            playlist_item_t *p_item;
+            int i_id;
+
+            tmp = ToUTF8( p_intf, psz_name );
+            free( psz_name );
+            psz_name = tmp;
+            tmp = ToUTF8( p_intf, mrl );
+            free( mrl );
+            mrl = tmp;
+
+            if( !*psz_name )
             {
-                return NULL;
+                p_item = parse_MRL( p_intf, mrl, mrl );
             }
-            break;
-        }
-        case '\'':
-        {
-            s_sent++;
-
-            while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
+            else
             {
-                if( *s_sent == '\"' )
-                {
-                    s_sent = Find_end_MRL( s_sent );
-
-                    if( s_sent == NULL )
-                    {
-                        return NULL;
-                    }
-                } else
-                {
-                    s_sent++;
-                }
+                p_item = parse_MRL( p_intf, mrl, psz_name );
             }
 
-            if( *s_sent == '\'' )
+            if( p_item == NULL || p_item->input.psz_uri == NULL ||
+                 !*p_item->input.psz_uri )
             {
-                s_sent++;
-                return s_sent;
-            } else  /* *s_sent == '\0' , which means the number of ' is incorrect */
+                i_id = VLC_EGENERIC;
+                msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
+            }
+            else
             {
-                return NULL;
+                i_id = playlist_AddItem( p_sys->p_playlist, p_item,
+                                         PLAYLIST_APPEND, PLAYLIST_END );
+                msg_Dbg( p_intf, "requested mrl add: %s", mrl );
             }
-            break;
+            SSPushN( st, i_id );
+
+            free( mrl );
+            free( psz_name );
         }
-        default: /* now we can look for spaces */
+        else if( !strcmp( s, "playlist_empty" ) )
         {
-            while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
-            {
-                if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
-                {
-                    s_sent = Find_end_MRL( s_sent );
-                } else
-                {
-                    s_sent++;
-                }
-            }
-            return s_sent;
+            playlist_LockClear( p_sys->p_playlist );
+            msg_Dbg( p_intf, "requested playlist empty" );
+        }
+        else
+        {
+            SSPush( st, s );
         }
     }
 }
 
 /**********************************************************************
  * parse_MRL: parse the MRL, find the mrl string and the options,
- * create an item with all informations in it, and return the item.
+ * create an item with all information in it, and return the item.
  * return NULL if there is an error.
  **********************************************************************/
-playlist_item_t * parse_MRL( char *psz )
+static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *_psz,
+                                   char *psz_name )
 {
-    char **ppsz_options = NULL;
-    char *mrl;
+    char *psz = strdup( _psz );
     char *s_mrl = psz;
-    int i_error = 0;
     char *s_temp;
-    int i = 0;
-    int i_options = 0;
-    playlist_item_t * p_item;
-
-    /* In case there is spaces before the mrl */
-    while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
-    {
-        s_mrl++;
-    }
+    playlist_item_t * p_item = NULL;
 
     /* extract the mrl */
-    s_temp = strstr( s_mrl , " :" );
+    s_temp = FirstWord( s_mrl, s_mrl );
     if( s_temp == NULL )
     {
         s_temp = s_mrl + strlen( s_mrl );
-    } else
-    {
-        while( (*s_temp == ' ') && (s_temp != s_mrl ) )
-        {
-            s_temp--;
-        }
-        s_temp++;
-    }
-
-    /* if the mrl is between " or ', we must remove them */
-    if( (*s_mrl == '\'') || (*s_mrl == '\"') )
-    {
-        mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
-        strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
-        mrl[ s_temp - s_mrl - 2 ] = '\0';
-    } else
-    {
-        mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
-        strncpy( mrl , s_mrl , s_temp - s_mrl );
-        mrl[ s_temp - s_mrl ] = '\0';
     }
 
+    p_item = playlist_ItemNew( p_intf, s_mrl, psz_name );
     s_mrl = s_temp;
 
     /* now we can take care of the options */
-    while( (*s_mrl != '\0') && (i_error == 0) )
+    while( *s_mrl != '\0' )
     {
-        switch( *s_mrl )
+        s_temp = FirstWord( s_mrl, s_mrl );
+        if( s_mrl == '\0' )
+            break;
+        if( s_temp == NULL )
         {
-            case ' ':
-            {
-                s_mrl++;
-                break;
-            }
-            case ':': /* an option */
-            {
-                s_temp = Find_end_MRL( s_mrl );
-
-                if( s_temp == NULL )
-                {
-                    i_error = 1;
-                } else
-                {
-                    i_options++;
-                    ppsz_options = (char **)realloc( ppsz_options , i_options * sizeof(char *) );
-                    ppsz_options[ i_options - 1 ] = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
-
-                    strncpy( ppsz_options[ i_options - 1 ] , s_mrl , s_temp - s_mrl );
-                    /* don't forget to finish the string with a '\0' */
-                    (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
-
-                    s_mrl = s_temp;
-                }
-                break;
-            }
-            default:
-            {
-                i_error = 1;
-                break;
-            }
+            s_temp = s_mrl + strlen( s_mrl );
         }
+        if( *s_mrl != ':' )
+            msg_Warn( p_intf, "invalid MRL option: %s", s_mrl );
+        else
+            playlist_ItemAddOption( p_item, s_mrl );
+        s_mrl = s_temp;
     }
 
-    if( i_error != 0 )
-    {
-        free( mrl );
-        for( i = 0 ; i < i_options ; i++ )
-        {
-            free( ppsz_options[i] );
-        }
-        free( ppsz_options );
-        return NULL;
-    } else
-    {
-        /* now create an item */
-        p_item = malloc( sizeof( playlist_item_t ) );
-
-        p_item->psz_name   = mrl;
-        p_item->psz_uri    = strdup( mrl );
-        p_item->psz_author = strdup( "" );
-        p_item->i_duration = -1;
-        p_item->i_type = 0;
-        p_item->i_status = 0;
-        p_item->b_autodeletion = VLC_FALSE;
-        p_item->b_enabled = VLC_TRUE;
-        p_item->i_group = PLAYLIST_TYPE_MANUAL;
-
-        p_item->ppsz_options = NULL;
-        p_item->i_options = i_options;
-
-        if( i_options )
-        {
-            p_item->ppsz_options = ppsz_options;
-        }
-
-        return p_item;
-    }
+    free( psz );
+    return p_item;
 }