root/src/input/vlmshell.c

Revision bd03c387b82dad16831e76091aae66b37080910b, 55.0 kB (checked in by Pavlov Konstantin <thresh@altlinux.ru>, 1 week ago)

Spelling: mili -> milli.

  • Property mode set to 100644
Line 
1 /*****************************************************************************
2  * vlm.c: VLM interface plugin
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Simon Latapie <garf@videolan.org>
8  *          Laurent Aimar <fenrir@videolan.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34
35 #include <stdio.h>
36 #include <ctype.h>                                              /* tolower() */
37 #include <assert.h>
38
39 #include <vlc_vlm.h>
40
41 #ifdef ENABLE_VLM
42
43 #ifndef WIN32
44 #   include <sys/time.h>                                   /* gettimeofday() */
45 #endif
46
47 #ifdef HAVE_TIME_H
48 #   include <time.h>                                              /* ctime() */
49 #   include <sys/timeb.h>                                         /* ftime() */
50 #endif
51
52 #include <vlc_input.h>
53 #include "input_internal.h"
54 #include <vlc_stream.h>
55 #include "vlm_internal.h"
56 #include <vlc_vod.h>
57 #include <vlc_charset.h>
58 #include <vlc_sout.h>
59 #include "../stream_output/stream_output.h"
60 #include "../libvlc.h"
61
62 /*****************************************************************************
63  * Local prototypes.
64  *****************************************************************************/
65
66 /* ugly kludge to avoid "null format string" warnings,
67  * even if we handle NULL format string in vlm_MessageNew() */
68 static const char *vlm_NULL = NULL;
69
70 /* */
71 static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * );
72
73 static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
74
75 static char *Save( vlm_t * );
76 static int Load( vlm_t *, char * );
77
78 static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
79 static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
80                               const char *psz_value );
81
82 /* */
83 static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
84
85 static const char quotes[] = "\"'";
86 /**
87  * FindCommandEnd: look for the end of a possibly quoted string
88  * @return NULL on mal-formatted string,
89  * pointer past the last character otherwise.
90  */
91 static const char *FindCommandEnd( const char *psz_sent )
92 {
93     char c, quote = 0;
94
95     while( (c = *psz_sent) != '\0' )
96     {
97         if( !quote )
98         {
99             if( strchr(quotes,c) )   // opening quote
100                 quote = c;
101             else if( isspace(c) )         // non-escaped space
102                 return psz_sent;
103             else if( c == '\\' )
104             {
105                 psz_sent++;         // skip escaped character
106                 if( *psz_sent == '\0' )
107                     return psz_sent;
108             }
109         }
110         else
111         {
112             if( c == quote )         // non-escaped matching quote
113                 quote = 0;
114             else if( (quote == '"') && (c == '\\') )
115             {
116                 psz_sent++;         // skip escaped character
117                 if (*psz_sent == '\0')
118                     return NULL;    // error, closing quote missing
119             }
120         }
121         psz_sent++;
122     }
123
124     // error (NULL) if we could not find a matching quote
125     return quote ? NULL : psz_sent;
126 }
127
128
129 /**
130  * Unescape a nul-terminated string.
131  * Note that in and out can be identical.
132  *
133  * @param out output buffer (at least <strlen (in) + 1> characters long)
134  * @param in nul-terminated string to be unescaped
135  *
136  * @return 0 on success, -1 on error.
137  */
138 static int Unescape( char *out, const char *in )
139 {
140     char c, quote = 0;
141
142     while( (c = *in++) != '\0' )
143     {
144         if( !quote )
145         {
146             if (strchr(quotes,c))   // opening quote
147             {
148                 quote = c;
149                 continue;
150             }
151             else if( c == '\\' )
152             {
153                 switch (c = *in++)
154                 {
155                     case '"':
156                     case '\'':
157                     case '\\':
158                         *out++ = c;
159                         continue;
160
161                     case '\0':
162                         *out = '\0';
163                         return 0;
164                 }
165                 if( isspace(c) )
166                 {
167                     *out++ = c;
168                     continue;
169                 }
170                 /* None of the special cases - copy the backslash */
171                 *out++ = '\\';
172             }
173         }
174         else
175         {
176             if( c == quote )         // non-escaped matching quote
177             {
178                 quote = 0;
179                 continue;
180             }
181             if( (quote == '"') && (c == '\\') )
182             {
183                 switch( c = *in++ )
184                 {
185                     case '"':
186                     case '\\':
187                         *out++ = c;
188                         continue;
189
190                     case '\0':   // should never happen
191                         *out = '\0';
192                         return -1;
193                 }
194                 /* None of the special cases - copy the backslash */
195                 *out++ = '\\';
196             }
197         }
198         *out++ = c;
199     }
200
201     *out = '\0';
202     return 0;
203 }
204
205
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 )
212 {
213     *pp_status = vlm_MessageNew( psz_cmd, "Wrong command syntax" );
214     return VLC_EGENERIC;
215 }
216
217 static bool ExecuteIsMedia( vlm_t *p_vlm, const char *psz_name )
218 {
219     int64_t id;
220
221     if( !psz_name || vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
222         return false;
223     return true;
224 }
225 static bool ExecuteIsSchedule( vlm_t *p_vlm, const char *psz_name )
226 {
227     if( !psz_name || !vlm_ScheduleSearch( p_vlm, psz_name ) )
228         return false;
229     return true;
230 }
231
232 static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
233 {
234     vlm_media_sys_t *p_media;
235     vlm_schedule_sys_t *p_schedule;
236
237     p_media = vlm_MediaSearch( p_vlm, psz_name );
238     p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
239
240     if( p_schedule != NULL )
241     {
242         vlm_ScheduleDelete( p_vlm, p_schedule );
243     }
244     else if( p_media != NULL )
245     {
246         vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_media->cfg.id );
247     }
248     else if( !strcmp(psz_name, "media") )
249     {
250         vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
251     }
252     else if( !strcmp(psz_name, "schedule") )
253     {
254         vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
255     }
256     else if( !strcmp(psz_name, "all") )
257     {
258         vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
259         vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
260     }
261     else
262     {
263         *pp_status = vlm_MessageNew( "del", "%s: media unknown", psz_name );
264         return VLC_EGENERIC;
265     }
266
267     *pp_status = vlm_MessageNew( "del", vlm_NULL );
268     return VLC_SUCCESS;
269 }
270
271 static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
272 {
273     vlm_media_sys_t *p_media;
274     vlm_schedule_sys_t *p_schedule;
275
276     if( !psz_name )
277     {
278         *pp_status = vlm_Show( p_vlm, NULL, NULL, NULL );
279         return VLC_SUCCESS;
280     }
281
282     p_media = vlm_MediaSearch( p_vlm, psz_name );
283     p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
284
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 );
289     else
290         *pp_status = vlm_Show( p_vlm, NULL, NULL, psz_name );
291
292     return VLC_SUCCESS;
293 }
294
295 static int ExecuteHelp( vlm_message_t **pp_status )
296 {
297     vlm_message_t *message_child;
298
299 #define MessageAdd( a ) \
300         vlm_MessageAdd( *pp_status, vlm_MessageNew( a, vlm_NULL ) );
301 #define MessageAddChild( a ) \
302         vlm_MessageAdd( message_child, vlm_MessageNew( a, vlm_NULL ) );
303
304     *pp_status = vlm_MessageNew( "help", vlm_NULL );
305
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)" );
315
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)" );
325
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):"
330                      "(seconds)|now" );
331     MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
332                      "(days)-(hours):(minutes):(seconds)" );
333     MessageAddChild( "repeat (number_of_repetitions)" );
334
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" );
340
341     return VLC_SUCCESS;
342 }
343
344 static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, char ** ppsz_arg, vlm_message_t **pp_status )
345 {
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;
350     int i_index;
351     int i_result;
352
353     if( !ExecuteIsMedia( p_vlm, psz_name ) )
354     {
355         *pp_status = vlm_MessageNew( "control", "%s: media unknown", psz_name );
356         return VLC_EGENERIC;
357     }
358
359     assert( i_arg > 0 );
360
361 #define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
362     i_index = 0;
363     if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
364     {
365         i_index = 1;
366         psz_instance = ppsz_arg[0];
367
368         if( i_index >= i_arg || ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
369             return ExecuteSyntaxError( "control", pp_status );
370     }
371 #undef IS
372     psz_control = ppsz_arg[i_index];
373
374     if( i_index+1 < i_arg )
375         psz_argument = ppsz_arg[i_index+1];
376
377     p_media = vlm_MediaSearch( p_vlm, psz_name );
378     assert( p_media );
379
380     if( !strcmp( psz_control, "play" ) )
381     {
382         int i_input_index = 0;
383         int i;
384
385         if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input )
386         {
387             i_input_index = i-1;
388         }
389         else if( psz_argument )
390         {
391             int j;
392             vlm_media_t *p_cfg = &p_media->cfg;
393             for ( j=0; j < p_cfg->i_input; j++)
394             {
395                 if( !strcmp( p_cfg->ppsz_input[j], psz_argument ) )
396                 {
397                     i_input_index = j;
398                     break;
399                 }
400             }
401         }
402
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
405         else
406             i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, psz_instance, i_input_index );
407     }
408     else if( !strcmp( psz_control, "seek" ) )
409     {
410         if( psz_argument )
411         {
412             bool b_relative;
413             if( psz_argument[0] == '+' || psz_argument[0] == '-' )
414                 b_relative = true;
415             else
416                 b_relative = false;
417
418             if( strstr( psz_argument, "ms" ) || strstr( psz_argument, "s" ) )
419             {
420                 /* Time (ms or s) */
421                 int64_t i_new_time;
422
423                 if( strstr( psz_argument, "ms" ) )
424                     i_new_time =  1000 * (int64_t)atoi( psz_argument );
425                 else
426                     i_new_time = 1000000 * (int64_t)atoi( psz_argument );
427
428                 if( b_relative )
429                 {
430                     int64_t i_time = 0;
431                     vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, &i_time );
432                     i_new_time += i_time;
433                 }
434                 if( i_new_time < 0 )
435                     i_new_time = 0;
436                 i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, i_new_time );
437             }
438             else
439             {
440                 /* Percent */
441                 double d_new_position = us_atof( psz_argument ) / 100.0;
442
443                 if( b_relative )
444                 {
445                     double d_position = 0.0;
446
447                     vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
448                     d_new_position += d_position;
449                 }
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 );
455             }
456         }
457         else
458         {
459             i_result = VLC_EGENERIC;
460         }
461     }
462     else if( !strcmp( psz_control, "rewind" ) )
463     {
464         if( psz_argument )
465         {
466             const double d_scale = us_atof( psz_argument );
467             double d_position;
468
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 )
472                 d_position = 0.0;
473             i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
474         }
475         else
476         {
477             i_result = VLC_EGENERIC;
478         }
479     }
480     else if( !strcmp( psz_control, "forward" ) )
481     {
482         if( psz_argument )
483         {
484             const double d_scale = us_atof( psz_argument );
485             double d_position;
486
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 )
490                 d_position = 1.0;
491             i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
492
493         }
494         else
495         {
496             i_result = VLC_EGENERIC;
497         }
498     }
499     else if( !strcmp( psz_control, "stop" ) )
500     {
501         i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
502     }
503     else if( !strcmp( psz_control, "pause" ) )
504     {
505         i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
506     }
507     else
508     {
509         i_result = VLC_EGENERIC;
510     }
511
512     if( i_result )
513     {
514         *pp_status = vlm_MessageNew( "control", "unknown error" );
515         return VLC_SUCCESS;
516     }
517     *pp_status = vlm_MessageNew( "control", vlm_NULL );
518     return VLC_SUCCESS;
519 }
520
521 static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
522 {
523     char *psz_export = Save( p_vlm );
524
525     *pp_status = vlm_MessageNew( "export", psz_export );
526     free( psz_export );
527     return VLC_SUCCESS;
528 }
529
530 static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
531 {
532     FILE *f = utf8_fopen( psz_file, "wt" );
533     char *psz_save = NULL;
534
535     if( !f )
536         goto error;
537
538     psz_save = Save( p_vlm );
539     if( psz_save == NULL )
540         goto error;
541     if( fputs( psz_save, f ) == EOF )
542         goto error;;
543     if( fclose( f ) )
544     {
545         f = NULL;
546         goto error;
547     }
548
549     free( psz_save );
550
551     *pp_status = vlm_MessageNew( "save", vlm_NULL );
552     return VLC_SUCCESS;
553
554 error:
555     free( psz_save );
556     if( f )
557          fclose( f );
558     *pp_status = vlm_MessageNew( "save", "Unable to save to file");
559     return VLC_EGENERIC;
560 }
561
562 static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
563 {
564     stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
565     int64_t i_size;
566     char *psz_buffer;
567
568     if( !p_stream )
569     {
570         *pp_status = vlm_MessageNew( "load", "Unable to load from file" );
571         return VLC_EGENERIC;
572     }
573
574     /* FIXME needed ? */
575     if( stream_Seek( p_stream, 0 ) != 0 )
576     {
577         stream_Delete( p_stream );
578
579         *pp_status = vlm_MessageNew( "load", "Read file error" );
580         return VLC_EGENERIC;
581     }
582
583     i_size = stream_Size( p_stream );
584
585     psz_buffer = malloc( i_size + 1 );
586     if( !psz_buffer )
587     {
588         stream_Delete( p_stream );
589
590         *pp_status = vlm_MessageNew( "load", "Read file error" );
591         return VLC_EGENERIC;
592     }
593
594     stream_Read( p_stream, psz_buffer, i_size );
595     psz_buffer[i_size] = '\0';
596
597     stream_Delete( p_stream );
598
599     if( Load( p_vlm, psz_buffer ) )
600     {
601         free( psz_buffer );
602
603         *pp_status = vlm_MessageNew( "load", "Error while loading file" );
604         return VLC_EGENERIC;
605     }
606
607     free( psz_buffer );
608
609     *pp_status = vlm_MessageNew( "load", vlm_NULL );
610     return VLC_SUCCESS;
611 }
612
613 static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,
614                                     const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
615 {
616     const char *psz_cmd = b_new ? "new" : "setup";
617     int i;
618
619     for( i = 0; i < i_property; i++ )
620     {
621         if( !strcmp( ppsz_property[i], "enabled" ) ||
622             !strcmp( ppsz_property[i], "disabled" ) )
623         {
624             if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )
625                 goto error;
626         }
627         else if( !strcmp( ppsz_property[i], "append" ) )
628         {
629             char *psz_line;
630             int j;
631             /* Beware: everything behind append is considered as
632              * command line */
633
634             if( ++i >= i_property )
635                 break;
636
637             psz_line = strdup( ppsz_property[i] );
638             for( j = i+1; j < i_property; j++ )
639             {
640                 psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
641                 strcat( psz_line, " " );
642                 strcat( psz_line, ppsz_property[j] );
643             }
644
645             if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
646                 goto error;
647             break;
648         }
649         else
650         {
651             if( i + 1 >= i_property )
652             {
653                 if( b_new )
654                     vlm_ScheduleDelete( p_vlm, p_schedule );
655                 return ExecuteSyntaxError( psz_cmd, pp_status );
656             }
657
658             if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )
659                 goto error;
660             i++;
661         }
662     }
663     *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
664     return VLC_SUCCESS;
665
666 error:
667     *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",
668                                  ppsz_property[i] );
669     return VLC_EGENERIC;
670 }
671
672 static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
673                                  const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
674 {
675     const char *psz_cmd = b_new ? "new" : "setup";
676     vlm_media_t *p_cfg = NULL;
677     int i_result;
678     int i;
679
680 #undef ERROR
681 #undef MISSING
682 #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)
683     if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )
684         ERROR( "unknown media" );
685
686 #define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
687     for( i = 0; i < i_property; i++ )
688     {
689         const char *psz_option = ppsz_property[i];
690         const char *psz_value = i+1 < i_property ? ppsz_property[i+1] :  NULL;
691
692         if( !strcmp( psz_option, "enabled" ) )
693         {
694             p_cfg->b_enabled = true;
695         }
696         else if( !strcmp( psz_option, "disabled" ) )
697         {
698             p_cfg->b_enabled = false;
699         }
700         else if( !strcmp( psz_option, "input" ) )
701         {
702             MISSING( "input" );
703             TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
704             i++;
705         }
706         else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
707         {
708             while( p_cfg->i_input > 0 )
709                 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
710             i++;
711         }
712         else if( !strcmp( psz_option, "inputdel" ) )
713         {
714             int j;
715
716             MISSING( "inputdel" );
717
718             for( j = 0; j < p_cfg->i_input; j++ )
719             {
720                 if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
721                 {
722                     TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
723                     break;
724                 }
725             }
726             i++;
727         }
728         else if( !strcmp( psz_option, "inputdeln" ) )
729         {
730             int i_index;
731
732             MISSING( "inputdeln" );
733  
734             i_index = atoi( psz_value );
735             if( i_index > 0 && i_index <= p_cfg->i_input )
736                 TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
737             i++;
738         }
739         else if( !strcmp( psz_option, "output" ) )
740         {
741             MISSING( "output" );
742
743             free( p_cfg->psz_output );
744             p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
745             i++;
746         }
747         else if( !strcmp( psz_option, "option" ) )
748         {
749             MISSING( "option" );
750
751             TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
752             i++;
753         }
754         else if( !strcmp( psz_option, "loop" ) )
755         {
756             if( p_cfg->b_vod )
757                 ERROR( "invalid loop option for vod" );
758             p_cfg->broadcast.b_loop = true;
759         }
760         else if( !strcmp( psz_option, "unloop" ) )
761         {
762             if( p_cfg->b_vod )
763                 ERROR( "invalid unloop option for vod" );
764             p_cfg->broadcast.b_loop = false;
765         }
766         else if( !strcmp( psz_option, "mux" ) )
767         {
768             MISSING( "mux" );
769             if( !p_cfg->b_vod )
770                 ERROR( "invalid mux option for broadcast" );
771
772             free( p_cfg->vod.psz_mux );
773             p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
774             i++;
775         }
776         else
777         {
778             fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
779             ERROR( "Wrong command syntax" );
780         }
781     }
782 #undef MISSING
783 #undef ERROR
784
785     /* */
786     i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
787     vlm_media_Delete( p_cfg );
788
789     *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );
790     return i_result;
791
792 error:
793     if( p_cfg )
794     {
795         if( b_new )
796             vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
797         vlm_media_Delete( p_cfg );
798     }
799     return VLC_EGENERIC;
800 }
801
802 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 )
803 {
804     /* Check name */
805     if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
806     {
807         *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
808         return VLC_EGENERIC;
809     }
810     if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
811     {
812         *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
813         return VLC_EGENERIC;
814     }
815     /* */
816     if( !strcmp( psz_type, "schedule" ) )
817     {
818         vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
819         if( !p_schedule )
820         {
821             *pp_status = vlm_MessageNew( "new", "could not create schedule" );
822             return VLC_EGENERIC;
823         }
824         return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );
825     }
826     else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
827     {
828         vlm_media_t cfg;
829         int64_t id;
830
831         vlm_media_Init( &cfg );
832         cfg.psz_name = strdup( psz_name );
833         cfg.b_vod = !strcmp( psz_type, "vod" );
834
835         if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
836         {
837             vlm_media_Clean( &cfg );
838             *pp_status = vlm_MessageNew( "new", "could not create media" );
839             return VLC_EGENERIC;
840         }
841         vlm_media_Clean( &cfg );
842         return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );
843     }
844     else
845     {
846         *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
847         return VLC_EGENERIC;
848     }
849 }
850
851 static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
852 {
853     if( ExecuteIsSchedule( p_vlm, psz_name ) )
854     {
855         vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
856         return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );
857     }
858     else if( ExecuteIsMedia( p_vlm, psz_name ) )
859     {
860         int64_t id;
861         if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
862             goto error;
863         return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );
864     }
865
866 error:
867     *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
868     return VLC_EGENERIC;
869