]> git.sesse.net Git - vlc/blobdiff - src/input/vlmshell.c
vlm: remove dead code (AFAIK a relative seek does exactly the same thing).
[vlc] / src / input / vlmshell.c
index a3ce6542aa6b217d86c51f0dc831dbaa1e2fbb5d..d3ba1b8dac8b6bf773f5ebe39e220ea43618b0ee 100644 (file)
 
 #ifdef ENABLE_VLM
 
-#ifndef WIN32
-#   include <sys/time.h>                                   /* gettimeofday() */
-#endif
-
-#ifdef HAVE_TIME_H
-#   include <time.h>                                              /* ctime() */
-#   include <sys/timeb.h>                                         /* ftime() */
-#endif
+#include <time.h>                                                 /* ctime() */
 
 #include <vlc_input.h>
 #include "input_internal.h"
 #include <vlc_stream.h>
 #include "vlm_internal.h"
-#include <vlc_vod.h>
 #include <vlc_charset.h>
+#include <vlc_fs.h>
 #include <vlc_sout.h>
 #include "../stream_output/stream_output.h"
 #include "../libvlc.h"
  * Local prototypes.
  *****************************************************************************/
 
-/* ugly kludge to avoid "null format string" warnings,
- * even if we handle NULL format string in vlm_MessageNew() */
-static const char *vlm_NULL = NULL;
-
 /* */
 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
 
@@ -138,9 +127,20 @@ static const char *FindCommandEnd( const char *psz_sent )
 static int Unescape( char *out, const char *in )
 {
     char c, quote = 0;
+    bool param = false;
 
     while( (c = *in++) != '\0' )
     {
+        // Don't escape the end of the string if we find a '#'
+        // that's the begining of a vlc command
+        // TODO: find a better solution
+        if( ( c == '#' && !quote ) || param )
+        {
+            param = true;
+            *out++ = c;
+            continue;
+        }
+
         if( !quote )
         {
             if (strchr(quotes,c))   // opening quote
@@ -264,7 +264,7 @@ static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_st
         return VLC_EGENERIC;
     }
 
-    *pp_status = vlm_MessageNew( "del", vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( "del" );
     return VLC_SUCCESS;
 }
 
@@ -297,11 +297,11 @@ static int ExecuteHelp( vlm_message_t **pp_status )
     vlm_message_t *message_child;
 
 #define MessageAdd( a ) \
-        vlm_MessageAdd( *pp_status, vlm_MessageNew( a, vlm_NULL ) );
+        vlm_MessageAdd( *pp_status, vlm_MessageSimpleNew( a ) );
 #define MessageAddChild( a ) \
-        vlm_MessageAdd( message_child, vlm_MessageNew( a, vlm_NULL ) );
+        vlm_MessageAdd( message_child, vlm_MessageSimpleNew( a ) );
 
-    *pp_status = vlm_MessageNew( "help", vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( "help" );
 
     message_child = MessageAdd( "Commands Syntax:" );
     MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
@@ -336,7 +336,7 @@ static int ExecuteHelp( vlm_message_t **pp_status )
     MessageAddChild( "play [input_number]" );
     MessageAddChild( "pause" );
     MessageAddChild( "stop" );
-    MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" );
+    MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](milliseconds)ms" );
 
     return VLC_SUCCESS;
 }
@@ -459,43 +459,6 @@ static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg,
             i_result = VLC_EGENERIC;
         }
     }
-    else if( !strcmp( psz_control, "rewind" ) )
-    {
-        if( psz_argument )
-        {
-            const double d_scale = us_atof( psz_argument );
-            double d_position;
-
-            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
-            d_position -= (d_scale / 1000.0);
-            if( d_position < 0.0 )
-                d_position = 0.0;
-            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
-        }
-        else
-        {
-            i_result = VLC_EGENERIC;
-        }
-    }
-    else if( !strcmp( psz_control, "forward" ) )
-    {
-        if( psz_argument )
-        {
-            const double d_scale = us_atof( psz_argument );
-            double d_position;
-
-            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
-            d_position += (d_scale / 1000.0);
-            if( d_position > 1.0 )
-                d_position = 1.0;
-            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
-
-        }
-        else
-        {
-            i_result = VLC_EGENERIC;
-        }
-    }
     else if( !strcmp( psz_control, "stop" ) )
     {
         i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
@@ -514,7 +477,7 @@ static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg,
         *pp_status = vlm_MessageNew( "control", "unknown error" );
         return VLC_SUCCESS;
     }
