1 /*****************************************************************************
2 * vlm.c: VLM interface plugin
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Simon Latapie <garf@videolan.org>
8 * Laurent Aimar <fenrir@videolan.org>
9 * Gildas Bazin <gbazin@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
33 #include <vlc_common.h>
36 #include <ctype.h> /* tolower() */
44 # include <sys/time.h> /* gettimeofday() */
48 # include <time.h> /* ctime() */
49 # include <sys/timeb.h> /* ftime() */
52 #include <vlc_input.h>
53 #include "input_internal.h"
54 #include <vlc_stream.h>
55 #include "vlm_internal.h"
57 #include <vlc_charset.h>
59 #include "../stream_output/stream_output.h"
60 #include "../libvlc.h"
62 /*****************************************************************************
64 *****************************************************************************/
66 /* ugly kludge to avoid "null format string" warnings,
67 * even if we handle NULL format string in vlm_MessageNew() */
68 static const char *vlm_NULL = NULL;
71 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
73 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
75 static char *Save( vlm_t * );
76 static int Load( vlm_t *, char * );
78 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
79 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
80 const char *psz_value );
83 static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
85 static const char quotes[] = "\"'";
87 * FindCommandEnd: look for the end of a possibly quoted string
88 * @return NULL on mal-formatted string,
89 * pointer past the last character otherwise.
91 static const char *FindCommandEnd( const char *psz_sent )
95 while( (c = *psz_sent) != '\0' )
99 if( strchr(quotes,c) ) // opening quote
101 else if( isspace(c) ) // non-escaped space
105 psz_sent++; // skip escaped character
106 if( *psz_sent == '\0' )
112 if( c == quote ) // non-escaped matching quote
114 else if( (quote == '"') && (c == '\\') )
116 psz_sent++; // skip escaped character
117 if (*psz_sent == '\0')
118 return NULL; // error, closing quote missing
124 // error (NULL) if we could not find a matching quote
125 return quote ? NULL : psz_sent;
130 * Unescape a nul-terminated string.
131 * Note that in and out can be identical.
133 * @param out output buffer (at least <strlen (in) + 1> characters long)
134 * @param in nul-terminated string to be unescaped
136 * @return 0 on success, -1 on error.
138 static int Unescape( char *out, const char *in )
142 while( (c = *in++) != '\0' )
146 if (strchr(quotes,c)) // opening quote
170 /* None of the special cases - copy the backslash */
176 if( c == quote ) // non-escaped matching quote
181 if( (quote == '"') && (c == '\\') )
190 case '\0': // should never happen
194 /* None of the special cases - copy the backslash */
206 /*****************************************************************************
207 * ExecuteCommand: The main state machine
208 *****************************************************************************
209 * Execute a command which ends with '\0' (string)
210 *****************************************************************************/
211 static int ExecuteSyntaxError( const char *psz_cmd, vlm_message_t **pp_status )
213 *pp_status = vlm_MessageNew( psz_cmd, "Wrong command syntax" );
217 static bool ExecuteIsMedia( vlm_t *p_vlm, const char *psz_name )
221 if( !psz_name || vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
225 static bool ExecuteIsSchedule( vlm_t *p_vlm, const char *psz_name )
227 if( !psz_name || !vlm_ScheduleSearch( p_vlm, psz_name ) )
232 static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
234 vlm_media_sys_t *p_media;
235 vlm_schedule_sys_t *p_schedule;
237 p_media = vlm_MediaSearch( p_vlm, psz_name );
238 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
240 if( p_schedule != NULL )
242 vlm_ScheduleDelete( p_vlm, p_schedule );
244 else if( p_media != NULL )
246 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_media->cfg.id );
248 else if( !strcmp(psz_name, "media") )
250 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
252 else if( !strcmp(psz_name, "schedule") )
254 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
256 else if( !strcmp(psz_name, "all") )
258 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
259 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
263 *pp_status = vlm_MessageNew( "del", "%s: media unknown", psz_name );
267 *pp_status = vlm_MessageNew( "del", vlm_NULL );
271 static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
273 vlm_media_sys_t *p_media;
274 vlm_schedule_sys_t *p_schedule;
278 *pp_status = vlm_Show( p_vlm, NULL, NULL, NULL );
282 p_media = vlm_MediaSearch( p_vlm, psz_name );
283 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
285 if( p_schedule != NULL )
286 *pp_status = vlm_Show( p_vlm, NULL, p_schedule, NULL );
287 else if( p_media != NULL )
288 *pp_status = vlm_Show( p_vlm, p_media, NULL, NULL );
290 *pp_status = vlm_Show( p_vlm, NULL, NULL, psz_name );
295 static int ExecuteHelp( vlm_message_t **pp_status )
297 vlm_message_t *message_child;
299 #define MessageAdd( a ) \
300 vlm_MessageAdd( *pp_status, vlm_MessageNew( a, vlm_NULL ) );
301 #define MessageAddChild( a ) \
302 vlm_MessageAdd( message_child, vlm_MessageNew( a, vlm_NULL ) );
304 *pp_status = vlm_MessageNew( "help", vlm_NULL );
306 message_child = MessageAdd( "Commands Syntax:" );
307 MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
308 MessageAddChild( "setup (name) (properties)" );
309 MessageAddChild( "show [(name)|media|schedule]" );
310 MessageAddChild( "del (name)|all|media|schedule" );
311 MessageAddChild( "control (name) [instance_name] (command)" );
312 MessageAddChild( "save (config_file)" );
313 MessageAddChild( "export" );
314 MessageAddChild( "load (config_file)" );
316 message_child = MessageAdd( "Media Proprieties Syntax:" );
317 MessageAddChild( "input (input_name)" );
318 MessageAddChild( "inputdel (input_name)|all" );
319 MessageAddChild( "inputdeln input_number" );
320 MessageAddChild( "output (output_name)" );
321 MessageAddChild( "option (option_name)[=value]" );
322 MessageAddChild( "enabled|disabled" );
323 MessageAddChild( "loop|unloop (broadcast only)" );
324 MessageAddChild( "mux (mux_name)" );
326 message_child = MessageAdd( "Schedule Proprieties Syntax:" );
327 MessageAddChild( "enabled|disabled" );
328 MessageAddChild( "append (command_until_rest_of_the_line)" );
329 MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):"
331 MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
332 "(days)-(hours):(minutes):(seconds)" );
333 MessageAddChild( "repeat (number_of_repetitions)" );
335 message_child = MessageAdd( "Control Commands Syntax:" );
336 MessageAddChild( "play [input_number]" );
337 MessageAddChild( "pause" );
338 MessageAddChild( "stop" );
339 MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" );
344 static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, char ** ppsz_arg, vlm_message_t **pp_status )
346 vlm_media_sys_t *p_media;
347 const char *psz_control = NULL;
348 const char *psz_instance = NULL;
349 const char *psz_argument = NULL;
353 if( !ExecuteIsMedia( p_vlm, psz_name ) )
355 *pp_status = vlm_MessageNew( "control", "%s: media unknown", psz_name );
361 #define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
363 if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
366 psz_instance = ppsz_arg[0];
368 if( i_index >= i_arg || ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
369 return ExecuteSyntaxError( "control", pp_status );
372 psz_control = ppsz_arg[i_index];
374 if( i_index+1 < i_arg )
375 psz_argument = ppsz_arg[i_index+1];
377 p_media = vlm_MediaSearch( p_vlm, psz_name );
380 if( !strcmp( psz_control, "play" ) )
382 int i_input_index = 0;
385 if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input )
389 else if( psz_argument )
392 vlm_media_t *p_cfg = &p_media->cfg;
393 for ( j=0; j < p_cfg->i_input; j++)
395 if( !strcmp( p_cfg->ppsz_input[j], psz_argument ) )
403 if( p_media->cfg.b_vod )
404 i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_VOD_INSTANCE, p_media->cfg.id, psz_instance, i_input_index, NULL ); // we should get here now
406 i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, psz_instance, i_input_index );
408 else if( !strcmp( psz_control, "seek" ) )
413 if( psz_argument[0] == '+' || psz_argument[0] == '-' )
418 if( strstr( psz_argument, "ms" ) || strstr( psz_argument, "s" ) )
423 if( strstr( psz_argument, "ms" ) )
424 i_new_time = 1000 * (int64_t)atoi( psz_argument );
426 i_new_time = 1000000 * (int64_t)atoi( psz_argument );
431 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, &i_time );
432 i_new_time += i_time;
436 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, i_new_time );
441 double d_new_position = us_atof( psz_argument ) / 100.0;
445 double d_position = 0.0;
447 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
448 d_new_position += d_position;
450 if( d_new_position < 0.0 )
451 d_new_position = 0.0;
452 else if( d_new_position > 1.0 )
453 d_new_position = 1.0;
454 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_new_position );
459 i_result = VLC_EGENERIC;
462 else if( !strcmp( psz_control, "rewind" ) )
466 const double d_scale = us_atof( psz_argument );
469 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
470 d_position -= (d_scale / 1000.0);
471 if( d_position < 0.0 )
473 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
477 i_result = VLC_EGENERIC;
480 else if( !strcmp( psz_control, "forward" ) )
484 const double d_scale = us_atof( psz_argument );
487 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
488 d_position += (d_scale / 1000.0);
489 if( d_position > 1.0 )
491 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
496 i_result = VLC_EGENERIC;
499 else if( !strcmp( psz_control, "stop" ) )
501 i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
503 else if( !strcmp( psz_control, "pause" ) )
505 i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
509 i_result = VLC_EGENERIC;
514 *pp_status = vlm_MessageNew( "control", "unknown error" );
517 *pp_status = vlm_MessageNew( "control", vlm_NULL );
521 static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
523 char *psz_export = Save( p_vlm );
525 *pp_status = vlm_MessageNew( "export", psz_export );
530 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
532 FILE *f = utf8_fopen( psz_file, "wt" );
533 char *psz_save = NULL;
538 psz_save = Save( p_vlm );
539 if( psz_save == NULL )
541 if( fputs( psz_save, f ) == EOF )
551 *pp_status = vlm_MessageNew( "save", vlm_NULL );
558 *pp_status = vlm_MessageNew( "save", "Unable to save to file");
562 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
564 stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
570 *pp_status = vlm_MessageNew( "load", "Unable to load from file" );
575 if( stream_Seek( p_stream, 0 ) != 0 )
577 stream_Delete( p_stream );
579 *pp_status = vlm_MessageNew( "load", "Read file error" );
583 i_size = stream_Size( p_stream );
585 psz_buffer = malloc( i_size + 1 );
588 stream_Delete( p_stream );
590 *pp_status = vlm_MessageNew( "load", "Read file error" );
594 stream_Read( p_stream, psz_buffer, i_size );
595 psz_buffer[i_size] = '\0';
597 stream_Delete( p_stream );
599 if( Load( p_vlm, psz_buffer ) )
603 *pp_status = vlm_MessageNew( "load", "Error while loading file" );
609 *pp_status = vlm_MessageNew( "load", vlm_NULL );
613 static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,
614 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
616 const char *psz_cmd = b_new ? "new" : "setup";
619 for( i = 0; i < i_property; i++ )
621 if( !strcmp( ppsz_property[i], "enabled" ) ||
622 !strcmp( ppsz_property[i], "disabled" ) )
624 vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL );
626 else if( !strcmp( ppsz_property[i], "append" ) )
630 /* Beware: everything behind append is considered as
633 if( ++i >= i_property )
636 psz_line = strdup( ppsz_property[i] );
637 for( j = i+1; j < i_property; j++ )
639 psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
640 strcat( psz_line, " " );
641 strcat( psz_line, ppsz_property[j] );
644 vlm_ScheduleSetup( p_schedule, "append", psz_line );
649 if( i + 1 >= i_property )
652 vlm_ScheduleDelete( p_vlm, p_schedule );
653 return ExecuteSyntaxError( psz_cmd, pp_status );
656 vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] );
660 *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
664 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
665 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
667 const char *psz_cmd = b_new ? "new" : "setup";
668 vlm_media_t *p_cfg = NULL;
674 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
675 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )
676 ERROR( "unknown media" );
678 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
679 for( i = 0; i < i_property; i++ )
681 const char *psz_option = ppsz_property[i];
682 const char *psz_value = i+1 < i_property ? ppsz_property[i+1] : NULL;
684 if( !strcmp( psz_option, "enabled" ) )
686 p_cfg->b_enabled = true;
688 else if( !strcmp( psz_option, "disabled" ) )
690 p_cfg->b_enabled = false;
692 else if( !strcmp( psz_option, "input" ) )
695 TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
698 else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
700 while( p_cfg->i_input > 0 )
701 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
704 else if( !strcmp( psz_option, "inputdel" ) )
708 MISSING( "inputdel" );
710 for( j = 0; j < p_cfg->i_input; j++ )
712 if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
714 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
720 else if( !strcmp( psz_option, "inputdeln" ) )
724 MISSING( "inputdeln" );
726 i_index = atoi( psz_value );
727 if( i_index > 0 && i_index <= p_cfg->i_input )
728 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
731 else if( !strcmp( psz_option, "output" ) )
735 free( p_cfg->psz_output );
736 p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
739 else if( !strcmp( psz_option, "option" ) )
743 TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
746 else if( !strcmp( psz_option, "loop" ) )
749 ERROR( "invalid loop option for vod" );
750 p_cfg->broadcast.b_loop = true;
752 else if( !strcmp( psz_option, "unloop" ) )
755 ERROR( "invalid unloop option for vod" );
756 p_cfg->broadcast.b_loop = false;
758 else if( !strcmp( psz_option, "mux" ) )
762 ERROR( "invalid mux option for broadcast" );
764 free( p_cfg->vod.psz_mux );
765 p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
770 fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
771 ERROR( "Wrong command syntax" );
778 i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
779 vlm_media_Delete( p_cfg );
781 *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
788 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
789 vlm_media_Delete( p_cfg );
794 static int ExecuteNew( vlm_t *p_vlm, const char *psz_name, const char *psz_type, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
797 if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
799 *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
802 if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
804 *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
808 if( !strcmp( psz_type, "schedule" ) )
810 vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
813 *pp_status = vlm_MessageNew( "new", "could not create schedule" );
816 return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );
818 else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
823 vlm_media_Init( &cfg );
824 cfg.psz_name = strdup( psz_name );
825 cfg.b_vod = !strcmp( psz_type, "vod" );
827 if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
829 vlm_media_Clean( &cfg );
830 *pp_status = vlm_MessageNew( "new", "could not create media" );
833 vlm_media_Clean( &cfg );
834 return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );
838 *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
843 static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
845 if( ExecuteIsSchedule( p_vlm, psz_name ) )
847 vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
848 return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );
850 else if( ExecuteIsMedia( p_vlm, psz_name ) )
853 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
855 return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );
859 *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
863 int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
864 vlm_message_t **pp_message )
866 size_t i_command = 0;
867 char buf[strlen (psz_command) + 1], *psz_buf = buf;
868 char *ppsz_command[3+sizeof (buf) / 2];
869 vlm_message_t *p_message = NULL;
871 /* First, parse the line and cut it */
872 while( *psz_command != '\0' )
874 const char *psz_temp;
876 if(isspace (*psz_command))
882 /* support for comments */
883 if( i_command == 0 && *psz_command == '#')
885 p_message = vlm_MessageNew( "", vlm_NULL );
889 psz_temp = FindCommandEnd( psz_command );
891 if( psz_temp == NULL )
893 p_message = vlm_MessageNew( "Incomplete command", psz_command );
897 assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
899 ppsz_command[i_command] = psz_buf;
900 memcpy (psz_buf, psz_command, psz_temp - psz_command);
901 psz_buf[psz_temp - psz_command] = '\0';
903 Unescape (psz_buf, psz_buf);
906 psz_buf += psz_temp - psz_command + 1;
907 psz_command = psz_temp;
909 assert (buf + sizeof (buf) >= psz_buf);
913 * And then Interpret it
916 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; }
919 p_message = vlm_MessageNew( "", vlm_NULL );
922 else IF_EXECUTE( "del", (i_command != 2), ExecuteDel(p_vlm, ppsz_command[1], &p_message) )
923 else IF_EXECUTE( "show", (i_command > 2), ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) )
924 else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp( &p_message ) )
925 else IF_EXECUTE( "control", (i_command < 3), ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) )
926 else IF_EXECUTE( "save", (i_command != 2), ExecuteSave(p_vlm, ppsz_command[1], &p_message) )
927 else IF_EXECUTE( "export", (i_command != 1), ExecuteExport(p_vlm, &p_message) )
928 else IF_EXECUTE( "load", (i_command != 2), ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )
929 else IF_EXECUTE( "new", (i_command < 3), ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )
930 else IF_EXECUTE( "setup", (i_command < 2), ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
933 p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
939 *pp_message = p_message;
943 return ExecuteSyntaxError( ppsz_command[0], pp_message );
946 *pp_message = p_message;
950 /*****************************************************************************
952 *****************************************************************************/
953 vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
957 for( i = 0; i < vlm->i_media; i++ )
959 if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
960 return vlm->media[i];
966 /*****************************************************************************
968 *****************************************************************************/
969 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
974 vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
978 p_sched->psz_name = strdup( psz_name );
979 p_sched->b_enabled = false;
980 p_sched->i_command = 0;
981 p_sched->command = NULL;
983 p_sched->i_period = 0;
984 p_sched->i_repeat = -1;
986 TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
991 /* for now, simple delete. After, del with options (last arg) */
992 void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
994 if( sched == NULL ) return;
996 TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
998 if( vlm->i_schedule == 0 ) free( vlm->schedule );
999 free( sched->psz_name );
1000 while( sched->i_command )
1002 char *psz_cmd = sched->command[0];
1003 TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
1009 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
1013 for( i = 0; i < vlm->i_schedule; i++ )
1015 if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
1017 return vlm->schedule[i];
1024 /* Ok, setup schedule command will be able to support only one (argument value) at a time */
1025 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
1026 const char *psz_value )
1028 if( !strcmp( psz_cmd, "enabled" ) )
1030 schedule->b_enabled = true;
1032 else if( !strcmp( psz_cmd, "disabled" ) )
1034 schedule->b_enabled = false;
1036 else if( !strcmp( psz_cmd, "date" ) )
1042 time.tm_sec = 0; /* seconds */
1043 time.tm_min = 0; /* minutes */
1044 time.tm_hour = 0; /* hours */
1045 time.tm_mday = 0; /* day of the month */
1046 time.tm_mon = 0; /* month */
1047 time.tm_year = 0; /* year */
1048 time.tm_wday = 0; /* day of the week */
1049 time.tm_yday = 0; /* day in the year */
1050 time.tm_isdst = -1; /* daylight saving time */
1052 /* date should be year/month/day-hour:minutes:seconds */
1053 p = strchr( psz_value, '-' );
1055 if( !strcmp( psz_value, "now" ) )
1057 schedule->i_date = 0;
1059 else if( (p == NULL) && sscanf( psz_value, "%d:%d:%d", &time.tm_hour,
1060 &time.tm_min, &time.tm_sec ) != 3 )
1061 /* it must be a hour:minutes:seconds */
1069 switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
1087 switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
1093 time.tm_mon = i - 1;
1097 time.tm_year = i - 1900;
1098 time.tm_mon = j - 1;
1105 date = mktime( &time );
1106 schedule->i_date = ((mtime_t) date) * 1000000;
1109 else if( !strcmp( psz_cmd, "period" ) )
1113 const char *psz_time = NULL, *psz_date = NULL;
1117 /* First, if date or period are modified, repeat should be equal to -1 */
1118 schedule->i_repeat = -1;
1120 time.tm_sec = 0; /* seconds */
1121 time.tm_min = 0; /* minutes */
1122 time.tm_hour = 0; /* hours */
1123 time.tm_mday = 0; /* day of the month */
1124 time.tm_mon = 0; /* month */
1125 time.tm_year = 0; /* year */
1126 time.tm_wday = 0; /* day of the week */
1127 time.tm_yday = 0; /* day in the year */
1128 time.tm_isdst = -1; /* daylight saving time */
1130 /* date should be year/month/day-hour:minutes:seconds */
1131 p = strchr( psz_value, '-' );
1134 psz_date = psz_value;
1139 psz_time = psz_value;
1142 switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
1161 switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
1180 /* ok, that's stupid... who is going to schedule streams every 42 years ? */
1181 date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;
1182 schedule->i_period = ((mtime_t) date) * 1000000;
1184 else if( !strcmp( psz_cmd, "repeat" ) )
1188 if( sscanf( psz_value, "%d", &i ) == 1 )
1190 schedule->i_repeat = i;
1197 else if( !strcmp( psz_cmd, "append" ) )
1199 char *command = strdup( psz_value );
1201 TAB_APPEND( schedule->i_command, schedule->command, command );
1210 /*****************************************************************************
1211 * Message handling functions
1212 *****************************************************************************/
1213 vlm_message_t *vlm_MessageNew( const char *psz_name,
1214 const char *psz_format, ... )
1216 vlm_message_t *p_message;
1219 if( !psz_name ) return NULL;
1221 p_message = malloc( sizeof(vlm_message_t) );
1227 p_message->psz_value = 0;
1231 va_start( args, psz_format );
1232 if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
1241 p_message->psz_name = strdup( psz_name );
1242 p_message->i_child = 0;
1243 p_message->child = NULL;
1248 void vlm_MessageDelete( vlm_message_t *p_message )
1250 free( p_message->psz_name );
1251 free( p_message->psz_value );
1252 while( p_message->i_child-- )
1253 vlm_MessageDelete( p_message->child[p_message->i_child] );
1254 free( p_message->child );
1259 vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
1260 vlm_message_t *p_child )
1262 if( p_message == NULL ) return NULL;
1266 TAB_APPEND( p_message->i_child, p_message->child, p_child );
1272 /*****************************************************************************
1273 * Misc utility functions
1274 *****************************************************************************/
1275 static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
1277 vlm_media_t *p_cfg = &p_media->cfg;
1278 vlm_message_t *p_msg;
1279 vlm_message_t *p_msg_sub;
1282 p_msg = vlm_MessageNew( p_cfg->psz_name, vlm_NULL );
1283 vlm_MessageAdd( p_msg,
1284 vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
1285 vlm_MessageAdd( p_msg,
1286 vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );
1289 vlm_MessageAdd( p_msg,
1290 vlm_MessageNew( "mux", p_cfg->vod.psz_mux ) );
1292 vlm_MessageAdd( p_msg,
1293 vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
1295 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", vlm_NULL ) );
1296 for( i = 0; i < p_cfg->i_input; i++ )
1299 if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )
1301 vlm_MessageAdd( p_msg_sub,
1302 vlm_MessageNew( psz_tmp, p_cfg->ppsz_input[i] ) );
1307 vlm_MessageAdd( p_msg,
1308 vlm_MessageNew( "output", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
1310 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", vlm_NULL ) );
1311 for( i = 0; i < p_cfg->i_option; i++ )
1312 vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], vlm_NULL ) );
1314 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", vlm_NULL ) );
1315 for( i = 0; i < p_media->i_instance; i++ )
1317 vlm_media_instance_sys_t *p_instance = p_media->instance[i];
1319 vlm_message_t *p_msg_instance;
1323 if( p_instance->p_input )
1324 var_Get( p_instance->p_input, "state", &val );
1326 p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , vlm_NULL ) );
1328 vlm_MessageAdd( p_msg_instance,
1329 vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );
1330 vlm_MessageAdd( p_msg_instance,
1331 vlm_MessageNew( "state",
1332 val.i_int == PLAYING_S ? "playing" :
1333 val.i_int == PAUSE_S ? "paused" :
1336 /* FIXME should not do that this way */
1337 if( p_instance->p_input )
1339 #define APPEND_INPUT_INFO( a, format, type ) \
1340 if( asprintf( &psz_tmp, format, \
1341 var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
1343 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
1347 APPEND_INPUT_INFO( "position", "%f", Float );
1348 APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
1349 APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
1350 APPEND_INPUT_INFO( "rate", "%d", Integer );
1351 APPEND_INPUT_INFO( "title", "%d", Integer );
1352 APPEND_INPUT_INFO( "chapter", "%d", Integer );
1353 APPEND_INPUT_INFO( "seekable", "%d", Bool );
1355 #undef APPEND_INPUT_INFO
1356 if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
1358 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
1366 static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
1367 vlm_schedule_sys_t *schedule,
1368 const char *psz_filter )
1372 vlm_message_t *p_msg = vlm_MessageNew( "show", vlm_NULL );
1374 vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) );
1378 else if( schedule != NULL )
1382 vlm_message_t *msg_schedule;
1383 vlm_message_t *msg_child;
1386 msg = vlm_MessageNew( "show", vlm_NULL );
1388 vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, vlm_NULL ) );
1390 vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
1392 vlm_MessageAdd( msg_schedule,
1393 vlm_MessageNew( "enabled", schedule->b_enabled ?
1396 if( schedule->i_date != 0 )
1399 time_t i_time = (time_t)( schedule->i_date / 1000000 );
1402 localtime_r( &i_time, &date);
1403 if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
1404 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1405 date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
1407 vlm_MessageAdd( msg_schedule,
1408 vlm_MessageNew( "date", psz_date ) );
1413 vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
1415 if( schedule->i_period != 0 )
1417 time_t i_time = (time_t) ( schedule->i_period / 1000000 );
1420 date.tm_sec = (int)( i_time % 60 );
1421 i_time = i_time / 60;
1422 date.tm_min = (int)( i_time % 60 );
1423 i_time = i_time / 60;
1424 date.tm_hour = (int)( i_time % 24 );
1425 i_time = i_time / 24;
1426 date.tm_mday = (int)( i_time % 30 );
1427 i_time = i_time / 30;
1428 /* okay, okay, months are not always 30 days long */
1429 date.tm_mon = (int)( i_time % 12 );
1430 i_time = i_time / 12;
1431 date.tm_year = (int)i_time;
1433 sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
1434 date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
1436 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", buffer) );
1439 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
1441 sprintf( buffer, "%d", schedule->i_repeat );
1442 vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
1445 vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", vlm_NULL ) );
1447 for( i = 0; i < schedule->i_command; i++ )
1449 vlm_MessageAdd( msg_child,
1450 vlm_MessageNew( schedule->command[i], vlm_NULL ) );
1457 else if( psz_filter && !strcmp( psz_filter, "media" ) )
1459 vlm_message_t *p_msg;
1460 vlm_message_t *p_msg_child;
1461 int i_vod = 0, i_broadcast = 0;
1465 for( i = 0; i < vlm->i_media; i++ )
1467 if( vlm->media[i]->cfg.b_vod )
1473 if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
1476 p_msg = vlm_MessageNew( "show", vlm_NULL );
1477 p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", psz_count ) );
1480 for( i = 0; i < vlm->i_media; i++ )
1481 vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
1486 else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
1490 vlm_message_t *msg_child;
1492 msg = vlm_MessageNew( "show", vlm_NULL );
1493 msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", vlm_NULL ) );
1495 for( i = 0; i < vlm->i_schedule; i++ )
1497 vlm_schedule_sys_t *s = vlm->schedule[i];
1498 vlm_message_t *msg_schedule;
1499 mtime_t i_time, i_next_date;
1501 msg_schedule = vlm_MessageAdd( msg_child,
1502 vlm_MessageNew( s->psz_name, vlm_NULL ) );
1503 vlm_MessageAdd( msg_schedule,
1504 vlm_MessageNew( "enabled", s->b_enabled ?
1507 /* calculate next date */
1508 i_time = vlm_Date();
1509 i_next_date = s->i_date;
1511 if( s->i_period != 0 )
1514 while( s->i_date + j * s->i_period <= i_time &&
1520 i_next_date = s->i_date + j * s->i_period;
1523 if( i_next_date > i_time )
1525 time_t i_date = (time_t) (i_next_date / 1000000) ;
1527 #if !defined( UNDER_CE )
1530 ctime_r( &i_date, psz_date );
1532 char *psz_date = ctime( &i_date );
1535 vlm_MessageAdd( msg_schedule,
1536 vlm_MessageNew( "next launch", psz_date ) );
1544 else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
1546 vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
1547 vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
1549 vlm_MessageAdd( show1, show2->child[0] );
1551 /* We must destroy the parent node "show" of show2
1552 * and not the children */
1553 free( show2->psz_name );
1561 return vlm_MessageNew( "show", vlm_NULL );
1565 /*****************************************************************************
1566 * Config handling functions
1567 *****************************************************************************/
1568 static int Load( vlm_t *vlm, char *file )
1573 while( *pf != '\0' )
1575 vlm_message_t *message = NULL;
1578 while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
1583 if( pf[i_end] == '\r' || pf[i_end] == '\n' )
1587 if( pf[i_end] == '\n' ) i_end++;
1590 if( *pf && ExecuteCommand( vlm, pf, &message ) )
1594 if( message->psz_value )
1595 msg_Err( vlm, "Load error on line %d: %s: %s",
1596 i_line, message->psz_name, message->psz_value );
1597 vlm_MessageDelete( message );
1601 if( message ) vlm_MessageDelete( message );
1610 static char *Save( vlm_t *vlm )
1613 char psz_header[] = "\n"
1614 "# VLC media player VLM command batch\n"
1615 "# http://www.videolan.org/vlc/\n\n" ;
1618 int i_length = strlen( psz_header );
1620 for( i = 0; i < vlm->i_media; i++ )
1622 vlm_media_sys_t *media = vlm->media[i];
1623 vlm_media_t *p_cfg = &media->cfg;
1626 i_length += strlen( "new * vod " ) + strlen(p_cfg->psz_name);
1628 i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
1630 if( p_cfg->b_enabled == true )
1631 i_length += strlen( "enabled" );
1633 i_length += strlen( "disabled" );
1635 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == true )
1636 i_length += strlen( " loop\n" );
1638 i_length += strlen( "\n" );
1640 for( j = 0; j < p_cfg->i_input; j++ )
1641 i_length += strlen( "setup * input \"\"\n" ) + strlen( p_cfg->psz_name ) + strlen( p_cfg->ppsz_input[j] );
1643 if( p_cfg->psz_output != NULL )
1644 i_length += strlen( "setup * output \n" ) + strlen(p_cfg->psz_name) + strlen(p_cfg->psz_output);
1646 for( j = 0; j < p_cfg->i_option; j++ )
1647 i_length += strlen("setup * option \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->ppsz_option[j]);
1649 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1650 i_length += strlen("setup * mux \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->vod.psz_mux);
1653 for( i = 0; i < vlm->i_schedule; i++ )
1655 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1657 i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
1659 if( schedule->b_enabled == true )
1661 i_length += strlen( "date //-:: enabled\n" ) + 14;
1665 i_length += strlen( "date //-:: disabled\n" ) + 14;
1669 if( schedule->i_period != 0 )
1671 i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
1672 strlen( "period //-::\n" ) + 14;
1675 if( schedule->i_repeat >= 0 )
1679 sprintf( buffer, "%d", schedule->i_repeat );
1680 i_length += strlen( "setup repeat \n" ) +
1681 strlen( schedule->psz_name ) + strlen( buffer );
1688 for( j = 0; j < schedule->i_command; j++ )
1690 i_length += strlen( "setup append \n" ) +
1691 strlen( schedule->psz_name ) + strlen( schedule->command[j] );
1696 /* Don't forget the '\0' */
1698 /* now we have the length of save */
1700 p = save = malloc( i_length );
1701 if( !save ) return NULL;
1704 p += sprintf( p, "%s", psz_header );
1706 /* finally we can write in it */
1707 for( i = 0; i < vlm->i_media; i++ )
1709 vlm_media_sys_t *media = vlm->media[i];
1710 vlm_media_t *p_cfg = &media->cfg;
1713 p += sprintf( p, "new %s vod ", p_cfg->psz_name );
1715 p += sprintf( p, "new %s broadcast ", p_cfg->psz_name );
1717 if( p_cfg->b_enabled )
1718 p += sprintf( p, "enabled" );
1720 p += sprintf( p, "disabled" );
1722 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
1723 p += sprintf( p, " loop\n" );
1725 p += sprintf( p, "\n" );
1727 for( j = 0; j < p_cfg->i_input; j++ )
1728 p += sprintf( p, "setup %s input \"%s\"\n", p_cfg->psz_name, p_cfg->ppsz_input[j] );
1730 if( p_cfg->psz_output )
1731 p += sprintf( p, "setup %s output %s\n", p_cfg->psz_name, p_cfg->psz_output );
1733 for( j = 0; j < p_cfg->i_option; j++ )
1734 p += sprintf( p, "setup %s option %s\n", p_cfg->psz_name, p_cfg->ppsz_option[j] );
1736 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1737 p += sprintf( p, "setup %s mux %s\n", p_cfg->psz_name, p_cfg->vod.psz_mux );
1740 /* and now, the schedule scripts */
1741 for( i = 0; i < vlm->i_schedule; i++ )
1743 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1745 time_t i_time = (time_t) ( schedule->i_date / 1000000 );
1747 localtime_r( &i_time, &date);
1748 p += sprintf( p, "new %s schedule ", schedule->psz_name);
1750 if( schedule->b_enabled == true )
1752 p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
1753 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1754 date.tm_hour, date.tm_min, date.tm_sec );
1758 p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
1759 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1760 date.tm_hour, date.tm_min, date.tm_sec);
1763 if( schedule->i_period != 0 )
1765 p += sprintf( p, "setup %s ", schedule->psz_name );
1767 i_time = (time_t) ( schedule->i_period / 1000000 );
1769 date.tm_sec = (int)( i_time % 60 );
1770 i_time = i_time / 60;
1771 date.tm_min = (int)( i_time % 60 );
1772 i_time = i_time / 60;
1773 date.tm_hour = (int)( i_time % 24 );
1774 i_time = i_time / 24;
1775 date.tm_mday = (int)( i_time % 30 );
1776 i_time = i_time / 30;
1777 /* okay, okay, months are not always 30 days long */
1778 date.tm_mon = (int)( i_time % 12 );
1779 i_time = i_time / 12;
1780 date.tm_year = (int)i_time;
1782 p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
1783 date.tm_year, date.tm_mon, date.tm_mday,
1784 date.tm_hour, date.tm_min, date.tm_sec);
1787 if( schedule->i_repeat >= 0 )
1789 p += sprintf( p, "setup %s repeat %d\n",
1790 schedule->psz_name, schedule->i_repeat );
1794 p += sprintf( p, "\n" );
1797 for( j = 0; j < schedule->i_command; j++ )
1799 p += sprintf( p, "setup %s append %s\n",
1800 schedule->psz_name, schedule->command[j] );
1808 #endif /* ENABLE_VLM */