]> git.sesse.net Git - vlc/blobdiff - modules/control/http.c
* src/input/control.c: added INPUT_ADD_INFO/INPUT_SET_NAME to input_Control().
[vlc] / modules / control / http.c
index 9d066116bf563cbcbfcb6f1faeb657a173a340ae..1e547915eca2ed51fea0ce416c28f6596b67065d 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * http.c :  http mini-server ;)
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.21 2003/08/01 17:30:33 fenrir Exp $
+ * Copyright (C) 2001-2004 VideoLAN
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-/*
- * TODO:
- *
+/* TODO:
  * - clean up ?
  * - doc ! (mouarf ;)
- *
  */
 
 #include <stdlib.h>
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 
-#include "httpd.h"
+#include <vlc/aout.h>
+#include <vlc/vout.h> /* for fullscreen */
+
+#include "vlc_httpd.h"
+#include "vlc_vlm.h"
 
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 /*****************************************************************************
  * 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" )
 
 vlc_module_begin();
     set_description( _("HTTP remote control interface") );
-    add_category_hint( N_("HTTP remote control"), NULL, VLC_TRUE );
         add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
         add_string ( "http-src",  NULL, NULL, SRC_TEXT,  SRC_LONGTEXT,  VLC_TRUE );
     set_capability( "interface", 0 );
-    set_callbacks( Activate, Close );
+    set_callbacks( Open, Close );
 vlc_module_end();
 
 
@@ -112,15 +112,21 @@ static int DirectoryCheck( char *psz_dir )
     return VLC_SUCCESS;
 }
 
+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,
+                                char *psz_value, int i_value_max );
+static int uri_test_param( char *psz_uri, char *psz_name );
 
-static void uri_extract_value( char *psz_uri, char *psz_name,
-                               char *psz_value, int i_value_max );
 static void uri_decode_url_encoded( char *psz );
 
+static char *Find_end_MRL( char *psz );
+
+static playlist_item_t * parse_MRL( intf_thread_t * , char *psz );
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -140,30 +146,32 @@ 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;
 
     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;
 };
 
 
@@ -171,7 +179,7 @@ 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;
@@ -200,22 +208,18 @@ static int Activate( vlc_object_t *p_this )
 
     msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
     p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
-    p_sys->p_playlist = NULL;
-    p_sys->p_input    = NULL;
-
-    if( ( p_sys->p_httpd = httpd_Find( VLC_OBJECT(p_intf), VLC_TRUE ) ) == NULL )
+    if( !p_intf->p_sys )
     {
-        msg_Err( p_intf, "cannot create/find httpd" );
-        free( p_sys );
-        return VLC_EGENERIC;
+        return( VLC_ENOMEM );
     }
+    p_sys->p_playlist = NULL;
+    p_sys->p_input    = NULL;
+    p_sys->p_vlm      = NULL;
 
-    if( ( p_sys->p_httpd_host =
-                p_sys->p_httpd->pf_register_host( p_sys->p_httpd,
-                                                  psz_address, i_port ) ) == NULL )
+    p_sys->p_httpd_host = httpd_HostNew( VLC_OBJECT(p_intf), psz_address, i_port );
+    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 );
         return VLC_EGENERIC;
     }
@@ -225,8 +229,8 @@ 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 *) );
+    p_sys->i_files  = 0;
+    p_sys->pp_files = NULL;
 
 #if defined(SYS_DARWIN) || defined(SYS_BEOS) || \
         ( defined(WIN32) && !defined(UNDER_CE ) )
@@ -234,6 +238,10 @@ static int Activate( vlc_object_t *p_this )
     {
         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 defined(WIN32)
         sprintf( psz_src, "%s/http", psz_vlcpath);
 #else
@@ -278,14 +286,17 @@ 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 );
     return VLC_EGENERIC;
 }
@@ -300,19 +311,29 @@ void Close ( vlc_object_t *p_this )
 
     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 );
+       }
+
        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 );
 }
 
@@ -381,6 +402,11 @@ static char *FileToUrl( char *name )
 
     url = p = malloc( strlen( name ) + 1 );
 
+    if( !url || !p )
+    {
+        return NULL;
+    }
+
 #ifdef WIN32
     while( *name == '\\' || *name == '/' )
 #else
@@ -417,63 +443,6 @@ static char *FileToUrl( char *name )
     return url;
 }
 
-/****************************************************************************
- * FileToMime: XXX duplicated with modules/access_out/http.c
- ****************************************************************************/
-static struct
-{
-    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" },
-
-    /* end */
-    { NULL,     NULL }
-};
-
-static char *FileToMime( char *psz_name )
-{
-    char *psz_ext;
-
-    psz_ext = strrchr( psz_name, '.' );
-    if( psz_ext )
-    {
-        int i;
-
-        for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
-        {
-            if( !strcmp( http_mime[i].psz_ext, psz_ext ) )
-            {
-                return( http_mime[i].psz_mime );
-            }
-        }
-    }
-    return( "application/octet-stream" );
-}
-
 /****************************************************************************
  * ParseDirectory: parse recursively a directory, adding each file
  ****************************************************************************/
