]> git.sesse.net Git - vlc/blobdiff - src/misc/vlm.c
fileinfo.hpp: we need to use b_stats in Update()
[vlc] / src / misc / vlm.c
index 2b1b9da35f78fc4101d38aef8f3e7cba2f5d26dd..0bc74afded1e366780609ba989f287aa895744d4 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vlm.c: VLM interface plugin
  *****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
+ * Copyright (C) 2000-2005 the VideoLAN team
  * $Id$
  *
  * Authors: Simon Latapie <garf@videolan.org>
@@ -20,7 +20,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 
 #ifdef HAVE_TIME_H
 #   include <time.h>                                              /* ctime() */
+#   include <sys/timeb.h>                                         /* ftime() */
 #endif
 
-#include "vlc_vlm.h"
-#include "vlc_vod.h"
+#include <vlc_vlm.h>
+#include <vlc_vod.h>
+#include <charset.h>
 
 #define FREE( p ) \
         if( p ) { free( p ); (p) = NULL; }
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static char          *vlm_Save( vlm_t * );
-static int            vlm_Load( vlm_t *, char *);
 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * );
 static vlm_message_t *vlm_Help( vlm_t *, char * );
 
-static vlm_media_t *vlm_MediaNew    ( vlm_t *, char *, int );
-static void         vlm_MediaDelete ( vlm_t *, vlm_media_t *, char * );
-static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * );
-static int          vlm_MediaSetup  ( vlm_t *, vlm_media_t *, char *, char * );
-static int          vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char *, char * );
-static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, char * );
+static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, const char * );
 
 static vlm_message_t *vlm_MessageNew( char *, const char *, ... );
-static vlm_message_t *vlm_MessageAdd( vlm_message_t*, vlm_message_t* );
+static vlm_message_t *vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
 
-static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *);
-static void            vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *);
-static int             vlm_ScheduleSetup( vlm_schedule_t *, char *, char *);
-static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *);
+static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, const char * );
 
-static int vlm_MediaVodControl( void *, vod_media_t *, char *, int, va_list );
-
-static int ExecuteCommand( vlm_t *, char *, vlm_message_t **);
-static int Manage( vlc_object_t* );
+static char *Save( vlm_t * );
+static int Load( vlm_t *, char * );
+static int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
+static int Manage( vlc_object_t * );
 
 /*****************************************************************************
  * vlm_New:
@@ -81,6 +73,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
 {
     vlc_value_t lockval;
     vlm_t *p_vlm = NULL;
+    char *psz_vlmconf;
 
     /* to be sure to avoid multiple creation */
     var_Create( p_this->p_libvlc, "vlm_mutex", VLC_VAR_MUTEX );
@@ -116,8 +109,8 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
         return NULL;
     }
 
-    /* try loading the vlm conf file given by --vlm-conf */
-    char *psz_vlmconf =  config_GetPsz( p_vlm, "vlm-conf" );
+    /* Try loading the vlm conf file given by --vlm-conf */
+    psz_vlmconf = config_GetPsz( p_vlm, "vlm-conf" );
 
     if( psz_vlmconf && *psz_vlmconf )
     {
@@ -132,7 +125,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
             if( vlm_ExecuteCommand( p_vlm, psz_buffer, &p_message ) ){
                 msg_Warn( p_this, "error while loading the vlm conf file" );
             }
-            free(p_message);
+            vlm_MessageDelete(p_message);
             free(psz_buffer);
         }
    }
@@ -179,7 +172,7 @@ void vlm_Delete( vlm_t *p_vlm )
 /*****************************************************************************
  * vlm_ExecuteCommand:
  *****************************************************************************/
