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() */
43 #include <time.h> /* ctime() */
45 #include <vlc_input.h>
46 #include "input_internal.h"
47 #include <vlc_stream.h>
48 #include "vlm_internal.h"
49 #include <vlc_charset.h>
52 #include "../stream_output/stream_output.h"
53 #include "../libvlc.h"
55 /*****************************************************************************
57 *****************************************************************************/
60 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
62 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
64 static char *Save( vlm_t * );
65 static int Load( vlm_t *, char * );
67 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
68 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
69 const char *psz_value );
72 static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
74 static const char quotes[] = "\"'";
76 * FindCommandEnd: look for the end of a possibly quoted string
77 * @return NULL on mal-formatted string,
78 * pointer past the last character otherwise.
80 static const char *FindCommandEnd( const char *psz_sent )
84 while( (c = *psz_sent) != '\0' )
88 if( strchr(quotes,c) ) // opening quote
90 else if( isspace(c) ) // non-escaped space
94 psz_sent++; // skip escaped character
95 if( *psz_sent == '\0' )
101 if( c == quote ) // non-escaped matching quote
103 else if( (quote == '"') && (c == '\\') )
105 psz_sent++; // skip escaped character
106 if (*psz_sent == '\0')
107 return NULL; // error, closing quote missing
113 // error (NULL) if we could not find a matching quote
114 return quote ? NULL : psz_sent;
119 * Unescape a nul-terminated string.
120 * Note that in and out can be identical.
122 * @param out output buffer (at least <strlen (in) + 1> characters long)
123 * @param in nul-terminated string to be unescaped
125 * @return 0 on success, -1 on error.
127 static int Unescape( char *out, const char *in )
132 while( (c = *in++) != '\0' )
134 // Don't escape the end of the string if we find a '#'
135 // that's the begining of a vlc command
136 // TODO: find a better solution
137 if( c == '#' || param )
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_MessageSimpleNew( "del" );
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_MessageSimpleNew( a ) );
301 #define MessageAddChild( a ) \
302 vlm_MessageAdd( message_child, vlm_MessageSimpleNew( a ) );
304 *pp_status = vlm_MessageSimpleNew( "help" );
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 | [+-](milliseconds)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_MessageSimpleNew( "control" );
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", "%s", psz_export );
530 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
532 FILE *f = vlc_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_MessageSimpleNew( "save" );
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 );
584 if( i_size > SIZE_MAX - 1 )
585 i_size = SIZE_MAX - 1;
587 psz_buffer = malloc( i_size + 1 );
590 stream_Delete( p_stream );
592 *pp_status = vlm_MessageNew( "load", "Read file error" );
596 stream_Read( p_stream, psz_buffer, i_size );
597 psz_buffer[i_size] = '\0';
599 stream_Delete( p_stream );
601 if( Load( p_vlm, psz_buffer ) )
605 *pp_status = vlm_MessageNew( "load", "Error while loading file" );
611 *pp_status = vlm_MessageSimpleNew( "load" );
615 static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,
616 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
618 const char *psz_cmd = b_new ? "new" : "setup";
621 for( i = 0; i < i_property; i++ )
623 if( !strcmp( ppsz_property[i], "enabled" ) ||
624 !strcmp( ppsz_property[i], "disabled" ) )
626 if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )
629 else if( !strcmp( ppsz_property[i], "append" ) )
633 /* Beware: everything behind append is considered as
636 if( ++i >= i_property )
639 psz_line = strdup( ppsz_property[i] );
640 for( j = i+1; j < i_property; j++ )
642 psz_line = xrealloc( psz_line,
643 strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
644 strcat( psz_line, " " );
645 strcat( psz_line, ppsz_property[j] );
648 if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
654 if( i + 1 >= i_property )
657 vlm_ScheduleDelete( p_vlm, p_schedule );
658 return ExecuteSyntaxError( psz_cmd, pp_status );
661 if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )
666 *pp_status = vlm_MessageSimpleNew( psz_cmd );
670 *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",
675 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
676 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
678 const char *psz_cmd = b_new ? "new" : "setup";
679 vlm_media_t *p_cfg = NULL;
685 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
686 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )
687 ERROR( "unknown media" );
689 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
690 for( i = 0; i < i_property; i++ )
692 const char *psz_option = ppsz_property[i];
693 const char *psz_value = i+1 < i_property ? ppsz_property[i+1] : NULL;
695 if( !strcmp( psz_option, "enabled" ) )
697 p_cfg->b_enabled = true;
699 else if( !strcmp( psz_option, "disabled" ) )
701 p_cfg->b_enabled = false;
703 else if( !strcmp( psz_option, "input" ) )
706 TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
709 else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
711 while( p_cfg->i_input > 0 )
712 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
715 else if( !strcmp( psz_option, "inputdel" ) )
719 MISSING( "inputdel" );
721 for( j = 0; j < p_cfg->i_input; j++ )
723 if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
725 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
731 else if( !strcmp( psz_option, "inputdeln" ) )
735 MISSING( "inputdeln" );
737 i_index = atoi( psz_value );
738 if( i_index > 0 && i_index <= p_cfg->i_input )
739 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
742 else if( !strcmp( psz_option, "output" ) )
746 free( p_cfg->psz_output );
747 p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
750 else if( !strcmp( psz_option, "option" ) )
754 TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
757 else if( !strcmp( psz_option, "loop" ) )
760 ERROR( "invalid loop option for vod" );
761 p_cfg->broadcast.b_loop = true;
763 else if( !strcmp( psz_option, "unloop" ) )
766 ERROR( "invalid unloop option for vod" );
767 p_cfg->broadcast.b_loop = false;
769 else if( !strcmp( psz_option, "mux" ) )
773 ERROR( "invalid mux option for broadcast" );
775 free( p_cfg->vod.psz_mux );
776 p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
781 fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
782 ERROR( "Wrong command syntax" );
789 i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
790 vlm_media_Delete( p_cfg );
792 *pp_status = vlm_MessageSimpleNew( psz_cmd );
799 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
800 vlm_media_Delete( p_cfg );
805 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 )
808 if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
810 *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
813 if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
815 *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
819 if( !strcmp( psz_type, "schedule" ) )
821 vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
824 *pp_status = vlm_MessageNew( "new", "could not create schedule" );
827 return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );
829 else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
834 vlm_media_Init( &cfg );
835 cfg.psz_name = strdup( psz_name );
836 cfg.b_vod = !strcmp( psz_type, "vod" );
838 if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
840 vlm_media_Clean( &cfg );
841 *pp_status = vlm_MessageNew( "new", "could not create media" );
844 vlm_media_Clean( &cfg );
845 return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );
849 *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
854 static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
856 if( ExecuteIsSchedule( p_vlm, psz_name ) )
858 vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
859 return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );
861 else if( ExecuteIsMedia( p_vlm, psz_name ) )
864 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
866 return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );
870 *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
874 int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
875 vlm_message_t **pp_message )
877 size_t i_command = 0;
878 char buf[strlen (psz_command) + 1], *psz_buf = buf;
879 char *ppsz_command[3+sizeof (buf) / 2];
880 vlm_message_t *p_message = NULL;
882 /* First, parse the line and cut it */
883 while( *psz_command != '\0' )
885 const char *psz_temp;
887 if(isspace (*psz_command))
893 /* support for comments */
894 if( i_command == 0 && *psz_command == '#')
896 p_message = vlm_MessageSimpleNew( "" );
900 psz_temp = FindCommandEnd( psz_command );
902 if( psz_temp == NULL )
904 p_message = vlm_MessageNew( "Incomplete command", "%s", psz_command );
908 assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
910 ppsz_command[i_command] = psz_buf;
911 memcpy (psz_buf, psz_command, psz_temp - psz_command);
912 psz_buf[psz_temp - psz_command] = '\0';
914 Unescape (psz_buf, psz_buf);
917 psz_buf += psz_temp - psz_command + 1;
918 psz_command = psz_temp;
920 assert (buf + sizeof (buf) >= psz_buf);
924 * And then Interpret it
927 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; }
930 p_message = vlm_MessageSimpleNew( "" );
933 else IF_EXECUTE( "del", (i_command != 2), ExecuteDel(p_vlm, ppsz_command[1], &p_message) )
934 else IF_EXECUTE( "show", (i_command > 2), ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) )
935 else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp( &p_message ) )
936 else IF_EXECUTE( "control", (i_command < 3), ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) )
937 else IF_EXECUTE( "save", (i_command != 2), ExecuteSave(p_vlm, ppsz_command[1], &p_message) )
938 else IF_EXECUTE( "export", (i_command != 1), ExecuteExport(p_vlm, &p_message) )
939 else IF_EXECUTE( "load", (i_command != 2), ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )
940 else IF_EXECUTE( "new", (i_command < 3), ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )
941 else IF_EXECUTE( "setup", (i_command < 2), ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
944 p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
950 *pp_message = p_message;
954 return ExecuteSyntaxError( ppsz_command[0], pp_message );
957 *pp_message = p_message;
961 /*****************************************************************************
963 *****************************************************************************/
964 vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
968 for( i = 0; i < vlm->i_media; i++ )
970 if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
971 return vlm->media[i];
977 /*****************************************************************************
979 *****************************************************************************/
980 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
985 vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
989 p_sched->psz_name = strdup( psz_name );
990 p_sched->b_enabled = false;
991 p_sched->i_command = 0;
992 p_sched->command = NULL;
994 p_sched->i_period = 0;
995 p_sched->i_repeat = -1;
997 TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
999 vlc_mutex_lock( &vlm->lock_manage );
1000 vlc_cond_signal( &vlm->wait_manage );
1001 vlc_mutex_unlock( &vlm->lock_manage );
1006 /* for now, simple delete. After, del with options (last arg) */
1007 void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
1009 if( sched == NULL ) return;
1011 TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
1013 if( vlm->i_schedule == 0 ) free( vlm->schedule );
1014 free( sched->psz_name );
1015 while( sched->i_command )
1017 char *psz_cmd = sched->command[0];
1018 TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
1024 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
1028 for( i = 0; i < vlm->i_schedule; i++ )
1030 if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
1032 return vlm->schedule[i];
1039 /* Ok, setup schedule command will be able to support only one (argument value) at a time */
1040 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
1041 const char *psz_value )
1043 if( !strcmp( psz_cmd, "enabled" ) )
1045 schedule->b_enabled = true;
1047 else if( !strcmp( psz_cmd, "disabled" ) )
1049 schedule->b_enabled = false;
1051 else if( !strcmp( psz_cmd, "date" ) )
1057 time.tm_sec = 0; /* seconds */
1058 time.tm_min = 0; /* minutes */
1059 time.tm_hour = 0; /* hours */
1060 time.tm_mday = 0; /* day of the month */
1061 time.tm_mon = 0; /* month */
1062 time.tm_year = 0; /* year */
1063 time.tm_wday = 0; /* day of the week */
1064 time.tm_yday = 0; /* day in the year */
1065 time.tm_isdst = -1; /* daylight saving time */
1067 /* date should be year/month/day-hour:minutes:seconds */
1068 p = strchr( psz_value, '-' );
1070 if( !strcmp( psz_value, "now" ) )
1072 schedule->i_date = 0;
1082 switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
1100 switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
1106 time.tm_mon = i - 1;
1110 time.tm_year = i - 1900;
1111 time.tm_mon = j - 1;
1118 date = mktime( &time );
1119 schedule->i_date = ((mtime_t) date) * 1000000;
1122 else if( !strcmp( psz_cmd, "period" ) )
1126 const char *psz_time = NULL, *psz_date = NULL;
1130 /* First, if date or period are modified, repeat should be equal to -1 */
1131 schedule->i_repeat = -1;
1133 time.tm_sec = 0; /* seconds */
1134 time.tm_min = 0; /* minutes */
1135 time.tm_hour = 0; /* hours */
1136 time.tm_mday = 0; /* day of the month */
1137 time.tm_mon = 0; /* month */
1138 time.tm_year = 0; /* year */
1139 time.tm_wday = 0; /* day of the week */
1140 time.tm_yday = 0; /* day in the year */
1141 time.tm_isdst = -1; /* daylight saving time */
1143 /* date should be year/month/day-hour:minutes:seconds */
1144 p = strchr( psz_value, '-' );
1147 psz_date = psz_value;
1152 psz_time = psz_value;
1155 switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
1174 switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
1193 /* ok, that's stupid... who is going to schedule streams every 42 years ? */
1194 date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;
1195 schedule->i_period = ((mtime_t) date) * 1000000;
1197 else if( !strcmp( psz_cmd, "repeat" ) )
1201 if( sscanf( psz_value, "%d", &i ) == 1 )
1203 schedule->i_repeat = i;
1210 else if( !strcmp( psz_cmd, "append" ) )
1212 char *command = strdup( psz_value );
1214 TAB_APPEND( schedule->i_command, schedule->command, command );
1223 /*****************************************************************************
1224 * Message handling functions
1225 *****************************************************************************/
1226 vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
1228 if( !psz_name ) return NULL;
1230 vlm_message_t *p_message = malloc( sizeof(*p_message) );
1234 p_message->psz_name = strdup( psz_name );
1235 if( !p_message->psz_name )
1240 p_message->psz_value = NULL;
1241 p_message->i_child = 0;
1242 p_message->child = NULL;
1247 vlm_message_t *vlm_MessageNew( const char *psz_name,
1248 const char *psz_format, ... )
1250 vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
1256 assert( psz_format );
1257 va_start( args, psz_format );
1258 if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
1259 p_message->psz_value = NULL;
1262 if( !p_message->psz_value )
1264 vlm_MessageDelete( p_message );
1270 void vlm_MessageDelete( vlm_message_t *p_message )
1272 free( p_message->psz_name );
1273 free( p_message->psz_value );
1274 while( p_message->i_child-- )
1275 vlm_MessageDelete( p_message->child[p_message->i_child] );
1276 free( p_message->child );
1281 vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
1282 vlm_message_t *p_child )
1284 if( p_message == NULL ) return NULL;
1288 TAB_APPEND( p_message->i_child, p_message->child, p_child );
1294 /*****************************************************************************
1295 * Misc utility functions
1296 *****************************************************************************/
1297 static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
1299 vlm_media_t *p_cfg = &p_media->cfg;
1300 vlm_message_t *p_msg;
1301 vlm_message_t *p_msg_sub;
1304 p_msg = vlm_MessageSimpleNew( p_cfg->psz_name );
1305 vlm_MessageAdd( p_msg,
1306 vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
1307 vlm_MessageAdd( p_msg,
1308 vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );
1311 vlm_MessageAdd( p_msg,
1312 vlm_MessageNew( "mux", "%s", p_cfg->vod.psz_mux ) );
1314 vlm_MessageAdd( p_msg,
1315 vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
1317 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "inputs" ) );
1318 for( i = 0; i < p_cfg->i_input; i++ )
1321 if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )
1323 vlm_MessageAdd( p_msg_sub,
1324 vlm_MessageNew( psz_tmp, "%s", p_cfg->ppsz_input[i] ) );
1329 vlm_MessageAdd( p_msg,
1330 vlm_MessageNew( "output", "%s", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
1332 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "options" ) );
1333 for( i = 0; i < p_cfg->i_option; i++ )
1334 vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( p_cfg->ppsz_option[i] ) );
1336 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "instances" ) );
1337 for( i = 0; i < p_media->i_instance; i++ )
1339 vlm_media_instance_sys_t *p_instance = p_media->instance[i];
1341 vlm_message_t *p_msg_instance;
1345 if( p_instance->p_input )
1346 var_Get( p_instance->p_input, "state", &val );
1348 p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( "instance" ) );
1350 vlm_MessageAdd( p_msg_instance,
1351 vlm_MessageNew( "name" , "%s", p_instance->psz_name ? p_instance->psz_name : "default" ) );
1352 vlm_MessageAdd( p_msg_instance,
1353 vlm_MessageNew( "state",
1354 val.i_int == PLAYING_S ? "playing" :
1355 val.i_int == PAUSE_S ? "paused" :
1358 /* FIXME should not do that this way */
1359 if( p_instance->p_input )
1361 #define APPEND_INPUT_INFO( a, format, type ) \
1362 if( asprintf( &psz_tmp, format, \
1363 var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
1365 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
1366 "%s", psz_tmp ) ); \
1369 APPEND_INPUT_INFO( "position", "%f", Float );
1370 APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
1371 APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
1372 APPEND_INPUT_INFO( "rate", "%f", Float );
1373 APPEND_INPUT_INFO( "title", "%d", Integer );
1374 APPEND_INPUT_INFO( "chapter", "%d", Integer );
1375 APPEND_INPUT_INFO( "can-seek", "%d", Bool );
1377 #undef APPEND_INPUT_INFO
1378 if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
1380 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
1388 static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
1389 vlm_schedule_sys_t *schedule,
1390 const char *psz_filter )
1394 vlm_message_t *p_msg = vlm_MessageSimpleNew( "show" );
1396 vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) );
1400 else if( schedule != NULL )
1404 vlm_message_t *msg_schedule;
1405 vlm_message_t *msg_child;
1408 msg = vlm_MessageSimpleNew( "show" );
1410 vlm_MessageAdd( msg, vlm_MessageSimpleNew( schedule->psz_name ) );
1412 vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
1414 vlm_MessageAdd( msg_schedule,
1415 vlm_MessageNew( "enabled", schedule->b_enabled ?
1418 if( schedule->i_date != 0 )
1421 time_t i_time = (time_t)( schedule->i_date / 1000000 );
1424 localtime_r( &i_time, &date);
1425 if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
1426 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1427 date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
1429 vlm_MessageAdd( msg_schedule,
1430 vlm_MessageNew( "date", "%s", psz_date ) );
1435 vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
1437 if( schedule->i_period != 0 )
1439 time_t i_time = (time_t) ( schedule->i_period / 1000000 );
1442 date.tm_sec = (int)( i_time % 60 );
1443 i_time = i_time / 60;
1444 date.tm_min = (int)( i_time % 60 );
1445 i_time = i_time / 60;
1446 date.tm_hour = (int)( i_time % 24 );
1447 i_time = i_time / 24;
1448 date.tm_mday = (int)( i_time % 30 );
1449 i_time = i_time / 30;
1450 /* okay, okay, months are not always 30 days long */
1451 date.tm_mon = (int)( i_time % 12 );
1452 i_time = i_time / 12;
1453 date.tm_year = (int)i_time;
1455 sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
1456 date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
1458 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "%s", buffer) );
1461 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
1463 sprintf( buffer, "%d", schedule->i_repeat );
1464 vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", "%s", buffer ) );
1467 vlm_MessageAdd( msg_schedule, vlm_MessageSimpleNew("commands" ) );
1469 for( i = 0; i < schedule->i_command; i++ )
1471 vlm_MessageAdd( msg_child,
1472 vlm_MessageSimpleNew( schedule->command[i] ) );
1479 else if( psz_filter && !strcmp( psz_filter, "media" ) )
1481 vlm_message_t *p_msg;
1482 vlm_message_t *p_msg_child;
1483 int i_vod = 0, i_broadcast = 0;
1487 for( i = 0; i < vlm->i_media; i++ )
1489 if( vlm->media[i]->cfg.b_vod )
1495 if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
1498 p_msg = vlm_MessageSimpleNew( "show" );
1499 p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", "%s",
1503 for( i = 0; i < vlm->i_media; i++ )
1504 vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
1509 else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
1513 vlm_message_t *msg_child;
1515 msg = vlm_MessageSimpleNew( "show" );
1516 msg_child = vlm_MessageAdd( msg, vlm_MessageSimpleNew( "schedule" ) );
1518 for( i = 0; i < vlm->i_schedule; i++ )
1520 vlm_schedule_sys_t *s = vlm->schedule[i];
1521 vlm_message_t *msg_schedule;
1522 mtime_t i_time, i_next_date;
1524 msg_schedule = vlm_MessageAdd( msg_child,
1525 vlm_MessageSimpleNew( s->psz_name ) );
1526 vlm_MessageAdd( msg_schedule,
1527 vlm_MessageNew( "enabled", s->b_enabled ?
1530 /* calculate next date */
1531 i_time = vlm_Date();
1532 i_next_date = s->i_date;
1534 if( s->i_period != 0 )
1537 while( s->i_date + j * s->i_period <= i_time &&
1543 i_next_date = s->i_date + j * s->i_period;
1546 if( i_next_date > i_time )
1548 time_t i_date = (time_t) (i_next_date / 1000000) ;
1550 #if !defined( UNDER_CE )
1553 ctime_r( &i_date, psz_date );
1555 char *psz_date = ctime( &i_date );
1558 vlm_MessageAdd( msg_schedule,
1559 vlm_MessageNew( "next launch", "%s", psz_date ) );
1567 else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
1569 vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
1570 vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
1572 vlm_MessageAdd( show1, show2->child[0] );
1574 /* We must destroy the parent node "show" of show2
1575 * and not the children */
1576 free( show2->psz_name );
1584 return vlm_MessageSimpleNew( "show" );
1588 /*****************************************************************************
1589 * Config handling functions
1590 *****************************************************************************/
1591 static int Load( vlm_t *vlm, char *file )
1596 while( *pf != '\0' )
1598 vlm_message_t *message = NULL;
1601 while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
1606 if( pf[i_end] == '\r' || pf[i_end] == '\n' )
1610 if( pf[i_end] == '\n' ) i_end++;
1613 if( *pf && ExecuteCommand( vlm, pf, &message ) )
1617 if( message->psz_value )
1618 msg_Err( vlm, "Load error on line %d: %s: %s",
1619 i_line, message->psz_name, message->psz_value );
1620 vlm_MessageDelete( message );
1624 if( message ) vlm_MessageDelete( message );
1633 static char *Save( vlm_t *vlm )
1636 char psz_header[] = "\n"
1637 "# VLC media player VLM command batch\n"
1638 "# http://www.videolan.org/vlc/\n\n" ;
1641 int i_length = strlen( psz_header );
1643 for( i = 0; i < vlm->i_media; i++ )
1645 vlm_media_sys_t *media = vlm->media[i];
1646 vlm_media_t *p_cfg = &media->cfg;
1649 i_length += strlen( "new * vod " ) + strlen(p_cfg->psz_name);
1651 i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
1653 if( p_cfg->b_enabled == true )
1654 i_length += strlen( "enabled" );
1656 i_length += strlen( "disabled" );
1658 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == true )
1659 i_length += strlen( " loop\n" );
1661 i_length += strlen( "\n" );
1663 for( j = 0; j < p_cfg->i_input; j++ )
1664 i_length += strlen( "setup * input \"\"\n" ) + strlen( p_cfg->psz_name ) + strlen( p_cfg->ppsz_input[j] );
1666 if( p_cfg->psz_output != NULL )
1667 i_length += strlen( "setup * output \n" ) + strlen(p_cfg->psz_name) + strlen(p_cfg->psz_output);
1669 for( j = 0; j < p_cfg->i_option; j++ )
1670 i_length += strlen("setup * option \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->ppsz_option[j]);
1672 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1673 i_length += strlen("setup * mux \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->vod.psz_mux);
1676 for( i = 0; i < vlm->i_schedule; i++ )
1678 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1680 i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
1682 if( schedule->b_enabled == true )
1684 i_length += strlen( "date //-:: enabled\n" ) + 14;
1688 i_length += strlen( "date //-:: disabled\n" ) + 14;
1692 if( schedule->i_period != 0 )
1694 i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
1695 strlen( "period //-::\n" ) + 14;
1698 if( schedule->i_repeat >= 0 )
1702 sprintf( buffer, "%d", schedule->i_repeat );
1703 i_length += strlen( "setup repeat \n" ) +
1704 strlen( schedule->psz_name ) + strlen( buffer );
1711 for( j = 0; j < schedule->i_command; j++ )
1713 i_length += strlen( "setup append \n" ) +
1714 strlen( schedule->psz_name ) + strlen( schedule->command[j] );
1719 /* Don't forget the '\0' */
1721 /* now we have the length of save */
1723 p = save = malloc( i_length );
1724 if( !save ) return NULL;
1727 p += sprintf( p, "%s", psz_header );
1729 /* finally we can write in it */
1730 for( i = 0; i < vlm->i_media; i++ )
1732 vlm_media_sys_t *media = vlm->media[i];
1733 vlm_media_t *p_cfg = &media->cfg;
1736 p += sprintf( p, "new %s vod ", p_cfg->psz_name );
1738 p += sprintf( p, "new %s broadcast ", p_cfg->psz_name );
1740 if( p_cfg->b_enabled )
1741 p += sprintf( p, "enabled" );
1743 p += sprintf( p, "disabled" );
1745 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
1746 p += sprintf( p, " loop\n" );
1748 p += sprintf( p, "\n" );
1750 for( j = 0; j < p_cfg->i_input; j++ )
1751 p += sprintf( p, "setup %s input \"%s\"\n", p_cfg->psz_name, p_cfg->ppsz_input[j] );
1753 if( p_cfg->psz_output )
1754 p += sprintf( p, "setup %s output %s\n", p_cfg->psz_name, p_cfg->psz_output );
1756 for( j = 0; j < p_cfg->i_option; j++ )
1757 p += sprintf( p, "setup %s option %s\n", p_cfg->psz_name, p_cfg->ppsz_option[j] );
1759 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1760 p += sprintf( p, "setup %s mux %s\n", p_cfg->psz_name, p_cfg->vod.psz_mux );
1763 /* and now, the schedule scripts */
1764 for( i = 0; i < vlm->i_schedule; i++ )
1766 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1768 time_t i_time = (time_t) ( schedule->i_date / 1000000 );
1770 localtime_r( &i_time, &date);
1771 p += sprintf( p, "new %s schedule ", schedule->psz_name);
1773 if( schedule->b_enabled == true )
1775 p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
1776 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1777 date.tm_hour, date.tm_min, date.tm_sec );
1781 p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
1782 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1783 date.tm_hour, date.tm_min, date.tm_sec);
1786 if( schedule->i_period != 0 )
1788 p += sprintf( p, "setup %s ", schedule->psz_name );
1790 i_time = (time_t) ( schedule->i_period / 1000000 );
1792 date.tm_sec = (int)( i_time % 60 );
1793 i_time = i_time / 60;
1794 date.tm_min = (int)( i_time % 60 );
1795 i_time = i_time / 60;
1796 date.tm_hour = (int)( i_time % 24 );
1797 i_time = i_time / 24;
1798 date.tm_mday = (int)( i_time % 30 );
1799 i_time = i_time / 30;
1800 /* okay, okay, months are not always 30 days long */
1801 date.tm_mon = (int)( i_time % 12 );
1802 i_time = i_time / 12;
1803 date.tm_year = (int)i_time;
1805 p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
1806 date.tm_year, date.tm_mon, date.tm_mday,
1807 date.tm_hour, date.tm_min, date.tm_sec);
1810 if( schedule->i_repeat >= 0 )
1812 p += sprintf( p, "setup %s repeat %d\n",
1813 schedule->psz_name, schedule->i_repeat );
1817 p += sprintf( p, "\n" );
1820 for( j = 0; j < schedule->i_command; j++ )
1822 p += sprintf( p, "setup %s append %s\n",
1823 schedule->psz_name, schedule->command[j] );
1831 #endif /* ENABLE_VLM */