-    *pp_status = vlm_MessageNew( "control", vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( "control" );
     return VLC_SUCCESS;
 }
 
@@ -522,14 +485,14 @@ static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
 {
     char *psz_export = Save( p_vlm );
 
-    *pp_status = vlm_MessageNew( "export", psz_export );
+    *pp_status = vlm_MessageNew( "export", "%s", psz_export );
     free( psz_export );
     return VLC_SUCCESS;
 }
 
 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
 {
-    FILE *f = utf8_fopen( psz_file, "wt" );
+    FILE *f = vlc_fopen( psz_file, "wt" );
     char *psz_save = NULL;
 
     if( !f )
@@ -548,7 +511,7 @@ static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_s
 
     free( psz_save );
 
-    *pp_status = vlm_MessageNew( "save", vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( "save" );
     return VLC_SUCCESS;
 
 error:
@@ -562,7 +525,7 @@ error:
 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
 {
     stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
-    int64_t i_size;
+    uint64_t i_size;
     char *psz_buffer;
 
     if( !p_stream )
@@ -581,6 +544,8 @@ static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_st
     }
 
     i_size = stream_Size( p_stream );
+    if( i_size > SIZE_MAX - 1 )
+        i_size = SIZE_MAX - 1;
 
     psz_buffer = malloc( i_size + 1 );
     if( !psz_buffer )
@@ -606,7 +571,7 @@ static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_st
 
     free( psz_buffer );
 
-    *pp_status = vlm_MessageNew( "load", vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( "load" );
     return VLC_SUCCESS;
 }
 
@@ -621,7 +586,8 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
         if( !strcmp( ppsz_property[i], "enabled" ) ||
             !strcmp( ppsz_property[i], "disabled" ) )
         {
-            vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL );
+            if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )
+                goto error;
         }
         else if( !strcmp( ppsz_property[i], "append" ) )
         {
@@ -636,12 +602,14 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
             psz_line = strdup( ppsz_property[i] );
             for( j = i+1; j < i_property; j++ )
             {
-                psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
+                psz_line = xrealloc( psz_line,
+                        strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
                 strcat( psz_line, " " );
                 strcat( psz_line, ppsz_property[j] );
             }
 
-            vlm_ScheduleSetup( p_schedule, "append", psz_line );
+            if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
+                goto error;
             break;
         }
         else
@@ -653,12 +621,24 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
                 return ExecuteSyntaxError( psz_cmd, pp_status );
             }
 
-            vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] );
+            if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )
+                goto error;
             i++;
         }
     }
-    *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( psz_cmd );
+
+    vlc_mutex_lock( &p_vlm->lock_manage );
+    p_vlm->input_state_changed = true;
+    vlc_cond_signal( &p_vlm->wait_manage );
+    vlc_mutex_unlock( &p_vlm->lock_manage );
+
     return VLC_SUCCESS;
+
+error:
+    *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",
+                                 ppsz_property[i] );
+    return VLC_EGENERIC;
 }
 
 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
@@ -778,7 +758,7 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
     i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
     vlm_media_Delete( p_cfg );
 
-    *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
+    *pp_status = vlm_MessageSimpleNew( psz_cmd );
     return i_result;
 
 error:
@@ -882,7 +862,7 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
         /* support for comments */
         if( i_command == 0 && *psz_command == '#')
         {
-            p_message = vlm_MessageNew( "", vlm_NULL );
+            p_message = vlm_MessageSimpleNew( "" );
             goto success;
         }
 