-int vlm_ExecuteCommand( vlm_t *p_vlm, char *psz_command,
+int vlm_ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
                         vlm_message_t **pp_message)
 {
     int i_result;
@@ -192,12 +185,81 @@ int vlm_ExecuteCommand( vlm_t *p_vlm, char *psz_command,
 }
 
 /*****************************************************************************
- * FindEndCommand
+ * vlm_Save:
  *****************************************************************************/
-static char *FindEndCommand( char *psz )
+int vlm_Save( vlm_t *p_vlm, const char *psz_file )
 {
-    char *psz_sent = psz;
+    FILE *file;
+    char *psz_save;
+
+    if( !p_vlm || !psz_file ) return 1;
+
+    file = utf8_fopen( psz_file, "wt" );
+    if( file == NULL ) return 1;
+
+    psz_save = Save( p_vlm );
+    if( psz_save == NULL )
+    {
+        fclose( file );
+        return 1;
+    }
+    fwrite( psz_save, strlen( psz_save ), 1, file );
+    fclose( file );
+    free( psz_save );
+
+    return 0;
+}
+
+/*****************************************************************************
+ * vlm_Load:
+ *****************************************************************************/
+int vlm_Load( vlm_t *p_vlm, const char *psz_file )
+{
+    stream_t *p_stream;
+    int64_t i_size;
+    char *psz_buffer;
+
+    if( !p_vlm || !psz_file ) return 1;
+
+    p_stream = stream_UrlNew( p_vlm, psz_file );
+    if( p_stream == NULL ) return 1;
+
+    if( stream_Seek( p_stream, 0 ) != 0 )
+    {
+        stream_Delete( p_stream );
+        return 2;
+    }
+
+    i_size = stream_Size( p_stream );
+
+    psz_buffer = malloc( i_size + 1 );
+    if( !psz_buffer )
+    {
+        stream_Delete( p_stream );
+        return 2;
+    }
+
+    stream_Read( p_stream, psz_buffer, i_size );
+    psz_buffer[ i_size ] = '\0';
+
+    stream_Delete( p_stream );
+
+    if( Load( p_vlm, psz_buffer ) )
+    {
+        free( psz_buffer );
+        return 3;
+    }
 
+    free( psz_buffer );
+
+    return 0;
+}
+
+/*****************************************************************************
+ * FindEndCommand
+ *****************************************************************************/
+static const char *FindEndCommand( const char *psz_sent )
+{
     switch( *psz_sent )
     {
     case '\"':
@@ -254,6 +316,7 @@ static char *FindEndCommand( char *psz )
             if( ( *psz_sent == '\'' ) || ( *psz_sent == '\"' ) )
             {
                 psz_sent = FindEndCommand( psz_sent );
+                if( psz_sent == NULL ) return NULL;
             }
             else psz_sent++;
         }
@@ -267,12 +330,12 @@ static char *FindEndCommand( char *psz )
  *****************************************************************************
  * Execute a command which ends with '\0' (string)
  *****************************************************************************/
-static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
+static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
                            vlm_message_t **pp_message )
 {
     int i_command = 0;
     char **ppsz_command = NULL;
-    char *psz_cmd = psz_command;
+    const char *psz_cmd = psz_command;
     vlm_message_t *p_message = NULL;
     int i, j;
 
@@ -286,7 +349,7 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
         }
         else
         {
-            char *psz_temp;
+            const char *psz_temp;
             int   i_temp;
 
             /* support for comments */
@@ -298,7 +361,11 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
 
             psz_temp = FindEndCommand( psz_cmd );
 
-            if( psz_temp == NULL ) goto error;
+            if( psz_temp == NULL )
+            {
+                p_message = vlm_MessageNew( "Incomplete command", psz_cmd );
+                goto error;
+            }
 
             i_temp = psz_temp - psz_cmd;
 
@@ -538,80 +605,52 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
 
     else if( !strcmp(ppsz_command[0], "save") )
     {
-        FILE *file;
-
         if( i_command != 2 ) goto syntax_error;
 
-        file = fopen( ppsz_command[1], "w" );
-        if( file == NULL )
+        if( vlm_Save( p_vlm, ppsz_command[1] ) )
         {
             p_message = vlm_MessageNew( "save", "Unable to save to file" );
             goto error;
         }
         else
         {
-            char *psz_save = vlm_Save( p_vlm );
-            if( psz_save == NULL )
-            {
-                fclose( file );
-                goto error;
-            }
-            fwrite( psz_save, strlen( psz_save ), 1, file );
-            fclose( file );
-            free( psz_save );
             p_message = vlm_MessageNew( "save", NULL );
             goto success;
         }
     }
 
-    else if( !strcmp(ppsz_command[0], "load") )
+    else if( !strcmp(ppsz_command[0], "export" ) )
     {
-        FILE *file;
+        char *psz_buf;
 
-        if( i_command != 2 ) goto syntax_error;
+        if( i_command != 1 ) goto syntax_error;
 
-        file = fopen( ppsz_command[1], "r" );
+        p_message = vlm_MessageNew( "export", psz_buf = Save( p_vlm ) );
+        free( psz_buf );
 
-        if( file == NULL )
-        {
-            p_message = vlm_MessageNew( "load", "Unable to load from file" );
-            goto error;
-        }
-        else
-        {
-            int64_t i_size;
-            char *psz_buffer;
+        goto success;
+    }
 
-            if( fseek( file, 0, SEEK_END) == 0 )
-            {
-                i_size = ftell( file );
-                fseek( file, 0, SEEK_SET);
-                psz_buffer = malloc( i_size + 1 );
-                if( !psz_buffer )
-                {
-                    fclose( file );
-                    goto error;
-                }
-                fread( psz_buffer, 1, i_size, file);
-                psz_buffer[ i_size ] = '\0';
-                if( vlm_Load( p_vlm, psz_buffer ) )
-                {
-                    free( psz_buffer );
-                    p_message = vlm_MessageNew( "load", "error while loading "
-                                              "file" );
-                    goto error;
-                }
-                free( psz_buffer );
-            }
-            else
-            {
+    else if( !strcmp(ppsz_command[0], "load") )
+    {
+        if( i_command != 2 ) goto syntax_error;
+
+        switch( vlm_Load( p_vlm, ppsz_command[1] ) )
+        {
+            case 0:
+                p_message = vlm_MessageNew( "load", NULL );
+                goto success;
+            case 2:
                 p_message = vlm_MessageNew( "load", "read file error" );
                 goto error;
-            }
-
-            fclose( file );
-            p_message = vlm_MessageNew( "load", NULL );
-            goto success;
+            case 3:
+                p_message =
+                    vlm_MessageNew( "load", "error while loading file" );
+                goto error;
+            default:
+                p_message =
+                    vlm_MessageNew( "load", "Unable to load from file" );
+                goto error;
         }
     }
 
@@ -734,7 +773,7 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
                 }
                 else
                 {
-                    if( i + 1 >= i_command &&
+                    if( ( (i + 1) >= i_command ) &&
                         !strcmp(ppsz_command[0], "new") )
                     {
                         vlm_MediaDelete( p_vlm, p_media, NULL );
@@ -743,7 +782,7 @@ static int ExecuteCommand( vlm_t *p_vlm, char *psz_command,
                                             "Wrong properties syntax" );
                         goto error;
                     }
-                    else if( i + 1 >= i_command )
+                    else if( (i + 1) >= i_command )
                     {
                         p_message =
                             vlm_MessageNew( ppsz_command[0],
@@ -780,7 +819,7 @@ error:
     return VLC_EGENERIC;
 }
 
-static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name )
+vlm_media_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
 {
     int i;
 
@@ -799,7 +838,8 @@ static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name )
  * Media handling
  *****************************************************************************/
 static vlm_media_instance_t *
-vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media, char *psz_name )
+vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media,
+                         const char *psz_name )
 {
     int i;
 
@@ -816,7 +856,7 @@ vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media, char *psz_name )
     return NULL;
 }
 
-static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
+vlm_media_t *vlm_MediaNew( vlm_t *vlm, const char *psz_name, int i_type )
 {
     vlm_media_t *media = malloc( sizeof( vlm_media_t ) );
 
@@ -863,7 +903,6 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
     media->i_instance = 0;
     media->instance = NULL;
 
-    media->item.psz_uri = strdup( psz_name );
     vlc_input_item_Init( VLC_OBJECT(vlm), &media->item );
 
     TAB_APPEND( vlm->i_media, vlm->media, media );
@@ -872,7 +911,7 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
 }
 
 /* for now, simple delete. After, del with options (last arg) */
-static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
+void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, const char *psz_name )
 {
     if( media == NULL ) return;
 
@@ -917,8 +956,8 @@ static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
     free( media );
 }
 