@@ -556,59 +525,44 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
         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 ) );
+            httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
+
             f->p_intf  = p_intf;
+            f->p_file = NULL;
+            f->p_redir = NULL;
             f->file = strdup( dir );
             f->name = FileToUrl( &dir[strlen( psz_root )] );
-            f->mime = FileToMime( &dir[strlen( psz_root )] );
+            f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
 
-            msg_Dbg( p_intf, "file=%s (url=%s mime=%s)",
-                     f->file, f->name, f->mime );
+            if( !f->name )
+            {
+                msg_Err( p_intf , "unable to parse directory" );
+                closedir( p_dir );
+                free( f );
+                return( VLC_ENOMEM );
+            }
+            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 ? "text/html" : NULL,
+                                       user, password,
+                                       HttpCallback, f );
 
-            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 )
             {
-                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( strlen(fold->name) > 1 &&
-                fold->name[strlen(fold->name) - 1] == '/' )
+            /* For rep/ add a redir from rep to rep/ */
+            if( f && f->name[strlen(f->name) - 1] == '/' )
             {
-                f = malloc( sizeof( httpd_file_callback_args_t ) );
-                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 )
-                {
-                    p_sys->i_files++;
-                    p_sys->pp_files =
-                        realloc( p_sys->pp_files, (p_sys->i_files+1) *
-                                 sizeof( httpd_file_callback_args_t ) );
-                }
+                char *psz_redir = strdup( f->name );
+                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 );
             }
-#undef fold
-#undef f
         }
     }
 
@@ -620,6 +574,9 @@ static int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
     {
         free( password );
     }
+
+    closedir( p_dir );
+
     return VLC_SUCCESS;
 }
 
@@ -631,6 +588,7 @@ static mvar_t *mvar_New( char *name, char *value )
 {
     mvar_t *v = malloc( sizeof( mvar_t ) );
 
+    if( !v ) return NULL;
     v->name = strdup( name );
     v->value = strdup( value ? value : "" );
 
@@ -890,7 +848,12 @@ static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
         sprintf( value, "%d", i );
         mvar_AppendNewVar( itm, "index", value );
 
-        mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->psz_name );
+        mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->input.psz_name );
+
+        mvar_AppendNewVar( itm, "uri", p_pl->pp_items[i]->input.psz_uri );
+
+        sprintf( value, "%d", p_pl->pp_items[i]->i_group );
+        mvar_AppendNewVar( itm, "group", value );
 
         mvar_AppendVar( s, itm );
     }
@@ -902,9 +865,7 @@ static mvar_t *mvar_PlaylistSetNew( char *name, playlist_t *p_pl )
 static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
 {
     mvar_t *s = mvar_New( name, "set" );
-
-    input_info_category_t * p_category;
-    input_info_t * p_info;
+    int i, j;
 
     fprintf( stderr," mvar_InfoSetNew: name=`%s'\n", name );
     if( p_input == NULL )
@@ -912,35 +873,34 @@ static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
         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->p_item->lock );
+    for ( i = 0; i < p_input->p_item->i_categories; i++ )
     {
+        info_category_t *p_category = p_input->p_item->pp_categories[i];
         mvar_t *cat  = mvar_New( name, "set" );
         mvar_t *iset = mvar_New( "info", "set" );
 
         mvar_AppendNewVar( cat, "name", p_category->psz_name );
         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 );
