1 /*****************************************************************************
2 * rpn.c : RPN evaluator for the HTTP Interface
3 *****************************************************************************
4 * Copyright (C) 2001-2006 the VideoLAN team
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 *****************************************************************************/
29 #include "vlc_strings.h"
31 static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
32 const char *psz_object,
33 vlc_bool_t *pb_need_release )
35 intf_sys_t *p_sys = p_intf->p_sys;
36 int i_object_type = 0;
37 vlc_object_t *p_object = NULL;
38 *pb_need_release = VLC_FALSE;
40 if( !strcmp( psz_object, "VLC_OBJECT_LIBVLC" ) )
41 p_object = VLC_OBJECT(p_intf->p_libvlc);
42 else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )
43 p_object = VLC_OBJECT(p_intf);
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( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )
49 i_object_type = VLC_OBJECT_VOUT;
50 else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )
51 i_object_type = VLC_OBJECT_AOUT;
52 else if( !strcmp( psz_object, "VLC_OBJECT_SOUT" ) )
53 i_object_type = VLC_OBJECT_SOUT;
55 msg_Warn( p_intf, "unknown object type (%s)", psz_object );
57 if( p_object == NULL && i_object_type )
59 *pb_need_release = VLC_TRUE;
60 p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );
66 void E_(SSInit)( rpn_stack_t *st )
71 void E_(SSClean)( rpn_stack_t *st )
73 while( st->i_stack > 0 )
75 free( st->stack[--st->i_stack] );
79 void E_(SSPush)( rpn_stack_t *st, const char *s )
81 if( st->i_stack < STACK_MAX )
83 st->stack[st->i_stack++] = strdup( s );
87 char *E_(SSPop)( rpn_stack_t *st )
89 if( st->i_stack <= 0 )
95 return st->stack[--st->i_stack];
99 int E_(SSPopN)( rpn_stack_t *st, mvar_t *vars )
107 name = E_(SSPop)( st );
108 i = strtol( name, &end, 0 );
111 value = E_(mvar_GetValue)( vars, name );
119 void E_(SSPushN)( rpn_stack_t *st, int i )
123 snprintf( v, sizeof (v), "%d", i );
127 void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t *vars,
128 rpn_stack_t *st, char *exp )
130 intf_sys_t *p_sys = p_intf->p_sys;
132 while( exp != NULL && *exp != '\0' )
145 p = E_(FirstWord)( exp, exp );
146 E_(SSPush)( st, exp );
152 p = E_(FirstWord)( exp, exp );
156 exp += strlen( exp );
168 /* 1. Integer function */
169 if( !strcmp( s, "!" ) )
171 E_(SSPushN)( st, ~E_(SSPopN)( st, vars ) );
173 else if( !strcmp( s, "^" ) )
175 E_(SSPushN)( st, E_(SSPopN)( st, vars ) ^ E_(SSPopN)( st, vars ) );
177 else if( !strcmp( s, "&" ) )
179 E_(SSPushN)( st, E_(SSPopN)( st, vars ) & E_(SSPopN)( st, vars ) );
181 else if( !strcmp( s, "|" ) )
183 E_(SSPushN)( st, E_(SSPopN)( st, vars ) | E_(SSPopN)( st, vars ) );
185 else if( !strcmp( s, "+" ) )
187 E_(SSPushN)( st, E_(SSPopN)( st, vars ) + E_(SSPopN)( st, vars ) );
189 else if( !strcmp( s, "-" ) )
191 int j = E_(SSPopN)( st, vars );
192 int i = E_(SSPopN)( st, vars );
193 E_(SSPushN)( st, i - j );
195 else if( !strcmp( s, "*" ) )
197 E_(SSPushN)( st, E_(SSPopN)( st, vars ) * E_(SSPopN)( st, vars ) );
199 else if( !strcmp( s, "/" ) )
203 j = E_(SSPopN)( st, vars );
204 i = E_(SSPopN)( st, vars );
206 E_(SSPushN)( st, j != 0 ? i / j : 0 );
208 else if( !strcmp( s, "%" ) )
212 j = E_(SSPopN)( st, vars );
213 i = E_(SSPopN)( st, vars );
215 E_(SSPushN)( st, j != 0 ? i % j : 0 );
217 /* 2. integer tests */
218 else if( !strcmp( s, "=" ) )
220 E_(SSPushN)( st, E_(SSPopN)( st, vars ) == E_(SSPopN)( st, vars ) ? -1 : 0 );
222 else if( !strcmp( s, "!=" ) )
224 E_(SSPushN)( st, E_(SSPopN)( st, vars ) != E_(SSPopN)( st, vars ) ? -1 : 0 );
226 else if( !strcmp( s, "<" ) )
228 int j = E_(SSPopN)( st, vars );
229 int i = E_(SSPopN)( st, vars );
231 E_(SSPushN)( st, i < j ? -1 : 0 );
233 else if( !strcmp( s, ">" ) )
235 int j = E_(SSPopN)( st, vars );
236 int i = E_(SSPopN)( st, vars );
238 E_(SSPushN)( st, i > j ? -1 : 0 );
240 else if( !strcmp( s, "<=" ) )
242 int j = E_(SSPopN)( st, vars );
243 int i = E_(SSPopN)( st, vars );
245 E_(SSPushN)( st, i <= j ? -1 : 0 );
247 else if( !strcmp( s, ">=" ) )
249 int j = E_(SSPopN)( st, vars );
250 int i = E_(SSPopN)( st, vars );
252 E_(SSPushN)( st, i >= j ? -1 : 0 );
254 /* 3. string functions */
255 else if( !strcmp( s, "strcat" ) )
257 char *s2 = E_(SSPop)( st );
258 char *s1 = E_(SSPop)( st );
259 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
264 E_(SSPush)( st, str );
269 else if( !strcmp( s, "strcmp" ) )
271 char *s2 = E_(SSPop)( st );
272 char *s1 = E_(SSPop)( st );
274 E_(SSPushN)( st, strcmp( s1, s2 ) );
278 else if( !strcmp( s, "strncmp" ) )
280 int n = E_(SSPopN)( st, vars );
281 char *s2 = E_(SSPop)( st );
282 char *s1 = E_(SSPop)( st );
284 E_(SSPushN)( st, strncmp( s1, s2 , n ) );
288 else if( !strcmp( s, "strsub" ) )
290 int n = E_(SSPopN)( st, vars );
291 int m = E_(SSPopN)( st, vars );
293 char *s = E_(SSPop)( st );
305 str = malloc( i_len + 1 );
307 memcpy( str, s + m - 1, i_len );
310 E_(SSPush)( st, str );
314 else if( !strcmp( s, "strlen" ) )
316 char *str = E_(SSPop)( st );
318 E_(SSPushN)( st, strlen( str ) );
321 else if( !strcmp( s, "str_replace" ) )
323 char *psz_to = E_(SSPop)( st );
324 char *psz_from = E_(SSPop)( st );
325 char *psz_in = E_(SSPop)( st );
326 char *psz_in_current = psz_in;
327 char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
328 char *psz_out_current = psz_out;
330 while( (p = strstr( psz_in_current, psz_from )) != NULL )
332 memcpy( psz_out_current, psz_in_current, p - psz_in_current );
333 psz_out_current += p - psz_in_current;
334 strcpy( psz_out_current, psz_to );
335 psz_out_current += strlen(psz_to);
336 psz_in_current = p + strlen(psz_from);
338 strcpy( psz_out_current, psz_in_current );
339 psz_out_current += strlen(psz_in_current);
340 *psz_out_current = '\0';
342 E_(SSPush)( st, psz_out );
348 else if( !strcmp( s, "url_extract" ) )
350 char *url = E_(mvar_GetValue)( vars, "url_value" );
351 char *name = E_(SSPop)( st );
352 char *value = E_(ExtractURIString)( url, name );
356 E_(SSPush)( st, value );
360 E_(SSPush)( st, "" );
364 else if( !strcmp( s, "url_encode" ) )
366 char *url = E_(SSPop)( st );
367 char *value = vlc_UrlEncode( url );
369 E_(SSPush)( st, value );
372 else if( !strcmp( s, "addslashes" ) )
374 char *psz_src = E_(SSPop)( st );
378 p = psz_dest = malloc( strlen( str ) * 2 + 1 );
380 while( *str != '\0' )
382 if( *str == '"' || *str == '\'' || *str == '\\' )
391 E_(SSPush)( st, psz_dest );
395 else if( !strcmp( s, "stripslashes" ) )
397 char *psz_src = E_(SSPop)( st );
401 p = psz_dest = strdup( psz_src );
405 if( *str == '\\' && *(str + 1) )
413 E_(SSPush)( st, psz_dest );
417 else if( !strcmp( s, "htmlspecialchars" ) )
419 char *psz_src = E_(SSPop)( st );
422 psz_dest = convert_xml_special_chars( psz_src );
424 E_(SSPush)( st, psz_dest );
428 else if( !strcmp( s, "realpath" ) )
430 char *psz_src = E_(SSPop)( st );
431 char *psz_dir = E_(RealPath)( p_intf, psz_src );
433 E_(SSPush)( st, psz_dir );
437 /* 4. stack functions */
438 else if( !strcmp( s, "dup" ) )
440 char *str = E_(SSPop)( st );
441 E_(SSPush)( st, str );
442 E_(SSPush)( st, str );
445 else if( !strcmp( s, "drop" ) )
447 char *str = E_(SSPop)( st );
450 else if( !strcmp( s, "swap" ) )
452 char *s1 = E_(SSPop)( st );
453 char *s2 = E_(SSPop)( st );
455 E_(SSPush)( st, s1 );
456 E_(SSPush)( st, s2 );
460 else if( !strcmp( s, "flush" ) )
465 else if( !strcmp( s, "store" ) )
467 char *value = E_(SSPop)( st );
468 char *name = E_(SSPop)( st );
470 E_(mvar_PushNewVar)( vars, name, value );
474 else if( !strcmp( s, "value" ) )
476 char *name = E_(SSPop)( st );
477 char *value = E_(mvar_GetValue)( vars, name );
479 E_(SSPush)( st, value );
483 /* 5. player control */
484 else if( !strcmp( s, "vlc_play" ) )
486 int i_id = E_(SSPopN)( st, vars );
489 i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
491 playlist_ItemGetById( p_sys->p_playlist,
493 msg_Dbg( p_intf, "requested playlist item: %i", i_id );
494 E_(SSPushN)( st, i_ret );
496 else if( !strcmp( s, "vlc_stop" ) )
498 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP, VLC_TRUE );
499 msg_Dbg( p_intf, "requested playlist stop" );
501 else if( !strcmp( s, "vlc_pause" ) )
503 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE, VLC_TRUE );
504 msg_Dbg( p_intf, "requested playlist pause" );
506 else if( !strcmp( s, "vlc_next" ) )
508 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, VLC_TRUE, 1 );
509 msg_Dbg( p_intf, "requested playlist next" );
511 else if( !strcmp( s, "vlc_previous" ) )
513 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, VLC_TRUE, -1 );
514 msg_Dbg( p_intf, "requested playlist previous" );
516 else if( !strcmp( s, "vlc_seek" ) )
518 char *psz_value = E_(SSPop)( st );
519 E_(HandleSeek)( p_intf, psz_value );
520 msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
523 else if( !strcmp( s, "vlc_var_type" )
524 || !strcmp( s, "vlc_config_type" ) )
526 vlc_object_t *p_object;
527 const char *psz_type = NULL;
530 if( !strcmp( s, "vlc_var_type" ) )
532 char *psz_object = E_(SSPop)( st );
533 char *psz_variable = E_(SSPop)( st );
534 vlc_bool_t b_need_release;
536 p_object = GetVLCObject( p_intf, psz_object, &b_need_release );
538 if( p_object != NULL )
539 i_type = var_Type( p_object, psz_variable );
540 free( psz_variable );
542 if( b_need_release && p_object != NULL )
543 vlc_object_release( p_object );
547 char *psz_variable = E_(SSPop)( st );
548 p_object = VLC_OBJECT(p_intf);
549 i_type = config_GetType( p_object, psz_variable );
550 free( psz_variable );
553 if( p_object != NULL )
555 switch( i_type & VLC_VAR_TYPE )
558 psz_type = "VLC_VAR_BOOL";
560 case VLC_VAR_INTEGER:
561 psz_type = "VLC_VAR_INTEGER";
564 psz_type = "VLC_VAR_HOTKEY";
567 psz_type = "VLC_VAR_STRING";
570 psz_type = "VLC_VAR_MODULE";
573 psz_type = "VLC_VAR_FILE";
575 case VLC_VAR_DIRECTORY:
576 psz_type = "VLC_VAR_DIRECTORY";
578 case VLC_VAR_VARIABLE:
579 psz_type = "VLC_VAR_VARIABLE";
582 psz_type = "VLC_VAR_FLOAT";
585 psz_type = "UNDEFINED";
589 psz_type = "INVALID";
591 E_(SSPush)( st, psz_type );
593 else if( !strcmp( s, "vlc_var_set" ) )
595 char *psz_object = E_(SSPop)( st );
596 char *psz_variable = E_(SSPop)( st );
597 vlc_bool_t b_need_release;
599 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
602 if( p_object != NULL )
604 vlc_bool_t b_error = VLC_FALSE;
605 char *psz_value = NULL;
609 i_type = var_Type( p_object, psz_variable );
611 switch( i_type & VLC_VAR_TYPE )
614 val.b_bool = E_(SSPopN)( st, vars );
615 msg_Dbg( p_intf, "requested %s var change: %s->%d",
616 psz_object, psz_variable, val.b_bool );
618 case VLC_VAR_INTEGER:
620 val.i_int = E_(SSPopN)( st, vars );
621 msg_Dbg( p_intf, "requested %s var change: %s->%d",
622 psz_object, psz_variable, val.i_int );
627 case VLC_VAR_DIRECTORY:
628 case VLC_VAR_VARIABLE:
629 val.psz_string = psz_value = E_(SSPop)( st );
630 msg_Dbg( p_intf, "requested %s var change: %s->%s",
631 psz_object, psz_variable, psz_value );
634 psz_value = E_(SSPop)( st );
635 val.f_float = atof( psz_value );
636 msg_Dbg( p_intf, "requested %s var change: %s->%f",
637 psz_object, psz_variable, val.f_float );
640 E_(SSPopN)( st, vars );
641 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
642 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
647 var_Set( p_object, psz_variable, val );
648 if( psz_value != NULL )
652 msg_Warn( p_intf, "vlc_var_set called without an object" );
653 free( psz_variable );
656 if( b_need_release && p_object != NULL )
657 vlc_object_release( p_object );
659 else if( !strcmp( s, "vlc_var_get" ) )
661 char *psz_object = E_(SSPop)( st );
662 char *psz_variable = E_(SSPop)( st );
663 vlc_bool_t b_need_release;
665 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
668 if( p_object != NULL )
673 i_type = var_Type( p_object, psz_variable );
674 var_Get( p_object, psz_variable, &val );
676 switch( i_type & VLC_VAR_TYPE )
679 E_(SSPushN)( st, val.b_bool );
681 case VLC_VAR_INTEGER:
683 E_(SSPushN)( st, val.i_int );
688 case VLC_VAR_DIRECTORY:
689 case VLC_VAR_VARIABLE:
690 E_(SSPush)( st, val.psz_string );
691 free( val.psz_string );
696 lldiv_t value = lldiv( val.f_float * 1000000, 1000000 );
697 snprintf( psz_value, sizeof(psz_value), "%lld.%06u",
698 value.quot, (unsigned int)value.rem );
699 E_(SSPush)( st, psz_value );
703 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
704 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
705 E_(SSPush)( st, "" );
710 msg_Warn( p_intf, "vlc_var_get called without an object" );
711 E_(SSPush)( st, "" );
713 free( psz_variable );
716 if( b_need_release && p_object != NULL )
717 vlc_object_release( p_object );
719 else if( !strcmp( s, "vlc_object_exists" ) )
721 char *psz_object = E_(SSPop)( st );
722 vlc_bool_t b_need_release;
724 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
726 if( b_need_release && p_object != NULL )
727 vlc_object_release( p_object );
729 if( p_object != NULL )
730 E_(SSPush)( st, "1" );
732 E_(SSPush)( st, "0" );
734 else if( !strcmp( s, "vlc_config_set" ) )
736 char *psz_variable = E_(SSPop)( st );
737 int i_type = config_GetType( p_intf, psz_variable );
739 switch( i_type & VLC_VAR_TYPE )
742 case VLC_VAR_INTEGER:
743 config_PutInt( p_intf, psz_variable, E_(SSPopN)( st, vars ) );
748 case VLC_VAR_DIRECTORY:
750 char *psz_string = E_(SSPop)( st );
751 config_PutPsz( p_intf, psz_variable, psz_string );
757 char *psz_string = E_(SSPop)( st );
758 config_PutFloat( p_intf, psz_variable, atof(psz_string) );
763 msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)",
766 free( psz_variable );
768 else if( !strcmp( s, "vlc_config_get" ) )
770 char *psz_variable = E_(SSPop)( st );
771 int i_type = config_GetType( p_intf, psz_variable );
773 switch( i_type & VLC_VAR_TYPE )
776 case VLC_VAR_INTEGER:
777 E_(SSPushN)( st, config_GetInt( p_intf, psz_variable ) );
782 case VLC_VAR_DIRECTORY:
784 char *psz_string = config_GetPsz( p_intf, psz_variable );
785 E_(SSPush)( st, psz_string );
792 lldiv_t value = lldiv( config_GetFloat( p_intf, psz_variable )
793 * 1000000, 1000000 );
794 snprintf( psz_string, sizeof(psz_string), "%lld.%06u",
795 value.quot, (unsigned int)value.rem );
796 E_(SSPush)( st, psz_string );
800 msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)",
802 E_(SSPush)( st, "" );
804 free( psz_variable );
806 else if( !strcmp( s, "vlc_config_save" ) )
808 char *psz_module = E_(SSPop)( st );
816 i_result = config_SaveConfigFile( p_intf, psz_module );
818 if( psz_module != NULL )
820 E_(SSPushN)( st, i_result );
822 else if( !strcmp( s, "vlc_config_reset" ) )
824 config_ResetAll( p_intf );
826 /* 6. playlist functions */
827 else if( !strcmp( s, "playlist_add" ) )
829 char *psz_name = E_(SSPop)( st );
830 char *mrl = E_(SSPop)( st );
831 input_item_t *p_input;
834 p_input = E_(MRLParse)( p_intf, mrl, psz_name );
836 char *psz_uri = input_item_GetURI( p_input );
837 if( !p_input || !psz_uri || !*psz_uri )
839 i_ret = VLC_EGENERIC;
840 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
844 i_ret = playlist_AddInput( p_sys->p_playlist, p_input,
845 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
847 vlc_gc_decref( p_input );
848 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
851 E_(SSPushN)( st, i_ret );
856 else if( !strcmp( s, "playlist_empty" ) )
858 playlist_Clear( p_sys->p_playlist, VLC_FALSE );
859 msg_Dbg( p_intf, "requested playlist empty" );
861 else if( !strcmp( s, "playlist_delete" ) )
863 int i_id = E_(SSPopN)( st, vars );
864 playlist_item_t *p_item = playlist_ItemGetById( p_sys->p_playlist,
868 playlist_DeleteFromInput( p_sys->p_playlist,
869 p_item->p_input->i_id, VLC_FALSE );
870 msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
874 msg_Dbg( p_intf, "couldn't find playlist item to delete (%d)",
878 else if( !strcmp( s, "playlist_move" ) )
880 /*int i_newpos =*/ E_(SSPopN)( st, vars );
881 /*int i_pos =*/ E_(SSPopN)( st, vars );
882 /* FIXME FIXME TODO TODO XXX XXX
883 do not release before fixing this
884 if ( i_pos < i_newpos )
886 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
890 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
892 msg_Dbg( p_intf, "requested to move playlist item %d to %d",
894 FIXME FIXME TODO TODO XXX XXX */
895 msg_Err( p_intf, "moving using indexes is obsolete. We need to update this function" );
897 else if( !strcmp( s, "playlist_sort" ) )
899 int i_order = E_(SSPopN)( st, vars );
900 int i_sort = E_(SSPopN)( st, vars );
901 i_order = i_order % 2;
903 /* FIXME FIXME TODO TODO XXX XXX
904 do not release before fixing this
905 playlist_RecursiveNodeSort( p_sys->p_playlist,
906 p_sys->p_playlist->p_general,
908 msg_Dbg( p_intf, "requested sort playlist by : %d in order : %d",
910 FIXME FIXME TODO TODO XXX XXX */
911 msg_Err( p_intf, "this needs to be fixed to use the new playlist framework" );
913 else if( !strcmp( s, "services_discovery_add" ) )
915 char *psz_sd = E_(SSPop)( st );
916 playlist_ServicesDiscoveryAdd( p_sys->p_playlist, psz_sd );
919 else if( !strcmp( s, "services_discovery_remove" ) )
921 char *psz_sd = E_(SSPop)( st );
922 playlist_ServicesDiscoveryRemove( p_sys->p_playlist, psz_sd );
925 else if( !strcmp( s, "services_discovery_is_loaded" ) )
927 char *psz_sd = E_(SSPop)( st );
929 playlist_IsServicesDiscoveryLoaded( p_sys->p_playlist, psz_sd ) );
932 else if( !strcmp( s, "vlc_volume_set" ) )
934 char *psz_vol = E_(SSPop)( st );
936 audio_volume_t i_volume;
937 aout_VolumeGet( p_intf, &i_volume );
938 if( psz_vol[0] == '+' )
940 i_value = atoi( psz_vol );
941 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
942 aout_VolumeSet( p_intf, AOUT_VOLUME_MAX );
944 aout_VolumeSet( p_intf, i_volume + i_value );
946 else if( psz_vol[0] == '-' )
948 i_value = atoi( psz_vol );
949 if( (i_volume + i_value) < AOUT_VOLUME_MIN )
950 aout_VolumeSet( p_intf, AOUT_VOLUME_MIN );
952 aout_VolumeSet( p_intf, i_volume + i_value );
954 else if( strstr( psz_vol, "%") != NULL )
956 i_value = atoi( psz_vol );
957 if( i_value < 0 ) i_value = 0;
958 if( i_value > 400 ) i_value = 400;
959 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);
963 i_value = atoi( psz_vol );
964 if( i_value > AOUT_VOLUME_MAX ) i_value = AOUT_VOLUME_MAX;
965 if( i_value < AOUT_VOLUME_MIN ) i_value = AOUT_VOLUME_MIN;
966 aout_VolumeSet( p_intf, i_value );
968 aout_VolumeGet( p_intf, &i_volume );
971 else if( !strcmp( s, "vlc_get_meta" ) )
973 char *psz_meta = E_(SSPop)( st );
974 char *psz_val = NULL;
975 if( p_sys->p_input && input_GetItem(p_sys->p_input) )
977 #define p_item input_GetItem( p_sys->p_input )
978 if( !strcmp( psz_meta, "ARTIST" ) )
980 psz_val = input_ItemGetInfo( p_item,
981 _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
983 else if( !strcmp( psz_meta, "TITLE" ) )
985 psz_val = input_ItemGetInfo( p_item,
986 _(VLC_META_INFO_CAT), _(VLC_META_TITLE) );
987 if( psz_val == NULL )
988 psz_val = strdup( p_item->psz_name );
990 else if( !strcmp( psz_meta, "ALBUM" ) )
992 psz_val = input_ItemGetInfo( p_item,
993 _(VLC_META_INFO_CAT), _(VLC_META_COLLECTION) );
995 else if( !strcmp( psz_meta, "GENRE" ) )
997 psz_val = input_ItemGetInfo( p_item,
998 _(VLC_META_INFO_CAT), _(VLC_META_GENRE) );
1002 psz_val = input_ItemGetInfo( p_item,
1003 _(VLC_META_INFO_CAT), psz_meta );
1007 if( psz_val == NULL ) psz_val = strdup( "" );
1008 E_(SSPush)( st, psz_val );
1012 else if( !strcmp( s, "vlm_command" ) || !strcmp( s, "vlm_cmd" ) )
1015 char *psz_cmd = strdup( "" );
1017 vlm_message_t *vlm_answer;
1019 /* make sure that we have a vlm object */
1020 if( p_intf->p_sys->p_vlm == NULL )
1021 p_intf->p_sys->p_vlm = vlm_New( p_intf );
1024 /* vlm command uses the ';' delimiter
1025 * (else we can't know when to stop) */
1026 while( strcmp( psz_elt = E_(SSPop)( st ), "" )
1027 && strcmp( psz_elt, ";" ) )
1030 (char *)malloc( strlen( psz_cmd ) + strlen( psz_elt ) + 2 );
1031 sprintf( psz_buf, "%s %s", psz_cmd, psz_elt );
1037 msg_Dbg( p_intf, "executing vlm command: %s", psz_cmd );
1038 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz_cmd, &vlm_answer );
1040 if( vlm_answer->psz_value == NULL )
1042 psz_error = strdup( "" );
1046 psz_error = malloc( strlen(vlm_answer->psz_name) +
1047 strlen(vlm_answer->psz_value) +
1048 strlen( " : ") + 1 );
1049 sprintf( psz_error , "%s : %s" , vlm_answer->psz_name,
1050 vlm_answer->psz_value );
1053 E_(mvar_AppendNewVar)( vars, "vlm_error", psz_error );
1054 /* this is kind of a duplicate but we need to have the message
1055 * without the command name for the "export" command */
1056 E_(mvar_AppendNewVar)( vars, "vlm_value", vlm_answer->psz_value );
1057 vlm_MessageDelete( vlm_answer );
1062 else if( !strcmp( s, "snapshot" ) )
1064 if( p_sys->p_input )
1066 vout_thread_t *p_vout;
1067 p_vout = vlc_object_find( p_sys->p_input,
1068 VLC_OBJECT_VOUT, FIND_CHILD );
1072 vout_Control( p_vout, VOUT_SNAPSHOT );
1073 vlc_object_release( p_vout );
1074 msg_Dbg( p_intf, "requested snapshot" );
1082 E_(SSPush)( st, s );