-static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
-                           char *psz_value )
+int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
+                    const char *psz_value )
 {
     if( !psz_cmd) return VLC_EGENERIC;
 
@@ -965,6 +1004,50 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
 
         TAB_APPEND( media->i_input, media->input, input );
     }
+    else if( !strcmp( psz_cmd, "inputdel" ) && !strcmp( psz_value, "all" ) )
+    {
+        while( media->i_input > 0 )
+        {
+            TAB_REMOVE( media->i_input, media->input, media->input[0] );
+        }
+    }
+    else if( !strcmp( psz_cmd, "inputdel" ) )
+    {
+        char *input;
+        int i;
+
+        if( psz_value != NULL && strlen(psz_value) > 1 &&
+            ( psz_value[0] == '\'' || psz_value[0] == '\"' ) &&
+            ( psz_value[ strlen(psz_value) - 1 ] == '\'' ||
+              psz_value[ strlen(psz_value) - 1 ] == '\"' )  )
+        {
+            input = malloc( strlen(psz_value) - 1 );
+
+            memcpy( input, psz_value + 1, strlen(psz_value) - 2 );
+            input[ strlen(psz_value) - 2 ] = '\0';
+        }
+        else
+        {
+            input = strdup( psz_value );
+        }
+
+        for( i = 0; i < media->i_input; i++ )
+        {
+            if( !strcmp( input, media->input[i] ) )
+            {
+                TAB_REMOVE( media->i_input, media->input, media->input[i] );
+                break;
+            }
+        }
+    }
+    else if( !strcmp( psz_cmd, "inputdeln" ) )
+    {
+        int index = atoi( psz_value );
+        if( index > 0 && index <= media->i_input )
+        {
+            TAB_REMOVE( media->i_input, media->input, media->input[index-1] );
+        }
+    }
     else if( !strcmp( psz_cmd, "output" ) )
     {
         if( media->psz_output != NULL )
@@ -998,6 +1081,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
             /* Pre-parse the input */
             input_thread_t *p_input;
             char *psz_output;
+            char *psz_header;
             int i;
 
             vlc_input_item_Clean( &media->item );
@@ -1022,7 +1106,10 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
                     strdup( media->option[i] );
             }
 