@@ -890,7 +870,7 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
 
         if( psz_temp == NULL )
         {
-            p_message = vlm_MessageNew( "Incomplete command", psz_command );
+            p_message = vlm_MessageNew( "Incomplete command", "%s", psz_command );
             goto error;
         }
 
@@ -916,7 +896,7 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error;  if( (cmd) ) goto error; goto success; }
     if( i_command == 0 )
     {
-        p_message = vlm_MessageNew( "", vlm_NULL );
+        p_message = vlm_MessageSimpleNew( "" );
         goto success;
     }
     else IF_EXECUTE( "del",     (i_command != 2),   ExecuteDel(p_vlm, ppsz_command[1], &p_message) )
@@ -968,17 +948,12 @@ vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
  *****************************************************************************/
 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
 {
-    vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
+    if( !psz_name )
+        return NULL;
 
+    vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
     if( !p_sched )
-    {
         return NULL;
-    }
-
-    if( !psz_name )
-    {
-        return NULL;
-    }
 
     p_sched->psz_name = strdup( psz_name );
     p_sched->b_enabled = false;
@@ -1061,9 +1036,7 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const 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)
         {
             return 1;
         }
@@ -1209,47 +1182,57 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
     {
         return 1;
     }
+
     return 0;
 }
 
 /*****************************************************************************
  * Message handling functions
  *****************************************************************************/
-vlm_message_t *vlm_MessageNew( const char *psz_name,
-                               const char *psz_format, ... )
+vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
 {
-    vlm_message_t *p_message;
-    va_list args;
-
     if( !psz_name ) return NULL;
 
-    p_message = malloc( sizeof(vlm_message_t) );
-    if( !p_message)
-    {
+    vlm_message_t *p_message = malloc( sizeof(*p_message) );
+    if( !p_message )
         return NULL;
-    }
-
-    p_message->psz_value = 0;
 
-    if( psz_format )
+    p_message->psz_name = strdup( psz_name );
+    if( !p_message->psz_name )
     {
-        va_start( args, psz_format );
-        if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
-        {
-            va_end( args );
-            free( p_message );
-            return NULL;
-        }
-        va_end( args );
+        free( p_message );
+        return NULL;
     }
-
-    p_message->psz_name = strdup( psz_name );
+    p_message->psz_value = NULL;
     p_message->i_child = 0;
     p_message->child = NULL;
 
     return p_message;
 }
 
+vlm_message_t *vlm_MessageNew( const char *psz_name,
+                               const char *psz_format, ... )
+{
+    vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
+    va_list args;
+
+    if( !p_message )
+        return NULL;
+
+    assert( psz_format );
+    va_start( args, psz_format );
+    if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
+        p_message->psz_value = NULL;
+    va_end( args );
+
+    if( !p_message->psz_value )
+    {
+        vlm_MessageDelete( p_message );
+        return NULL;
+    }
+    return p_message;
+}
+
 void vlm_MessageDelete( vlm_message_t *p_message )
 {
     free( p_message->psz_name );
@@ -1284,7 +1267,7 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
     vlm_message_t *p_msg_sub;
     int i;
 
-    p_msg = vlm_MessageNew( p_cfg->psz_name, vlm_NULL );
+    p_msg = vlm_MessageSimpleNew( p_cfg->psz_name );
     vlm_MessageAdd( p_msg,
                     vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
     vlm_MessageAdd( p_msg,
@@ -1292,46 +1275,45 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
 
     if( p_cfg->b_vod )
         vlm_MessageAdd( p_msg,
-                        vlm_MessageNew( "mux", p_cfg->vod.psz_mux ) );
+                        vlm_MessageNew( "mux", "%s", p_cfg->vod.psz_mux ) );
     else
         vlm_MessageAdd( p_msg,
                         vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
 
-    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", vlm_NULL ) );
+    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "inputs" ) );
     for( i = 0; i < p_cfg->i_input; i++ )
     {
         char *psz_tmp;
         if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )
         {
             vlm_MessageAdd( p_msg_sub,
-                            vlm_MessageNew( psz_tmp, p_cfg->ppsz_input[i] ) );
+                       vlm_MessageNew( psz_tmp, "%s", p_cfg->ppsz_input[i] ) );
             free( psz_tmp );
         }
     }
 
     vlm_MessageAdd( p_msg,
-                    vlm_MessageNew( "output", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
+                    vlm_MessageNew( "output", "%s", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
 
-    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", vlm_NULL ) );
+    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "options" ) );
     for( i = 0; i < p_cfg->i_option; i++ )
-        vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], vlm_NULL ) );
+        vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( p_cfg->ppsz_option[i] ) );
 
