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