+            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 );
             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->p_item->lock );
 
     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" );
@@ -974,9 +934,15 @@ 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;
 }
+#endif
+
 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
 {
     mvar_t *s = mvar_New( name, "set" );
@@ -1148,6 +1114,81 @@ 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;
+
+    /* fprintf( stderr," mvar_VlmSetNew: name=`%s'\n", name ); */
+    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 );
+
+            /* fprintf( stderr, "#### name=%s\n", 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" );
+
+                    /* fprintf( stderr, "        child=%s [%d]\n", ch->psz_name, ch->i_child ); */
+                    for( c = 0; c < ch->i_child; c++ )
+                    {
+                        mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
+                        mvar_AppendVar( n, in );
+
+                        /* fprintf( stderr, "            sub=%s\n", ch->child[c]->psz_name );*/
+                    }
+                    mvar_AppendVar( set, n );
+                }
+                else
+                {
+                    /* fprintf( stderr, "        child=%s->%s\n", ch->psz_name, ch->psz_value ); */
+                    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 * );
@@ -1289,9 +1330,26 @@ enum macroType
         MVLC_ADD,
         MVLC_DEL,
         MVLC_EMPTY,
+        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_FOREACH,
     MVLC_IF,
     MVLC_RPN,
@@ -1320,16 +1378,33 @@ StrToMacroTypeTab [] =
         { "pause",          MVLC_PAUSE },
         { "next",           MVLC_NEXT },
         { "previous",       MVLC_PREVIOUS },
+        { "seek",           MVLC_SEEK },
+        { "keep",           MVLC_KEEP },
+        { "fullscreen",     MVLC_FULLSCREEN },
+        { "volume",         MVLC_VOLUME },
 
         /* playlist management */
         { "add",            MVLC_ADD },
