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