-            if( (p_input = input_CreateThread( vlm, &media->item ) ) )
+            asprintf( &psz_header, _("Media: %s"), media->psz_name );
+
+            if( (p_input = input_CreateThread2( vlm, &media->item, psz_header
+                                              ) ) )
             {
                 while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );
 
@@ -1032,6 +1119,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
                 vlc_object_destroy( p_input );
             }
             free( psz_output );
+            free( psz_header );
 
             if( media->psz_mux )
             {
@@ -1062,15 +1150,16 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
     return VLC_SUCCESS;
 }
 
-static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
-                             char *psz_command, char *psz_args )
+int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
+                      const char *psz_command, const char *psz_args )
 {
     vlm_media_instance_t *p_instance;
     int i;
+    char *psz_header;
 
     p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
 
-    if( !strcmp( psz_command, "play" ) && !p_instance )
+    if( !strcmp( psz_command, "play" ) )
     {
         if( !media->b_enabled || media->i_input == 0 ) return 0;
 
@@ -1082,7 +1171,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
             vlc_input_item_Init( VLC_OBJECT(vlm), &p_instance->item );
             p_instance->p_input = NULL;
 
-            if( media->psz_output != NULL || media->psz_vod_output != NULL )
+            if( ( media->psz_output != NULL ) || ( media->psz_vod_output != NULL ) )
             {
                 p_instance->item.ppsz_options = malloc( sizeof( char* ) );
                 asprintf( &p_instance->item.ppsz_options[0], "sout=%s%s%s",
@@ -1107,7 +1196,7 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
             TAB_APPEND( media->i_instance, media->instance, p_instance );
         }
 
-        if( psz_args && sscanf(psz_args, "%d", &i) == 1 && i < media->i_input )
+        if( ( psz_args && sscanf(psz_args, "%d", &i) == 1 ) && ( i < media->i_input ) )
         {
             p_instance->i_index = i;
         }
@@ -1124,13 +1213,16 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
             vlc_object_destroy( p_instance->p_input );
         }
 
-        p_instance->p_input = input_CreateThread( vlm, &p_instance->item );
+        asprintf( &psz_header, _("Media: %s"), media->psz_name );
+        p_instance->p_input = input_CreateThread2( vlm, &p_instance->item,
+                                                   psz_header );
         if( !p_instance->p_input )
         {
             TAB_REMOVE( media->i_instance, media->instance, p_instance );
             vlc_input_item_Clean( &p_instance->item );
             if( p_instance->psz_name ) free( p_instance->psz_name );
         }
+        free( psz_header );
 
         return VLC_SUCCESS;
     }
@@ -1188,7 +1280,18 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
 /*****************************************************************************
  * Schedule handling
  *****************************************************************************/
-static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
+static int64_t vlm_Date()
+{
+#ifdef WIN32
+    struct timeb tm;
+    ftime( &tm );
+    return ((int64_t)tm.time) * 1000000 + ((int64_t)tm.millitm) * 1000;
+#else
+    return mdate();
+#endif
+}
+
+vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
 {
     vlm_schedule_t *p_sched = malloc( sizeof( vlm_schedule_t ) );
 
@@ -1216,8 +1319,8 @@ static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
 }
 
 /* for now, simple delete. After, del with options (last arg) */
-static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
-                                char *psz_name )
+void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
+                         const char *psz_name )
 {
     if( sched == NULL ) return;
 
@@ -1225,11 +1328,16 @@ static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
 
     if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule );
     free( sched->psz_name );