-        { "del",            MVLC_DEL },
+        { "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 },
 
     { "foreach",    MVLC_FOREACH },
@@ -1366,7 +1441,7 @@ 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,
@@ -1389,7 +1464,17 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
 
 #define PRINTS( str, s ) \
     ALLOC( strlen( str ) + strlen( s ) + 1 ); \
-    *pp_dst += sprintf( *pp_dst, str, s );
+    { \
+        char * psz_cur = *pp_dst; \
+        *pp_dst += sprintf( *pp_dst, str, s ); \
+        while( psz_cur && *psz_cur ) \
+        {  \
+            /* Prevent script injection */ \
+            if( *psz_cur == '<' ) *psz_cur = '*'; \
+            if( *psz_cur == '>' ) *psz_cur = '*'; \
+            psz_cur++ ; \
+        } \
+    }
 
     switch( StrToMacroType( m->id ) )
     {
@@ -1435,28 +1520,353 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                                       p_sys->p_playlist->i_index - 1 );
                     msg_Dbg( p_intf, "requested playlist next" );
                     break;
+                case MVLC_FULLSCREEN:
+                {
+                    if( p_sys->p_input )
+                    {
+                        vout_thread_t *p_vout;
+                        p_vout = vlc_object_find( p_sys->p_input,
+                                                  VLC_OBJECT_VOUT, FIND_CHILD );
+
+                        if( p_vout )
+                        {
+                            p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
+                            vlc_object_release( p_vout );
+                            msg_Dbg( p_intf, "requested fullscreen toggle" );
+                        }
+                    }
+                }
+                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
+                    break;
+                }
+                case MVLC_VOLUME:
+                {
+                    char vol[8];
+                    audio_volume_t i_volume;
+                    int i_value;
+
+                    uri_extract_value( p_request, "value", vol, 8 );
+                    aout_VolumeGet( p_intf, &i_volume );
+                    uri_decode_url_encoded( vol );
+
+                    if( vol[0] == '+' )
+                    {
+                        i_value = atoi( vol + 1 );
+                        if( (i_volume + i_value) > AOUT_VOLUME_MAX )
+                        {
+                            aout_VolumeSet( p_intf , AOUT_VOLUME_MAX );
+                            msg_Dbg( p_intf, "requested volume set: max" );
+                        } 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] == '-' )
+                    {
+                        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
+                        {
+                            aout_VolumeSet( p_intf , (i_volume - i_value) );
+                            msg_Dbg( p_intf, "requested volume set: -%i", (i_volume - i_value) );
+                        }
+                    } else
+                    {
+                        i_value = atoi( vol );
+                        if( ( i_value <= AOUT_VOLUME_MAX ) && ( i_value >= AOUT_VOLUME_MIN ) )
+                        {
+                            aout_VolumeSet( p_intf , atoi( vol ) );
+                            msg_Dbg( p_intf, "requested volume set: %i", atoi( vol ) );
+                        }
+                    }
+                    break;
+                }
 
                 /* playlist management */
                 case MVLC_ADD:
                 {
                     char mrl[512];
+                    playlist_item_t * p_item;
+
                     uri_extract_value( p_request, "mrl", mrl, 512 );
                     uri_decode_url_encoded( mrl );
-                    playlist_Add( p_sys->p_playlist, mrl, NULL, 0,
-                                  PLAYLIST_APPEND, PLAYLIST_END );
-                    msg_Dbg( p_intf, "requested playlist add: %s", mrl );
+                    p_item = parse_MRL( p_intf, mrl );
+
+                    if( !p_item || !p_item->input.psz_uri ||
+                        !*p_item->input.psz_uri )
+                    {
+                        msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
+                    } else
+                    {
+                        playlist_AddItem( p_sys->p_playlist , p_item ,
+                                          PLAYLIST_APPEND, PLAYLIST_END );
+                        msg_Dbg( p_intf, "requested mrl add: %s", mrl );
+                    }
+
                     break;
                 }
                 case MVLC_DEL:
                 {
-                    int i_item;
-                    char item[512];
+                    int i_item, *p_items = NULL, i_nb_items = 0;
+                    char item[512], *p_parser = p_request;
 
-                    uri_extract_value( p_request, "item", item, 512 );
-                    i_item = atoi( item );
+                    /* Get the list of items to delete */
+                    while( (p_parser =
+                            uri_extract_value( p_parser, "item", item, 512 )) )
+                    {
+                        if( !*item ) continue;
+
+                        i_item = atoi( item );
+                        p_items = realloc( p_items, (i_nb_items + 1) *
+                                           sizeof(int) );
+                        p_items[i_nb_items] = i_item;
+                        i_nb_items++;
+                    }
 
-                    playlist_Delete( p_sys->p_playlist, i_item );
-                    msg_Dbg( p_intf, "requested playlist del: %d", i_item );
+                    /* 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] );
+                            msg_Dbg( p_intf, "requested playlist delete: %d",
+                                     p_items[i_index] );
+                            p_items[i_index] = -1;
+                        }
+                    }
+
+                    if( p_items ) free( p_items );
+                    break;
+                }
+                case MVLC_KEEP:
+                {
+                    int i_item, *p_items = NULL, i_nb_items = 0;
+                    char item[512], *p_parser = p_request;
+                    int i,j;
+
+                    /* Get the list of items to keep */
+                    while( (p_parser =
+                            uri_extract_value( p_parser, "item", item, 512 )) )
+                    {
+                        if( !*item ) continue;
+
+                        i_item = atoi( item );
+                        p_items = realloc( p_items, (i_nb_items + 1) *
+                                           sizeof(int) );
+                        p_items[i_nb_items] = i_item;
+                        i_nb_items++;
+                    }
+
+                    /* The items need to be deleted from in reversed order */
+                    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( j == i_nb_items )
+                        {
+                            playlist_Delete( p_sys->p_playlist, i );
+                            msg_Dbg( p_intf, "requested playlist delete: %d",
+                                     i );
+                        }
+                    }
+
+                    if( p_items ) free( p_items );
                     break;
                 }
                 case MVLC_EMPTY:
@@ -1468,6 +1878,57 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     msg_Dbg( p_intf, "requested playlist empty" );
                     break;
                 }