-    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", vlm_NULL ) );
+    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "instances" ) );
     for( i = 0; i < p_media->i_instance; i++ )
     {
         vlm_media_instance_sys_t *p_instance = p_media->instance[i];
         vlc_value_t val;
         vlm_message_t *p_msg_instance;
-        char *psz_tmp;
 
         val.i_int = END_S;
         if( p_instance->p_input )
             var_Get( p_instance->p_input, "state", &val );
 
-        p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , vlm_NULL ) );
+        p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( "instance" ) );
 
         vlm_MessageAdd( p_msg_instance,
-                        vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );
+                        vlm_MessageNew( "name" , "%s", p_instance->psz_name ? p_instance->psz_name : "default" ) );
         vlm_MessageAdd( p_msg_instance,
                         vlm_MessageNew( "state",
                             val.i_int == PLAYING_S ? "playing" :
@@ -1341,29 +1323,20 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
         /* FIXME should not do that this way */
         if( p_instance->p_input )
         {
-#define APPEND_INPUT_INFO( a, format, type ) \
-            if( asprintf( &psz_tmp, format, \
-                      var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
-            { \
-                vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
-                                psz_tmp ) ); \
-                free( psz_tmp ); \
-            }
+#define APPEND_INPUT_INFO( key, format, type ) \
+            vlm_MessageAdd( p_msg_instance, vlm_MessageNew( key, format, \
+                            var_Get ## type( p_instance->p_input, key ) ) )
             APPEND_INPUT_INFO( "position", "%f", Float );
             APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
             APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
-            APPEND_INPUT_INFO( "rate", "%d", Integer );
-            APPEND_INPUT_INFO( "title", "%d", Integer );
-            APPEND_INPUT_INFO( "chapter", "%d", Integer );
-            APPEND_INPUT_INFO( "seekable", "%d", Bool );
+            APPEND_INPUT_INFO( "rate", "%f", Float );
+            APPEND_INPUT_INFO( "title", "%"PRId64, Integer );
+            APPEND_INPUT_INFO( "chapter", "%"PRId64, Integer );
+            APPEND_INPUT_INFO( "can-seek", "%d", Bool );
         }
 #undef APPEND_INPUT_INFO
-        if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
-        {
-            vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
-                            psz_tmp ) );
-            free( psz_tmp );
-        }
+        vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
+                        "%d", p_instance->i_index + 1 ) );
     }
     return p_msg;
 }
@@ -1374,7 +1347,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
 {
     if( media != NULL )
     {
-        vlm_message_t *p_msg = vlm_MessageNew( "show", vlm_NULL );
+        vlm_message_t *p_msg = vlm_MessageSimpleNew( "show" );
         if( p_msg )
             vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) );
         return p_msg;
@@ -1388,9 +1361,9 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         vlm_message_t *msg_child;
         char buffer[100];
 
-        msg = vlm_MessageNew( "show", vlm_NULL );
+        msg = vlm_MessageSimpleNew( "show" );
         msg_schedule =
-            vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, vlm_NULL ) );
+            vlm_MessageAdd( msg, vlm_MessageSimpleNew( schedule->psz_name ) );
 
         vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
 
@@ -1402,17 +1375,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         {
             struct tm date;
             time_t i_time = (time_t)( schedule->i_date / 1000000 );
-            char *psz_date;
 
             localtime_r( &i_time, &date);
-            if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
-                          date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
-                          date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
-            {
-                 vlm_MessageAdd( msg_schedule,
-                                 vlm_MessageNew( "date", psz_date ) );
-                 free( psz_date );
-            }
+            vlm_MessageAdd( msg_schedule,
+                            vlm_MessageNew( "date", "%d/%d/%d-%d:%d:%d",
+                                            date.tm_year + 1900, date.tm_mon + 1,
+                                            date.tm_mday, date.tm_hour, date.tm_min,
+                                            date.tm_sec ) );
         }
         else
             vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