-    while( sched->i_command-- ) free( sched->command[sched->i_command] );
+    while( sched->i_command )
+    {
+        char *psz_cmd = sched->command[0];
+        TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
+        free( psz_cmd );
+    }
     free( sched );
 }
 
-static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name )
+static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
 {
     int i;
 
@@ -1245,8 +1353,8 @@ static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name )
 }
 
 /* Ok, setup schedule command will be able to support only one (argument value) at a time  */
-static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
-                              char *psz_value )
+int vlm_ScheduleSetup( vlm_schedule_t *schedule, const char *psz_cmd,
+                       const char *psz_value )
 {
     if( !strcmp( psz_cmd, "enabled" ) )
     {
@@ -1260,7 +1368,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
     else if( !strcmp( psz_cmd, "date" ) )
     {
         struct tm time;
-        char *p;
+        const char *p;
         time_t date;
 
         time.tm_sec = 0;         /* seconds */
@@ -1271,7 +1379,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
         time.tm_year = 0;        /* year */
         time.tm_wday = 0;        /* day of the week */
         time.tm_yday = 0;        /* day in the year */
-        time.tm_isdst = 0;       /* daylight saving time */
+        time.tm_isdst = -1;       /* daylight saving time */
 
         /* date should be year/month/day-hour:minutes:seconds */
         p = strchr( psz_value, '-' );
@@ -1280,15 +1388,17 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
         {
             schedule->i_date = 0;
         }
-        else if( p == NULL && sscanf( psz_value, "%d:%d:%d", &time.tm_hour, &time.tm_min, &time.tm_sec ) != 3 ) /* it must be a hour:minutes:seconds */
+        else if( (p == NULL) && sscanf( psz_value, "%d:%d:%d", &time.tm_hour,
+                                        &time.tm_min, &time.tm_sec ) != 3 )
+                                        /* it must be a hour:minutes:seconds */
         {
             return 1;
         }
         else
         {
-            int i,j,k;
+            unsigned i,j,k;
 
-            switch( sscanf( p + 1, "%d:%d:%d", &i, &j, &k ) )
+            switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
             {
                 case 1:
                     time.tm_sec = i;
@@ -1306,8 +1416,6 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
                     return 1;
             }
 
-            *p = '\0';
-
             switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
             {
                 case 1:
@@ -1333,10 +1441,10 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
     else if( !strcmp( psz_cmd, "period" ) )
     {
         struct tm time;
-        char *p;
-        char *psz_time = NULL, *psz_date = NULL;
+        const char *p;
+        const char *psz_time = NULL, *psz_date = NULL;
         time_t date;
-        int i,j,k;
+        unsigned i,j,k;
 
         /* First, if date or period are modified, repeat should be equal to -1 */
         schedule->i_repeat = -1;
@@ -1349,7 +1457,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
         time.tm_year = 0;        /* year */
         time.tm_wday = 0;        /* day of the week */
         time.tm_yday = 0;        /* day in the year */
-        time.tm_isdst = 0;       /* daylight saving time */
+        time.tm_isdst = -1;       /* daylight saving time */
 
         /* date should be year/month/day-hour:minutes:seconds */
         p = strchr( psz_value, '-' );
@@ -1357,16 +1465,13 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
         {
             psz_date = psz_value;
             psz_time = p + 1;
-
-            *p = '\0';
         }
         else
         {
             psz_time = psz_value;
         }
 
-
-        switch( sscanf( psz_time, "%d:%d:%d", &i, &j, &k ) )
+        switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
         {
             case 1:
                 time.tm_sec = i;
@@ -1385,7 +1490,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
         }
         if( psz_date )
         {
-            switch( sscanf( psz_date, "%d/%d/%d", &i, &j, &k ) )
+            switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
             {
                 case 1:
                     time.tm_mday = i;
@@ -1555,16 +1660,35 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
         {
             vlm_media_instance_t *p_instance = media->instance[i];
             vlc_value_t val;
+            vlm_message_t *msg_instance;
+            char *psz_tmp;
 
             if( !p_instance->p_input ) val.i_int = END_S;
             else var_Get( p_instance->p_input, "state", &val );
 
-            vlm_MessageAdd( msg_child,
-                vlm_MessageNew( p_instance->psz_name ?
-                                p_instance->psz_name : "default",
+            msg_instance = vlm_MessageNew( "instance" , NULL );
+            vlm_MessageAdd( msg_instance, vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );
+            vlm_MessageAdd( msg_instance, vlm_MessageNew( "state",
                                 val.i_int == PLAYING_S ? "playing" :
                                 val.i_int == PAUSE_S ? "paused" :
                                 "stopped" ) );
+#define APPEND_INPUT_INFO( a, format, type ) \
+            asprintf( &psz_tmp, format, \
+                      var_Get ## type( p_instance->p_input, a ) ); \
+            vlm_MessageAdd( msg_instance, vlm_MessageNew( a, psz_tmp ) ); \
+            free( psz_tmp );
+            APPEND_INPUT_INFO( "position", "%f", Float );
+            APPEND_INPUT_INFO( "time", "%d", Integer );
+            APPEND_INPUT_INFO( "length", "%d", Integer );
+            APPEND_INPUT_INFO( "rate", "%d", Integer );
+            APPEND_INPUT_INFO( "title", "%d", Integer );
+            APPEND_INPUT_INFO( "chapter", "%d", Integer );
+            APPEND_INPUT_INFO( "seekable", "%d", Bool );
+#undef APPEND_INPUT_INFO
+            asprintf( &psz_tmp, "%d", p_instance->i_index + 1 );
+            vlm_MessageAdd( msg_instance, vlm_MessageNew( "playlistindex", psz_tmp ) );
+            free( psz_tmp );
+            vlm_MessageAdd( msg_child, msg_instance );
         }
 
         return msg;
@@ -1666,9 +1790,22 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
         int i, j;
         vlm_message_t *msg;
         vlm_message_t *msg_child;
+        int i_vod = 0, i_broadcast = 0;
+        char *psz_count;
+
+        for( i = 0; i < vlm->i_media; i++ )
+        {
+            if( vlm->media[i]->i_type == VOD_TYPE )
+                i_vod ++;
+            else
+                i_broadcast ++;
+        }
+
+        asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast, i_vod);
 
         msg = vlm_MessageNew( "show", NULL );
-        msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "media", NULL ) );
+        msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "media", psz_count ) );
+        free( psz_count );
 
         for( i = 0; i < vlm->i_media; i++ )
         {
@@ -1734,14 +1871,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
                             vlm_MessageNew( "enabled", s->b_enabled ?
                                             "yes" : "no" ) );
 
-            if( !s->b_enabled ) return msg;
-
-
-            vlm_MessageAdd( msg_schedule,
-                            vlm_MessageNew( "enabled", "yes" ) );
-
             /* calculate next date */
-            i_time = mdate();
+            i_time = vlm_Date();
             i_next_date = s->i_date;
 
             if( s->i_period != 0 )
@@ -1777,7 +1908,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
         return msg;
     }
 
-    else if( psz_filter == NULL && media == NULL && schedule == NULL )
+    else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
     {
         vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
         vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
@@ -1818,11 +1949,15 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
         MessageAddChild( "del (name)|all|media|schedule" );
         MessageAddChild( "control (name) [instance_name] (command)" );
         MessageAddChild( "save (config_file)" );
+        MessageAddChild( "export" );
         MessageAddChild( "load (config_file)" );
 
         message_child = MessageAdd( "Media Proprieties Syntax:" );
         MessageAddChild( "input (input_name)" );
+        MessageAddChild( "inputdel (input_name)|all" );
+        MessageAddChild( "inputdeln input_number" );
         MessageAddChild( "output (output_name)" );
+        MessageAddChild( "option (option_name)[=value]" );
         MessageAddChild( "enabled|disabled" );
         MessageAddChild( "loop|unloop (broadcast only)" );
         MessageAddChild( "mux (mux_name)" );
@@ -1851,50 +1986,57 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
 /*****************************************************************************
  * Config handling functions
  *****************************************************************************/
-static int vlm_Load( vlm_t *vlm, char *file )
+static int Load( vlm_t *vlm, char *file )
 {
     char *pf = file;
+    int  i_line = 1;
 
     while( *pf != '\0' )
     {
         vlm_message_t *message = NULL;
-        int i_temp = 0;
-        int i_next;
+        int i_end = 0;
 
-        while( pf[i_temp] != '\n' && pf[i_temp] != '\0' && pf[i_temp] != '\r' )
+        while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
         {
-            i_temp++;
+            i_end++;
         }
 
-        if( pf[i_temp] == '\r' || pf[i_temp] == '\n' )
-        {
-            pf[i_temp] = '\0';
-            i_next = i_temp + 1;
-        }
-        else
+        if( pf[i_end] == '\r' || pf[i_end] == '\n' )
         {
-            i_next = i_temp;
+            pf[i_end] = '\0';
+            i_end++;
+            if( pf[i_end] == '\n' ) i_end++;
         }
 
-        if( ExecuteCommand( vlm, pf, &message ) )
+        if( *pf && ExecuteCommand( vlm, pf, &message ) )
         {
-            free( message );
+            if( message )
+            {
+                if( message->psz_value )
+                    msg_Err( vlm, "Load error on line %d: %s: %s",
+                             i_line, message->psz_name, message->psz_value );
+                vlm_MessageDelete( message );
+            }
             return 1;
         }
-        free( message );
+        if( message ) vlm_MessageDelete( message );
 
-        pf += i_next;
+        pf += i_end;
+        i_line++;
     }
 
     return 0;
 }
 
-static char *vlm_Save( vlm_t *vlm )
+static char *Save( vlm_t *vlm )
 {
     char *save = NULL;
+    char psz_header[] = "\n"
+                        "# VLC media player VLM command batch\n"
+                        "# http://www.videolan.org/vlc/\n\n" ;
     char *p;
     int i,j;
-    int i_length = 0;
+    int i_length = strlen( psz_header );
 
     for( i = 0; i < vlm->i_media; i++ )
     {
@@ -1996,6 +2138,8 @@ static char *vlm_Save( vlm_t *vlm )
     p = save = malloc( i_length );
     *save = '\0';
 
+    p += sprintf( p, "%s", psz_header );
+
     /* finally we can write in it */
     for( i = 0; i < vlm->i_media; i++ )
     {
@@ -2126,8 +2270,8 @@ static char *vlm_Save( vlm_t *vlm )
 /*****************************************************************************
  * Manage:
  *****************************************************************************/
-static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
-                                char *psz_id, int i_query, va_list args )
+int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
+                         const char *psz_id, int i_query, va_list args )
 {
     vlm_t *vlm = (vlm_t *)p_private;
     int i, i_ret = VLC_EGENERIC;
@@ -2164,6 +2308,16 @@ static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
         i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "stop", 0 );
         break;
 
+    case VOD_MEDIA_SEEK:
+    {
+        double f_pos = (double)va_arg( args, double );
+        char psz_pos[50];
+
+        sprintf( psz_pos, "%f", f_pos );
+        i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "seek", psz_pos);
+        break;
+    }
+
     default:
         break;
     }
@@ -2183,12 +2337,14 @@ static int Manage( vlc_object_t* p_object )
     mtime_t i_lastcheck;
     mtime_t i_time;
 
-    i_lastcheck = mdate();
+    i_lastcheck = vlm_Date();
 
     msleep( 100000 );
 
     while( !vlm->b_die )
     {
+        char **ppsz_scheduled_commands = NULL;
+        int    i_scheduled_commands = 0;
         vlc_mutex_lock( &vlm->lock );
 
         /* destroy the inputs that wants to die, and launch the next input */
@@ -2230,7 +2386,7 @@ static int Manage( vlc_object_t* p_object )
         }
 
         /* scheduling */
-        i_time = mdate();
+        i_time = vlm_Date();
 
         for( i = 0; i < vlm->i_schedule; i++ )
         {
@@ -2262,17 +2418,26 @@ static int Manage( vlc_object_t* p_object )
                 {
                     for( j = 0; j < vlm->schedule[i]->i_command; j++ )
                     {
-                        vlm_message_t *message = NULL;
-
-                        ExecuteCommand( vlm, vlm->schedule[i]->command[j],
-                                        &message );
-
-                        /* for now, drop the message */
-                        free( message );
+                        TAB_APPEND( i_scheduled_commands,
+                                    ppsz_scheduled_commands,
+                                    strdup(vlm->schedule[i]->command[j] ) );
                     }
                 }
             }
         }
+        while( i_scheduled_commands )
+        {
+            vlm_message_t *message = NULL;
+            char *psz_command = ppsz_scheduled_commands[0];
+            ExecuteCommand( vlm, psz_command,&message );
+
+            /* for now, drop the message */
+            vlm_MessageDelete( message );
+            TAB_REMOVE( i_scheduled_commands,
+                        ppsz_scheduled_commands,
+                        psz_command );
+            free( psz_command );
+        }
 
         i_lastcheck = i_time;
 
@@ -2295,5 +2460,18 @@ vlm_t *__vlm_New( vlc_object_t *a )
 void vlm_Delete( vlm_t *a ){}
 int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c ){ return -1; }
 void vlm_MessageDelete( vlm_message_t *a ){}
+vlm_media_t *vlm_MediaNew( vlm_t *a, char *b, int c ){ return NULL; }
+vlm_media_t *vlm_MediaSearch (vlm_t *a, const char *b ) { return NULL; }
+void vlm_MediaDelete( vlm_t *a, vlm_media_t *b, char *c ){}
+int vlm_MediaSetup( vlm_t *a, vlm_media_t *b, char *c, char *d ){ return -1; }
+int vlm_MediaControl( vlm_t *a, vlm_media_t *b, char *c, char *d, char *e )
+    { return -1; }
+vlm_schedule_t * vlm_ScheduleNew( vlm_t *a, char *b ){ return NULL; }
+void  vlm_ScheduleDelete( vlm_t *a, vlm_schedule_t *b, char *c ){}
+int vlm_ScheduleSetup( vlm_schedule_t *a, char *b, char *c ){ return -1; }
+int vlm_MediaVodControl( void *a, vod_media_t *b, char *c, int d, va_list e )
+    { return -1; }
+int vlm_Save( vlm_t *a, char *b ){ return -1; }
+int vlm_Load( vlm_t *a, char *b ){ return -1; }
 
 #endif /* ENABLE_VLM */