+                case MVLC_SORT:
+                {
+                    char type[12];
+                    char order[2];
+                    int i_order;
+
+                    uri_extract_value( p_request, "type", type, 12 );
+                    uri_extract_value( p_request, "order", order, 2 );
+
+                    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 );
+                        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" ) )
+                    {
+                        playlist_SortAuthor( p_sys->p_playlist , i_order );
+                        msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
+                    } else if( !strcmp( type , "shuffle" ) )
+                    {
+                        playlist_Sort( p_sys->p_playlist , SORT_RANDOM, ORDER_NORMAL );
+                        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:
@@ -1475,10 +1936,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:
@@ -1487,8 +1950,152 @@ 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", "append", "date", "period", "repeat",
+                    };
+                    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 );
+
+                    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] );
+                        }
+                    }
+                    fprintf( stderr, "vlm_ExecuteCommand: %s\n", psz );
+                    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 );
+
+                    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 );
+
+                    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 );
+
+                    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) unsuported -->", control );
+                    }
                     break;
             }
             break;
@@ -1551,6 +2158,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 case MVLC_STRING:
                     psz = config_GetPsz( p_intf, m->param1 );
                     sprintf( value, "%s", psz ? psz : "" );
+                    if( psz ) free( psz );
                     break;
                 default:
                     sprintf( value, "invalid type(%s) in set", m->param2 );
@@ -1582,6 +2190,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
         case MVLC_RPN:
             EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
             break;
+
         case MVLC_UNKNOWN:
         default:
             PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
