]> git.sesse.net Git - vlc/blob - modules/control/rc.c
Suppress copy-cat code (more to come)
[vlc] / modules / control / rc.c
1 /*****************************************************************************
2  * rc.c : remote control stdin/stdout module for vlc
3  *****************************************************************************
4  * Copyright (C) 2004 - 2005 the VideoLAN team
5  * $Id$
6  *
7  * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8  *         Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <string.h>
32
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <stdio.h>
35 #include <ctype.h>
36 #include <signal.h>
37
38 #include <vlc/intf.h>
39 #include <vlc/aout.h>
40 #include <vlc/vout.h>
41 #include <vlc_video.h>
42 #include <vlc_osd.h>
43 #include <vlc_update.h>
44
45 #ifdef HAVE_UNISTD_H
46 #    include <unistd.h>
47 #endif
48
49 #ifdef HAVE_SYS_TIME_H
50 #    include <sys/time.h>
51 #endif
52 #include <sys/types.h>
53
54 #include "vlc_error.h"
55 #include "network.h"
56 #include "vlc_url.h"
57
58 #include "charset.h"
59
60 #if defined(AF_UNIX) && !defined(AF_LOCAL)
61 #    define AF_LOCAL AF_UNIX
62 #endif
63
64 #if defined(AF_LOCAL) && ! defined(WIN32)
65 #    include <sys/un.h>
66 #endif
67
68 #define MAX_LINE_LENGTH 256
69 #define STATUS_CHANGE "status change: "
70
71 /*****************************************************************************
72  * Local prototypes
73  *****************************************************************************/
74 static int  Activate     ( vlc_object_t * );
75 static void Deactivate   ( vlc_object_t * );
76 static void Run          ( intf_thread_t * );
77
78 static void Help         ( intf_thread_t *, vlc_bool_t );
79 static void RegisterCallbacks( intf_thread_t * );
80
81 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
82
83 static input_item_t *parse_MRL( intf_thread_t *, char * );
84
85 static int  Input        ( vlc_object_t *, char const *,
86                            vlc_value_t, vlc_value_t, void * );
87 static int  Playlist     ( vlc_object_t *, char const *,
88                            vlc_value_t, vlc_value_t, void * );
89 static int  Other        ( vlc_object_t *, char const *,
90                            vlc_value_t, vlc_value_t, void * );
91 static int  Quit         ( vlc_object_t *, char const *,
92                            vlc_value_t, vlc_value_t, void * );
93 static int  Intf         ( vlc_object_t *, char const *,
94                            vlc_value_t, vlc_value_t, void * );
95 static int  Volume       ( vlc_object_t *, char const *,
96                            vlc_value_t, vlc_value_t, void * );
97 static int  VolumeMove   ( vlc_object_t *, char const *,
98                            vlc_value_t, vlc_value_t, void * );
99 static int  VideoConfig  ( vlc_object_t *, char const *,
100                            vlc_value_t, vlc_value_t, void * );
101 static int  AudioConfig  ( vlc_object_t *, char const *,
102                            vlc_value_t, vlc_value_t, void * );
103 static int  Menu         ( vlc_object_t *, char const *,
104                            vlc_value_t, vlc_value_t, void * );
105 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
106
107 /* Status Callbacks */
108 static int TimeOffsetChanged( vlc_object_t *, char const *,
109                               vlc_value_t, vlc_value_t , void * );
110 static int VolumeChanged    ( vlc_object_t *, char const *,
111                               vlc_value_t, vlc_value_t, void * );
112 static int StateChanged     ( vlc_object_t *, char const *,
113                               vlc_value_t, vlc_value_t, void * );
114 static int RateChanged      ( vlc_object_t *, char const *,
115                               vlc_value_t, vlc_value_t, void * );
116
117 struct intf_sys_t
118 {
119     int *pi_socket_listen;
120     int i_socket;
121     char *psz_unix_path;
122
123     /* status changes */
124     vlc_mutex_t       status_lock;
125     playlist_status_t i_last_state;
126
127 #ifdef WIN32
128     HANDLE hConsoleIn;
129     vlc_bool_t b_quiet;
130 #endif
131 };
132
133 #ifdef HAVE_VARIADIC_MACROS
134 #   define msg_rc( psz_format, args... ) \
135       __msg_rc( p_intf, psz_format, ## args )
136 #endif
137
138 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
139 {
140     va_list args;
141     va_start( args, psz_fmt );
142
143     if( p_intf->p_sys->i_socket == -1 )
144     {
145         utf8_vfprintf( stdout, psz_fmt, args );
146         printf( "\r\n" );
147     }
148     else
149     {
150         net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
151         net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
152     }
153     va_end( args );
154 }
155
156 /*****************************************************************************
157  * Module descriptor
158  *****************************************************************************/
159 #define POS_TEXT N_("Show stream position")
160 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
161                         "stream from time to time." )
162
163 #define TTY_TEXT N_("Fake TTY")
164 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
165
166 #define UNIX_TEXT N_("UNIX socket command input")
167 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
168                          "stdin." )
169
170 #define HOST_TEXT N_("TCP command input")
171 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
172             "You can set the address and port the interface will bind to." )
173
174 #ifdef WIN32
175 #define QUIET_TEXT N_("Do not open a DOS command box interface")
176 #define QUIET_LONGTEXT N_( \
177     "By default the rc interface plugin will start a DOS command box. " \
178     "Enabling the quiet mode will not bring this command box but can also " \
179     "be pretty annoying when you want to stop VLC and no video window is " \
180     "open." )
181 #endif
182
183 vlc_module_begin();
184     set_shortname( _("RC"));
185     set_category( CAT_INTERFACE );
186     set_subcategory( SUBCAT_INTERFACE_MAIN );
187     set_description( _("Remote control interface") );
188     add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
189 #ifdef HAVE_ISATTY
190     add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
191 #endif
192     add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
193     add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
194
195 #ifdef WIN32
196     add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
197 #endif
198
199     set_capability( "interface", 20 );
200     set_callbacks( Activate, Deactivate );
201 vlc_module_end();
202
203 /*****************************************************************************
204  * Activate: initialize and create stuff
205  *****************************************************************************/
206 static int Activate( vlc_object_t *p_this )
207 {
208     intf_thread_t *p_intf = (intf_thread_t*)p_this;
209     char *psz_host, *psz_unix_path;
210     int  *pi_socket = NULL;
211
212 #if defined(HAVE_ISATTY) && !defined(WIN32)
213     /* Check that stdin is a TTY */
214     if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
215     {
216         msg_Warn( p_intf, "fd 0 is not a TTY" );
217         return VLC_EGENERIC;
218     }
219 #endif
220
221     psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
222     if( psz_unix_path )
223     {
224         int i_socket, i_overwrite;
225
226         i_overwrite = config_GetInt( p_intf, "rc-overwrite" );
227
228
229 #if !defined(AF_LOCAL) || defined(WIN32)
230         msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
231         free( psz_unix_path );
232         return VLC_EGENERIC;
233 #else
234         struct sockaddr_un addr;
235
236         memset( &addr, 0, sizeof(struct sockaddr_un) );
237
238         msg_Dbg( p_intf, "trying UNIX socket" );
239
240         if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
241         {
242             msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
243             free( psz_unix_path );
244             return VLC_EGENERIC;
245         }
246
247         addr.sun_family = AF_LOCAL;
248         strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
249         addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
250
251         if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
252          && (errno == EADDRINUSE)
253          && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
254          && (errno == ECONNREFUSED))
255         {
256             msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
257             unlink (psz_unix_path);
258
259             if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
260             {
261                 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
262                          psz_unix_path, strerror (errno));
263                 free (psz_unix_path);
264                 net_Close (i_socket);
265                 return VLC_EGENERIC;
266             }
267         }
268
269         if( listen( i_socket, 1 ) )
270         {
271             msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
272             free( psz_unix_path );
273             net_Close( i_socket );
274             return VLC_EGENERIC;
275         }
276
277         /* FIXME: we need a core function to merge listening sockets sets */
278         pi_socket = calloc( 2, sizeof( int ) );
279         if( pi_socket == NULL )
280         {
281             free( psz_unix_path );
282             net_Close( i_socket );
283             return VLC_ENOMEM;
284         }
285         pi_socket[0] = i_socket;
286         pi_socket[1] = -1;
287 #endif
288     }
289
290     if( ( pi_socket == NULL ) &&
291         ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
292     {
293         vlc_url_t url;
294
295         vlc_UrlParse( &url, psz_host, 0 );
296
297         msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
298
299         pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
300         if( pi_socket == NULL )
301         {
302             msg_Warn( p_intf, "can't listen to %s port %i",
303                       url.psz_host, url.i_port );
304             vlc_UrlClean( &url );
305             free( psz_host );
306             return VLC_EGENERIC;
307         }
308
309         vlc_UrlClean( &url );
310         free( psz_host );
311     }
312
313     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
314     if( !p_intf->p_sys )
315     {
316         msg_Err( p_intf, "no memory" );
317         return VLC_ENOMEM;
318     }
319
320     p_intf->p_sys->pi_socket_listen = pi_socket;
321     p_intf->p_sys->i_socket = -1;
322     p_intf->p_sys->psz_unix_path = psz_unix_path;
323     vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
324     p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
325
326     /* Non-buffered stdout */
327     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
328
329     p_intf->pf_run = Run;
330
331 #ifdef WIN32
332     p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
333     if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
334 #else
335     CONSOLE_INTRO_MSG;
336 #endif
337
338     msg_rc( _("Remote control interface initialized. Type `help' for help.") );
339     return VLC_SUCCESS;
340 }
341
342 /*****************************************************************************
343  * Deactivate: uninitialize and cleanup
344  *****************************************************************************/
345 static void Deactivate( vlc_object_t *p_this )
346 {
347     intf_thread_t *p_intf = (intf_thread_t*)p_this;
348
349     net_ListenClose( p_intf->p_sys->pi_socket_listen );
350     if( p_intf->p_sys->i_socket != -1 )
351         net_Close( p_intf->p_sys->i_socket );
352     if( p_intf->p_sys->psz_unix_path != NULL )
353     {
354 #if defined(AF_LOCAL) && !defined(WIN32)
355         unlink( p_intf->p_sys->psz_unix_path );
356 #endif
357         free( p_intf->p_sys->psz_unix_path );
358     }
359     vlc_mutex_destroy( &p_intf->p_sys->status_lock );
360     free( p_intf->p_sys );
361 }
362
363 /*****************************************************************************
364  * RegisterCallbacks: Register callbacks to dynamic variables
365  *****************************************************************************/
366 static void RegisterCallbacks( intf_thread_t *p_intf )
367 {
368     /* Register commands that will be cleaned up upon object destruction */
369     var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
370     var_AddCallback( p_intf, "quit", Quit, NULL );
371     var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
372     var_AddCallback( p_intf, "intf", Intf, NULL );
373
374     var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
375     var_AddCallback( p_intf, "add", Playlist, NULL );
376     var_Create( p_intf, "repeat", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
377     var_AddCallback( p_intf, "repeat", Playlist, NULL );
378     var_Create( p_intf, "loop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
379     var_AddCallback( p_intf, "loop", Playlist, NULL );
380     var_Create( p_intf, "enqueue", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
381     var_AddCallback( p_intf, "enqueue", Playlist, NULL );
382     var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
383     var_AddCallback( p_intf, "playlist", Playlist, NULL );
384     var_Create( p_intf, "sort", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
385     var_AddCallback( p_intf, "sort", Playlist, NULL );
386     var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
387     var_AddCallback( p_intf, "play", Playlist, NULL );
388     var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
389     var_AddCallback( p_intf, "stop", Playlist, NULL );
390     var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
391     var_AddCallback( p_intf, "clear", Playlist, NULL );
392     var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
393     var_AddCallback( p_intf, "prev", Playlist, NULL );
394     var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
395     var_AddCallback( p_intf, "next", Playlist, NULL );
396     var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397     var_AddCallback( p_intf, "goto", Playlist, NULL );
398     var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399     var_AddCallback( p_intf, "status", Playlist, NULL );
400
401     /* marquee on the fly items */
402     var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
403     var_AddCallback( p_intf, "marq-marquee", Other, NULL );
404     var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
405     var_AddCallback( p_intf, "marq-x", Other, NULL );
406     var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
407     var_AddCallback( p_intf, "marq-y", Other, NULL );
408     var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
409     var_AddCallback( p_intf, "marq-position", Other, NULL );
410     var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
411     var_AddCallback( p_intf, "marq-color", Other, NULL );
412     var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
413     var_AddCallback( p_intf, "marq-opacity", Other, NULL );
414     var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
415     var_AddCallback( p_intf, "marq-timeout", Other, NULL );
416     var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
417     var_AddCallback( p_intf, "marq-size", Other, NULL );
418
419     var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420     var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
421     var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
422     var_AddCallback( p_intf, "mosaic-height", Other, NULL );
423     var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
424     var_AddCallback( p_intf, "mosaic-width", Other, NULL );
425     var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
426     var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
427     var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
428     var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
429     var_Create( p_intf, "mosaic-offsets", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
430     var_AddCallback( p_intf, "mosaic-offsets", Other, NULL );
431     var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
432     var_AddCallback( p_intf, "mosaic-align", Other, NULL );
433     var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
434     var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
435     var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
436     var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
437     var_Create( p_intf, "mosaic-position",
438                      VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
439     var_AddCallback( p_intf, "mosaic-position", Other, NULL );
440     var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
441     var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
442     var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
443     var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
444     var_Create( p_intf, "mosaic-order", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
445     var_AddCallback( p_intf, "mosaic-order", Other, NULL );
446     var_Create( p_intf, "mosaic-keep-aspect-ratio",
447                      VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448     var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
449
450     /* logo on the fly items */
451     var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
452     var_AddCallback( p_intf, "logo-file", Other, NULL );
453     var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
454     var_AddCallback( p_intf, "logo-x", Other, NULL );
455     var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
456     var_AddCallback( p_intf, "logo-y", Other, NULL );
457     var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
458     var_AddCallback( p_intf, "logo-position", Other, NULL );
459     var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
460     var_AddCallback( p_intf, "logo-transparency", Other, NULL );
461
462     /* OSD menu commands */
463     var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
464     var_AddCallback( p_intf, "menu", Menu, NULL );
465
466     /* DVD commands */
467     var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
468     var_AddCallback( p_intf, "pause", Input, NULL );
469     var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
470     var_AddCallback( p_intf, "seek", Input, NULL );
471     var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
472     var_AddCallback( p_intf, "title", Input, NULL );
473     var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
474     var_AddCallback( p_intf, "title_n", Input, NULL );
475     var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
476     var_AddCallback( p_intf, "title_p", Input, NULL );
477     var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
478     var_AddCallback( p_intf, "chapter", Input, NULL );
479     var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
480     var_AddCallback( p_intf, "chapter_n", Input, NULL );
481     var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
482     var_AddCallback( p_intf, "chapter_p", Input, NULL );
483
484     var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
485     var_AddCallback( p_intf, "fastforward", Input, NULL );
486     var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
487     var_AddCallback( p_intf, "rewind", Input, NULL );
488     var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
489     var_AddCallback( p_intf, "faster", Input, NULL );
490     var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491     var_AddCallback( p_intf, "slower", Input, NULL );
492     var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
493     var_AddCallback( p_intf, "normal", Input, NULL );
494
495     var_Create( p_intf, "atrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
496     var_AddCallback( p_intf, "atrack", Input, NULL );
497     var_Create( p_intf, "vtrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
498     var_AddCallback( p_intf, "vtrack", Input, NULL );
499     var_Create( p_intf, "strack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
500     var_AddCallback( p_intf, "strack", Input, NULL );
501
502     /* video commands */
503     var_Create( p_intf, "vratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
504     var_AddCallback( p_intf, "vratio", VideoConfig, NULL );
505     var_Create( p_intf, "vcrop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
506     var_AddCallback( p_intf, "vcrop", VideoConfig, NULL );
507     var_Create( p_intf, "vzoom", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
508     var_AddCallback( p_intf, "vzoom", VideoConfig, NULL );
509
510     /* audio commands */
511     var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
512     var_AddCallback( p_intf, "volume", Volume, NULL );
513     var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
514     var_AddCallback( p_intf, "volup", VolumeMove, NULL );
515     var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
516     var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
517     var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
518     var_AddCallback( p_intf, "adev", AudioConfig, NULL );
519     var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
520     var_AddCallback( p_intf, "achan", AudioConfig, NULL );
521 }
522
523 /*****************************************************************************
524  * Run: rc thread
525  *****************************************************************************
526  * This part of the interface is in a separate thread so that we can call
527  * exec() from within it without annoying the rest of the program.
528  *****************************************************************************/
529 static void Run( intf_thread_t *p_intf )
530 {
531     input_thread_t * p_input;
532     playlist_t *     p_playlist;
533
534     char       p_buffer[ MAX_LINE_LENGTH + 1 ];
535     vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
536     vlc_bool_t b_longhelp = VLC_FALSE;
537
538     int        i_size = 0;
539     int        i_oldpos = 0;
540     int        i_newpos;
541
542     p_buffer[0] = 0;
543     p_input = NULL;
544     p_playlist = NULL;
545
546     /* Register commands that will be cleaned up upon object destruction */
547     RegisterCallbacks( p_intf );
548
549     /* status callbacks */
550     /* Listen to audio volume updates */
551     var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
552
553 #ifdef WIN32
554     /* Get the file descriptor of the console input */
555     p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
556     if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
557     {
558         msg_Err( p_intf, "couldn't find user input handle" );
559         p_intf->b_die = VLC_TRUE;
560     }
561 #endif
562
563     while( !intf_ShouldDie( p_intf ) )
564     {
565         char *psz_cmd, *psz_arg;
566         vlc_bool_t b_complete;
567
568         if( p_intf->p_sys->pi_socket_listen != NULL &&
569             p_intf->p_sys->i_socket == -1 )
570         {
571             p_intf->p_sys->i_socket =
572                 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
573         }
574
575         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
576
577         /* Manage the input part */
578         if( p_input == NULL )
579         {
580             if( p_playlist )
581             {
582                 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
583                                                        FIND_CHILD );
584             }
585             else
586             {
587                 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
588                                                    FIND_ANYWHERE );
589                 if( p_input )
590                 {
591                     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
592                                                            FIND_PARENT );
593                 }
594             }
595             /* New input has been registered */
596             if( p_input )
597             {
598                 if( !p_input->b_dead || !p_input->b_die )
599                 {
600                     msg_rc( STATUS_CHANGE "( new input: %s )", p_input->input.p_item->psz_uri );
601                     msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
602                 }
603                 var_AddCallback( p_input, "state", StateChanged, p_intf );
604                 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
605                 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
606                 var_AddCallback( p_input, "rate", RateChanged, p_intf );
607                 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
608             }
609         }
610         else if( p_input->b_dead )
611         {
612             var_DelCallback( p_input, "state", StateChanged, p_intf );
613             var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
614             var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
615             var_DelCallback( p_input, "rate", RateChanged, p_intf );
616             var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
617             vlc_object_release( p_input );
618             p_input = NULL;
619
620             if( p_playlist )
621             {
622                 vlc_mutex_lock( &p_playlist->object_lock );
623                 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
624                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
625                 vlc_mutex_unlock( &p_playlist->object_lock );
626             }
627         }
628
629         if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
630             (p_playlist != NULL) )
631         {
632             vlc_mutex_lock( &p_playlist->object_lock );
633             if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
634                 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
635             {
636                 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
637                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
638             }
639             else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
640                 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
641             {
642                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
643                 msg_rc( STATUS_CHANGE "( play state: 1 )" );
644             }
645             else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
646                 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
647             {
648                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
649                 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
650             }
651             vlc_mutex_unlock( &p_playlist->object_lock );
652         }
653
654         if( p_input && b_showpos )
655         {
656             i_newpos = 100 * var_GetFloat( p_input, "position" );
657             if( i_oldpos != i_newpos )
658             {
659                 i_oldpos = i_newpos;
660                 msg_rc( "pos: %d%%", i_newpos );
661             }
662         }
663
664         /* Is there something to do? */
665         if( !b_complete ) continue;
666
667
668         /* Skip heading spaces */
669         psz_cmd = p_buffer;
670         while( *psz_cmd == ' ' )
671         {
672             psz_cmd++;
673         }
674
675         /* Split psz_cmd at the first space and make sure that
676          * psz_arg is valid */
677         psz_arg = strchr( psz_cmd, ' ' );
678         if( psz_arg )
679         {
680             *psz_arg++ = 0;
681             while( *psz_arg == ' ' )
682             {
683                 psz_arg++;
684             }
685         }
686         else
687         {
688             psz_arg = "";
689         }
690
691         /* If the user typed a registered local command, try it */
692         if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
693         {
694             vlc_value_t val;
695             int i_ret;
696
697             val.psz_string = psz_arg;
698             i_ret = var_Set( p_intf, psz_cmd, val );
699             msg_rc( "%s: returned %i (%s)",
700                     psz_cmd, i_ret, vlc_error( i_ret ) );
701         }
702         /* Or maybe it's a global command */
703         else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
704         {
705             vlc_value_t val;
706             int i_ret;
707
708             val.psz_string = psz_arg;
709             /* FIXME: it's a global command, but we should pass the
710              * local object as an argument, not p_intf->p_libvlc_global. */
711             i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
712             if( i_ret != 0 )
713             {
714                 msg_rc( "%s: returned %i (%s)",
715                          psz_cmd, i_ret, vlc_error( i_ret ) );
716             }
717         }
718         else if( !strcmp( psz_cmd, "logout" ) )
719         {
720             /* Close connection */
721             if( p_intf->p_sys->i_socket != -1 )
722             {
723                 net_Close( p_intf->p_sys->i_socket );
724             }
725             p_intf->p_sys->i_socket = -1;
726         }
727         else if( !strcmp( psz_cmd, "info" ) )
728         {
729             if( p_input )
730             {
731                 int i, j;
732                 vlc_mutex_lock( &p_input->input.p_item->lock );
733                 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
734                 {
735                     info_category_t *p_category =
736                         p_input->input.p_item->pp_categories[i];
737
738                     msg_rc( "+----[ %s ]", p_category->psz_name );
739                     msg_rc( "| " );
740                     for ( j = 0; j < p_category->i_infos; j++ )
741                     {
742                         info_t *p_info = p_category->pp_infos[j];
743                         msg_rc( "| %s: %s", p_info->psz_name,
744                                 p_info->psz_value );
745                     }
746                     msg_rc( "| " );
747                 }
748                 msg_rc( "+----[ end of stream info ]" );
749                 vlc_mutex_unlock( &p_input->input.p_item->lock );
750             }
751             else
752             {
753                 msg_rc( "no input" );
754             }
755         }
756         else if( !strcmp( psz_cmd, "is_playing" ) )
757         {
758             if( ! p_input )
759             {
760                 msg_rc( "0" );
761             }
762             else
763             {
764                 msg_rc( "1" );
765             }
766         }
767         else if( !strcmp( psz_cmd, "get_time" ) )
768         {
769             if( ! p_input )
770             {
771                 msg_rc("0");
772             }
773             else
774             {
775                 vlc_value_t time;
776                 var_Get( p_input, "time", &time );
777                 msg_rc( "%i", time.i_time / 1000000);
778             }
779         }
780         else if( !strcmp( psz_cmd, "get_length" ) )
781         {
782             if( ! p_input )
783             {
784                 msg_rc("0");
785             }
786             else
787             {
788                 vlc_value_t time;
789                 var_Get( p_input, "length", &time );
790                 msg_rc( "%i", time.i_time / 1000000);
791             }
792         }
793         else if( !strcmp( psz_cmd, "get_title" ) )
794         {
795             if( ! p_input )
796             {
797                 msg_rc("");
798             }
799             else
800             {
801                 msg_rc( "%s", p_input->input.p_item->psz_name );
802             }
803         }
804         else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
805                  || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
806         {
807             if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
808                  b_longhelp = VLC_TRUE;
809             else b_longhelp = VLC_FALSE;
810
811             Help( p_intf, b_longhelp );
812         }
813         else if( !strcmp( psz_cmd, "check-updates" ) )
814         {
815             checkUpdates( p_intf, psz_arg );
816         }
817         else switch( psz_cmd[0] )
818         {
819         case 'f':
820         case 'F':
821             if( p_input )
822             {
823                 vout_thread_t *p_vout;
824                 p_vout = vlc_object_find( p_input,
825                                           VLC_OBJECT_VOUT, FIND_CHILD );
826
827                 if( p_vout )
828                 {
829                     vlc_value_t val;
830                     vlc_bool_t b_update = VLC_FALSE;
831                     var_Get( p_vout, "fullscreen", &val );
832                     val.b_bool = !val.b_bool;
833                     if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
834                     {
835                         b_update = VLC_TRUE;
836                         val.b_bool = VLC_TRUE;
837                     }
838                     else if( !strncmp(psz_arg, "off", 3)  && (val.b_bool == VLC_FALSE) )
839                     {
840                         b_update = VLC_TRUE;
841                         val.b_bool = VLC_FALSE;
842                     }
843                     else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
844                         b_update = VLC_TRUE;
845                     if( b_update ) var_Set( p_vout, "fullscreen", val );
846                     vlc_object_release( p_vout );
847                 }
848             }
849             break;
850
851         case 's':
852         case 'S':
853             ;
854             break;
855
856         case '\0':
857             /* Ignore empty lines */
858             break;
859
860         default:
861             msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
862             break;
863         }
864
865         /* Command processed */
866         i_size = 0; p_buffer[0] = 0;
867     }
868
869     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
870     msg_rc( STATUS_CHANGE "( quit )" );
871
872     if( p_input )
873     {
874         var_DelCallback( p_input, "state", StateChanged, p_intf );
875         var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
876         var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
877         var_DelCallback( p_input, "rate", RateChanged, p_intf );
878         var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
879         vlc_object_release( p_input );
880         p_input = NULL;
881     }
882
883     if( p_playlist )
884     {
885         vlc_object_release( p_playlist );
886         p_playlist = NULL;
887     }
888
889     var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
890 }
891
892 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
893 {
894     msg_rc(_("+----[ Remote control commands ]"));
895     msg_rc(  "| ");
896     msg_rc(_("| add XYZ  . . . . . . . . . . add XYZ to playlist"));
897     msg_rc(_("| enqueue XYZ  . . . . . . . queue XYZ to playlist"));
898     msg_rc(_("| playlist . . .  show items currently in playlist"));
899     msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
900     msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
901     msg_rc(_("| next . . . . . . . . . . . .  next playlist item"));
902     msg_rc(_("| prev . . . . . . . . . .  previous playlist item"));
903     msg_rc(_("| goto . . . . . . . . . . . .  goto item at index"));
904     msg_rc(_("| repeat [on|off] . .  toggle playlist item repeat"));
905     msg_rc(_("| loop [on|off] . . . .  toggle playlist item loop"));
906     msg_rc(_("| clear . . . . . . . . . . .   clear the playlist"));
907     msg_rc(_("| status . . . . . . . . . current playlist status"));
908     msg_rc(_("| title [X]  . . . . set/get title in current item"));
909     msg_rc(_("| title_n  . . . . . .  next title in current item"));
910     msg_rc(_("| title_p  . . . .  previous title in current item"));
911     msg_rc(_("| chapter [X]  . . set/get chapter in current item"));
912     msg_rc(_("| chapter_n  . . . .  next chapter in current item"));
913     msg_rc(_("| chapter_p  . .  previous chapter in current item"));
914     msg_rc(  "| ");
915     msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
916     msg_rc(_("| pause  . . . . . . . . . . . . . .  toggle pause"));
917     msg_rc(_("| fastforward  . . . . . .  .  set to maximum rate"));
918     msg_rc(_("| rewind  . . . . . . . . . .  set to minimum rate"));
919     msg_rc(_("| faster . . . . . . . .  faster playing of stream"));
920     msg_rc(_("| slower . . . . . . . .  slower playing of stream"));
921     msg_rc(_("| normal . . . . . . . .  normal playing of stream"));
922     msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
923     msg_rc(_("| info . . .  information about the current stream"));
924     msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
925     msg_rc(_("| is_playing . .  1 if a stream plays, 0 otherwise"));
926     msg_rc(_("| get_title . . .  the title of the current stream"));
927     msg_rc(_("| get_length . .  the length of the current stream"));
928     msg_rc(  "| ");
929     msg_rc(_("| volume [X] . . . . . . . .  set/get audio volume"));
930     msg_rc(_("| volup [X]  . . . . .  raise audio volume X steps"));
931     msg_rc(_("| voldown [X]  . . . .  lower audio volume X steps"));
932     msg_rc(_("| adev [X] . . . . . . . . .  set/get audio device"));
933     msg_rc(_("| achan [X]. . . . . . . .  set/get audio channels"));
934     msg_rc(_("| atrack [X] . . . . . . . . . set/get audio track"));
935     msg_rc(_("| vtrack [X] . . . . . . . . . set/get video track"));
936     msg_rc(_("| vratio [X]  . . . . . set/get video aspect ratio"));
937     msg_rc(_("| vcrop [X]  . . . . . . . . .  set/get video crop"));
938     msg_rc(_("| vzoom [X]  . . . . . . . . .  set/get video zoom"));
939     msg_rc(_("| strack [X] . . . . . . . set/get subtitles track"));
940     msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
941     msg_rc(  "| ");
942
943     if (b_longhelp)
944     {
945         msg_rc(_("| marq-marquee STRING  . . overlay STRING in video"));
946         msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
947         msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
948         msg_rc(_("| marq-position #. . .  .relative position control"));
949         msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
950         msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
951         msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
952         msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
953         msg_rc(  "| ");
954         msg_rc(_("| logo-file STRING . . .the overlay file path/name"));
955         msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
956         msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
957         msg_rc(_("| logo-position #. . . . . . . . relative position"));
958         msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
959         msg_rc(  "| ");
960         msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
961         msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
962         msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
963         msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
964         msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
965         msg_rc(_("| mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
966         msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
967         msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
968         msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
969         msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
970         msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
971         msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
972         msg_rc(_("| mosaic-order id(,id)* . . . . order of pictures "));
973         msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
974         msg_rc(  "| ");
975         msg_rc(_("| check-updates [newer] [equal] [older]\n"
976                  "|               [undef] [info] [source] [binary] [plugin]"));
977         msg_rc(  "| ");
978     }
979     msg_rc(_("| help . . . . . . . . . . . . . this help message"));
980     msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
981     msg_rc(_("| logout . . . . .  exit (if in socket connection)"));
982     msg_rc(_("| quit . . . . . . . . . . . . . . . . .  quit vlc"));
983     msg_rc(  "| ");
984     msg_rc(_("+----[ end of help ]"));
985 }
986
987 /********************************************************************
988  * Status callback routines
989  ********************************************************************/
990 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
991     vlc_value_t oldval, vlc_value_t newval, void *p_data )
992 {
993     intf_thread_t *p_intf = (intf_thread_t*)p_data;
994     input_thread_t *p_input = NULL;
995
996     vlc_mutex_lock( &p_intf->p_sys->status_lock );
997     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
998     if( p_input )
999     {
1000         msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
1001         vlc_object_release( p_input );
1002     }
1003     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1004     return VLC_SUCCESS;
1005 }
1006
1007 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
1008     vlc_value_t oldval, vlc_value_t newval, void *p_data )
1009 {
1010     intf_thread_t *p_intf = (intf_thread_t*)p_data;
1011
1012     vlc_mutex_lock( &p_intf->p_sys->status_lock );
1013     msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
1014     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1015     return VLC_SUCCESS;
1016 }
1017
1018 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
1019     vlc_value_t oldval, vlc_value_t newval, void *p_data )
1020 {
1021     intf_thread_t *p_intf = (intf_thread_t*)p_data;
1022     playlist_t    *p_playlist = NULL;
1023     input_thread_t *p_input = NULL;
1024
1025     vlc_mutex_lock( &p_intf->p_sys->status_lock );
1026     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1027     if( p_input )
1028     {
1029         p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1030         if( p_playlist )
1031         {
1032             char cmd[5] = "";
1033             switch( p_playlist->status.i_status )
1034             {
1035             case PLAYLIST_STOPPED:
1036                 strncpy( &cmd[0], "stop", 4);
1037                 cmd[4] = '\0';
1038                 break;
1039             case PLAYLIST_RUNNING:
1040                 strncpy( &cmd[0], "play", 4);
1041                 cmd[4] = '\0';
1042                 break;
1043             case PLAYLIST_PAUSED:
1044                 strncpy( &cmd[0], "pause", 5);
1045                 cmd[5] = '\0';
1046                 break;
1047             } /* var_GetInteger( p_input, "state" )  */
1048             msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1049             vlc_object_release( p_playlist );
1050         }
1051         vlc_object_release( p_input );
1052     }
1053     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1054     return VLC_SUCCESS;
1055 }
1056
1057 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1058     vlc_value_t oldval, vlc_value_t newval, void *p_data )
1059 {
1060     intf_thread_t *p_intf = (intf_thread_t*)p_data;
1061     input_thread_t *p_input = NULL;
1062
1063     vlc_mutex_lock( &p_intf->p_sys->status_lock );
1064     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1065     if( p_input )
1066     {
1067         msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1068         vlc_object_release( p_input );
1069     }
1070     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1071     return VLC_SUCCESS;
1072 }
1073
1074 /********************************************************************
1075  * Command routines
1076  ********************************************************************/
1077 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1078                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
1079 {
1080     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1081     input_thread_t *p_input;
1082     vlc_value_t     val;
1083
1084     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1085     if( !p_input ) return VLC_ENOOBJ;
1086
1087     var_Get( p_input, "state", &val );
1088     if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1089         ( strcmp( psz_cmd, "pause" ) != 0 ) )
1090     {
1091         msg_rc( _("Press menu select or pause to continue.") );
1092         vlc_object_release( p_input );
1093         return VLC_EGENERIC;
1094     }
1095
1096     /* Parse commands that only require an input */
1097     if( !strcmp( psz_cmd, "pause" ) )
1098     {
1099         val.i_int = config_GetInt( p_intf, "key-play-pause" );
1100         var_Set( p_intf->p_libvlc, "key-pressed", val );
1101         vlc_object_release( p_input );
1102         return VLC_SUCCESS;
1103     }
1104     else if( !strcmp( psz_cmd, "seek" ) )
1105     {
1106         if( strlen( newval.psz_string ) > 0 &&
1107             newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1108         {
1109             val.f_float = (float)atof( newval.psz_string ) / 100.0;
1110             var_Set( p_input, "position", val );
1111         }
1112         else
1113         {
1114             val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1115             var_Set( p_input, "time", val );
1116         }
1117         vlc_object_release( p_input );
1118         return VLC_SUCCESS;
1119     }
1120     else if ( !strcmp( psz_cmd, "fastforward" ) )
1121     {
1122         val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1123         var_Set( p_intf->p_libvlc, "key-pressed", val );
1124         vlc_object_release( p_input );
1125         return VLC_SUCCESS;
1126     }
1127     else if ( !strcmp( psz_cmd, "rewind" ) )
1128     {
1129         val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1130         var_Set( p_intf->p_libvlc, "key-pressed", val );
1131         vlc_object_release( p_input );
1132         return VLC_SUCCESS;
1133     }
1134     else if ( !strcmp( psz_cmd, "faster" ) )
1135     {
1136         val.b_bool = VLC_TRUE;
1137         var_Set( p_input, "rate-faster", val );
1138         vlc_object_release( p_input );
1139         return VLC_SUCCESS;
1140     }
1141     else if ( !strcmp( psz_cmd, "slower" ) )
1142     {
1143         val.b_bool = VLC_TRUE;
1144         var_Set( p_input, "rate-slower", val );
1145         vlc_object_release( p_input );
1146         return VLC_SUCCESS;
1147     }
1148     else if ( !strcmp( psz_cmd, "normal" ) )
1149     {
1150         val.i_int = INPUT_RATE_DEFAULT;
1151         var_Set( p_input, "rate", val );
1152         vlc_object_release( p_input );
1153         return VLC_SUCCESS;
1154     }
1155     else if( !strcmp( psz_cmd, "chapter" ) ||
1156              !strcmp( psz_cmd, "chapter_n" ) ||
1157              !strcmp( psz_cmd, "chapter_p" ) )
1158     {
1159         if( !strcmp( psz_cmd, "chapter" ) )
1160         {
1161             if ( *newval.psz_string )
1162             {
1163                 /* Set. */
1164                 val.i_int = atoi( newval.psz_string );
1165                 var_Set( p_input, "chapter", val );
1166             }
1167             else
1168             {
1169                 vlc_value_t val_list;
1170
1171                 /* Get. */
1172                 var_Get( p_input, "chapter", &val );
1173                 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1174                             &val_list, NULL );
1175                 msg_rc( "Currently playing chapter %d/%d.",
1176                         val.i_int, val_list.p_list->i_count );
1177                 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1178                             &val_list, NULL );
1179             }
1180         }
1181         else if( !strcmp( psz_cmd, "chapter_n" ) )
1182         {
1183             val.b_bool = VLC_TRUE;
1184             var_Set( p_input, "next-chapter", val );
1185         }
1186         else if( !strcmp( psz_cmd, "chapter_p" ) )
1187         {
1188             val.b_bool = VLC_TRUE;
1189             var_Set( p_input, "prev-chapter", val );
1190         }
1191         vlc_object_release( p_input );
1192         return VLC_SUCCESS;
1193     }
1194     else if( !strcmp( psz_cmd, "title" ) ||
1195              !strcmp( psz_cmd, "title_n" ) ||
1196              !strcmp( psz_cmd, "title_p" ) )
1197     {
1198         if( !strcmp( psz_cmd, "title" ) )
1199         {
1200             if ( *newval.psz_string )
1201             {
1202                 /* Set. */
1203                 val.i_int = atoi( newval.psz_string );
1204                 var_Set( p_input, "title", val );
1205             }
1206             else
1207             {
1208                 vlc_value_t val_list;
1209
1210                 /* Get. */
1211                 var_Get( p_input, "title", &val );
1212                 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1213                             &val_list, NULL );
1214                 msg_rc( "Currently playing title %d/%d.",
1215                         val.i_int, val_list.p_list->i_count );
1216                 var_Change( p_this, "title", VLC_VAR_FREELIST,
1217                             &val_list, NULL );
1218             }
1219         }
1220         else if( !strcmp( psz_cmd, "title_n" ) )
1221         {
1222             val.b_bool = VLC_TRUE;
1223             var_Set( p_input, "next-title", val );
1224         }
1225         else if( !strcmp( psz_cmd, "title_p" ) )
1226         {
1227             val.b_bool = VLC_TRUE;
1228             var_Set( p_input, "prev-title", val );
1229         }
1230
1231         vlc_object_release( p_input );
1232         return VLC_SUCCESS;
1233     }
1234     else if(    !strcmp( psz_cmd, "atrack" )
1235              || !strcmp( psz_cmd, "vtrack" )
1236              || !strcmp( psz_cmd, "strack" ) )
1237     {
1238         char *psz_variable;
1239         vlc_value_t val_name;
1240         int i_error;
1241
1242         if( !strcmp( psz_cmd, "atrack" ) )
1243         {
1244             psz_variable = "audio-es";
1245         }
1246         else if( !strcmp( psz_cmd, "vtrack" ) )
1247         {
1248             psz_variable = "video-es";
1249         }
1250         else
1251         {
1252             psz_variable = "spu-es";
1253         }
1254
1255         /* Get the descriptive name of the variable */
1256         var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1257                      &val_name, NULL );
1258         if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1259
1260         if( newval.psz_string && *newval.psz_string )
1261         {
1262             /* set */
1263             vlc_value_t val;
1264             val.i_int = atoi( newval.psz_string );
1265
1266             i_error = var_Set( p_input, psz_variable, val );
1267         }
1268         else
1269         {
1270             /* get */
1271             vlc_value_t val, text;
1272             int i, i_value;
1273
1274             if ( var_Get( p_input, psz_variable, &val ) < 0 )
1275             {
1276                 vlc_object_release( p_input );
1277                 return VLC_EGENERIC;
1278             }
1279             i_value = val.i_int;
1280
1281             if ( var_Change( p_input, psz_variable,
1282                              VLC_VAR_GETLIST, &val, &text ) < 0 )
1283             {
1284                 vlc_object_release( p_input );
1285                 return VLC_EGENERIC;
1286             }
1287
1288             msg_rc( "+----[ %s ]", val_name.psz_string );
1289             for ( i = 0; i < val.p_list->i_count; i++ )
1290             {
1291                 if ( i_value == val.p_list->p_values[i].i_int )
1292                     msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1293                             text.p_list->p_values[i].psz_string );
1294                 else
1295                     msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1296                             text.p_list->p_values[i].psz_string );
1297             }
1298             var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1299                         &val, &text );
1300             msg_rc( "+----[ end of %s ]", val_name.psz_string );
1301
1302             if( val_name.psz_string ) free( val_name.psz_string );
1303
1304             i_error = VLC_SUCCESS;
1305         }
1306         vlc_object_release( p_input );
1307         return i_error;
1308     }
1309
1310     /* Never reached. */
1311     vlc_object_release( p_input );
1312     return VLC_EGENERIC;
1313 }
1314
1315 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1316                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
1317 {
1318     vlc_value_t val;
1319
1320     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1321     playlist_t *p_playlist = pl_Yield( p_this );
1322
1323     PL_LOCK;
1324     if( p_playlist->p_input )
1325     {
1326         var_Get( p_playlist->p_input, "state", &val );
1327         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1328         {
1329             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1330             vlc_object_release( p_playlist );
1331             PL_UNLOCK;
1332             return VLC_EGENERIC;
1333         }
1334     }
1335     PL_UNLOCK;
1336
1337     /* Parse commands that require a playlist */
1338     if( !strcmp( psz_cmd, "prev" ) )
1339     {
1340         playlist_Prev( p_playlist );
1341     }
1342     else if( !strcmp( psz_cmd, "next" ) )
1343     {
1344         playlist_Next( p_playlist );
1345     }
1346     else if( !strcmp( psz_cmd, "play" ) )
1347     {
1348         msg_Warn( p_playlist, "play" );
1349         playlist_Play( p_playlist );
1350     }
1351     else if( !strcmp( psz_cmd, "repeat" ) )
1352     {
1353         vlc_bool_t b_update = VLC_TRUE;
1354
1355         var_Get( p_playlist, "repeat", &val );
1356
1357         if( strlen( newval.psz_string ) > 0 )
1358         {
1359             if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1360                  ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1361             {
1362                 b_update = VLC_FALSE;
1363             }
1364         }
1365
1366         if ( b_update )
1367         {
1368             val.b_bool = !val.b_bool;
1369             var_Set( p_playlist, "repeat", val );
1370         }
1371         msg_rc( "Setting repeat to %d", val.b_bool );
1372     }
1373     else if( !strcmp( psz_cmd, "loop" ) )
1374     {
1375         vlc_bool_t b_update = VLC_TRUE;
1376
1377         var_Get( p_playlist, "loop", &val );
1378
1379         if( strlen( newval.psz_string ) > 0 )
1380         {
1381             if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1382                  ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1383             {
1384                 b_update = VLC_FALSE;
1385             }
1386         }
1387
1388         if ( b_update )
1389         {
1390             val.b_bool = !val.b_bool;
1391             var_Set( p_playlist, "loop", val );
1392         }
1393         msg_rc( "Setting loop to %d", val.b_bool );
1394     }
1395     else if (!strcmp( psz_cmd, "goto" ) )
1396     {
1397         msg_rc( _("goto is deprecated" ) );
1398         msg_Err( p_playlist, "goto is deprecated" );
1399     }
1400     else if( !strcmp( psz_cmd, "stop" ) )
1401     {
1402         playlist_Stop( p_playlist );
1403     }
1404     else if( !strcmp( psz_cmd, "clear" ) )
1405     {
1406         playlist_Stop( p_playlist );
1407         vlc_mutex_lock( &p_playlist->object_lock );
1408         playlist_Clear( p_playlist );
1409         vlc_mutex_unlock( &p_playlist->object_lock );
1410     }
1411     else if( !strcmp( psz_cmd, "add" ) &&
1412              newval.psz_string && *newval.psz_string )
1413     {
1414         input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1415
1416         if( p_item )
1417         {
1418             msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1419             playlist_PlaylistAddInput( p_playlist, p_item,
1420                               PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1421         }
1422     }
1423     else if( !strcmp( psz_cmd, "enqueue" ) &&
1424              newval.psz_string && *newval.psz_string )
1425     {
1426         input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1427
1428         if( p_item )
1429         {
1430             msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1431             playlist_PlaylistAddInput( p_playlist, p_item,
1432                               PLAYLIST_APPEND, PLAYLIST_END );
1433         }
1434     }
1435     else if( !strcmp( psz_cmd, "playlist" ) )
1436     {
1437         msg_Dbg( p_playlist, "Dumping category" );
1438         playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1439         msg_Dbg( p_playlist, "Dumping Onelevel" );
1440         playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1441     }
1442     else if( !strcmp( psz_cmd, "sort" ))
1443     {
1444         playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel, 
1445                                     SORT_ARTIST, ORDER_NORMAL );
1446     }
1447     else if( !strcmp( psz_cmd, "status" ) )
1448     {
1449         if( p_playlist->p_input )
1450         {
1451             /* Replay the current state of the system. */
1452             msg_rc( STATUS_CHANGE "( new input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1453             msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1454
1455             vlc_mutex_lock( &p_playlist->object_lock );
1456             switch( p_playlist->status.i_status )
1457             {
1458                 case PLAYLIST_STOPPED:
1459                     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1460                     break;
1461                 case PLAYLIST_RUNNING:
1462                     msg_rc( STATUS_CHANGE "( play state: 1 )" );
1463                     break;
1464                 case PLAYLIST_PAUSED:
1465                     msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1466                     break;
1467                 default:
1468                     msg_rc( STATUS_CHANGE "( state unknown )" );
1469                     break;
1470             }
1471             vlc_mutex_unlock( &p_playlist->object_lock );
1472         }
1473     }
1474
1475     /*
1476      * sanity check
1477      */
1478     else
1479     {
1480         msg_rc( "unknown command!" );
1481     }
1482
1483     vlc_object_release( p_playlist );
1484     return VLC_SUCCESS;
1485 }
1486
1487 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1488                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
1489 {
1490     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1491     vlc_object_t  *p_playlist;
1492     vlc_value_t    val;
1493     vlc_object_t  *p_input;
1494
1495     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1496     if( !p_playlist )
1497     {
1498         return VLC_ENOOBJ;
1499     }
1500
1501     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1502     if( !p_input )
1503     {
1504         vlc_object_release( p_playlist );
1505         return VLC_ENOOBJ;
1506     }
1507
1508     if( p_input )
1509     {
1510         var_Get( p_input, "state", &val );
1511         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1512         {
1513             msg_rc( _("Type 'pause' to continue.") );
1514             vlc_object_release( p_playlist );
1515             vlc_object_release( p_input );
1516             return VLC_EGENERIC;
1517         }
1518     }
1519
1520     /* Parse miscellaneous commands */
1521     if( !strcmp( psz_cmd, "marq-marquee" ) )
1522     {
1523         var_SetString( p_input->p_libvlc_global, "marq-marquee", newval.psz_string );
1524     }
1525     else
1526     if( strlen( newval.psz_string ) == 0)
1527     {
1528         /* All the variable above expects strlen > 0 */
1529     }
1530     else if( !strcmp( psz_cmd, "marq-x" ) )
1531     {
1532         val.i_int = atoi( newval.psz_string );
1533         var_Set( p_input->p_libvlc_global, "marq-x", val );
1534     }
1535     else if( !strcmp( psz_cmd, "marq-y" ) )
1536     {
1537         val.i_int = atoi( newval.psz_string );
1538         var_Set( p_input->p_libvlc_global, "marq-y", val );
1539     }
1540     else if( !strcmp( psz_cmd, "marq-position" ) )
1541     {
1542         val.i_int = atoi( newval.psz_string );
1543         var_Set( p_input->p_libvlc_global, "marq-position", val );
1544     }
1545     else if( !strcmp( psz_cmd, "marq-color" ) )
1546     {
1547         val.i_int = strtol( newval.psz_string, NULL, 0 );
1548         var_Set( p_input->p_libvlc_global, "marq-color", val );
1549     }
1550     else if( !strcmp( psz_cmd, "marq-opacity" ) )
1551     {
1552         val.i_int = strtol( newval.psz_string, NULL, 0 );
1553         var_Set( p_input->p_libvlc_global, "marq-opacity", val );
1554     }
1555     else if( !strcmp( psz_cmd, "marq-size" ) )
1556     {
1557         val.i_int = atoi( newval.psz_string );
1558         var_Set( p_input->p_libvlc_global, "marq-size", val );
1559     }
1560     else if( !strcmp( psz_cmd, "marq-timeout" ) )
1561     {
1562         val.i_int = atoi( newval.psz_string );
1563         var_Set( p_input, "marq-timeout", val );
1564     }
1565     else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1566     {
1567         val.i_int = atoi( newval.psz_string );
1568         var_Set( p_input->p_libvlc_global, "mosaic-alpha", val );
1569     }
1570     else if( !strcmp( psz_cmd, "mosaic-height" ) )
1571     {
1572         val.i_int = atoi( newval.psz_string );
1573         var_Set( p_input->p_libvlc_global, "mosaic-height", val );
1574     }
1575     else if( !strcmp( psz_cmd, "mosaic-width" ) )
1576     {
1577         val.i_int = atoi( newval.psz_string );
1578         var_Set( p_input->p_libvlc_global, "mosaic-width", val );
1579     }
1580     else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1581     {
1582         val.i_int = atoi( newval.psz_string );
1583         var_Set( p_input->p_libvlc_global, "mosaic-xoffset", val );
1584     }
1585     else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1586     {
1587         val.i_int = atoi( newval.psz_string );
1588         var_Set( p_input->p_libvlc_global, "mosaic-yoffset", val );
1589     }
1590     else if( !strcmp( psz_cmd, "mosaic-align" ) )
1591     {
1592         val.i_int = atoi( newval.psz_string );
1593         var_Set( p_input->p_libvlc_global, "mosaic-align", val );
1594     }
1595     else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1596     {
1597         val.i_int = atoi( newval.psz_string );
1598         var_Set( p_input->p_libvlc_global, "mosaic-vborder", val );
1599     }
1600     else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1601     {
1602         val.i_int = atoi( newval.psz_string );
1603         var_Set( p_input->p_libvlc_global, "mosaic-hborder", val );
1604     }
1605     else if( !strcmp( psz_cmd, "mosaic-position" ) )
1606     {
1607         val.i_int = atoi( newval.psz_string );
1608         var_Set( p_input->p_libvlc_global, "mosaic-position", val );
1609     }
1610     else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1611     {
1612         val.i_int = atoi( newval.psz_string );
1613         var_Set( p_input->p_libvlc_global, "mosaic-rows", val );
1614     }
1615     else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1616     {
1617         val.i_int = atoi( newval.psz_string );
1618         var_Set( p_input->p_libvlc_global, "mosaic-cols", val );
1619     }
1620     else if( !strcmp( psz_cmd, "mosaic-order" ) )
1621     {
1622         val.psz_string = newval.psz_string;
1623         var_Set( p_input->p_libvlc_global, "mosaic-order", val );
1624     }
1625     else if( !strcmp( psz_cmd, "mosaic-offsets" ) )
1626     {
1627         val.psz_string = newval.psz_string;
1628         var_Set( p_input->p_libvlc_global, "mosaic-offsets", val );
1629     }
1630     else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1631     {
1632         val.i_int = atoi( newval.psz_string );
1633         var_Set( p_input->p_libvlc_global, "mosaic-keep-aspect-ratio", val );
1634     }
1635     else if( !strcmp( psz_cmd, "logo-file" ) )
1636     {
1637         val.psz_string = newval.psz_string;
1638         var_Set( p_input->p_libvlc_global, "logo-file", val );
1639     }
1640     else if( !strcmp( psz_cmd, "logo-x" ) )
1641     {
1642         val.i_int = atoi( newval.psz_string );
1643         var_Set( p_input->p_libvlc_global, "logo-x", val );
1644     }
1645     else if( !strcmp( psz_cmd, "logo-y" ) )
1646     {
1647         val.i_int = atoi( newval.psz_string );
1648         var_Set( p_input->p_libvlc_global, "logo-y", val );
1649     }
1650     else if( !strcmp( psz_cmd, "logo-position" ) )
1651     {
1652         val.i_int = atoi( newval.psz_string );
1653         var_Set( p_input->p_libvlc_global, "logo-position", val );
1654     }
1655     else if( !strcmp( psz_cmd, "logo-transparency" ) )
1656     {
1657         val.i_int = atoi( newval.psz_string );
1658         var_Set( p_input->p_libvlc_global, "logo-transparency", val );
1659     }
1660     /*
1661      * sanity check
1662      */
1663     else
1664         msg_rc( "Unknown command!" );
1665
1666     vlc_object_release( p_playlist );
1667     vlc_object_release( p_input );
1668     return VLC_SUCCESS;
1669 }
1670
1671 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1672                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
1673 {
1674     playlist_t *p_playlist;
1675
1676     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1677     if( p_playlist )
1678     {
1679         playlist_Stop( p_playlist );
1680         vlc_object_release( p_playlist );
1681     }
1682     p_this->p_libvlc->b_die = VLC_TRUE;
1683     return VLC_SUCCESS;
1684 }
1685
1686 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1687                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
1688 {
1689     intf_thread_t *p_newintf = NULL;
1690
1691     p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1692     if( p_newintf )
1693     {
1694         p_newintf->b_block = VLC_FALSE;
1695         if( intf_RunThread( p_newintf ) )
1696         {
1697             vlc_object_detach( p_newintf );
1698             intf_Destroy( p_newintf );
1699         }
1700     }
1701
1702     return VLC_SUCCESS;
1703 }
1704
1705 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1706                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
1707 {
1708     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1709     input_thread_t *p_input = NULL;
1710     int i_error = VLC_EGENERIC;
1711
1712     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1713     if( !p_input )
1714         return VLC_ENOOBJ;
1715
1716     if( p_input )
1717     {
1718         vlc_value_t val;
1719
1720         var_Get( p_input, "state", &val );
1721         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1722         {
1723             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1724             vlc_object_release( p_input );
1725             return VLC_EGENERIC;
1726         }
1727         vlc_object_release( p_input );
1728     }
1729
1730     if ( *newval.psz_string )
1731     {
1732         /* Set. */
1733         audio_volume_t i_volume = atoi( newval.psz_string );
1734         if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1735         {
1736             msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1737                     AOUT_VOLUME_MAX );
1738             i_error = VLC_EBADVAR;
1739         }
1740         else
1741         {
1742             if( i_volume == AOUT_VOLUME_MIN )
1743             {
1744                 vlc_value_t keyval;
1745
1746                 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1747                 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1748             }
1749             i_error = aout_VolumeSet( p_this, i_volume );
1750             osd_Volume( p_this );
1751             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1752         }
1753     }
1754     else
1755     {
1756         /* Get. */
1757         audio_volume_t i_volume;
1758         if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1759         {
1760             i_error = VLC_EGENERIC;
1761         }
1762         else
1763         {
1764             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1765             i_error = VLC_SUCCESS;
1766         }
1767     }
1768
1769     return i_error;
1770 }
1771
1772 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1773                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1774 {
1775     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1776     audio_volume_t i_volume;
1777     input_thread_t *p_input = NULL;
1778     int i_nb_steps = atoi(newval.psz_string);
1779     int i_error = VLC_SUCCESS;
1780     int i_volume_step = 0;
1781
1782     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1783     if( !p_input )
1784         return VLC_ENOOBJ;
1785
1786     if( p_input )
1787     {
1788         vlc_value_t val;
1789
1790         var_Get( p_input, "state", &val );
1791         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1792         {
1793             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1794             vlc_object_release( p_input );
1795             return VLC_EGENERIC;
1796         }
1797         vlc_object_release( p_input );
1798     }
1799
1800     i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1801     if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1802     {
1803         i_nb_steps = 1;
1804     }
1805
1806     if ( !strcmp(psz_cmd, "volup") )
1807     {
1808         if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1809             i_error = VLC_EGENERIC;
1810     }
1811     else
1812     {
1813         if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1814             i_error = VLC_EGENERIC;
1815     }
1816     osd_Volume( p_this );
1817
1818     if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1819     return i_error;
1820 }
1821
1822
1823 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1824                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
1825 {
1826     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1827     input_thread_t *p_input = NULL;
1828     vout_thread_t * p_vout;
1829     const char * psz_variable;
1830     vlc_value_t val_name;
1831     int i_error;
1832
1833     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1834     if( !p_input )
1835         return VLC_ENOOBJ;
1836
1837     p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1838     vlc_object_release( p_input );
1839     if( !p_vout )
1840         return VLC_ENOOBJ;
1841
1842     if( !strcmp( psz_cmd, "vcrop" ) )
1843     {
1844         psz_variable = "crop";
1845     }
1846     else if( !strcmp( psz_cmd, "vratio" ) )
1847     {
1848         psz_variable = "aspect-ratio";
1849     }
1850     else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1851     {
1852         psz_variable = "zoom";
1853     }
1854
1855
1856     /* Get the descriptive name of the variable */
1857     var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1858                  &val_name, NULL );
1859     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1860
1861     if( newval.psz_string && *newval.psz_string )
1862     {
1863         /* set */
1864         if( !strcmp( psz_variable, "zoom" ) )
1865         {
1866             vlc_value_t val;
1867             val.f_float = atof( newval.psz_string );
1868             i_error = var_Set( p_vout, psz_variable, val );
1869         }
1870         else
1871         {
1872             i_error = var_Set( p_vout, psz_variable, newval );
1873         }
1874     }
1875     else
1876     {
1877         /* get */
1878         vlc_value_t val, text;
1879         int i;
1880         float f_value = 0.;
1881         char *psz_value = NULL;
1882
1883         if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1884         {
1885             vlc_object_release( p_vout );
1886             return VLC_EGENERIC;
1887         }
1888         if( !strcmp( psz_variable, "zoom" ) )
1889         {
1890             f_value = val.f_float;
1891         }
1892         else
1893         {
1894             psz_value = strdup( val.psz_string );
1895         }
1896
1897         if ( var_Change( p_vout, psz_variable,
1898                          VLC_VAR_GETLIST, &val, &text ) < 0 )
1899         {
1900             vlc_object_release( p_vout );
1901             return VLC_EGENERIC;
1902         }
1903
1904         msg_rc( "+----[ %s ]", val_name.psz_string );
1905         if( !strcmp( psz_variable, "zoom" ) )
1906         {
1907             for ( i = 0; i < val.p_list->i_count; i++ )
1908             {
1909                 if ( f_value == val.p_list->p_values[i].f_float )
1910                     msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1911                             text.p_list->p_values[i].psz_string );
1912                 else
1913                     msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1914                             text.p_list->p_values[i].psz_string );
1915             }
1916         }
1917         else
1918         {
1919             for ( i = 0; i < val.p_list->i_count; i++ )
1920             {
1921                 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1922                     msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1923                             text.p_list->p_values[i].psz_string );
1924                 else
1925                     msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1926                             text.p_list->p_values[i].psz_string );
1927             }
1928             free( psz_value );
1929         }
1930         var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1931                     &val, &text );
1932         msg_rc( "+----[ end of %s ]", val_name.psz_string );
1933
1934         if( val_name.psz_string ) free( val_name.psz_string );
1935
1936         i_error = VLC_SUCCESS;
1937     }
1938     vlc_object_release( p_vout );
1939     return i_error;
1940 }
1941
1942 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1943                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
1944 {
1945     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1946     input_thread_t *p_input = NULL;
1947     aout_instance_t * p_aout;
1948     const char * psz_variable;
1949     vlc_value_t val_name;
1950     int i_error;
1951
1952     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1953     if( !p_input )
1954         return VLC_ENOOBJ;
1955
1956     if( p_input )
1957     {
1958         vlc_value_t val;
1959
1960         var_Get( p_input, "state", &val );
1961         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )        {
1962             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1963             vlc_object_release( p_input );
1964             return VLC_EGENERIC;
1965         }
1966         vlc_object_release( p_input );
1967     }
1968
1969     p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1970     if ( p_aout == NULL ) return VLC_ENOOBJ;
1971
1972     if ( !strcmp( psz_cmd, "adev" ) )
1973     {
1974         psz_variable = "audio-device";
1975     }
1976     else
1977     {
1978         psz_variable = "audio-channels";
1979     }
1980
1981     /* Get the descriptive name of the variable */
1982     var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1983                  &val_name, NULL );
1984     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1985
1986     if ( !*newval.psz_string )
1987     {
1988         /* Retrieve all registered ***. */
1989         vlc_value_t val, text;
1990         int i, i_value;
1991
1992         if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1993         {
1994             vlc_object_release( (vlc_object_t *)p_aout );
1995             return VLC_EGENERIC;
1996         }
1997         i_value = val.i_int;
1998
1999         if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
2000                          VLC_VAR_GETLIST, &val, &text ) < 0 )
2001         {
2002             vlc_object_release( (vlc_object_t *)p_aout );
2003             return VLC_EGENERIC;
2004         }
2005
2006         msg_rc( "+----[ %s ]", val_name.psz_string );
2007         for ( i = 0; i < val.p_list->i_count; i++ )
2008         {
2009             if ( i_value == val.p_list->p_values[i].i_int )
2010                 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
2011                         text.p_list->p_values[i].psz_string );
2012             else
2013                 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
2014                         text.p_list->p_values[i].psz_string );
2015         }
2016         var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
2017                     &val, &text );
2018         msg_rc( "+----[ end of %s ]", val_name.psz_string );
2019
2020         if( val_name.psz_string ) free( val_name.psz_string );
2021         i_error = VLC_SUCCESS;
2022     }
2023     else
2024     {
2025         vlc_value_t val;
2026         val.i_int = atoi( newval.psz_string );
2027
2028         i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
2029     }
2030     vlc_object_release( (vlc_object_t *)p_aout );
2031
2032     return i_error;
2033 }
2034
2035 /* OSD menu commands */
2036 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
2037     vlc_value_t oldval, vlc_value_t newval, void *p_data )
2038 {
2039     intf_thread_t *p_intf = (intf_thread_t*)p_this;
2040     playlist_t    *p_playlist = NULL;
2041     vlc_value_t val;
2042     int i_error = VLC_EGENERIC;
2043
2044     if ( !*newval.psz_string )
2045     {
2046         msg_rc( _("Please provide one of the following parameters:") );
2047         msg_rc( "[on|off|up|down|left|right|select]" );
2048         return i_error;
2049     }
2050
2051     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
2052     if( !p_playlist )
2053         return VLC_ENOOBJ;
2054
2055     if( p_playlist->p_input )
2056     {
2057         var_Get( p_playlist->p_input, "state", &val );
2058         if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
2059             ( strcmp( newval.psz_string, "select" ) != 0 ) )
2060         {
2061             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
2062             vlc_object_release( p_playlist );
2063             return VLC_EGENERIC;
2064         }
2065     }
2066     vlc_object_release( p_playlist );
2067
2068     val.psz_string = strdup( newval.psz_string );
2069     if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
2070         osd_MenuShow( p_this );
2071     else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
2072         osd_MenuHide( p_this );
2073     else if( !strcmp( val.psz_string, "up" ) )
2074         osd_MenuUp( p_this );
2075     else if( !strcmp( val.psz_string, "down" ) )
2076         osd_MenuDown( p_this );
2077     else if( !strcmp( val.psz_string, "left" ) )
2078         osd_MenuPrev( p_this );
2079     else if( !strcmp( val.psz_string, "right" ) )
2080         osd_MenuNext( p_this );
2081     else if( !strcmp( val.psz_string, "select" ) )
2082         osd_MenuActivate( p_this );
2083     else
2084     {
2085         msg_rc( _("Please provide one of the following parameters:") );
2086         msg_rc( "[on|off|up|down|left|right|select]" );
2087         if( val.psz_string ) free( val.psz_string );
2088             return i_error;
2089     }
2090
2091     i_error = VLC_SUCCESS;
2092     if( val.psz_string ) free( val.psz_string );
2093     return i_error;
2094 }
2095
2096 #ifdef WIN32
2097 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2098 {
2099     INPUT_RECORD input_record;
2100     DWORD i_dw;
2101
2102     /* On Win32, select() only works on socket descriptors */
2103     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2104                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2105     {
2106         while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2107                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2108                                  1, &i_dw ) )
2109         {
2110             if( input_record.EventType != KEY_EVENT ||
2111                 !input_record.Event.KeyEvent.bKeyDown ||
2112                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2113                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2114                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2115                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2116             {
2117                 /* nothing interesting */
2118                 continue;
2119             }
2120
2121             p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2122
2123             /* Echo out the command */
2124             putc( p_buffer[ *pi_size ], stdout );
2125
2126             /* Handle special keys */
2127             if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2128             {
2129                 putc( '\n', stdout );
2130                 break;
2131             }
2132             switch( p_buffer[ *pi_size ] )
2133             {
2134             case '\b':
2135                 if( *pi_size )
2136                 {
2137                     *pi_size -= 2;
2138                     putc( ' ', stdout );
2139                     putc( '\b', stdout );
2140                 }
2141                 break;
2142             case '\r':
2143                 (*pi_size) --;
2144                 break;
2145             }
2146
2147             (*pi_size)++;
2148         }
2149
2150         if( *pi_size == MAX_LINE_LENGTH ||
2151             p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2152         {
2153             p_buffer[ *pi_size ] = 0;
2154             return VLC_TRUE;
2155         }
2156     }
2157
2158     return VLC_FALSE;
2159 }
2160 #endif
2161
2162 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2163 {
2164     int i_read = 0;
2165
2166 #ifdef WIN32
2167     if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2168         return ReadWin32( p_intf, p_buffer, pi_size );
2169     else if( p_intf->p_sys->i_socket == -1 )
2170     {
2171         msleep( INTF_IDLE_SLEEP );
2172         return VLC_FALSE;
2173     }
2174 #endif
2175
2176     while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2177            (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2178                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2179                   (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2180     {
2181         if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2182             break;
2183
2184         (*pi_size)++;
2185     }
2186
2187     /* Connection closed */
2188     if( i_read == -1 )
2189     {
2190         p_intf->p_sys->i_socket = -1;
2191         p_buffer[ *pi_size ] = 0;
2192         return VLC_TRUE;
2193     }
2194
2195     if( *pi_size == MAX_LINE_LENGTH ||
2196         p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2197     {
2198         p_buffer[ *pi_size ] = 0;
2199         return VLC_TRUE;
2200     }
2201
2202     return VLC_FALSE;
2203 }
2204
2205 /*****************************************************************************
2206  * parse_MRL: build a input item from a full mrl
2207  *****************************************************************************
2208  * MRL format: "simplified-mrl [:option-name[=option-value]]"
2209  * We don't check for '"' or '\'', we just assume that a ':' that follows a
2210  * space is a new option. Should be good enough for our purpose.
2211  *****************************************************************************/
2212 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2213 {
2214 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2215 #define SKIPTRAILINGSPACE( p, d ) \
2216     { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2217
2218     input_item_t *p_item = NULL;
2219     char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2220     char **ppsz_options = NULL;
2221     int i, i_options = 0;
2222
2223     if( !psz_mrl ) return 0;
2224
2225     psz_mrl = psz_orig = strdup( psz_mrl );
2226     while( *psz_mrl )
2227     {
2228         SKIPSPACE( psz_mrl );
2229         psz_item = psz_mrl;
2230
2231         for( ; *psz_mrl; psz_mrl++ )
2232         {
2233             if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2234             {
2235                 /* We have a complete item */
2236                 break;
2237             }
2238             if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2239                 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2240             {
2241                 /* We have a complete item */
2242                 break;
2243             }
2244         }
2245
2246         if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2247         SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2248
2249         /* Remove '"' and '\'' if necessary */
2250         if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2251         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2252         if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2253         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2254
2255         if( !psz_item_mrl ) psz_item_mrl = psz_item;
2256         else if( *psz_item )
2257         {
2258             i_options++;
2259             ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2260             ppsz_options[i_options - 1] = &psz_item[1];
2261         }
2262
2263         if( *psz_mrl ) SKIPSPACE( psz_mrl );
2264     }
2265
2266     /* Now create a playlist item */
2267     if( psz_item_mrl )
2268     {
2269         p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2270         for( i = 0; i < i_options; i++ )
2271         {
2272             input_ItemAddOption( p_item, ppsz_options[i] );
2273         }
2274     }
2275
2276     if( i_options ) free( ppsz_options );
2277     free( psz_orig );
2278
2279     return p_item;
2280 }
2281
2282 /*****************************************************************************
2283  * checkUpdates : check for updates
2284  ****************************************************************************/
2285 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2286 {
2287     update_iterator_t *p_uit;
2288     update_t *p_u = update_New( p_intf );
2289     if( p_u == NULL ) return;
2290     p_uit = update_iterator_New( p_u );
2291     if( p_uit )
2292     {
2293         int s = 0, t = 0;
2294
2295         if( strstr( psz_arg, "newer" ) )
2296             s |= UPDATE_RELEASE_STATUS_NEWER;
2297         if( strstr( psz_arg, "equal" ) )
2298             s |= UPDATE_RELEASE_STATUS_EQUAL;
2299         if( strstr( psz_arg, "older" ) )
2300             s |= UPDATE_RELEASE_STATUS_OLDER;
2301         if( s ) p_uit->i_rs = s;
2302         else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2303
2304         if( strstr( psz_arg, "undef" ) )
2305             t |= UPDATE_FILE_TYPE_UNDEF;
2306         if( strstr( psz_arg, "info" ) )
2307             t |= UPDATE_FILE_TYPE_INFO;
2308         if( strstr( psz_arg, "source" ) )
2309             t |= UPDATE_FILE_TYPE_SOURCE;
2310         if( strstr( psz_arg, "binary" ) )
2311             t |= UPDATE_FILE_TYPE_BINARY;
2312         if( strstr( psz_arg, "plugin" ) )
2313             t |= UPDATE_FILE_TYPE_PLUGIN;
2314         if( t ) p_uit->i_t = t;
2315
2316         update_Check( p_u, VLC_FALSE );
2317         update_iterator_Action( p_uit, UPDATE_MIRROR );
2318         msg_rc( "\nUsing mirror: %s (%s) [%s]",
2319                 p_uit->mirror.psz_name,
2320                 p_uit->mirror.psz_location,
2321                 p_uit->mirror.psz_type );
2322         while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2323         {
2324             char *psz_tmp;
2325             if( s & UPDATE_RELEASE )
2326             {
2327                 switch( p_uit->release.i_status )
2328                 {
2329                     case UPDATE_RELEASE_STATUS_OLDER:
2330                         psz_tmp = strdup( "older" );
2331                         break;
2332                     case UPDATE_RELEASE_STATUS_EQUAL:
2333                         psz_tmp = strdup( "equal" );
2334                         break;
2335                     case UPDATE_RELEASE_STATUS_NEWER:
2336                         psz_tmp = strdup( "newer" );
2337                         break;
2338                     default:
2339                         psz_tmp = strdup( "?!?" );
2340                         break;
2341                 }
2342                 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2343                         p_uit->release.psz_version,
2344                         p_uit->release.psz_svn_revision,
2345                         psz_tmp );
2346                 free( psz_tmp );
2347             }
2348             switch( p_uit->file.i_type )
2349             {
2350                 case UPDATE_FILE_TYPE_UNDEF:
2351                     psz_tmp = strdup( "undef" );
2352                     break;
2353                 case UPDATE_FILE_TYPE_INFO:
2354                     psz_tmp = strdup( "info" );
2355                     break;
2356                 case UPDATE_FILE_TYPE_SOURCE:
2357                     psz_tmp = strdup( "source" );
2358                     break;
2359                 case UPDATE_FILE_TYPE_BINARY:
2360                     psz_tmp = strdup( "binary" );
2361                     break;
2362                 case UPDATE_FILE_TYPE_PLUGIN:
2363                     psz_tmp = strdup( "plugin" );
2364                     break;
2365                 default:
2366                     psz_tmp = strdup( "?!?" );
2367                     break;
2368             }
2369             msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2370             free( psz_tmp );
2371             if( p_uit->file.l_size )
2372             {
2373                 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2374                     asprintf( &psz_tmp, "(%ld GB)",
2375                               p_uit->file.l_size / (1024*1024*1024) );
2376                 if( p_uit->file.l_size > 1024 * 1024 )
2377                     asprintf( &psz_tmp, "(%ld MB)",
2378                               p_uit->file.l_size / (1024*1024) );
2379                 else if( p_uit->file.l_size > 1024 )
2380                     asprintf( &psz_tmp, "(%ld kB)",
2381                               p_uit->file.l_size / 1024 );
2382                 else
2383                     asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2384             }
2385             else
2386             {
2387                 psz_tmp = strdup( "" );
2388             }
2389             msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2390             msg_rc( "+----" );
2391             free( psz_tmp );
2392         }
2393         msg_rc( "" );
2394         update_iterator_Delete( p_uit );
2395     }
2396     update_Delete( p_u );
2397 }