1 /*****************************************************************************
2 * vlmshell.c: VLM interface plugin
3 *****************************************************************************
4 * Copyright (C) 2000-2005 VLC authors and VideoLAN
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 it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * 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() */
48 #include <vlc_input.h>
49 #include "input_internal.h"
50 #include <vlc_stream.h>
51 #include "vlm_internal.h"
52 #include <vlc_charset.h>
55 #include "../stream_output/stream_output.h"
56 #include "../libvlc.h"
58 /*****************************************************************************
60 *****************************************************************************/
63 static vlm_message_t
*vlm_Show( vlm_t
*, vlm_media_sys_t
*, vlm_schedule_sys_t
*, const char * );
65 static vlm_schedule_sys_t
*vlm_ScheduleSearch( vlm_t
*, const char * );
67 static char *Save( vlm_t
* );
68 static int Load( vlm_t
*, char * );
70 static vlm_schedule_sys_t
*vlm_ScheduleNew( vlm_t
*vlm
, const char *psz_name
);
71 static int vlm_ScheduleSetup( vlm_schedule_sys_t
*schedule
, const char *psz_cmd
,
72 const char *psz_value
);
75 static vlm_media_sys_t
*vlm_MediaSearch( vlm_t
*, const char *);
77 static const char quotes
[] = "\"'";
79 * FindCommandEnd: look for the end of a possibly quoted string
80 * @return NULL on mal-formatted string,
81 * pointer past the last character otherwise.
83 static const char *FindCommandEnd( const char *psz_sent
)
85 unsigned char c
, quote
= 0;
87 while( (c
= *psz_sent
) != '\0' )
91 if( strchr(quotes
,c
) ) // opening quote
93 else if( isspace(c
) ) // non-escaped space
97 psz_sent
++; // skip escaped character
98 if( *psz_sent
== '\0' )
104 if( c
== quote
) // non-escaped matching quote
106 else if( (quote
== '"') && (c
== '\\') )
108 psz_sent
++; // skip escaped character
109 if (*psz_sent
== '\0')
110 return NULL
; // error, closing quote missing
116 // error (NULL) if we could not find a matching quote
117 return quote
? NULL
: psz_sent
;
122 * Unescape a nul-terminated string.
123 * Note that in and out can be identical.
125 * @param out output buffer (at least <strlen (in) + 1> characters long)
126 * @param in nul-terminated string to be unescaped
128 * @return 0 on success, -1 on error.
130 static int Unescape( char *out
, const char *in
)
132 unsigned char c
, quote
= 0;
135 while( (c
= *in
++) != '\0' )
137 // Don't escape the end of the string if we find a '#'
138 // that's the beginning of a vlc command
139 // TODO: find a better solution
140 if( ( c
== '#' && !quote
) || param
)
149 if (strchr(quotes
,c
)) // opening quote
173 /* None of the special cases - copy the backslash */
179 if( c
== quote
) // non-escaped matching quote
184 if( (quote
== '"') && (c
== '\\') )
193 case '\0': // should never happen
197 /* None of the special cases - copy the backslash */
209 /*****************************************************************************
210 * ExecuteCommand: The main state machine
211 *****************************************************************************
212 * Execute a command which ends with '\0' (string)
213 *****************************************************************************/
214 static int ExecuteSyntaxError( const char *psz_cmd
, vlm_message_t
**pp_status
)
216 *pp_status
= vlm_MessageNew( psz_cmd
, "Wrong command syntax" );
220 static bool ExecuteIsMedia( vlm_t
*p_vlm
, const char *psz_name
)
224 if( !psz_name
|| vlm_ControlInternal( p_vlm
, VLM_GET_MEDIA_ID
, psz_name
, &id
) )
228 static bool ExecuteIsSchedule( vlm_t
*p_vlm
, const char *psz_name
)
230 if( !psz_name
|| !vlm_ScheduleSearch( p_vlm
, psz_name
) )
235 static int ExecuteDel( vlm_t
*p_vlm
, const char *psz_name
, vlm_message_t
**pp_status
)
237 vlm_media_sys_t
*p_media
;
238 vlm_schedule_sys_t
*p_schedule
;
240 p_media
= vlm_MediaSearch( p_vlm
, psz_name
);
241 p_schedule
= vlm_ScheduleSearch( p_vlm
, psz_name
);
243 if( p_schedule
!= NULL
)
245 vlm_ScheduleDelete( p_vlm
, p_schedule
);
247 else if( p_media
!= NULL
)
249 vlm_ControlInternal( p_vlm
, VLM_DEL_MEDIA
, p_media
->cfg
.id
);
251 else if( !strcmp(psz_name
, "media") )
253 vlm_ControlInternal( p_vlm
, VLM_CLEAR_MEDIAS
);
255 else if( !strcmp(psz_name
, "schedule") )
257 vlm_ControlInternal( p_vlm
, VLM_CLEAR_SCHEDULES
);
259 else if( !strcmp(psz_name
, "all") )
261 vlm_ControlInternal( p_vlm
, VLM_CLEAR_MEDIAS
);
262 vlm_ControlInternal( p_vlm
, VLM_CLEAR_SCHEDULES
);
266 *pp_status
= vlm_MessageNew( "del", "%s: media unknown", psz_name
);
270 *pp_status
= vlm_MessageSimpleNew( "del" );
274 static int ExecuteShow( vlm_t
*p_vlm
, const char *psz_name
, vlm_message_t
**pp_status
)
276 vlm_media_sys_t
*p_media
;
277 vlm_schedule_sys_t
*p_schedule
;
281 *pp_status
= vlm_Show( p_vlm
, NULL
, NULL
, NULL
);
285 p_media
= vlm_MediaSearch( p_vlm
, psz_name
);
286 p_schedule
= vlm_ScheduleSearch( p_vlm
, psz_name
);
288 if( p_schedule
!= NULL
)
289 *pp_status
= vlm_Show( p_vlm
, NULL
, p_schedule
, NULL
);
290 else if( p_media
!= NULL
)
291 *pp_status
= vlm_Show( p_vlm
, p_media
, NULL
, NULL
);
293 *pp_status
= vlm_Show( p_vlm
, NULL
, NULL
, psz_name
);
298 static int ExecuteHelp( vlm_message_t
**pp_status
)
300 vlm_message_t
*message_child
;
302 #define MessageAdd( a ) \
303 vlm_MessageAdd( *pp_status, vlm_MessageSimpleNew( a ) );
304 #define MessageAddChild( a ) \
305 vlm_MessageAdd( message_child, vlm_MessageSimpleNew( a ) );
307 *pp_status
= vlm_MessageSimpleNew( "help" );
309 message_child
= MessageAdd( "Commands Syntax:" );
310 MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
311 MessageAddChild( "setup (name) (properties)" );
312 MessageAddChild( "show [(name)|media|schedule]" );
313 MessageAddChild( "del (name)|all|media|schedule" );
314 MessageAddChild( "control (name) [instance_name] (command)" );
315 MessageAddChild( "save (config_file)" );
316 MessageAddChild( "export" );
317 MessageAddChild( "load (config_file)" );
319 message_child
= MessageAdd( "Media Proprieties Syntax:" );
320 MessageAddChild( "input (input_name)" );
321 MessageAddChild( "inputdel (input_name)|all" );
322 MessageAddChild( "inputdeln input_number" );
323 MessageAddChild( "output (output_name)" );
324 MessageAddChild( "option (option_name)[=value]" );
325 MessageAddChild( "enabled|disabled" );
326 MessageAddChild( "loop|unloop (broadcast only)" );
327 MessageAddChild( "mux (mux_name)" );
329 message_child
= MessageAdd( "Schedule Proprieties Syntax:" );
330 MessageAddChild( "enabled|disabled" );
331 MessageAddChild( "append (command_until_rest_of_the_line)" );
332 MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):"
334 MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
335 "(days)-(hours):(minutes):(seconds)" );
336 MessageAddChild( "repeat (number_of_repetitions)" );
338 message_child
= MessageAdd( "Control Commands Syntax:" );
339 MessageAddChild( "play [input_number]" );
340 MessageAddChild( "pause" );
341 MessageAddChild( "stop" );
342 MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](milliseconds)ms" );
347 static int ExecuteControl( vlm_t
*p_vlm
, const char *psz_name
, const int i_arg
, char ** ppsz_arg
, vlm_message_t
**pp_status
)
349 vlm_media_sys_t
*p_media
;
350 const char *psz_control
= NULL
;
351 const char *psz_instance
= NULL
;
352 const char *psz_argument
= NULL
;
356 if( !ExecuteIsMedia( p_vlm
, psz_name
) )
358 *pp_status
= vlm_MessageNew( "control", "%s: media unknown", psz_name
);
364 #define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
366 if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
369 psz_instance
= ppsz_arg
[0];
371 if( i_index
>= i_arg
|| ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
372 return ExecuteSyntaxError( "control", pp_status
);
375 psz_control
= ppsz_arg
[i_index
];
377 if( i_index
+1 < i_arg
)
378 psz_argument
= ppsz_arg
[i_index
+1];
380 p_media
= vlm_MediaSearch( p_vlm
, psz_name
);
383 if( !strcmp( psz_control
, "play" ) )
385 int i_input_index
= 0;
388 if( ( psz_argument
&& sscanf(psz_argument
, "%d", &i
) == 1 ) && i
> 0 && i
-1 < p_media
->cfg
.i_input
)
392 else if( psz_argument
)
395 vlm_media_t
*p_cfg
= &p_media
->cfg
;
396 for ( j
=0; j
< p_cfg
->i_input
; j
++)
398 if( !strcmp( p_cfg
->ppsz_input
[j
], psz_argument
) )
406 if( p_media
->cfg
.b_vod
)
407 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
409 i_result
= vlm_ControlInternal( p_vlm
, VLM_START_MEDIA_BROADCAST_INSTANCE
, p_media
->cfg
.id
, psz_instance
, i_input_index
);
411 else if( !strcmp( psz_control
, "seek" ) )
416 if( psz_argument
[0] == '+' || psz_argument
[0] == '-' )
421 if( strstr( psz_argument
, "ms" ) || strstr( psz_argument
, "s" ) )
426 if( strstr( psz_argument
, "ms" ) )
427 i_new_time
= 1000 * (int64_t)atoi( psz_argument
);
429 i_new_time
= 1000000 * (int64_t)atoi( psz_argument
);
434 vlm_ControlInternal( p_vlm
, VLM_GET_MEDIA_INSTANCE_TIME
, p_media
->cfg
.id
, psz_instance
, &i_time
);
435 i_new_time
+= i_time
;
439 i_result
= vlm_ControlInternal( p_vlm
, VLM_SET_MEDIA_INSTANCE_TIME
, p_media
->cfg
.id
, psz_instance
, i_new_time
);
444 double d_new_position
= us_atof( psz_argument
) / 100.0;
448 double d_position
= 0.0;
450 vlm_ControlInternal( p_vlm
, VLM_GET_MEDIA_INSTANCE_POSITION
, p_media
->cfg
.id
, psz_instance
, &d_position
);
451 d_new_position
+= d_position
;
453 if( d_new_position
< 0.0 )
454 d_new_position
= 0.0;
455 else if( d_new_position
> 1.0 )
456 d_new_position
= 1.0;
457 i_result
= vlm_ControlInternal( p_vlm
, VLM_SET_MEDIA_INSTANCE_POSITION
, p_media
->cfg
.id
, psz_instance
, d_new_position
);
462 i_result
= VLC_EGENERIC
;
465 else if( !strcmp( psz_control
, "stop" ) )
467 i_result
= vlm_ControlInternal( p_vlm
, VLM_STOP_MEDIA_INSTANCE
, p_media
->cfg
.id
, psz_instance
);
469 else if( !strcmp( psz_control
, "pause" ) )
471 i_result
= vlm_ControlInternal( p_vlm
, VLM_PAUSE_MEDIA_INSTANCE
, p_media
->cfg
.id
, psz_instance
);
475 i_result
= VLC_EGENERIC
;
480 *pp_status
= vlm_MessageNew( "control", "unknown error" );
483 *pp_status
= vlm_MessageSimpleNew( "control" );
487 static int ExecuteExport( vlm_t
*p_vlm
, vlm_message_t
**pp_status
)
489 char *psz_export
= Save( p_vlm
);
491 *pp_status
= vlm_MessageNew( "export", "%s", psz_export
);
496 static int ExecuteSave( vlm_t
*p_vlm
, const char *psz_file
, vlm_message_t
**pp_status
)
498 FILE *f
= vlc_fopen( psz_file
, "wt" );
499 char *psz_save
= NULL
;
504 psz_save
= Save( p_vlm
);
505 if( psz_save
== NULL
)
507 if( fputs( psz_save
, f
) == EOF
)
517 *pp_status
= vlm_MessageSimpleNew( "save" );
524 *pp_status
= vlm_MessageNew( "save", "Unable to save to file");
528 static int ExecuteLoad( vlm_t
*p_vlm
, const char *psz_path
, vlm_message_t
**pp_status
)
530 int fd
= vlc_open( psz_path
, O_RDONLY
|O_NONBLOCK
);
533 *pp_status
= vlm_MessageNew( "load", "Unable to load from file" );
538 char *psz_buffer
= NULL
;
540 if( fstat( fd
, &st
) || !S_ISREG( st
.st_mode
)
541 || st
.st_size
>= SSIZE_MAX
542 || ((psz_buffer
= malloc( st
.st_size
+ 1 )) == NULL
)
543 || read( fd
, psz_buffer
, st
.st_size
) < (ssize_t
)st
.st_size
)
548 *pp_status
= vlm_MessageNew( "load", "Read file error" );
554 psz_buffer
[st
.st_size
] = '\0';
556 if( Load( p_vlm
, psz_buffer
) )
560 *pp_status
= vlm_MessageNew( "load", "Error while loading file" );
566 *pp_status
= vlm_MessageSimpleNew( "load" );
570 static int ExecuteScheduleProperty( vlm_t
*p_vlm
, vlm_schedule_sys_t
*p_schedule
, bool b_new
,
571 const int i_property
, char *ppsz_property
[], vlm_message_t
**pp_status
)
573 const char *psz_cmd
= b_new
? "new" : "setup";
576 for( i
= 0; i
< i_property
; i
++ )
578 if( !strcmp( ppsz_property
[i
], "enabled" ) ||
579 !strcmp( ppsz_property
[i
], "disabled" ) )
581 if ( vlm_ScheduleSetup( p_schedule
, ppsz_property
[i
], NULL
) )
584 else if( !strcmp( ppsz_property
[i
], "append" ) )
586 char *psz_line
, *psz_realloc
;
587 int j
, i_ret
= VLC_SUCCESS
;
588 /* Beware: everything behind append is considered as
591 if( ++i
>= i_property
)
594 psz_line
= strdup( ppsz_property
[i
] );
595 if( unlikely(psz_line
== NULL
) )
598 for( j
= i
+1; j
< i_property
; j
++ )
600 psz_realloc
= realloc( psz_line
,
601 strlen(psz_line
) + strlen(ppsz_property
[j
]) + 1 + 1 );
602 if( likely(psz_realloc
) )
604 psz_line
= psz_realloc
;
605 strcat( psz_line
, " " );
606 strcat( psz_line
, ppsz_property
[j
] );
615 if( i_ret
== VLC_SUCCESS
)
616 i_ret
= vlm_ScheduleSetup( p_schedule
, "append", psz_line
);
625 if( i
+ 1 >= i_property
)
628 vlm_ScheduleDelete( p_vlm
, p_schedule
);
629 return ExecuteSyntaxError( psz_cmd
, pp_status
);
632 if( vlm_ScheduleSetup( p_schedule
, ppsz_property
[i
], ppsz_property
[i
+1] ) )
637 *pp_status
= vlm_MessageSimpleNew( psz_cmd
);
639 vlc_mutex_lock( &p_vlm
->lock_manage
);
640 p_vlm
->input_state_changed
= true;
641 vlc_cond_signal( &p_vlm
->wait_manage
);
642 vlc_mutex_unlock( &p_vlm
->lock_manage
);
647 *pp_status
= vlm_MessageNew( psz_cmd
, "Error while setting the property '%s' to the schedule",
652 static int ExecuteMediaProperty( vlm_t
*p_vlm
, int64_t id
, bool b_new
,
653 const int i_property
, char *ppsz_property
[], vlm_message_t
**pp_status
)
655 const char *psz_cmd
= b_new
? "new" : "setup";
656 vlm_media_t
*p_cfg
= NULL
;
662 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
663 if( vlm_ControlInternal( p_vlm
, VLM_GET_MEDIA
, id
, &p_cfg
) )
664 ERROR( "unknown media" );
666 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
667 for( i
= 0; i
< i_property
; i
++ )
669 const char *psz_option
= ppsz_property
[i
];
670 const char *psz_value
= i
+1 < i_property
? ppsz_property
[i
+1] : NULL
;
672 if( !strcmp( psz_option
, "enabled" ) )
674 p_cfg
->b_enabled
= true;
676 else if( !strcmp( psz_option
, "disabled" ) )
678 p_cfg
->b_enabled
= false;
680 else if( !strcmp( psz_option
, "input" ) )
683 TAB_APPEND( p_cfg
->i_input
, p_cfg
->ppsz_input
, strdup(psz_value
) );
686 else if( !strcmp( psz_option
, "inputdel" ) && psz_value
&& !strcmp( psz_value
, "all" ) )
688 while( p_cfg
->i_input
> 0 )
689 TAB_REMOVE( p_cfg
->i_input
, p_cfg
->ppsz_input
, p_cfg
->ppsz_input
[0] );
692 else if( !strcmp( psz_option
, "inputdel" ) )
696 MISSING( "inputdel" );
698 for( j
= 0; j
< p_cfg
->i_input
; j
++ )
700 if( !strcmp( p_cfg
->ppsz_input
[j
], psz_value
) )
702 TAB_REMOVE( p_cfg
->i_input
, p_cfg
->ppsz_input
, p_cfg
->ppsz_input
[j
] );
708 else if( !strcmp( psz_option
, "inputdeln" ) )
710 MISSING( "inputdeln" );
712 int idx
= atoi( psz_value
);
713 if( idx
> 0 && idx
<= p_cfg
->i_input
)
714 TAB_REMOVE( p_cfg
->i_input
, p_cfg
->ppsz_input
, p_cfg
->ppsz_input
[idx
-1] );
717 else if( !strcmp( psz_option
, "output" ) )
721 free( p_cfg
->psz_output
);
722 p_cfg
->psz_output
= *psz_value
? strdup( psz_value
) : NULL
;
725 else if( !strcmp( psz_option
, "option" ) )
729 TAB_APPEND( p_cfg
->i_option
, p_cfg
->ppsz_option
, strdup( psz_value
) );
732 else if( !strcmp( psz_option
, "loop" ) )
735 ERROR( "invalid loop option for vod" );
736 p_cfg
->broadcast
.b_loop
= true;
738 else if( !strcmp( psz_option
, "unloop" ) )
741 ERROR( "invalid unloop option for vod" );
742 p_cfg
->broadcast
.b_loop
= false;
744 else if( !strcmp( psz_option
, "mux" ) )
748 ERROR( "invalid mux option for broadcast" );
750 free( p_cfg
->vod
.psz_mux
);
751 p_cfg
->vod
.psz_mux
= *psz_value
? strdup( psz_value
) : NULL
;
756 fprintf( stderr
, "PROP: name=%s unknown\n", psz_option
);
757 ERROR( "Wrong command syntax" );
764 i_result
= vlm_ControlInternal( p_vlm
, VLM_CHANGE_MEDIA
, p_cfg
);
765 vlm_media_Delete( p_cfg
);
767 *pp_status
= vlm_MessageSimpleNew( psz_cmd
);
774 vlm_ControlInternal( p_vlm
, VLM_DEL_MEDIA
, p_cfg
->id
);
775 vlm_media_Delete( p_cfg
);
780 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
)
783 if( !strcmp( psz_name
, "all" ) || !strcmp( psz_name
, "media" ) || !strcmp( psz_name
, "schedule" ) )
785 *pp_status
= vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
788 if( ExecuteIsMedia( p_vlm
, psz_name
) || ExecuteIsSchedule( p_vlm
, psz_name
) )
790 *pp_status
= vlm_MessageNew( "new", "%s: Name already in use", psz_name
);
794 if( !strcmp( psz_type
, "schedule" ) )
796 vlm_schedule_sys_t
*p_schedule
= vlm_ScheduleNew( p_vlm
, psz_name
);
799 *pp_status
= vlm_MessageNew( "new", "could not create schedule" );
802 return ExecuteScheduleProperty( p_vlm
, p_schedule
, true, i_property
, ppsz_property
, pp_status
);
804 else if( !strcmp( psz_type
, "vod" ) || !strcmp( psz_type
, "broadcast" ) )
809 vlm_media_Init( &cfg
);
810 cfg
.psz_name
= strdup( psz_name
);
811 cfg
.b_vod
= !strcmp( psz_type
, "vod" );
813 if( vlm_ControlInternal( p_vlm
, VLM_ADD_MEDIA
, &cfg
, &id
) )
815 vlm_media_Clean( &cfg
);
816 *pp_status
= vlm_MessageNew( "new", "could not create media" );
819 vlm_media_Clean( &cfg
);
820 return ExecuteMediaProperty( p_vlm
, id
, true, i_property
, ppsz_property
, pp_status
);
824 *pp_status
= vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type
);
829 static int ExecuteSetup( vlm_t
*p_vlm
, const char *psz_name
, const int i_property
, char *ppsz_property
[], vlm_message_t
**pp_status
)
831 if( ExecuteIsSchedule( p_vlm
, psz_name
) )
833 vlm_schedule_sys_t
*p_schedule
= vlm_ScheduleSearch( p_vlm
, psz_name
);
834 return ExecuteScheduleProperty( p_vlm
, p_schedule
, false, i_property
, ppsz_property
, pp_status
);
836 else if( ExecuteIsMedia( p_vlm
, psz_name
) )
839 if( vlm_ControlInternal( p_vlm
, VLM_GET_MEDIA_ID
, psz_name
, &id
) )
841 return ExecuteMediaProperty( p_vlm
, id
, false, i_property
, ppsz_property
, pp_status
);
845 *pp_status
= vlm_MessageNew( "setup", "%s unknown", psz_name
);
849 int ExecuteCommand( vlm_t
*p_vlm
, const char *psz_command
,
850 vlm_message_t
**pp_message
)
852 size_t i_command
= 0;
853 size_t i_command_len
= strlen( psz_command
);
854 char *buf
= malloc( i_command_len
+ 1 ), *psz_buf
= buf
;
855 size_t i_ppsz_command_len
= (3 + (i_command_len
+ 1) / 2);
856 char **ppsz_command
= malloc( i_ppsz_command_len
* sizeof(char *) );
857 vlm_message_t
*p_message
= NULL
;
860 if( !psz_buf
|| !ppsz_command
)
862 p_message
= vlm_MessageNew( "Memory error",
863 "allocation failed for command of length %zu",
868 /* First, parse the line and cut it */
869 while( *psz_command
!= '\0' )
871 const char *psz_temp
;
873 if(isspace ((unsigned char)*psz_command
))
879 /* support for comments */
880 if( i_command
== 0 && *psz_command
== '#')
882 p_message
= vlm_MessageSimpleNew( "" );
886 psz_temp
= FindCommandEnd( psz_command
);
888 if( psz_temp
== NULL
)
890 p_message
= vlm_MessageNew( "Incomplete command", "%s", psz_command
);
894 assert (i_command
< i_ppsz_command_len
);
896 ppsz_command
[i_command
] = psz_buf
;
897 memcpy (psz_buf
, psz_command
, psz_temp
- psz_command
);
898 psz_buf
[psz_temp
- psz_command
] = '\0';
900 Unescape (psz_buf
, psz_buf
);
903 psz_buf
+= psz_temp
- psz_command
+ 1;
904 psz_command
= psz_temp
;
906 assert (buf
+ i_command_len
+ 1 >= psz_buf
);
910 * And then Interpret it
913 #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; }
916 p_message
= vlm_MessageSimpleNew( "" );
919 else IF_EXECUTE( "del", (i_command
!= 2), ExecuteDel(p_vlm
, ppsz_command
[1], &p_message
) )
920 else IF_EXECUTE( "show", (i_command
> 2), ExecuteShow(p_vlm
, i_command
> 1 ? ppsz_command
[1] : NULL
, &p_message
) )
921 else IF_EXECUTE( "help", (i_command
!= 1), ExecuteHelp( &p_message
) )
922 else IF_EXECUTE( "control", (i_command
< 3), ExecuteControl(p_vlm
, ppsz_command
[1], i_command
- 2, &ppsz_command
[2], &p_message
) )
923 else IF_EXECUTE( "save", (i_command
!= 2), ExecuteSave(p_vlm
, ppsz_command
[1], &p_message
) )
924 else IF_EXECUTE( "export", (i_command
!= 1), ExecuteExport(p_vlm
, &p_message
) )
925 else IF_EXECUTE( "load", (i_command
!= 2), ExecuteLoad(p_vlm
, ppsz_command
[1], &p_message
) )
926 else IF_EXECUTE( "new", (i_command
< 3), ExecuteNew(p_vlm
, ppsz_command
[1], ppsz_command
[2], i_command
-3, &ppsz_command
[3], &p_message
) )
927 else IF_EXECUTE( "setup", (i_command
< 2), ExecuteSetup(p_vlm
, ppsz_command
[1], i_command
-2, &ppsz_command
[2], &p_message
) )
930 p_message
= vlm_MessageNew( ppsz_command
[0], "Unknown VLM command" );
936 *pp_message
= p_message
;
938 free( ppsz_command
);
942 i_ret
= ExecuteSyntaxError( ppsz_command
[0], pp_message
);
944 free( ppsz_command
);
948 *pp_message
= p_message
;
950 free( ppsz_command
);
954 /*****************************************************************************
956 *****************************************************************************/
957 vlm_media_sys_t
*vlm_MediaSearch( vlm_t
*vlm
, const char *psz_name
)
961 for( i
= 0; i
< vlm
->i_media
; i
++ )
963 if( strcmp( psz_name
, vlm
->media
[i
]->cfg
.psz_name
) == 0 )
964 return vlm
->media
[i
];
970 /*****************************************************************************
972 *****************************************************************************/
973 static vlm_schedule_sys_t
*vlm_ScheduleNew( vlm_t
*vlm
, const char *psz_name
)
978 vlm_schedule_sys_t
*p_sched
= malloc( sizeof( vlm_schedule_sys_t
) );
982 p_sched
->psz_name
= strdup( psz_name
);
983 p_sched
->b_enabled
= false;
984 p_sched
->i_command
= 0;
985 p_sched
->command
= NULL
;
988 p_sched
->i_repeat
= -1;
990 TAB_APPEND( vlm
->i_schedule
, vlm
->schedule
, p_sched
);
995 /* for now, simple delete. After, del with options (last arg) */
996 void vlm_ScheduleDelete( vlm_t
*vlm
, vlm_schedule_sys_t
*sched
)
999 if( sched
== NULL
) return;
1001 TAB_REMOVE( vlm
->i_schedule
, vlm
->schedule
, sched
);
1003 if( vlm
->i_schedule
== 0 ) free( vlm
->schedule
);
1004 free( sched
->psz_name
);
1006 for ( i
= 0; i
< sched
->i_command
; i
++ )
1007 free( sched
->command
[i
] );
1008 free( sched
->command
);
1012 static vlm_schedule_sys_t
*vlm_ScheduleSearch( vlm_t
*vlm
, const char *psz_name
)
1016 for( i
= 0; i
< vlm
->i_schedule
; i
++ )
1018 if( strcmp( psz_name
, vlm
->schedule
[i
]->psz_name
) == 0 )
1020 return vlm
->schedule
[i
];
1027 /* Ok, setup schedule command will be able to support only one (argument value) at a time */
1028 static int vlm_ScheduleSetup( vlm_schedule_sys_t
*schedule
, const char *psz_cmd
,
1029 const char *psz_value
)
1031 if( !strcmp( psz_cmd
, "enabled" ) )
1033 schedule
->b_enabled
= true;
1035 else if( !strcmp( psz_cmd
, "disabled" ) )
1037 schedule
->b_enabled
= false;
1039 else if( !strcmp( psz_cmd
, "date" ) )
1044 time
.tm_sec
= 0; /* seconds */
1045 time
.tm_min
= 0; /* minutes */
1046 time
.tm_hour
= 0; /* hours */
1047 time
.tm_mday
= 0; /* day of the month */
1048 time
.tm_mon
= 0; /* month */
1049 time
.tm_year
= 0; /* year */
1050 time
.tm_wday
= 0; /* day of the week */
1051 time
.tm_yday
= 0; /* day in the year */
1052 time
.tm_isdst
= -1; /* daylight saving time */
1054 /* date should be year/month/day-hour:minutes:seconds */
1055 p
= strchr( psz_value
, '-' );
1057 if( !strcmp( psz_value
, "now" ) )
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 schedule
->date
= mktime(&time
);
1108 else if( !strcmp( psz_cmd
, "period" ) )
1112 const char *psz_time
= NULL
, *psz_date
= NULL
;
1115 /* First, if date or period are modified, repeat should be equal to -1 */
1116 schedule
->i_repeat
= -1;
1118 time
.tm_sec
= 0; /* seconds */
1119 time
.tm_min
= 0; /* minutes */
1120 time
.tm_hour
= 0; /* hours */
1121 time
.tm_mday
= 0; /* day of the month */
1122 time
.tm_mon
= 0; /* month */
1123 time
.tm_year
= 0; /* year */
1124 time
.tm_wday
= 0; /* day of the week */
1125 time
.tm_yday
= 0; /* day in the year */
1126 time
.tm_isdst
= -1; /* daylight saving time */
1128 /* date should be year/month/day-hour:minutes:seconds */
1129 p
= strchr( psz_value
, '-' );
1132 psz_date
= psz_value
;
1137 psz_time
= psz_value
;
1140 switch( sscanf( psz_time
, "%u:%u:%u", &i
, &j
, &k
) )
1159 switch( sscanf( psz_date
, "%u/%u/%u", &i
, &j
, &k
) )
1178 /* ok, that's stupid... who is going to schedule streams every 42 years ? */
1179 schedule
->period
= ((((time
.tm_year
* 12 + time
.tm_mon
) * 30
1180 + time
.tm_mday
) * 24 + time
.tm_hour
) * 60 + time
.tm_min
) * 60
1183 else if( !strcmp( psz_cmd
, "repeat" ) )
1187 if( sscanf( psz_value
, "%d", &i
) == 1 )
1189 schedule
->i_repeat
= i
;
1196 else if( !strcmp( psz_cmd
, "append" ) )
1198 char *command
= strdup( psz_value
);
1200 TAB_APPEND( schedule
->i_command
, schedule
->command
, command
);
1210 /*****************************************************************************
1211 * Message handling functions
1212 *****************************************************************************/
1213 vlm_message_t
*vlm_MessageSimpleNew( const char *psz_name
)
1215 if( !psz_name
) return NULL
;
1217 vlm_message_t
*p_message
= malloc( sizeof(*p_message
) );
1221 p_message
->psz_name
= strdup( psz_name
);
1222 if( !p_message
->psz_name
)
1227 p_message
->psz_value
= NULL
;
1228 p_message
->i_child
= 0;
1229 p_message
->child
= NULL
;
1234 vlm_message_t
*vlm_MessageNew( const char *psz_name
,
1235 const char *psz_format
, ... )
1237 vlm_message_t
*p_message
= vlm_MessageSimpleNew( psz_name
);
1243 assert( psz_format
);
1244 va_start( args
, psz_format
);
1245 if( vasprintf( &p_message
->psz_value
, psz_format
, args
) == -1 )
1246 p_message
->psz_value
= NULL
;
1249 if( !p_message
->psz_value
)
1251 vlm_MessageDelete( p_message
);
1257 void vlm_MessageDelete( vlm_message_t
*p_message
)
1259 free( p_message
->psz_name
);
1260 free( p_message
->psz_value
);
1261 while( p_message
->i_child
-- )
1262 vlm_MessageDelete( p_message
->child
[p_message
->i_child
] );
1263 free( p_message
->child
);
1268 vlm_message_t
*vlm_MessageAdd( vlm_message_t
*p_message
,
1269 vlm_message_t
*p_child
)
1271 if( p_message
== NULL
) return NULL
;
1275 TAB_APPEND( p_message
->i_child
, p_message
->child
, p_child
);
1281 /*****************************************************************************
1282 * Misc utility functions
1283 *****************************************************************************/
1284 static vlm_message_t
*vlm_ShowMedia( vlm_media_sys_t
*p_media
)
1286 vlm_media_t
*p_cfg
= &p_media
->cfg
;
1287 vlm_message_t
*p_msg
;
1288 vlm_message_t
*p_msg_sub
;
1291 p_msg
= vlm_MessageSimpleNew( p_cfg
->psz_name
);
1292 vlm_MessageAdd( p_msg
,
1293 vlm_MessageNew( "type", p_cfg
->b_vod
? "vod" : "broadcast" ) );
1294 vlm_MessageAdd( p_msg
,
1295 vlm_MessageNew( "enabled", p_cfg
->b_enabled
? "yes" : "no" ) );
1298 vlm_MessageAdd( p_msg
,
1299 vlm_MessageNew( "mux", "%s", p_cfg
->vod
.psz_mux
) );
1301 vlm_MessageAdd( p_msg
,
1302 vlm_MessageNew( "loop", p_cfg
->broadcast
.b_loop
? "yes" : "no" ) );
1304 p_msg_sub
= vlm_MessageAdd( p_msg
, vlm_MessageSimpleNew( "inputs" ) );
1305 for( i
= 0; i
< p_cfg
->i_input
; i
++ )
1308 if( asprintf( &psz_tmp
, "%d", i
+1 ) != -1 )
1310 vlm_MessageAdd( p_msg_sub
,
1311 vlm_MessageNew( psz_tmp
, "%s", p_cfg
->ppsz_input
[i
] ) );
1316 vlm_MessageAdd( p_msg
,
1317 vlm_MessageNew( "output", "%s", p_cfg
->psz_output
? p_cfg
->psz_output
: "" ) );
1319 p_msg_sub
= vlm_MessageAdd( p_msg
, vlm_MessageSimpleNew( "options" ) );
1320 for( i
= 0; i
< p_cfg
->i_option
; i
++ )
1321 vlm_MessageAdd( p_msg_sub
, vlm_MessageSimpleNew( p_cfg
->ppsz_option
[i
] ) );
1323 p_msg_sub
= vlm_MessageAdd( p_msg
, vlm_MessageSimpleNew( "instances" ) );
1324 for( i
= 0; i
< p_media
->i_instance
; i
++ )
1326 vlm_media_instance_sys_t
*p_instance
= p_media
->instance
[i
];
1328 vlm_message_t
*p_msg_instance
;
1331 if( p_instance
->p_input
)
1332 var_Get( p_instance
->p_input
, "state", &val
);
1334 p_msg_instance
= vlm_MessageAdd( p_msg_sub
, vlm_MessageSimpleNew( "instance" ) );
1336 vlm_MessageAdd( p_msg_instance
,
1337 vlm_MessageNew( "name" , "%s", p_instance
->psz_name
? p_instance
->psz_name
: "default" ) );
1338 vlm_MessageAdd( p_msg_instance
,
1339 vlm_MessageNew( "state",
1340 val
.i_int
== PLAYING_S
? "playing" :
1341 val
.i_int
== PAUSE_S
? "paused" :
1344 /* FIXME should not do that this way */
1345 if( p_instance
->p_input
)
1347 #define APPEND_INPUT_INFO( key, format, type ) \
1348 vlm_MessageAdd( p_msg_instance, vlm_MessageNew( key, format, \
1349 var_Get ## type( p_instance->p_input, key ) ) )
1350 APPEND_INPUT_INFO( "position", "%f", Float
);
1351 APPEND_INPUT_INFO( "time", "%"PRId64
, Integer
);
1352 APPEND_INPUT_INFO( "length", "%"PRId64
, Integer
);
1353 APPEND_INPUT_INFO( "rate", "%f", Float
);
1354 APPEND_INPUT_INFO( "title", "%"PRId64
, Integer
);
1355 APPEND_INPUT_INFO( "chapter", "%"PRId64
, Integer
);
1356 APPEND_INPUT_INFO( "can-seek", "%d", Bool
);
1358 #undef APPEND_INPUT_INFO
1359 vlm_MessageAdd( p_msg_instance
, vlm_MessageNew( "playlistindex",
1360 "%d", p_instance
->i_index
+ 1 ) );
1365 static vlm_message_t
*vlm_Show( vlm_t
*vlm
, vlm_media_sys_t
*media
,
1366 vlm_schedule_sys_t
*schedule
,
1367 const char *psz_filter
)
1371 vlm_message_t
*p_msg
= vlm_MessageSimpleNew( "show" );
1373 vlm_MessageAdd( p_msg
, vlm_ShowMedia( media
) );
1377 else if( schedule
!= NULL
)
1381 vlm_message_t
*msg_schedule
;
1382 vlm_message_t
*msg_child
;
1385 msg
= vlm_MessageSimpleNew( "show" );
1387 vlm_MessageAdd( msg
, vlm_MessageSimpleNew( schedule
->psz_name
) );
1389 vlm_MessageAdd( msg_schedule
, vlm_MessageNew("type", "schedule") );
1391 vlm_MessageAdd( msg_schedule
,
1392 vlm_MessageNew( "enabled", schedule
->b_enabled
?
1395 if( schedule
->date
!= 0 )
1399 localtime_r( &schedule
->date
, &date
);
1400 vlm_MessageAdd( msg_schedule
,
1401 vlm_MessageNew( "date", "%d/%d/%d-%d:%d:%d",
1402 date
.tm_year
+ 1900, date
.tm_mon
+ 1,
1403 date
.tm_mday
, date
.tm_hour
, date
.tm_min
,
1407 vlm_MessageAdd( msg_schedule
, vlm_MessageNew("date", "now") );
1409 if( schedule
->period
!= 0 )
1414 d
= div(schedule
->period
, 60);
1415 date
.tm_sec
= d
.rem
;
1416 d
= div(d
.quot
, 60);
1417 date
.tm_min
= d
.rem
;
1418 d
= div(d
.quot
, 24);
1419 date
.tm_hour
= d
.rem
;
1420 /* okay, okay, months are not always 30 days long */
1421 d
= div(d
.quot
, 30);
1422 date
.tm_mday
= d
.rem
;
1423 d
= div(d
.quot
, 12);
1424 date
.tm_mon
= d
.rem
;
1425 date
.tm_year
= d
.quot
;
1427 sprintf( buffer
, "%d/%d/%d-%d:%d:%d", date
.tm_year
, date
.tm_mon
,
1428 date
.tm_mday
, date
.tm_hour
, date
.tm_min
, date
.tm_sec
);
1430 vlm_MessageAdd( msg_schedule
, vlm_MessageNew("period", "%s", buffer
) );
1433 vlm_MessageAdd( msg_schedule
, vlm_MessageNew("period", "0") );
1435 sprintf( buffer
, "%d", schedule
->i_repeat
);
1436 vlm_MessageAdd( msg_schedule
, vlm_MessageNew( "repeat", "%s", buffer
) );
1439 vlm_MessageAdd( msg_schedule
, vlm_MessageSimpleNew("commands" ) );
1441 for( i
= 0; i
< schedule
->i_command
; i
++ )
1443 vlm_MessageAdd( msg_child
,
1444 vlm_MessageSimpleNew( schedule
->command
[i
] ) );
1451 else if( psz_filter
&& !strcmp( psz_filter
, "media" ) )
1453 vlm_message_t
*p_msg
;
1454 vlm_message_t
*p_msg_child
;
1455 int i_vod
= 0, i_broadcast
= 0;
1457 for( int i
= 0; i
< vlm
->i_media
; i
++ )
1459 if( vlm
->media
[i
]->cfg
.b_vod
)
1465 p_msg
= vlm_MessageSimpleNew( "show" );
1466 p_msg_child
= vlm_MessageAdd( p_msg
, vlm_MessageNew( "media",
1467 "( %d broadcast - %d vod )", i_broadcast
,
1470 for( int i
= 0; i
< vlm
->i_media
; i
++ )
1471 vlm_MessageAdd( p_msg_child
, vlm_ShowMedia( vlm
->media
[i
] ) );
1476 else if( psz_filter
&& !strcmp( psz_filter
, "schedule" ) )
1480 vlm_message_t
*msg_child
;
1482 msg
= vlm_MessageSimpleNew( "show" );
1483 msg_child
= vlm_MessageAdd( msg
, vlm_MessageSimpleNew( "schedule" ) );
1485 for( i
= 0; i
< vlm
->i_schedule
; i
++ )
1487 vlm_schedule_sys_t
*s
= vlm
->schedule
[i
];
1488 vlm_message_t
*msg_schedule
;
1489 time_t now
, next_date
;
1491 msg_schedule
= vlm_MessageAdd( msg_child
,
1492 vlm_MessageSimpleNew( s
->psz_name
) );
1493 vlm_MessageAdd( msg_schedule
,
1494 vlm_MessageNew( "enabled", s
->b_enabled
?
1497 /* calculate next date */
1499 next_date
= s
->date
;
1501 if( s
->period
!= 0 )
1504 while( ((s
->date
+ j
* s
->period
) <= now
) &&
1505 ( s
->i_repeat
> j
|| s
->i_repeat
< 0 ) )
1510 next_date
= s
->date
+ j
* s
->period
;
1513 if( next_date
> now
)
1518 strftime( psz_date
, sizeof(psz_date
), "%Y-%m-%d %H:%M:%S (%a)",
1519 localtime_r( &next_date
, &tm
) );
1520 vlm_MessageAdd( msg_schedule
,
1521 vlm_MessageNew( "next launch", "%s", psz_date
) );
1528 else if( ( psz_filter
== NULL
) && ( media
== NULL
) && ( schedule
== NULL
) )
1530 vlm_message_t
*show1
= vlm_Show( vlm
, NULL
, NULL
, "media" );
1531 vlm_message_t
*show2
= vlm_Show( vlm
, NULL
, NULL
, "schedule" );
1533 vlm_MessageAdd( show1
, show2
->child
[0] );
1535 /* We must destroy the parent node "show" of show2
1536 * and not the children */
1537 free( show2
->psz_name
);
1545 return vlm_MessageSimpleNew( "show" );
1549 /*****************************************************************************
1550 * Config handling functions
1551 *****************************************************************************/
1552 static int Load( vlm_t
*vlm
, char *file
)
1557 while( *pf
!= '\0' )
1559 vlm_message_t
*message
= NULL
;
1562 while( pf
[i_end
] != '\n' && pf
[i_end
] != '\0' && pf
[i_end
] != '\r' )
1567 if( pf
[i_end
] == '\r' || pf
[i_end
] == '\n' )
1571 if( pf
[i_end
] == '\n' ) i_end
++;
1574 if( *pf
&& ExecuteCommand( vlm
, pf
, &message
) )
1578 if( message
->psz_value
)
1579 msg_Err( vlm
, "Load error on line %d: %s: %s",
1580 i_line
, message
->psz_name
, message
->psz_value
);
1581 vlm_MessageDelete( message
);
1585 if( message
) vlm_MessageDelete( message
);
1594 static char *Save( vlm_t
*vlm
)
1597 char psz_header
[] = "\n"
1598 "# VLC media player VLM command batch\n"
1599 "# http://www.videolan.org/vlc/\n\n" ;
1602 int i_length
= strlen( psz_header
);
1604 for( i
= 0; i
< vlm
->i_media
; i
++ )
1606 vlm_media_sys_t
*media
= vlm
->media
[i
];
1607 vlm_media_t
*p_cfg
= &media
->cfg
;
1610 i_length
+= strlen( "new * vod " ) + strlen(p_cfg
->psz_name
);
1612 i_length
+= strlen( "new * broadcast " ) + strlen(p_cfg
->psz_name
);
1614 if( p_cfg
->b_enabled
)
1615 i_length
+= strlen( "enabled" );
1617 i_length
+= strlen( "disabled" );
1619 if( !p_cfg
->b_vod
&& p_cfg
->broadcast
.b_loop
)
1620 i_length
+= strlen( " loop\n" );
1622 i_length
+= strlen( "\n" );
1624 for( j
= 0; j
< p_cfg
->i_input
; j
++ )
1625 i_length
+= strlen( "setup * input \"\"\n" ) + strlen( p_cfg
->psz_name
) + strlen( p_cfg
->ppsz_input
[j
] );
1627 if( p_cfg
->psz_output
!= NULL
)
1628 i_length
+= strlen( "setup * output \n" ) + strlen(p_cfg
->psz_name
) + strlen(p_cfg
->psz_output
);
1630 for( j
= 0; j
< p_cfg
->i_option
; j
++ )
1631 i_length
+= strlen("setup * option \n") + strlen(p_cfg
->psz_name
) + strlen(p_cfg
->ppsz_option
[j
]);
1633 if( p_cfg
->b_vod
&& p_cfg
->vod
.psz_mux
)
1634 i_length
+= strlen("setup * mux \n") + strlen(p_cfg
->psz_name
) + strlen(p_cfg
->vod
.psz_mux
);
1637 for( i
= 0; i
< vlm
->i_schedule
; i
++ )
1639 vlm_schedule_sys_t
*schedule
= vlm
->schedule
[i
];
1641 i_length
+= strlen( "new schedule " ) + strlen( schedule
->psz_name
);
1643 if( schedule
->b_enabled
)
1645 i_length
+= strlen( "date //-:: enabled\n" ) + 14;
1649 i_length
+= strlen( "date //-:: disabled\n" ) + 14;
1653 if( schedule
->period
!= 0 )
1655 i_length
+= strlen( "setup " ) + strlen( schedule
->psz_name
) +
1656 strlen( "period //-::\n" ) + 14;
1659 if( schedule
->i_repeat
>= 0 )
1663 sprintf( buffer
, "%d", schedule
->i_repeat
);
1664 i_length
+= strlen( "setup repeat \n" ) +
1665 strlen( schedule
->psz_name
) + strlen( buffer
);
1672 for( j
= 0; j
< schedule
->i_command
; j
++ )
1674 i_length
+= strlen( "setup append \n" ) +
1675 strlen( schedule
->psz_name
) + strlen( schedule
->command
[j
] );
1680 /* Don't forget the '\0' */
1682 /* now we have the length of save */
1684 p
= save
= malloc( i_length
);
1685 if( !save
) return NULL
;
1688 p
+= sprintf( p
, "%s", psz_header
);
1690 /* finally we can write in it */
1691 for( i
= 0; i
< vlm
->i_media
; i
++ )
1693 vlm_media_sys_t
*media
= vlm
->media
[i
];
1694 vlm_media_t
*p_cfg
= &media
->cfg
;
1697 p
+= sprintf( p
, "new %s vod ", p_cfg
->psz_name
);
1699 p
+= sprintf( p
, "new %s broadcast ", p_cfg
->psz_name
);
1701 if( p_cfg
->b_enabled
)
1702 p
+= sprintf( p
, "enabled" );
1704 p
+= sprintf( p
, "disabled" );
1706 if( !p_cfg
->b_vod
&& p_cfg
->broadcast
.b_loop
)
1707 p
+= sprintf( p
, " loop\n" );
1709 p
+= sprintf( p
, "\n" );
1711 for( j
= 0; j
< p_cfg
->i_input
; j
++ )
1712 p
+= sprintf( p
, "setup %s input \"%s\"\n", p_cfg
->psz_name
, p_cfg
->ppsz_input
[j
] );
1714 if( p_cfg
->psz_output
)
1715 p
+= sprintf( p
, "setup %s output %s\n", p_cfg
->psz_name
, p_cfg
->psz_output
);
1717 for( j
= 0; j
< p_cfg
->i_option
; j
++ )
1718 p
+= sprintf( p
, "setup %s option %s\n", p_cfg
->psz_name
, p_cfg
->ppsz_option
[j
] );
1720 if( p_cfg
->b_vod
&& p_cfg
->vod
.psz_mux
)
1721 p
+= sprintf( p
, "setup %s mux %s\n", p_cfg
->psz_name
, p_cfg
->vod
.psz_mux
);
1724 /* and now, the schedule scripts */
1725 for( i
= 0; i
< vlm
->i_schedule
; i
++ )
1727 vlm_schedule_sys_t
*schedule
= vlm
->schedule
[i
];
1730 localtime_r( &schedule
->date
, &date
);
1731 p
+= sprintf( p
, "new %s schedule ", schedule
->psz_name
);
1733 if( schedule
->b_enabled
)
1735 p
+= sprintf( p
, "date %d/%d/%d-%d:%d:%d enabled\n",
1736 date
.tm_year
+ 1900, date
.tm_mon
+ 1, date
.tm_mday
,
1737 date
.tm_hour
, date
.tm_min
, date
.tm_sec
);
1741 p
+= sprintf( p
, "date %d/%d/%d-%d:%d:%d disabled\n",
1742 date
.tm_year
+ 1900, date
.tm_mon
+ 1, date
.tm_mday
,
1743 date
.tm_hour
, date
.tm_min
, date
.tm_sec
);
1746 if( schedule
->period
!= 0 )
1750 p
+= sprintf( p
, "setup %s ", schedule
->psz_name
);
1752 d
= div(schedule
->period
, 60);
1753 date
.tm_sec
= d
.rem
;
1754 d
= div(d
.quot
, 60);
1755 date
.tm_min
= d
.rem
;
1756 d
= div(d
.quot
, 24);
1757 date
.tm_hour
= d
.rem
;
1758 d
= div(d
.quot
, 30);
1759 date
.tm_mday
= d
.rem
;
1760 /* okay, okay, months are not always 30 days long */
1761 d
= div(d
.quot
, 12);
1762 date
.tm_mon
= d
.rem
;
1763 date
.tm_year
= d
.quot
;
1765 p
+= sprintf( p
, "period %d/%d/%d-%d:%d:%d\n",
1766 date
.tm_year
, date
.tm_mon
, date
.tm_mday
,
1767 date
.tm_hour
, date
.tm_min
, date
.tm_sec
);
1770 if( schedule
->i_repeat
>= 0 )
1772 p
+= sprintf( p
, "setup %s repeat %d\n",
1773 schedule
->psz_name
, schedule
->i_repeat
);
1777 p
+= sprintf( p
, "\n" );
1780 for( j
= 0; j
< schedule
->i_command
; j
++ )
1782 p
+= sprintf( p
, "setup %s append %s\n",
1783 schedule
->psz_name
, schedule
->command
[j
] );
1791 #endif /* ENABLE_VLM */