]> 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 13c2859a1f996a610dd5c168f1e2b15302f26483..1e547915eca2ed51fea0ce416c28f6596b67065d 100644 (file)
@@ -2,7 +2,7 @@
  * http.c :  http mini-server ;)
  *****************************************************************************
  * Copyright (C) 2001-2004 VideoLAN
- * $Id: http.c,v 1.53 2004/02/09 23:30:37 garf Exp $
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-/*
- * TODO:
- *
+/* TODO:
  * - clean up ?
  * - doc ! (mouarf ;)
- *
  */
 
 #include <stdlib.h>
@@ -40,7 +37,8 @@
 #include <vlc/aout.h>
 #include <vlc/vout.h> /* for fullscreen */
 
-#include "httpd.h"
+#include "vlc_httpd.h"
+#include "vlc_vlm.h"
 
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
@@ -66,8 +64,8 @@
 /*****************************************************************************
  * 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_( \
@@ -80,7 +78,7 @@ vlc_module_begin();
         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();
 
 
@@ -114,13 +112,15 @@ static int DirectoryCheck( char *psz_dir )
     return VLC_SUCCESS;
 }
 
-
-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 *,
+                          uint8_t *p_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_decode_url_encoded( char *psz );
 
 static char *Find_end_MRL( char *psz );
@@ -146,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;
 };
 
 
@@ -177,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;
@@ -212,20 +214,12 @@ static int Activate( vlc_object_t *p_this )
     }
     p_sys->p_playlist = NULL;
     p_sys->p_input    = NULL;
+    p_sys->p_vlm      = NULL;
 
-    if( ( p_sys->p_httpd = httpd_Find( VLC_OBJECT(p_intf), VLC_TRUE ) ) == NULL )
-    {
-        msg_Err( p_intf, "cannot create/find httpd" );
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
-
-    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;
     }
@@ -235,12 +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 *) );
-    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 ) )
@@ -250,7 +240,7 @@ static int Activate( vlc_object_t *p_this )
         psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
         if( !psz_src )
         {
-            return( VLC_ENOMEM );
+            return VLC_ENOMEM;
         }
 #if defined(WIN32)
         sprintf( psz_src, "%s/http", psz_vlcpath);
@@ -302,10 +292,11 @@ static int Activate( vlc_object_t *p_this )
 
 failed:
     if( psz_src ) free( psz_src );
-    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 );
     return VLC_EGENERIC;
 }
@@ -320,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 );
 }
 
@@ -442,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
  ****************************************************************************/
@@ -581,78 +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 ) );
-            if( !f )
-            {
-                msg_Err( p_intf, "out of memory" );
-                closedir( p_dir );
-                return( VLC_ENOMEM );
-            }
+            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;
 
-            if( !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 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 ? "text/html" : NULL,
+                                       user, password,
+                                       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 rep/ add a redir from rep 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" );
-                    closedir( p_dir );
-                    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 )
-                {
-                    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
         }
     }
 
@@ -938,7 +848,9 @@ 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 );
@@ -953,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 )
@@ -963,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" );
@@ -1032,6 +941,8 @@ static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
 
     return s;
 }
+#endif
+
 static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
 {
     mvar_t *s = mvar_New( name, "set" );
@@ -1203,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 * );
@@ -1347,11 +1333,23 @@ 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_FOREACH,
     MVLC_IF,
     MVLC_RPN,
@@ -1390,11 +1388,23 @@ 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 },
 
     { "foreach",    MVLC_FOREACH },
@@ -1431,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,
@@ -1766,7 +1776,8 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     uri_decode_url_encoded( mrl );
                     p_item = parse_MRL( p_intf, mrl );
 
-                    if( !p_item || !p_item->psz_uri || !*p_item->psz_uri )
+                    if( !p_item || !p_item->input.psz_uri ||
+                        !*p_item->input.psz_uri )
                     {
                         msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
                     } else
@@ -1891,10 +1902,33 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     {
                         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:
@@ -1902,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:
@@ -1914,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;
@@ -2010,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 );
@@ -2073,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,
@@ -2183,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 );
@@ -2195,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 );
@@ -2257,17 +2448,19 @@ 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;
 
@@ -2294,7 +2487,7 @@ static int  http_get( httpd_file_callback_args_t *p_args,
         return VLC_SUCCESS;
     }
 
-    if( strcmp( p_args->mime, "text/html" ) )
+    if( !p_args->b_html )
     {
         FileLoad( f, pp_data, pi_data );
     }
@@ -2383,6 +2576,22 @@ static int  http_get( httpd_file_callback_args_t *p_args,
 /****************************************************************************
  * uri parser
  ****************************************************************************/
+static int uri_test_param( char *psz_uri, 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' )
+        {
+            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 )
 {