@@ -1438,21 +1407,21 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
             sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
                      date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
 
-            vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", buffer) );
+            vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "%s", buffer) );
         }
         else
             vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
 
         sprintf( buffer, "%d", schedule->i_repeat );
-        vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
+        vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", "%s", buffer ) );
 
         msg_child =
-            vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", vlm_NULL ) );
+            vlm_MessageAdd( msg_schedule, vlm_MessageSimpleNew("commands" ) );
 
         for( i = 0; i < schedule->i_command; i++ )
         {
            vlm_MessageAdd( msg_child,
-                           vlm_MessageNew( schedule->command[i], vlm_NULL ) );
+                           vlm_MessageSimpleNew( schedule->command[i] ) );
         }
 
         return msg;
@@ -1464,10 +1433,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         vlm_message_t *p_msg;
         vlm_message_t *p_msg_child;
         int i_vod = 0, i_broadcast = 0;
-        int i;
-        char *psz_count;
 
-        for( i = 0; i < vlm->i_media; i++ )
+        for( int i = 0; i < vlm->i_media; i++ )
         {
             if( vlm->media[i]->cfg.b_vod )
                 i_vod++;
@@ -1475,14 +1442,12 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
                 i_broadcast++;
         }
 
-        if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
-                      i_vod) == -1 )
-            return NULL;
-        p_msg = vlm_MessageNew( "show", vlm_NULL );
-        p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", psz_count ) );
-        free( psz_count );
+        p_msg = vlm_MessageSimpleNew( "show" );
+        p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media",
+                                      "( %d broadcast - %d vod )", i_broadcast,
+                                      i_vod ) );
 
-        for( i = 0; i < vlm->i_media; i++ )
+        for( int i = 0; i < vlm->i_media; i++ )
             vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
 
         return p_msg;
@@ -1494,8 +1459,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         vlm_message_t *msg;
         vlm_message_t *msg_child;
 
-        msg = vlm_MessageNew( "show", vlm_NULL );
-        msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", vlm_NULL ) );
+        msg = vlm_MessageSimpleNew( "show" );
+        msg_child = vlm_MessageAdd( msg, vlm_MessageSimpleNew( "schedule" ) );
 
         for( i = 0; i < vlm->i_schedule; i++ )
         {
@@ -1504,7 +1469,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
             mtime_t i_time, i_next_date;
 
             msg_schedule = vlm_MessageAdd( msg_child,
-                                           vlm_MessageNew( s->psz_name, vlm_NULL ) );
+                                           vlm_MessageSimpleNew( s->psz_name ) );
             vlm_MessageAdd( msg_schedule,
                             vlm_MessageNew( "enabled", s->b_enabled ?
                                             "yes" : "no" ) );
@@ -1528,18 +1493,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
             if( i_next_date > i_time )
             {
                 time_t i_date = (time_t) (i_next_date / 1000000) ;
+                struct tm tm;
+                char psz_date[32];
 
-#if !defined( UNDER_CE )
-#ifdef HAVE_CTIME_R
-                char psz_date[500];
-                ctime_r( &i_date, psz_date );
-#else
-                char *psz_date = ctime( &i_date );
-#endif
-
+                strftime( psz_date, sizeof(psz_date), "%F %H:%M:%S (%a)",
+                          localtime_r( &i_date, &tm ) );
                 vlm_MessageAdd( msg_schedule,
-                                vlm_MessageNew( "next launch", psz_date ) );
-#endif
+                                vlm_MessageNew( "next launch", "%s", psz_date ) );
             }
         }
 
@@ -1563,7 +1523,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
 
     else
     {
-        return vlm_MessageNew( "show", vlm_NULL );
+        return vlm_MessageSimpleNew( "show" );
     }
 }