@@ -1622,6 +2231,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 ) )
             {
@@ -1643,7 +2254,7 @@ 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,
+static void Execute( httpd_file_sys_t *p_args,
                      uint8_t *p_request, int i_request,
                      uint8_t **pp_data, int *pi_data,
                      uint8_t **pp_dst,
@@ -1753,6 +2364,15 @@ static void Execute( httpd_file_callback_args_t *p_args,
                         {
                             index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
                         }
+                        else if( !strcmp( m.param2, "vlm" ) )
+                        {
+                            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 );
@@ -1765,6 +2385,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 );
@@ -1827,24 +2448,29 @@ 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 )
 {
+    int i_request = p_request ? strlen( p_request ) : 0;
     char *p;
     FILE *f;
 
     if( ( f = fopen( p_args->file, "r" ) ) == NULL )
     {
         p = *pp_data = malloc( 10240 );
-
+        if( !p )
+        {
+                return VLC_EGENERIC;
+        }
         p += sprintf( p, "<html>\n" );
         p += sprintf( p, "<head>\n" );
         p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
@@ -1852,16 +2478,16 @@ 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 );
     }
@@ -1870,12 +2496,57 @@ static int  http_get( httpd_file_callback_args_t *p_args,
         int  i_buffer;
         uint8_t *p_buffer;
         uint8_t *dst;
+        vlc_value_t val;
+        char position[4]; /* percentage */
+        char time[12]; /* in seconds */
+        char length[12]; /* in seconds */
+        audio_volume_t i_volume;
+        char volume[5];
+        char state[8];
+#define p_sys p_args->p_intf->p_sys
+        if( p_sys->p_input )
+        {
+            var_Get( p_sys->p_input, "position", &val);
+            sprintf( position, "%d" , (int)((val.f_float) * 100.0));
+            var_Get( p_sys->p_input, "time", &val);
+            sprintf( time, "%d" , (int)(val.i_time / 1000000) );
+            var_Get( p_sys->p_input, "length", &val);
+            sprintf( length, "%d" , (int)(val.i_time / 1000000) );
+
+            var_Get( p_sys->p_input, "state", &val );
+            if( val.i_int == PLAYING_S )
+            {
+                sprintf( state, "playing" );
+            } else if( val.i_int == PAUSE_S )
+            {
+                sprintf( state, "paused" );
+            } else
+            {
+                sprintf( state, "stop" );
+            }
+        } else
+        {
+            sprintf( position, "%d", 0 );
+            sprintf( time, "%d", 0 );
+            sprintf( length, "%d", 0 );
+            sprintf( state, "stop" );
+        }
+#undef p_sys
+
+        aout_VolumeGet( p_args->p_intf , &i_volume );
+        sprintf( volume , "%d" , (int)i_volume );
 
         p_args->vars = mvar_New( "variables", "" );
         mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" );
         mvar_AppendNewVar( p_args->vars, "url_value", p_request );
         mvar_AppendNewVar( p_args->vars, "version",   VERSION_MESSAGE );
         mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
+        mvar_AppendNewVar( p_args->vars, "stream_position", position );
+        mvar_AppendNewVar( p_args->vars, "stream_time", time );
+        mvar_AppendNewVar( p_args->vars, "stream_length", length );
+        mvar_AppendNewVar( p_args->vars, "volume", volume );
+        mvar_AppendNewVar( p_args->vars, "stream_state", state );
 
         SSInit( &p_args->stack );
 
@@ -1889,11 +2560,12 @@ static int  http_get( httpd_file_callback_args_t *p_args,
         /* 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] );
 
-        *dst++ = '\0';
+        *dst     = '\0';
         *pi_data = dst - *pp_data;
 
         SSClean( &p_args->stack );
         mvar_Delete( p_args->vars );
+        free( p_buffer );
     }
 
     fclose( f );
@@ -1904,12 +2576,35 @@ static int  http_get( httpd_file_callback_args_t *p_args,
 /****************************************************************************
  * uri parser
  ****************************************************************************/
-static void uri_extract_value( char *psz_uri, char *psz_name,
-                               char *psz_value, int i_value_max )
+static int uri_test_param( char *psz_uri, char *psz_name )
 {
-    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' )
+        {
+            return VLC_TRUE;
+        }
+        p++;
+    }
+
+    return VLC_FALSE;
+}
+static char *uri_extract_value( char *psz_uri, char *psz_name,
+                                char *psz_value, int i_value_max )
+{
+    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' )
+            break;
+        p++;
+    }
 
-    p = strstr( psz_uri, psz_name );
     if( p )
     {
         int i_len;
@@ -1944,11 +2639,14 @@ static void uri_extract_value( char *psz_uri, char *psz_name,
         {
             strncpy( psz_value, "", i_value_max );
         }
+        p += i_len;
     }
     else
     {
         strncpy( psz_value, "", i_value_max );
     }
+
+    return p;
 }
 
 static void uri_decode_url_encoded( char *psz )
@@ -2123,8 +2821,8 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         }
         else if( !strcmp( s, "-" ) )
         {
-            int i = SSPopN( st, vars );
             int j = SSPopN( st, vars );
+            int i = SSPopN( st, vars );
             SSPushN( st, i - j );
         }
         else if( !strcmp( s, "*" ) )
@@ -2135,8 +2833,8 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         {
             int i, j;
 
-            i = SSPopN( st, vars );
             j = SSPopN( st, vars );
+            i = SSPopN( st, vars );
 
             SSPushN( st, j != 0 ? i / j : 0 );
         }
@@ -2144,8 +2842,8 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         {
             int i, j;
 
-            i = SSPopN( st, vars );
             j = SSPopN( st, vars );
+            i = SSPopN( st, vars );
 
             SSPushN( st, j != 0 ? i % j : 0 );
         }
@@ -2156,37 +2854,37 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         }
         else if( !strcmp( s, "<" ) )
         {
-            int i = SSPopN( st, vars );
             int j = SSPopN( st, vars );
+            int i = SSPopN( st, vars );
 
             SSPushN( st, i < j ? -1 : 0 );
         }
         else if( !strcmp( s, ">" ) )
         {
-            int i = SSPopN( st, vars );
             int j = SSPopN( st, vars );
+            int i = SSPopN( st, vars );
 
             SSPushN( st, i > j ? -1 : 0 );
         }
         else if( !strcmp( s, "<=" ) )
         {
-            int i = SSPopN( st, vars );
             int j = SSPopN( st, vars );
+            int i = SSPopN( st, vars );
 
             SSPushN( st, i <= j ? -1 : 0 );
         }
         else if( !strcmp( s, ">=" ) )
         {
-            int i = SSPopN( st, vars );
             int j = SSPopN( st, vars );
+            int i = SSPopN( st, vars );
 
             SSPushN( st, i >= j ? -1 : 0 );
         }
         /* 3. string functions */
         else if( !strcmp( s, "strcat" ) )
         {
-            char *s1 = SSPop( st );
             char *s2 = SSPop( st );
+            char *s1 = SSPop( st );
             char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
 
             strcpy( str, s1 );
@@ -2199,14 +2897,50 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         }
         else if( !strcmp( s, "strcmp" ) )
         {
-            char *s1 = SSPop( st );
             char *s2 = SSPop( st );
+            char *s1 = SSPop( st );
 
             SSPushN( st, strcmp( s1, s2 ) );
             free( s1 );
             free( s2 );
         }
