librivox: create a node for each book of the podcast.
[vlc/asuraparaju-public.git] / modules / control / http / rpn.c
blobeb7aeee7b79d13e4e766f55e5c1a00bf6fd695e0
1 /*****************************************************************************
2 * rpn.c : RPN evaluator for the HTTP Interface
3 *****************************************************************************
4 * Copyright (C) 2001-2006 the VideoLAN team
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include "http.h"
30 #include <vlc_url.h>
31 #include <vlc_meta.h>
32 #include <vlc_strings.h>
34 static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
35 const char *psz_object,
36 bool *pb_need_release )
38 intf_sys_t *p_sys = p_intf->p_sys;
39 vlc_object_t *p_object = NULL;
40 *pb_need_release = false;
42 if( !strcmp( psz_object, "VLC_OBJECT_LIBVLC" ) )
43 p_object = VLC_OBJECT(p_intf->p_libvlc);
44 else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )
45 p_object = VLC_OBJECT(p_sys->p_playlist);
46 else if( !strcmp( psz_object, "VLC_OBJECT_INPUT" ) )
47 p_object = VLC_OBJECT(p_sys->p_input);
48 else if( p_sys->p_input )
50 if( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )
51 p_object = VLC_OBJECT( input_GetVout( p_sys->p_input ) );
52 else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )
53 p_object = VLC_OBJECT( input_GetAout( p_sys->p_input ) );
54 if( p_object )
55 *pb_need_release = true;
57 else
58 msg_Warn( p_intf, "unknown object type (%s)", psz_object );
60 return p_object;
63 void SSInit( rpn_stack_t *st )
65 st->i_stack = 0;
68 void SSClean( rpn_stack_t *st )
70 while( st->i_stack > 0 )
72 free( st->stack[--st->i_stack] );
76 void SSPush( rpn_stack_t *st, const char *s )
78 if( st->i_stack < STACK_MAX )
80 st->stack[st->i_stack++] = strdup( s );
84 char *SSPop( rpn_stack_t *st )
86 if( st->i_stack <= 0 )
88 return strdup( "" );
90 else
92 return st->stack[--st->i_stack];
96 int SSPopN( rpn_stack_t *st, mvar_t *vars )
98 char *name;
100 char *end;
101 int i;
103 name = SSPop( st );
104 i = strtol( name, &end, 0 );
105 if( end == name )
107 const char *value = mvar_GetValue( vars, name );
108 i = atoi( value );
110 free( name );
112 return( i );
115 void SSPushN( rpn_stack_t *st, int i )
117 char v[12];
119 snprintf( v, sizeof (v), "%d", i );
120 SSPush( st, v );
123 void EvaluateRPN( intf_thread_t *p_intf, mvar_t *vars,
124 rpn_stack_t *st, char *exp )
126 intf_sys_t *p_sys = p_intf->p_sys;
128 while( exp != NULL && *exp != '\0' )
130 char *p, *s;
132 /* skip space */
133 while( *exp == ' ' )
135 exp++;
138 if( *exp == '\'' )
140 /* extract string */
141 p = FirstWord( exp, exp );
142 SSPush( st, exp );
143 exp = p;
144 continue;
147 /* extract token */
148 p = FirstWord( exp, exp );
149 s = exp;
150 if( p == NULL )
152 exp += strlen( exp );
154 else
156 exp = p;
159 if( *s == '\0' )
161 break;
164 /* 1. Integer function */
165 if( !strcmp( s, "!" ) )
167 SSPushN( st, !SSPopN( st, vars ) );
169 else if( !strcmp( s, "^" ) )
171 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
173 else if( !strcmp( s, "&" ) )
175 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
177 else if( !strcmp( s, "|" ) )
179 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
181 else if( !strcmp( s, "+" ) )
183 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
185 else if( !strcmp( s, "-" ) )
187 int j = SSPopN( st, vars );
188 int i = SSPopN( st, vars );
189 SSPushN( st, i - j );
191 else if( !strcmp( s, "*" ) )
193 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
195 else if( !strcmp( s, "/" ) )
197 int i, j;
199 j = SSPopN( st, vars );
200 i = SSPopN( st, vars );
202 SSPushN( st, j != 0 ? i / j : 0 );
204 else if( !strcmp( s, "%" ) )
206 int i, j;
208 j = SSPopN( st, vars );
209 i = SSPopN( st, vars );
211 SSPushN( st, j != 0 ? i % j : 0 );
213 /* 2. integer tests */
214 else if( !strcmp( s, "=" ) )
216 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
218 else if( !strcmp( s, "!=" ) )
220 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
222 else if( !strcmp( s, "<" ) )
224 int j = SSPopN( st, vars );
225 int i = SSPopN( st, vars );
227 SSPushN( st, i < j ? -1 : 0 );
229 else if( !strcmp( s, ">" ) )
231 int j = SSPopN( st, vars );
232 int i = SSPopN( st, vars );
234 SSPushN( st, i > j ? -1 : 0 );
236 else if( !strcmp( s, "<=" ) )
238 int j = SSPopN( st, vars );
239 int i = SSPopN( st, vars );
241 SSPushN( st, i <= j ? -1 : 0 );
243 else if( !strcmp( s, ">=" ) )
245 int j = SSPopN( st, vars );
246 int i = SSPopN( st, vars );
248 SSPushN( st, i >= j ? -1 : 0 );
250 /* 3. string functions */
251 else if( !strcmp( s, "strcat" ) )
253 char *s2 = SSPop( st );
254 char *s1 = SSPop( st );
255 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
257 strcpy( str, s1 );
258 strcat( str, s2 );
260 SSPush( st, str );
261 free( s1 );
262 free( s2 );
263 free( str );
265 else if( !strcmp( s, "strcmp" ) )
267 char *s2 = SSPop( st );
268 char *s1 = SSPop( st );
270 SSPushN( st, strcmp( s1, s2 ) );
271 free( s1 );
272 free( s2 );
274 else if( !strcmp( s, "strncmp" ) )
276 int n = SSPopN( st, vars );
277 char *s2 = SSPop( st );
278 char *s1 = SSPop( st );
280 SSPushN( st, strncmp( s1, s2 , n ) );
281 free( s1 );
282 free( s2 );
284 else if( !strcmp( s, "strsub" ) )
286 int n = SSPopN( st, vars );
287 int m = SSPopN( st, vars );
288 int i_len;
289 char *s = SSPop( st );
290 char *str;
292 if( n >= m )
294 i_len = n - m + 1;
296 else
298 i_len = 0;
301 str = malloc( i_len + 1 );
303 memcpy( str, s + m - 1, i_len );
304 str[ i_len ] = '\0';
306 SSPush( st, str );
307 free( s );
308 free( str );
310 else if( !strcmp( s, "strlen" ) )
312 char *str = SSPop( st );
314 SSPushN( st, strlen( str ) );
315 free( str );
317 else if( !strcmp( s, "str_replace" ) )
319 char *psz_to = SSPop( st );
320 char *psz_from = SSPop( st );
321 char *psz_in = SSPop( st );
322 char *psz_in_current = psz_in;
323 char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
324 char *psz_out_current = psz_out;
326 while( (p = strstr( psz_in_current, psz_from )) != NULL )
328 memcpy( psz_out_current, psz_in_current, p - psz_in_current );
329 psz_out_current += p - psz_in_current;
330 strcpy( psz_out_current, psz_to );
331 psz_out_current += strlen(psz_to);
332 psz_in_current = p + strlen(psz_from);
334 strcpy( psz_out_current, psz_in_current );
335 psz_out_current += strlen(psz_in_current);
336 *psz_out_current = '\0';
338 SSPush( st, psz_out );
339 free( psz_to );
340 free( psz_from );
341 free( psz_in );
342 free( psz_out );
344 else if( !strcmp( s, "url_extract" ) )
346 const char *url = mvar_GetValue( vars, "url_value" );
347 char *name = SSPop( st );
348 char *value = ExtractURIString( url, name );
349 if( value != NULL )
351 decode_URI( value );
352 SSPush( st, value );
353 free( value );
355 else
356 SSPush( st, "" );
358 free( name );
360 else if( !strcmp( s, "url_encode" ) )
362 char *url = SSPop( st );
363 char *value = encode_URI_component( url );
364 free( url );
365 SSPush( st, value );
366 free( value );
368 else if( !strcmp( s, "xml_encode" )
369 || !strcmp( s, "htmlspecialchars" ) )
371 char *url = SSPop( st );
372 char *value = convert_xml_special_chars( url );
373 free( url );
374 SSPush( st, value );
375 free( value );
377 else if( !strcmp( s, "addslashes" ) )
379 char *psz_src = SSPop( st );
380 char *psz_dest;
381 char *str = psz_src;
383 p = psz_dest = malloc( strlen( str ) * 2 + 1 );
385 while( *str != '\0' )
387 if( *str == '"' || *str == '\'' || *str == '\\' )
389 *p++ = '\\';
391 *p++ = *str;
392 str++;
394 *p = '\0';
396 SSPush( st, psz_dest );
397 free( psz_src );
398 free( psz_dest );
400 else if( !strcmp( s, "stripslashes" ) )
402 char *psz_src = SSPop( st );
403 char *psz_dest;
404 char *str = psz_src;
406 p = psz_dest = strdup( psz_src );
408 while( *str )
410 if( *str == '\\' && *(str + 1) )
412 str++;
414 *p++ = *str++;
416 *p = '\0';
418 SSPush( st, psz_dest );
419 free( psz_src );
420 free( psz_dest );
422 else if( !strcmp( s, "realpath" ) )
424 char *psz_src = SSPop( st );
425 char *psz_dir = RealPath( psz_src );
427 SSPush( st, psz_dir );
428 free( psz_src );
429 free( psz_dir );
431 /* 4. stack functions */
432 else if( !strcmp( s, "dup" ) )
434 char *str = SSPop( st );
435 SSPush( st, str );
436 SSPush( st, str );
437 free( str );
439 else if( !strcmp( s, "drop" ) )
441 char *str = SSPop( st );
442 free( str );
444 else if( !strcmp( s, "swap" ) )
446 char *s1 = SSPop( st );
447 char *s2 = SSPop( st );
449 SSPush( st, s1 );
450 SSPush( st, s2 );
451 free( s1 );
452 free( s2 );
454 else if( !strcmp( s, "flush" ) )
456 SSClean( st );
457 SSInit( st );
459 else if( !strcmp( s, "store" ) )
461 char *value = SSPop( st );
462 char *name = SSPop( st );
464 mvar_PushNewVar( vars, name, value );
465 free( name );
466 free( value );
468 else if( !strcmp( s, "value" ) )
470 char *name = SSPop( st );
471 const char *value = mvar_GetValue( vars, name );
473 SSPush( st, value );
475 free( name );
477 /* 5. player control */
478 else if( !strcmp( s, "vlc_play" ) )
480 int i_id = SSPopN( st, vars );
481 int i_ret;
483 playlist_Lock( p_sys->p_playlist );
484 i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
485 pl_Locked, NULL,
486 playlist_ItemGetById( p_sys->p_playlist,
487 i_id ) );
488 playlist_Unlock( p_sys->p_playlist );
489 msg_Dbg( p_intf, "requested playlist item: %i", i_id );
490 SSPushN( st, i_ret );
492 else if( !strcmp( s, "vlc_stop" ) )
494 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP, pl_Unlocked );
495 msg_Dbg( p_intf, "requested playlist stop" );
497 else if( !strcmp( s, "vlc_pause" ) )
499 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE, pl_Unlocked );
500 msg_Dbg( p_intf, "requested playlist pause" );
502 else if( !strcmp( s, "vlc_next" ) )
504 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, 1 );
505 msg_Dbg( p_intf, "requested playlist next" );
507 else if( !strcmp( s, "vlc_previous" ) )
509 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, -1 );
510 msg_Dbg( p_intf, "requested playlist previous" );
512 else if( !strcmp( s, "vlc_seek" ) )
514 char *psz_value = SSPop( st );
515 HandleSeek( p_intf, psz_value );
516 msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
517 free( psz_value );
519 else if( !strcmp( s, "vlc_var_type" )
520 || !strcmp( s, "vlc_config_type" ) )
522 vlc_object_t *p_object;
523 const char *psz_type = NULL;
524 int i_type = 0;
526 if( !strcmp( s, "vlc_var_type" ) )
528 char *psz_object = SSPop( st );
529 char *psz_variable = SSPop( st );
530 bool b_need_release;
532 p_object = GetVLCObject( p_intf, psz_object, &b_need_release );
534 if( p_object != NULL )
535 i_type = var_Type( p_object, psz_variable );
536 free( psz_variable );
537 free( psz_object );
538 if( b_need_release && p_object != NULL )
539 vlc_object_release( p_object );
541 else
543 char *psz_variable = SSPop( st );
544 p_object = VLC_OBJECT(p_intf);
545 i_type = config_GetType( p_object, psz_variable );
546 free( psz_variable );
549 if( p_object != NULL )
551 switch( i_type & VLC_VAR_TYPE )
553 case VLC_VAR_BOOL:
554 psz_type = "VLC_VAR_BOOL";
555 break;
556 case VLC_VAR_INTEGER:
557 psz_type = "VLC_VAR_INTEGER";
558 break;
559 case VLC_VAR_HOTKEY:
560 psz_type = "VLC_VAR_HOTKEY";
561 break;
562 case VLC_VAR_STRING:
563 psz_type = "VLC_VAR_STRING";
564 break;
565 case VLC_VAR_MODULE:
566 psz_type = "VLC_VAR_MODULE";
567 break;
568 case VLC_VAR_FILE:
569 psz_type = "VLC_VAR_FILE";
570 break;
571 case VLC_VAR_DIRECTORY:
572 psz_type = "VLC_VAR_DIRECTORY";
573 break;
574 case VLC_VAR_VARIABLE:
575 psz_type = "VLC_VAR_VARIABLE";
576 break;
577 case VLC_VAR_FLOAT:
578 psz_type = "VLC_VAR_FLOAT";
579 break;
580 default:
581 psz_type = "UNDEFINED";
584 else
585 psz_type = "INVALID";
587 SSPush( st, psz_type );
589 else if( !strcmp( s, "vlc_var_set" ) )
591 char *psz_object = SSPop( st );
592 char *psz_variable = SSPop( st );
593 bool b_need_release;
595 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
596 &b_need_release );
598 if( p_object != NULL )
600 bool b_error = false;
601 char *psz_value = NULL;
602 vlc_value_t val;
603 int i_type;
605 i_type = var_Type( p_object, psz_variable );
607 switch( i_type & VLC_VAR_TYPE )
609 case VLC_VAR_BOOL:
610 val.b_bool = SSPopN( st, vars );
611 msg_Dbg( p_intf, "requested %s var change: %s->%d",
612 psz_object, psz_variable, val.b_bool );
613 break;
614 case VLC_VAR_INTEGER:
615 case VLC_VAR_HOTKEY:
616 val.i_int = SSPopN( st, vars );
617 msg_Dbg( p_intf, "requested %s var change: %s->%"PRIu64,
618 psz_object, psz_variable, val.i_int );
619 break;
620 case VLC_VAR_STRING:
621 case VLC_VAR_MODULE:
622 case VLC_VAR_FILE:
623 case VLC_VAR_DIRECTORY:
624 case VLC_VAR_VARIABLE:
625 val.psz_string = psz_value = SSPop( st );
626 msg_Dbg( p_intf, "requested %s var change: %s->%s",
627 psz_object, psz_variable, psz_value );
628 break;
629 case VLC_VAR_FLOAT:
630 psz_value = SSPop( st );
631 val.f_float = atof( psz_value );
632 msg_Dbg( p_intf, "requested %s var change: %s->%f",
633 psz_object, psz_variable, val.f_float );
634 break;
635 default:
636 SSPopN( st, vars );
637 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
638 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
639 b_error = true;
642 if( !b_error )
643 var_Set( p_object, psz_variable, val );
644 free( psz_value );
646 else
647 msg_Warn( p_intf, "vlc_var_set called without an object" );
648 free( psz_variable );
649 free( psz_object );
651 if( b_need_release && p_object != NULL )
652 vlc_object_release( p_object );
654 else if( !strcmp( s, "vlc_var_get" ) )
656 char *psz_object = SSPop( st );
657 char *psz_variable = SSPop( st );
658 bool b_need_release;
660 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
661 &b_need_release );
663 if( p_object != NULL )
665 vlc_value_t val;
666 int i_type;
668 i_type = var_Type( p_object, psz_variable );
669 var_Get( p_object, psz_variable, &val );
671 switch( i_type & VLC_VAR_TYPE )
673 case VLC_VAR_BOOL:
674 SSPushN( st, val.b_bool );
675 break;
676 case VLC_VAR_INTEGER:
677 case VLC_VAR_HOTKEY:
678 SSPushN( st, val.i_int );
679 break;
680 case VLC_VAR_STRING:
681 case VLC_VAR_MODULE:
682 case VLC_VAR_FILE:
683 case VLC_VAR_DIRECTORY:
684 case VLC_VAR_VARIABLE:
685 SSPush( st, val.psz_string );
686 free( val.psz_string );
687 break;
688 case VLC_VAR_FLOAT:
690 char psz_value[20];
691 lldiv_t value = lldiv( val.f_float * 1000000, 1000000 );
692 snprintf( psz_value, sizeof(psz_value), "%lld.%06u",
693 value.quot, (unsigned int)value.rem );
694 SSPush( st, psz_value );
695 break;
697 default:
698 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
699 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
700 SSPush( st, "" );
703 else
705 msg_Warn( p_intf, "vlc_var_get called without an object" );
706 SSPush( st, "" );
708 free( psz_variable );
709 free( psz_object );
711 if( b_need_release && p_object != NULL )
712 vlc_object_release( p_object );
714 else if( !strcmp( s, "vlc_object_exists" ) )
716 char *psz_object = SSPop( st );
717 bool b_need_release;
719 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
720 &b_need_release );
721 if( b_need_release && p_object != NULL )
722 vlc_object_release( p_object );
724 if( p_object != NULL )
725 SSPush( st, "1" );
726 else
727 SSPush( st, "0" );
729 else if( !strcmp( s, "vlc_config_set" ) )
731 char *psz_variable = SSPop( st );
732 int i_type = config_GetType( p_intf, psz_variable );
734 switch( i_type & VLC_VAR_TYPE )
736 case VLC_VAR_BOOL:
737 case VLC_VAR_INTEGER:
738 config_PutInt( p_intf, psz_variable, SSPopN( st, vars ) );
739 break;
740 case VLC_VAR_STRING:
741 case VLC_VAR_MODULE:
742 case VLC_VAR_FILE:
743 case VLC_VAR_DIRECTORY:
745 char *psz_string = SSPop( st );
746 config_PutPsz( p_intf, psz_variable, psz_string );
747 free( psz_string );
748 break;
750 case VLC_VAR_FLOAT:
752 char *psz_string = SSPop( st );
753 config_PutFloat( p_intf, psz_variable, atof(psz_string) );
754 free( psz_string );
755 break;
757 default:
758 msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)",
759 psz_variable );
761 free( psz_variable );
763 else if( !strcmp( s, "vlc_config_get" ) )
765 char *psz_variable = SSPop( st );
766 int i_type = config_GetType( p_intf, psz_variable );
768 switch( i_type & VLC_VAR_TYPE )
770 case VLC_VAR_BOOL:
771 case VLC_VAR_INTEGER:
772 SSPushN( st, config_GetInt( p_intf, psz_variable ) );
773 break;
774 case VLC_VAR_STRING:
775 case VLC_VAR_MODULE:
776 case VLC_VAR_FILE:
777 case VLC_VAR_DIRECTORY:
779 char *psz_string = config_GetPsz( p_intf, psz_variable );
780 SSPush( st, psz_string );
781 free( psz_string );
782 break;
784 case VLC_VAR_FLOAT:
786 char psz_string[20];
787 lldiv_t value = lldiv( config_GetFloat( p_intf, psz_variable )
788 * 1000000, 1000000 );
789 snprintf( psz_string, sizeof(psz_string), "%lld.%06u",
790 value.quot, (unsigned int)value.rem );
791 SSPush( st, psz_string );
792 break;
794 default:
795 msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)",
796 psz_variable );
797 SSPush( st, "" );
799 free( psz_variable );
801 else if( !strcmp( s, "vlc_config_save" ) )
803 char *psz_module = SSPop( st );
804 int i_result;
806 if( !*psz_module )
808 free( psz_module );
809 psz_module = NULL;
811 i_result = config_SaveConfigFile( p_intf, psz_module );
813 free( psz_module );
814 SSPushN( st, i_result );
816 else if( !strcmp( s, "vlc_config_reset" ) )
818 config_ResetAll( p_intf );
820 /* 6. playlist functions */
821 else if( !strcmp( s, "playlist_add" ) )
823 char *psz_name = SSPop( st );
824 char *mrl = SSPop( st );
825 input_item_t *p_input;
826 int i_ret;
828 p_input = MRLParse( p_intf, mrl, psz_name );
830 char *psz_uri = input_item_GetURI( p_input );
831 if( !p_input || !psz_uri || !*psz_uri )
833 i_ret = VLC_EGENERIC;
834 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
836 else
838 i_ret = playlist_AddInput( p_sys->p_playlist, p_input,
839 PLAYLIST_APPEND, PLAYLIST_END, true,
840 pl_Unlocked );
841 if( i_ret == VLC_SUCCESS )
843 playlist_item_t *p_item;
844 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
845 playlist_Lock( p_sys->p_playlist );
846 p_item = playlist_ItemGetByInput( p_sys->p_playlist,
847 p_input );
848 if( p_item )
849 i_ret = p_item->i_id;
850 playlist_Unlock( p_sys->p_playlist );
852 else
853 msg_Warn( p_intf, "adding mrl %s failed", mrl );
854 vlc_gc_decref( p_input );
856 free( psz_uri );
857 SSPushN( st, i_ret );
859 free( mrl );
860 free( psz_name );
862 else if( !strcmp( s, "playlist_empty" ) )
864 playlist_Clear( p_sys->p_playlist, pl_Unlocked );
865 msg_Dbg( p_intf, "requested playlist empty" );
867 else if( !strcmp( s, "playlist_delete" ) )
869 int i_id = SSPopN( st, vars );
870 playlist_Lock( p_sys->p_playlist );
871 playlist_item_t *p_item = playlist_ItemGetById( p_sys->p_playlist,
872 i_id );
873 if( p_item )
875 playlist_DeleteFromInput( p_sys->p_playlist,
876 p_item->p_input, pl_Locked );
877 msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
879 else
881 msg_Dbg( p_intf, "couldn't find playlist item to delete (%d)",
882 i_id );
884 playlist_Unlock( p_sys->p_playlist );
886 else if( !strcmp( s, "playlist_move" ) )
888 /*int i_newpos =*/ SSPopN( st, vars );
889 /*int i_pos =*/ SSPopN( st, vars );
890 /* FIXME FIXME TODO TODO XXX XXX
891 do not release before fixing this
892 if ( i_pos < i_newpos )
894 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
896 else
898 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
900 msg_Dbg( p_intf, "requested to move playlist item %d to %d",
901 i_pos, i_newpos);
902 FIXME FIXME TODO TODO XXX XXX */
903 msg_Err( p_intf, "moving using indexes is obsolete. We need to update this function" );
905 else if( !strcmp( s, "playlist_sort" ) )
907 int i_order = SSPopN( st, vars );
908 int i_sort = SSPopN( st, vars );
909 i_order = i_order % 2;
910 i_sort = i_sort % 9;
911 /* FIXME FIXME TODO TODO XXX XXX
912 do not release before fixing this
913 playlist_RecursiveNodeSort( p_sys->p_playlist,
914 p_sys->p_playlist->p_general,
915 i_sort, i_order );
916 msg_Dbg( p_intf, "requested sort playlist by : %d in order : %d",
917 i_sort, i_order );
918 FIXME FIXME TODO TODO XXX XXX */
919 msg_Err( p_intf, "this needs to be fixed to use the new playlist framework" );
921 else if( !strcmp( s, "services_discovery_add" ) )
923 char *psz_sd = SSPop( st );
924 playlist_ServicesDiscoveryAdd( p_sys->p_playlist, psz_sd );
925 free( psz_sd );
927 else if( !strcmp( s, "services_discovery_remove" ) )
929 char *psz_sd = SSPop( st );
930 playlist_ServicesDiscoveryRemove( p_sys->p_playlist, psz_sd );
931 free( psz_sd );
933 else if( !strcmp( s, "services_discovery_is_loaded" ) )
935 char *psz_sd = SSPop( st );
936 SSPushN( st,
937 playlist_IsServicesDiscoveryLoaded( p_sys->p_playlist, psz_sd ) );
938 free( psz_sd );
940 else if( !strcmp( s, "vlc_volume_set" ) )
942 char *psz_vol = SSPop( st );
943 int i_value;
944 audio_volume_t i_volume;
945 aout_VolumeGet( p_sys->p_playlist, &i_volume );
946 if( psz_vol[0] == '+' )
948 i_value = atoi( psz_vol );
949 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
950 aout_VolumeSet( p_sys->p_playlist, AOUT_VOLUME_MAX );
951 else
952 aout_VolumeSet( p_sys->p_playlist, i_volume + i_value );
954 else if( psz_vol[0] == '-' )
956 i_value = atoi( psz_vol );
957 if( (i_volume + i_value) < AOUT_VOLUME_MIN )
958 aout_VolumeSet( p_sys->p_playlist, AOUT_VOLUME_MIN );
959 else
960 aout_VolumeSet( p_sys->p_playlist, i_volume + i_value );
962 else if( strstr( psz_vol, "%") != NULL )
964 i_value = atoi( psz_vol );
965 if( i_value < 0 ) i_value = 0;
966 if( i_value > 400 ) i_value = 400;
967 aout_VolumeSet( p_sys->p_playlist, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);
969 else
971 i_value = atoi( psz_vol );
972 if( i_value > AOUT_VOLUME_MAX ) i_value = AOUT_VOLUME_MAX;
973 if( i_value < AOUT_VOLUME_MIN ) i_value = AOUT_VOLUME_MIN;
974 aout_VolumeSet( p_sys->p_playlist, i_value );
976 aout_VolumeGet( p_sys->p_playlist, &i_volume );
977 free( psz_vol );
979 else if( !strcmp( s, "vlc_get_meta" ) )
981 char *psz_meta = SSPop( st );
982 char *psz_val = NULL;
983 if( p_sys->p_input && input_GetItem(p_sys->p_input) )
985 #define p_item input_GetItem( p_sys->p_input )
986 if( !strcmp( psz_meta, "ARTIST" ) )
988 psz_val = input_item_GetArtist( p_item );
990 else if( !strcmp( psz_meta, "TITLE" ) )
992 psz_val = input_item_GetTitle( p_item );
993 if( !psz_val )
994 psz_val = input_item_GetName( p_item );
996 else if( !strcmp( psz_meta, "ALBUM" ) )
998 psz_val = input_item_GetAlbum( p_item );
1000 else if( !strcmp( psz_meta, "GENRE" ) )
1002 psz_val = input_item_GetGenre( p_item );
1004 else if( !strcmp( psz_meta, "COPYRIGHT" ) )
1006 psz_val = input_item_GetCopyright( p_item );
1008 else if( !strcmp( psz_meta, "TRACK_NUMBER" ) )
1010 psz_val = input_item_GetTrackNum( p_item );
1012 else if( !strcmp( psz_meta, "DESCRIPTION" ) )
1014 psz_val = input_item_GetDescription( p_item );
1016 else if( !strcmp( psz_meta, "RATING" ) )
1018 psz_val = input_item_GetRating( p_item );
1020 else if( !strcmp( psz_meta, "DATE" ) )
1022 psz_val = input_item_GetDate( p_item );
1024 else if( !strcmp( psz_meta, "URL" ) )
1026 psz_val = input_item_GetURL( p_item );
1028 else if( !strcmp( psz_meta, "LANGUAGE" ) )
1030 psz_val = input_item_GetLanguage( p_item );
1032 else if( !strcmp( psz_meta, "NOW_PLAYING" ) )
1034 psz_val = input_item_GetNowPlaying( p_item );
1036 else if( !strcmp( psz_meta, "PUBLISHER" ) )
1038 psz_val = input_item_GetPublisher( p_item );
1040 else if( !strcmp( psz_meta, "ENCODED_BY" ) )
1042 psz_val = input_item_GetEncodedBy( p_item );
1044 else if( !strcmp( psz_meta, "ART_URL" ) )
1046 psz_val = input_item_GetEncodedBy( p_item );
1048 else if( !strcmp( psz_meta, "TRACK_ID" ) )
1050 psz_val = input_item_GetTrackID( p_item );
1052 #undef p_item
1054 if( psz_val == NULL ) psz_val = strdup( "" );
1055 SSPush( st, psz_val );
1056 free( psz_meta );
1057 free( psz_val );
1059 #ifdef ENABLE_VLM
1060 else if( !strcmp( s, "vlm_command" ) || !strcmp( s, "vlm_cmd" ) )
1062 char *psz_elt;
1063 char *psz_cmd = strdup( "" );
1064 char *psz_error;
1065 vlm_message_t *vlm_answer;
1067 /* make sure that we have a vlm object */
1068 if( p_intf->p_sys->p_vlm == NULL )
1069 p_intf->p_sys->p_vlm = vlm_New( p_intf );
1072 /* vlm command uses the ';' delimiter
1073 * (else we can't know when to stop) */
1074 while( strcmp( psz_elt = SSPop( st ), "" )
1075 && strcmp( psz_elt, ";" ) )
1077 char* psz_buf;
1078 if( asprintf( &psz_buf, "%s %s", psz_cmd, psz_elt ) == -1 )
1079 psz_buf = NULL;
1080 free( psz_cmd );
1081 free( psz_elt );
1082 psz_cmd = psz_buf;
1085 msg_Dbg( p_intf, "executing vlm command: %s", psz_cmd );
1086 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz_cmd, &vlm_answer );
1088 if( vlm_answer->psz_value == NULL )
1090 psz_error = strdup( "" );
1092 else
1094 if( asprintf( &psz_error , "%s : %s" , vlm_answer->psz_name,
1095 vlm_answer->psz_value ) == -1 )
1096 psz_error = NULL;
1099 mvar_AppendNewVar( vars, "vlm_error", psz_error );
1100 /* this is kind of a duplicate but we need to have the message
1101 * without the command name for the "export" command */
1102 mvar_AppendNewVar( vars, "vlm_value", vlm_answer->psz_value );
1103 vlm_MessageDelete( vlm_answer );
1105 free( psz_cmd );
1106 free( psz_error );
1108 #endif /* ENABLE_VLM */
1109 else if( !strcmp( s, "snapshot" ) )
1111 if( p_sys->p_input )
1113 vout_thread_t *p_vout = input_GetVout( p_sys->p_input );
1114 if( p_vout )
1116 var_TriggerCallback( p_vout, "video-snapshot" );
1117 vlc_object_release( p_vout );
1118 msg_Dbg( p_intf, "requested snapshot" );
1121 break;
1124 else
1126 SSPush( st, s );