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() */
47 #include <time.h> /* ctime() */
49 #include <vlc_input.h>
50 #include "input_internal.h"
51 #include <vlc_stream.h>
52 #include "vlm_internal.h"
54 #include <vlc_charset.h>
56 #include "../stream_output/stream_output.h"
57 #include "../libvlc.h"
59 /*****************************************************************************
61 *****************************************************************************/
64 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
66 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
68 static char *Save( vlm_t * );
69 static int Load( vlm_t *, char * );
71 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
72 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
73 const char *psz_value );
76 static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
78 static const char quotes[] = "\"'";
80 * FindCommandEnd: look for the end of a possibly quoted string
81 * @return NULL on mal-formatted string,
82 * pointer past the last character otherwise.
84 static const char *FindCommandEnd( const char *psz_sent )
88 while( (c = *psz_sent) != '\0' )
92 if( strchr(quotes,c) ) // opening quote
94 else if( isspace(c) ) // non-escaped space
98 psz_sent++; // skip escaped character
99 if( *psz_sent == '\0' )
105 if( c == quote ) // non-escaped matching quote
107 else if( (quote == '"') && (c == '\\') )
109 psz_sent++; // skip escaped character
110 if (*psz_sent == '\0')
111 return NULL; // error, closing quote missing
117 // error (NULL) if we could not find a matching quote
118 return quote ? NULL : psz_sent;
123 * Unescape a nul-terminated string.
124 * Note that in and out can be identical.
126 * @param out output buffer (at least <strlen (in) + 1> characters long)
127 * @param in nul-terminated string to be unescaped
129 * @return 0 on success, -1 on error.
131 static int Unescape( char *out, const char *in )
136 while( (c = *in++) != '\0' )
138 // Don't escape the end of the string if we find a '#'
139 // that's the begining of a vlc command
140 // TODO: find a better solution
141 if( c == '#' || param )
150 if (strchr(quotes,c)) // opening quote
174 /* None of the special cases - copy the backslash */
180 if( c == quote ) // non-escaped matching quote
185 if( (quote == '"') && (c == '\\') )
194 case '\0': // should never happen
198 /* None of the special cases - copy the backslash */
210 /*****************************************************************************
211 * ExecuteCommand: The main state machine
212 *****************************************************************************
213 * Execute a command which ends with '\0' (string)
214 *****************************************************************************/
215 static int ExecuteSyntaxError( const char *psz_cmd, vlm_message_t **pp_status )
217 *pp_status = vlm_MessageNew( psz_cmd, "Wrong command syntax" );
221 static bool ExecuteIsMedia( vlm_t *p_vlm, const char *psz_name )
225 if( !psz_name || vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
229 static bool ExecuteIsSchedule( vlm_t *p_vlm, const char *psz_name )
231 if( !psz_name || !vlm_ScheduleSearch( p_vlm, psz_name ) )
236 static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
238 vlm_media_sys_t *p_media;
239 vlm_schedule_sys_t *p_schedule;
241 p_media = vlm_MediaSearch( p_vlm, psz_name );
242 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
244 if( p_schedule != NULL )
246 vlm_ScheduleDelete( p_vlm, p_schedule );
248 else if( p_media != NULL )
250 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_media->cfg.id );
252 else if( !strcmp(psz_name, "media") )
254 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
256 else if( !strcmp(psz_name, "schedule") )
258 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
260 else if( !strcmp(psz_name, "all") )
262 vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
263 vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
267 *pp_status = vlm_MessageNew( "del", "%s: media unknown", psz_name );
271 *pp_status = vlm_MessageSimpleNew( "del" );
275 static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
277 vlm_media_sys_t *p_media;
278 vlm_schedule_sys_t *p_schedule;
282 *pp_status = vlm_Show( p_vlm, NULL, NULL, NULL );
286 p_media = vlm_MediaSearch( p_vlm, psz_name );
287 p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
289 if( p_schedule != NULL )
290 *pp_status = vlm_Show( p_vlm, NULL, p_schedule, NULL );
291 else if( p_media != NULL )
292 *pp_status = vlm_Show( p_vlm, p_media, NULL, NULL );
294 *pp_status = vlm_Show( p_vlm, NULL, NULL, psz_name );
299 static int ExecuteHelp( vlm_message_t **pp_status )
301 vlm_message_t *message_child;
303 #define MessageAdd( a ) \
304 vlm_MessageAdd( *pp_status, vlm_MessageSimpleNew( a ) );
305 #define MessageAddChild( a ) \
306 vlm_MessageAdd( message_child, vlm_MessageSimpleNew( a ) );
308 *pp_status = vlm_MessageSimpleNew( "help" );
310 message_child = MessageAdd( "Commands Syntax:" );
311 MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
312 MessageAddChild( "setup (name) (properties)" );
313 MessageAddChild( "show [(name)|media|schedule]" );
314 MessageAddChild( "del (name)|all|media|schedule" );
315 MessageAddChild( "control (name) [instance_name] (command)" );
316 MessageAddChild( "save (config_file)" );
317 MessageAddChild( "export" );
318 MessageAddChild( "load (config_file)" );
320 message_child = MessageAdd( "Media Proprieties Syntax:" );
321 MessageAddChild( "input (input_name)" );
322 MessageAddChild( "inputdel (input_name)|all" );
323 MessageAddChild( "inputdeln input_number" );
324 MessageAddChild( "output (output_name)" );
325 MessageAddChild( "option (option_name)[=value]" );
326 MessageAddChild( "enabled|disabled" );
327 MessageAddChild( "loop|unloop (broadcast only)" );
328 MessageAddChild( "mux (mux_name)" );
330 message_child = MessageAdd( "Schedule Proprieties Syntax:" );
331 MessageAddChild( "enabled|disabled" );
332 MessageAddChild( "append (command_until_rest_of_the_line)" );
333 MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):"
335 MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
336 "(days)-(hours):(minutes):(seconds)" );
337 MessageAddChild( "repeat (number_of_repetitions)" );
339 message_child = MessageAdd( "Control Commands Syntax:" );
340 MessageAddChild( "play [input_number]" );
341 MessageAddChild( "pause" );
342 MessageAddChild( "stop" );
343 MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](milliseconds)ms" );
348 static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, char ** ppsz_arg, vlm_message_t **pp_status )
350 vlm_media_sys_t *p_media;
351 const char *psz_control = NULL;
352 const char *psz_instance = NULL;
353 const char *psz_argument = NULL;
357 if( !ExecuteIsMedia( p_vlm, psz_name ) )
359 *pp_status = vlm_MessageNew( "control", "%s: media unknown", psz_name );
365 #define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
367 if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
370 psz_instance = ppsz_arg[0];
372 if( i_index >= i_arg || ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
373 return ExecuteSyntaxError( "control", pp_status );
376 psz_control = ppsz_arg[i_index];
378 if( i_index+1 < i_arg )
379 psz_argument = ppsz_arg[i_index+1];
381 p_media = vlm_MediaSearch( p_vlm, psz_name );
384 if( !strcmp( psz_control, "play" ) )
386 int i_input_index = 0;
389 if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input )
393 else if( psz_argument )
396 vlm_media_t *p_cfg = &p_media->cfg;
397 for ( j=0; j < p_cfg->i_input; j++)
399 if( !strcmp( p_cfg->ppsz_input[j], psz_argument ) )
407 if( p_media->cfg.b_vod )
408 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
410 i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, psz_instance, i_input_index );
412 else if( !strcmp( psz_control, "seek" ) )
417 if( psz_argument[0] == '+' || psz_argument[0] == '-' )
422 if( strstr( psz_argument, "ms" ) || strstr( psz_argument, "s" ) )
427 if( strstr( psz_argument, "ms" ) )
428 i_new_time = 1000 * (int64_t)atoi( psz_argument );
430 i_new_time = 1000000 * (int64_t)atoi( psz_argument );
435 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, &i_time );
436 i_new_time += i_time;
440 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, i_new_time );
445 double d_new_position = us_atof( psz_argument ) / 100.0;
449 double d_position = 0.0;
451 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
452 d_new_position += d_position;
454 if( d_new_position < 0.0 )
455 d_new_position = 0.0;
456 else if( d_new_position > 1.0 )
457 d_new_position = 1.0;
458 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_new_position );
463 i_result = VLC_EGENERIC;
466 else if( !strcmp( psz_control, "rewind" ) )
470 const double d_scale = us_atof( psz_argument );
473 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
474 d_position -= (d_scale / 1000.0);
475 if( d_position < 0.0 )
477 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
481 i_result = VLC_EGENERIC;
484 else if( !strcmp( psz_control, "forward" ) )
488 const double d_scale = us_atof( psz_argument );
491 vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
492 d_position += (d_scale / 1000.0);
493 if( d_position > 1.0 )
495 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
500 i_result = VLC_EGENERIC;
503 else if( !strcmp( psz_control, "stop" ) )
505 i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
507 else if( !strcmp( psz_control, "pause" ) )
509 i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
513 i_result = VLC_EGENERIC;
518 *pp_status = vlm_MessageNew( "control", "unknown error" );
521 *pp_status = vlm_MessageSimpleNew( "control" );
525 static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
527 char *psz_export = Save( p_vlm );
529 *pp_status = vlm_MessageNew( "export", "%s", psz_export );
534 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
536 FILE *f = utf8_fopen( psz_file, "wt" );
537 char *psz_save = NULL;
542 psz_save = Save( p_vlm );
543 if( psz_save == NULL )
545 if( fputs( psz_save, f ) == EOF )
555 *pp_status = vlm_MessageSimpleNew( "save" );
562 *pp_status = vlm_MessageNew( "save", "Unable to save to file");
566 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
568 stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
574 *pp_status = vlm_MessageNew( "load", "Unable to load from file" );
579 if( stream_Seek( p_stream, 0 ) != 0 )
581 stream_Delete( p_stream );
583 *pp_status = vlm_MessageNew( "load", "Read file error" );
587 i_size = stream_Size( p_stream );
589 psz_buffer = malloc( i_size + 1 );
592 stream_Delete( p_stream );
594 *pp_status = vlm_MessageNew( "load", "Read file error" );
598 stream_Read( p_stream, psz_buffer, i_size );
599 psz_buffer[i_size] = '\0';
601 stream_Delete( p_stream );
603 if( Load( p_vlm, psz_buffer ) )
607 *pp_status = vlm_MessageNew( "load", "Error while loading file" );
613 *pp_status = vlm_MessageSimpleNew( "load" );
617 static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,
618 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
620 const char *psz_cmd = b_new ? "new" : "setup";
623 for( i = 0; i < i_property; i++ )
625 if( !strcmp( ppsz_property[i], "enabled" ) ||
626 !strcmp( ppsz_property[i], "disabled" ) )
628 if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )
631 else if( !strcmp( ppsz_property[i], "append" ) )
635 /* Beware: everything behind append is considered as
638 if( ++i >= i_property )
641 psz_line = strdup( ppsz_property[i] );
642 for( j = i+1; j < i_property; j++ )
644 psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
645 strcat( psz_line, " " );
646 strcat( psz_line, ppsz_property[j] );
649 if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
655 if( i + 1 >= i_property )
658 vlm_ScheduleDelete( p_vlm, p_schedule );
659 return ExecuteSyntaxError( psz_cmd, pp_status );
662 if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )
667 *pp_status = vlm_MessageSimpleNew( psz_cmd );
671 *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",
676 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
677 const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
679 const char *psz_cmd = b_new ? "new" : "setup";
680 vlm_media_t *p_cfg = NULL;
686 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
687 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )
688 ERROR( "unknown media" );
690 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
691 for( i = 0; i < i_property; i++ )
693 const char *psz_option = ppsz_property[i];
694 const char *psz_value = i+1 < i_property ? ppsz_property[i+1] : NULL;
696 if( !strcmp( psz_option, "enabled" ) )
698 p_cfg->b_enabled = true;
700 else if( !strcmp( psz_option, "disabled" ) )
702 p_cfg->b_enabled = false;
704 else if( !strcmp( psz_option, "input" ) )
707 TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
710 else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
712 while( p_cfg->i_input > 0 )
713 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
716 else if( !strcmp( psz_option, "inputdel" ) )
720 MISSING( "inputdel" );
722 for( j = 0; j < p_cfg->i_input; j++ )
724 if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
726 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
732 else if( !strcmp( psz_option, "inputdeln" ) )
736 MISSING( "inputdeln" );
738 i_index = atoi( psz_value );
739 if( i_index > 0 && i_index <= p_cfg->i_input )
740 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
743 else if( !strcmp( psz_option, "output" ) )
747 free( p_cfg->psz_output );
748 p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
751 else if( !strcmp( psz_option, "option" ) )
755 TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
758 else if( !strcmp( psz_option, "loop" ) )
761 ERROR( "invalid loop option for vod" );
762 p_cfg->broadcast.b_loop = true;
764 else if( !strcmp( psz_option, "unloop" ) )
767 ERROR( "invalid unloop option for vod" );
768 p_cfg->broadcast.b_loop = false;
770 else if( !strcmp( psz_option, "mux" ) )
774 ERROR( "invalid mux option for broadcast" );
776 free( p_cfg->vod.psz_mux );
777 p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
782 fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
783 ERROR( "Wrong command syntax" );
790 i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
791 vlm_media_Delete( p_cfg );
793 *pp_status = vlm_MessageSimpleNew( psz_cmd );
800 vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
801 vlm_media_Delete( p_cfg );
806 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 )
809 if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
811 *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
814 if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
816 *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
820 if( !strcmp( psz_type, "schedule" ) )
822 vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
825 *pp_status = vlm_MessageNew( "new", "could not create schedule" );
828 return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );
830 else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
835 vlm_media_Init( &cfg );
836 cfg.psz_name = strdup( psz_name );
837 cfg.b_vod = !strcmp( psz_type, "vod" );
839 if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
841 vlm_media_Clean( &cfg );
842 *pp_status = vlm_MessageNew( "new", "could not create media" );
845 vlm_media_Clean( &cfg );
846 return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );
850 *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
855 static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
857 if( ExecuteIsSchedule( p_vlm, psz_name ) )
859 vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
860 return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );
862 else if( ExecuteIsMedia( p_vlm, psz_name ) )
865 if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
867 return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );
871 *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
875 int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
876 vlm_message_t **pp_message )
878 size_t i_command = 0;
879 char buf[strlen (psz_command) + 1], *psz_buf = buf;
880 char *ppsz_command[3+sizeof (buf) / 2];
881 vlm_message_t *p_message = NULL;
883 /* First, parse the line and cut it */
884 while( *psz_command != '\0' )
886 const char *psz_temp;
888 if(isspace (*psz_command))
894 /* support for comments */
895 if( i_command == 0 && *psz_command == '#')
897 p_message = vlm_MessageSimpleNew( "" );
901 psz_temp = FindCommandEnd( psz_command );
903 if( psz_temp == NULL )
905 p_message = vlm_MessageNew( "Incomplete command", "%s", psz_command );
909 assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
911 ppsz_command[i_command] = psz_buf;
912 memcpy (psz_buf, psz_command, psz_temp - psz_command);
913 psz_buf[psz_temp - psz_command] = '\0';
915 Unescape (psz_buf, psz_buf);
918 psz_buf += psz_temp - psz_command + 1;
919 psz_command = psz_temp;
921 assert (buf + sizeof (buf) >= psz_buf);
925 * And then Interpret it
928 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; }
931 p_message = vlm_MessageSimpleNew( "" );
934 else IF_EXECUTE( "del", (i_command != 2), ExecuteDel(p_vlm, ppsz_command[1], &p_message) )
935 else IF_EXECUTE( "show", (i_command > 2), ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) )
936 else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp( &p_message ) )
937 else IF_EXECUTE( "control", (i_command < 3), ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) )
938 else IF_EXECUTE( "save", (i_command != 2), ExecuteSave(p_vlm, ppsz_command[1], &p_message) )
939 else IF_EXECUTE( "export", (i_command != 1), ExecuteExport(p_vlm, &p_message) )
940 else IF_EXECUTE( "load", (i_command != 2), ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )
941 else IF_EXECUTE( "new", (i_command < 3), ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )
942 else IF_EXECUTE( "setup", (i_command < 2), ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
945 p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
951 *pp_message = p_message;
955 return ExecuteSyntaxError( ppsz_command[0], pp_message );
958 *pp_message = p_message;
962 /*****************************************************************************
964 *****************************************************************************/
965 vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
969 for( i = 0; i < vlm->i_media; i++ )
971 if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
972 return vlm->media[i];
978 /*****************************************************************************
980 *****************************************************************************/
981 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
986 vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
990 p_sched->psz_name = strdup( psz_name );
991 p_sched->b_enabled = false;
992 p_sched->i_command = 0;
993 p_sched->command = NULL;
995 p_sched->i_period = 0;
996 p_sched->i_repeat = -1;
998 TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
1003 /* for now, simple delete. After, del with options (last arg) */
1004 void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
1006 if( sched == NULL ) return;
1008 TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
1010 if( vlm->i_schedule == 0 ) free( vlm->schedule );
1011 free( sched->psz_name );
1012 while( sched->i_command )
1014 char *psz_cmd = sched->command[0];
1015 TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
1021 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
1025 for( i = 0; i < vlm->i_schedule; i++ )
1027 if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
1029 return vlm->schedule[i];
1036 /* Ok, setup schedule command will be able to support only one (argument value) at a time */
1037 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
1038 const char *psz_value )
1040 if( !strcmp( psz_cmd, "enabled" ) )
1042 schedule->b_enabled = true;
1044 else if( !strcmp( psz_cmd, "disabled" ) )
1046 schedule->b_enabled = false;
1048 else if( !strcmp( psz_cmd, "date" ) )
1054 time.tm_sec = 0; /* seconds */
1055 time.tm_min = 0; /* minutes */
1056 time.tm_hour = 0; /* hours */
1057 time.tm_mday = 0; /* day of the month */
1058 time.tm_mon = 0; /* month */
1059 time.tm_year = 0; /* year */
1060 time.tm_wday = 0; /* day of the week */
1061 time.tm_yday = 0; /* day in the year */
1062 time.tm_isdst = -1; /* daylight saving time */
1064 /* date should be year/month/day-hour:minutes:seconds */
1065 p = strchr( psz_value, '-' );
1067 if( !strcmp( psz_value, "now" ) )
1069 schedule->i_date = 0;
1079 switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
1097 switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
1103 time.tm_mon = i - 1;
1107 time.tm_year = i - 1900;
1108 time.tm_mon = j - 1;
1115 date = mktime( &time );
1116 schedule->i_date = ((mtime_t) date) * 1000000;
1119 else if( !strcmp( psz_cmd, "period" ) )
1123 const char *psz_time = NULL, *psz_date = NULL;
1127 /* First, if date or period are modified, repeat should be equal to -1 */
1128 schedule->i_repeat = -1;
1130 time.tm_sec = 0; /* seconds */
1131 time.tm_min = 0; /* minutes */
1132 time.tm_hour = 0; /* hours */
1133 time.tm_mday = 0; /* day of the month */
1134 time.tm_mon = 0; /* month */
1135 time.tm_year = 0; /* year */
1136 time.tm_wday = 0; /* day of the week */
1137 time.tm_yday = 0; /* day in the year */
1138 time.tm_isdst = -1; /* daylight saving time */
1140 /* date should be year/month/day-hour:minutes:seconds */
1141 p = strchr( psz_value, '-' );
1144 psz_date = psz_value;
1149 psz_time = psz_value;
1152 switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
1171 switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
1190 /* ok, that's stupid... who is going to schedule streams every 42 years ? */
1191 date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;
1192 schedule->i_period = ((mtime_t) date) * 1000000;
1194 else if( !strcmp( psz_cmd, "repeat" ) )
1198 if( sscanf( psz_value, "%d", &i ) == 1 )
1200 schedule->i_repeat = i;
1207 else if( !strcmp( psz_cmd, "append" ) )
1209 char *command = strdup( psz_value );
1211 TAB_APPEND( schedule->i_command, schedule->command, command );
1220 /*****************************************************************************
1221 * Message handling functions
1222 *****************************************************************************/
1223 vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
1225 if( !psz_name ) return NULL;
1227 vlm_message_t *p_message = malloc( sizeof(*p_message) );
1231 p_message->psz_name = strdup( psz_name );
1232 if( !p_message->psz_name )
1237 p_message->psz_value = NULL;
1238 p_message->i_child = 0;
1239 p_message->child = NULL;
1244 vlm_message_t *vlm_MessageNew( const char *psz_name,
1245 const char *psz_format, ... )
1247 vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
1253 assert( psz_format );
1254 va_start( args, psz_format );
1255 if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
1256 p_message->psz_value = NULL;
1259 if( !p_message->psz_value )
1261 vlm_MessageDelete( p_message );
1267 void vlm_MessageDelete( vlm_message_t *p_message )
1269 free( p_message->psz_name );
1270 free( p_message->psz_value );
1271 while( p_message->i_child-- )
1272 vlm_MessageDelete( p_message->child[p_message->i_child] );
1273 free( p_message->child );
1278 vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
1279 vlm_message_t *p_child )
1281 if( p_message == NULL ) return NULL;
1285 TAB_APPEND( p_message->i_child, p_message->child, p_child );
1291 /*****************************************************************************
1292 * Misc utility functions
1293 *****************************************************************************/
1294 static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
1296 vlm_media_t *p_cfg = &p_media->cfg;
1297 vlm_message_t *p_msg;
1298 vlm_message_t *p_msg_sub;
1301 p_msg = vlm_MessageSimpleNew( p_cfg->psz_name );
1302 vlm_MessageAdd( p_msg,
1303 vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
1304 vlm_MessageAdd( p_msg,
1305 vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );
1308 vlm_MessageAdd( p_msg,
1309 vlm_MessageNew( "mux", "%s", p_cfg->vod.psz_mux ) );
1311 vlm_MessageAdd( p_msg,
1312 vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
1314 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "inputs" ) );
1315 for( i = 0; i < p_cfg->i_input; i++ )
1318 if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )
1320 vlm_MessageAdd( p_msg_sub,
1321 vlm_MessageNew( psz_tmp, "%s", p_cfg->ppsz_input[i] ) );
1326 vlm_MessageAdd( p_msg,
1327 vlm_MessageNew( "output", "%s", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
1329 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "options" ) );
1330 for( i = 0; i < p_cfg->i_option; i++ )
1331 vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( p_cfg->ppsz_option[i] ) );
1333 p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageSimpleNew( "instances" ) );
1334 for( i = 0; i < p_media->i_instance; i++ )
1336 vlm_media_instance_sys_t *p_instance = p_media->instance[i];
1338 vlm_message_t *p_msg_instance;
1342 if( p_instance->p_input )
1343 var_Get( p_instance->p_input, "state", &val );
1345 p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageSimpleNew( "instance" ) );
1347 vlm_MessageAdd( p_msg_instance,
1348 vlm_MessageNew( "name" , "%s", p_instance->psz_name ? p_instance->psz_name : "default" ) );
1349 vlm_MessageAdd( p_msg_instance,
1350 vlm_MessageNew( "state",
1351 val.i_int == PLAYING_S ? "playing" :
1352 val.i_int == PAUSE_S ? "paused" :
1355 /* FIXME should not do that this way */
1356 if( p_instance->p_input )
1358 #define APPEND_INPUT_INFO( a, format, type ) \
1359 if( asprintf( &psz_tmp, format, \
1360 var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
1362 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
1363 "%s", psz_tmp ) ); \
1366 APPEND_INPUT_INFO( "position", "%f", Float );
1367 APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
1368 APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
1369 APPEND_INPUT_INFO( "rate", "%d", Integer );
1370 APPEND_INPUT_INFO( "title", "%d", Integer );
1371 APPEND_INPUT_INFO( "chapter", "%d", Integer );
1372 APPEND_INPUT_INFO( "can-seek", "%d", Bool );
1374 #undef APPEND_INPUT_INFO
1375 if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
1377 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
1385 static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
1386 vlm_schedule_sys_t *schedule,
1387 const char *psz_filter )
1391 vlm_message_t *p_msg = vlm_MessageSimpleNew( "show" );
1393 vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) );
1397 else if( schedule != NULL )
1401 vlm_message_t *msg_schedule;
1402 vlm_message_t *msg_child;
1405 msg = vlm_MessageSimpleNew( "show" );
1407 vlm_MessageAdd( msg, vlm_MessageSimpleNew( schedule->psz_name ) );
1409 vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
1411 vlm_MessageAdd( msg_schedule,
1412 vlm_MessageNew( "enabled", schedule->b_enabled ?
1415 if( schedule->i_date != 0 )
1418 time_t i_time = (time_t)( schedule->i_date / 1000000 );
1421 localtime_r( &i_time, &date);
1422 if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
1423 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1424 date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
1426 vlm_MessageAdd( msg_schedule,
1427 vlm_MessageNew( "date", "%s", psz_date ) );
1432 vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
1434 if( schedule->i_period != 0 )
1436 time_t i_time = (time_t) ( schedule->i_period / 1000000 );
1439 date.tm_sec = (int)( i_time % 60 );
1440 i_time = i_time / 60;
1441 date.tm_min = (int)( i_time % 60 );
1442 i_time = i_time / 60;
1443 date.tm_hour = (int)( i_time % 24 );
1444 i_time = i_time / 24;
1445 date.tm_mday = (int)( i_time % 30 );
1446 i_time = i_time / 30;
1447 /* okay, okay, months are not always 30 days long */
1448 date.tm_mon = (int)( i_time % 12 );
1449 i_time = i_time / 12;
1450 date.tm_year = (int)i_time;
1452 sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
1453 date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
1455 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "%s", buffer) );
1458 vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
1460 sprintf( buffer, "%d", schedule->i_repeat );
1461 vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", "%s", buffer ) );
1464 vlm_MessageAdd( msg_schedule, vlm_MessageSimpleNew("commands" ) );
1466 for( i = 0; i < schedule->i_command; i++ )
1468 vlm_MessageAdd( msg_child,
1469 vlm_MessageSimpleNew( schedule->command[i] ) );
1476 else if( psz_filter && !strcmp( psz_filter, "media" ) )
1478 vlm_message_t *p_msg;
1479 vlm_message_t *p_msg_child;
1480 int i_vod = 0, i_broadcast = 0;
1484 for( i = 0; i < vlm->i_media; i++ )
1486 if( vlm->media[i]->cfg.b_vod )
1492 if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
1495 p_msg = vlm_MessageSimpleNew( "show" );
1496 p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", "%s",
1500 for( i = 0; i < vlm->i_media; i++ )
1501 vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
1506 else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
1510 vlm_message_t *msg_child;
1512 msg = vlm_MessageSimpleNew( "show" );
1513 msg_child = vlm_MessageAdd( msg, vlm_MessageSimpleNew( "schedule" ) );
1515 for( i = 0; i < vlm->i_schedule; i++ )
1517 vlm_schedule_sys_t *s = vlm->schedule[i];
1518 vlm_message_t *msg_schedule;
1519 mtime_t i_time, i_next_date;
1521 msg_schedule = vlm_MessageAdd( msg_child,
1522 vlm_MessageSimpleNew( s->psz_name ) );
1523 vlm_MessageAdd( msg_schedule,
1524 vlm_MessageNew( "enabled", s->b_enabled ?
1527 /* calculate next date */
1528 i_time = vlm_Date();
1529 i_next_date = s->i_date;
1531 if( s->i_period != 0 )
1534 while( s->i_date + j * s->i_period <= i_time &&
1540 i_next_date = s->i_date + j * s->i_period;
1543 if( i_next_date > i_time )
1545 time_t i_date = (time_t) (i_next_date / 1000000) ;
1547 #if !defined( UNDER_CE )
1550 ctime_r( &i_date, psz_date );
1552 char *psz_date = ctime( &i_date );
1555 vlm_MessageAdd( msg_schedule,
1556 vlm_MessageNew( "next launch", "%s", psz_date ) );
1564 else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
1566 vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
1567 vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
1569 vlm_MessageAdd( show1, show2->child[0] );
1571 /* We must destroy the parent node "show" of show2
1572 * and not the children */
1573 free( show2->psz_name );
1581 return vlm_MessageSimpleNew( "show" );
1585 /*****************************************************************************
1586 * Config handling functions
1587 *****************************************************************************/
1588 static int Load( vlm_t *vlm, char *file )
1593 while( *pf != '\0' )
1595 vlm_message_t *message = NULL;
1598 while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
1603 if( pf[i_end] == '\r' || pf[i_end] == '\n' )
1607 if( pf[i_end] == '\n' ) i_end++;
1610 if( *pf && ExecuteCommand( vlm, pf, &message ) )
1614 if( message->psz_value )
1615 msg_Err( vlm, "Load error on line %d: %s: %s",
1616 i_line, message->psz_name, message->psz_value );
1617 vlm_MessageDelete( message );
1621 if( message ) vlm_MessageDelete( message );
1630 static char *Save( vlm_t *vlm )
1633 char psz_header[] = "\n"
1634 "# VLC media player VLM command batch\n"
1635 "# http://www.videolan.org/vlc/\n\n" ;
1638 int i_length = strlen( psz_header );
1640 for( i = 0; i < vlm->i_media; i++ )
1642 vlm_media_sys_t *media = vlm->media[i];
1643 vlm_media_t *p_cfg = &media->cfg;
1646 i_length += strlen( "new * vod " ) + strlen(p_cfg->psz_name);
1648 i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
1650 if( p_cfg->b_enabled == true )
1651 i_length += strlen( "enabled" );
1653 i_length += strlen( "disabled" );
1655 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == true )
1656 i_length += strlen( " loop\n" );
1658 i_length += strlen( "\n" );
1660 for( j = 0; j < p_cfg->i_input; j++ )
1661 i_length += strlen( "setup * input \"\"\n" ) + strlen( p_cfg->psz_name ) + strlen( p_cfg->ppsz_input[j] );
1663 if( p_cfg->psz_output != NULL )
1664 i_length += strlen( "setup * output \n" ) + strlen(p_cfg->psz_name) + strlen(p_cfg->psz_output);
1666 for( j = 0; j < p_cfg->i_option; j++ )
1667 i_length += strlen("setup * option \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->ppsz_option[j]);
1669 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1670 i_length += strlen("setup * mux \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->vod.psz_mux);
1673 for( i = 0; i < vlm->i_schedule; i++ )
1675 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1677 i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
1679 if( schedule->b_enabled == true )
1681 i_length += strlen( "date //-:: enabled\n" ) + 14;
1685 i_length += strlen( "date //-:: disabled\n" ) + 14;
1689 if( schedule->i_period != 0 )
1691 i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
1692 strlen( "period //-::\n" ) + 14;
1695 if( schedule->i_repeat >= 0 )
1699 sprintf( buffer, "%d", schedule->i_repeat );
1700 i_length += strlen( "setup repeat \n" ) +
1701 strlen( schedule->psz_name ) + strlen( buffer );
1708 for( j = 0; j < schedule->i_command; j++ )
1710 i_length += strlen( "setup append \n" ) +
1711 strlen( schedule->psz_name ) + strlen( schedule->command[j] );
1716 /* Don't forget the '\0' */
1718 /* now we have the length of save */
1720 p = save = malloc( i_length );
1721 if( !save ) return NULL;
1724 p += sprintf( p, "%s", psz_header );
1726 /* finally we can write in it */
1727 for( i = 0; i < vlm->i_media; i++ )
1729 vlm_media_sys_t *media = vlm->media[i];
1730 vlm_media_t *p_cfg = &media->cfg;
1733 p += sprintf( p, "new %s vod ", p_cfg->psz_name );
1735 p += sprintf( p, "new %s broadcast ", p_cfg->psz_name );
1737 if( p_cfg->b_enabled )
1738 p += sprintf( p, "enabled" );
1740 p += sprintf( p, "disabled" );
1742 if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
1743 p += sprintf( p, " loop\n" );
1745 p += sprintf( p, "\n" );
1747 for( j = 0; j < p_cfg->i_input; j++ )
1748 p += sprintf( p, "setup %s input \"%s\"\n", p_cfg->psz_name, p_cfg->ppsz_input[j] );
1750 if( p_cfg->psz_output )
1751 p += sprintf( p, "setup %s output %s\n", p_cfg->psz_name, p_cfg->psz_output );
1753 for( j = 0; j < p_cfg->i_option; j++ )
1754 p += sprintf( p, "setup %s option %s\n", p_cfg->psz_name, p_cfg->ppsz_option[j] );
1756 if( p_cfg->b_vod && p_cfg->vod.psz_mux )
1757 p += sprintf( p, "setup %s mux %s\n", p_cfg->psz_name, p_cfg->vod.psz_mux );
1760 /* and now, the schedule scripts */
1761 for( i = 0; i < vlm->i_schedule; i++ )
1763 vlm_schedule_sys_t *schedule = vlm->schedule[i];
1765 time_t i_time = (time_t) ( schedule->i_date / 1000000 );
1767 localtime_r( &i_time, &date);
1768 p += sprintf( p, "new %s schedule ", schedule->psz_name);
1770 if( schedule->b_enabled == true )
1772 p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
1773 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1774 date.tm_hour, date.tm_min, date.tm_sec );
1778 p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
1779 date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
1780 date.tm_hour, date.tm_min, date.tm_sec);
1783 if( schedule->i_period != 0 )
1785 p += sprintf( p, "setup %s ", schedule->psz_name );
1787 i_time = (time_t) ( schedule->i_period / 1000000 );
1789 date.tm_sec = (int)( i_time % 60 );
1790 i_time = i_time / 60;
1791 date.tm_min = (int)( i_time % 60 );
1792 i_time = i_time / 60;
1793 date.tm_hour = (int)( i_time % 24 );
1794 i_time = i_time / 24;
1795 date.tm_mday = (int)( i_time % 30 );
1796 i_time = i_time / 30;
1797 /* okay, okay, months are not always 30 days long */
1798 date.tm_mon = (int)( i_time % 12 );
1799 i_time = i_time / 12;
1800 date.tm_year = (int)i_time;
1802 p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
1803 date.tm_year, date.tm_mon, date.tm_mday,
1804 date.tm_hour, date.tm_min, date.tm_sec);
1807 if( schedule->i_repeat >= 0 )
1809 p += sprintf( p, "setup %s repeat %d\n",
1810 schedule->psz_name, schedule->i_repeat );
1814 p += sprintf( p, "\n" );
1817 for( j = 0; j < schedule->i_command; j++ )
1819 p += sprintf( p, "setup %s append %s\n",
1820 schedule->psz_name, schedule->command[j] );
1828 #endif /* ENABLE_VLM */