-        else if( !strcmp( s, "strlen" ) )
+        else if( !strcmp( s, "strncmp" ) )
+        {
+            int n = SSPopN( st, vars );
+            char *s2 = SSPop( st );
+            char *s1 = SSPop( st );
+
+            SSPushN( st, strncmp( s1, s2 , n ) );
+            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 );
 
@@ -2243,8 +2977,8 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         }
         else if( !strcmp( s, "store" ) )
         {
-            char *name  = SSPop( st );
             char *value = SSPop( st );
+            char *name  = SSPop( st );
 
             mvar_PushNewVar( vars, name, value );
             free( name );
@@ -2276,5 +3010,210 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
     }
 }
 
+/**********************************************************************
+ * 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 '\"':
+        {
+            s_sent++;
+
+            while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
+            {
+                if( *s_sent == '\'' )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+
+                    if( s_sent == NULL )
+                    {
+                        return NULL;
+                    }
+                } else
+                {
+                    s_sent++;
+                }
+            }
+
+            if( *s_sent == '\"' )
+            {
+                s_sent++;
+                return s_sent;
+            } else  /* *s_sent == '\0' , which means the number of " is incorrect */
+            {
+                return NULL;
+            }
+            break;
+        }
+        case '\'':
+        {
+            s_sent++;
+
+            while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
+            {
+                if( *s_sent == '\"' )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+
+                    if( s_sent == NULL )
+                    {
+                        return NULL;
+                    }
+                } else
+                {
+                    s_sent++;
+                }
+            }
+
+            if( *s_sent == '\'' )
+            {
+                s_sent++;
+                return s_sent;
+            } else  /* *s_sent == '\0' , which means the number of ' is incorrect */
+            {
+                return NULL;
+            }
+            break;
+        }
+        default: /* now we can look for spaces */
+        {
+            while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
+            {
+                if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+                } else
+                {
+                    s_sent++;
+                }
+            }
+            return s_sent;
+        }
+    }
+}
+
+/**********************************************************************
+ * parse_MRL: parse the MRL, find the mrl string and the options,
+ * create an item with all informations in it, and return the item.
+ * return NULL if there is an error.
+ **********************************************************************/
+playlist_item_t * parse_MRL( intf_thread_t *p_intf, char *psz )
+{
+    char **ppsz_options = NULL;
+    char *mrl;
+    char *s_mrl = psz;
+    int i_error = 0;
+    char *s_temp;
+    int i = 0;
+    int i_options = 0;
+    playlist_item_t * p_item = NULL;
+
+    /* In case there is spaces before the mrl */
+    while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
+    {
+        s_mrl++;
+    }
 
+    /* extract the mrl */
+    s_temp = strstr( 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';
+    }
+
+    s_mrl = s_temp;
+
+    /* now we can take care of the options */
+    while( (*s_mrl != '\0') && (i_error == 0) )
+    {
+        switch( *s_mrl )
+        {
+            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 = realloc( ppsz_options , i_options *
+                                            sizeof(char *) );
+                    ppsz_options[ i_options - 1 ] =
+                        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;
+            }
+        }
+    }
+
+    if( i_error != 0 )
+    {
+        free( mrl );
+    }
+    else
+    {
+        /* now create an item */
+        p_item = playlist_ItemNew( p_intf, mrl, mrl);
+        for( i = 0 ; i< i_options ; i++ )
+        {
+            playlist_ItemAddOption( p_item, ppsz_options[i] );
+        }
+    }
+
+    for( i = 0 ; i < i_options ; i++ )
+    {
+        free( ppsz_options[i] );
+    }
+    free( ppsz_options );
+
+    return p_item;
+}