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 *****************************************************************************/
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 int i_object_type = 0;
40 vlc_object_t *p_object = NULL;
41 *pb_need_release = false;
43 if( !strcmp( psz_object, "VLC_OBJECT_LIBVLC" ) )
44 p_object = VLC_OBJECT(p_intf->p_libvlc);
45 else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )
46 p_object = VLC_OBJECT(p_intf);
47 else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )
48 p_object = VLC_OBJECT(p_sys->p_playlist);
49 else if( !strcmp( psz_object, "VLC_OBJECT_INPUT" ) )
50 p_object = VLC_OBJECT(p_sys->p_input);
51 else if( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )
52 i_object_type = VLC_OBJECT_VOUT;
53 else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )
54 i_object_type = VLC_OBJECT_AOUT;
56 msg_Warn( p_intf, "unknown object type (%s)", psz_object );
58 if( p_object == NULL && i_object_type )
60 *pb_need_release = true;
61 p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );
67 void SSInit( rpn_stack_t *st )
72 void SSClean( rpn_stack_t *st )
74 while( st->i_stack > 0 )
76 free( st->stack[--st->i_stack] );
80 void SSPush( rpn_stack_t *st, const char *s )
82 if( st->i_stack < STACK_MAX )
84 st->stack[st->i_stack++] = strdup( s );
88 char *SSPop( rpn_stack_t *st )
90 if( st->i_stack <= 0 )
96 return st->stack[--st->i_stack];
100 int SSPopN( rpn_stack_t *st, mvar_t *vars )
109 i = strtol( name, &end, 0 );
112 value = mvar_GetValue( vars, name );
120 void SSPushN( rpn_stack_t *st, int i )
124 snprintf( v, sizeof (v), "%d", i );
128 void EvaluateRPN( intf_thread_t *p_intf, mvar_t *vars,
129 rpn_stack_t *st, char *exp )
131 intf_sys_t *p_sys = p_intf->p_sys;
133 while( exp != NULL && *exp != '\0' )
146 p = FirstWord( exp, exp );
153 p = FirstWord( exp, exp );
157 exp += strlen( exp );
169 /* 1. Integer function */
170 if( !strcmp( s, "!" ) )
172 SSPushN( st, ~SSPopN( st, vars ) );
174 else if( !strcmp( s, "^" ) )
176 SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );
178 else if( !strcmp( s, "&" ) )
180 SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );
182 else if( !strcmp( s, "|" ) )
184 SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );
186 else if( !strcmp( s, "+" ) )
188 SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );
190 else if( !strcmp( s, "-" ) )
192 int j = SSPopN( st, vars );
193 int i = SSPopN( st, vars );
194 SSPushN( st, i - j );
196 else if( !strcmp( s, "*" ) )
198 SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );
200 else if( !strcmp( s, "/" ) )
204 j = SSPopN( st, vars );
205 i = SSPopN( st, vars );
207 SSPushN( st, j != 0 ? i / j : 0 );
209 else if( !strcmp( s, "%" ) )
213 j = SSPopN( st, vars );
214 i = SSPopN( st, vars );
216 SSPushN( st, j != 0 ? i % j : 0 );
218 /* 2. integer tests */
219 else if( !strcmp( s, "=" ) )
221 SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );
223 else if( !strcmp( s, "!=" ) )
225 SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );
227 else if( !strcmp( s, "<" ) )
229 int j = SSPopN( st, vars );
230 int i = SSPopN( st, vars );
232 SSPushN( st, i < j ? -1 : 0 );
234 else if( !strcmp( s, ">" ) )
236 int j = SSPopN( st, vars );
237 int i = SSPopN( st, vars );
239 SSPushN( st, i > j ? -1 : 0 );
241 else if( !strcmp( s, "<=" ) )
243 int j = SSPopN( st, vars );
244 int i = SSPopN( st, vars );
246 SSPushN( st, i <= j ? -1 : 0 );
248 else if( !strcmp( s, ">=" ) )
250 int j = SSPopN( st, vars );
251 int i = SSPopN( st, vars );
253 SSPushN( st, i >= j ? -1 : 0 );
255 /* 3. string functions */
256 else if( !strcmp( s, "strcat" ) )
258 char *s2 = SSPop( st );
259 char *s1 = SSPop( st );
260 char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );
270 else if( !strcmp( s, "strcmp" ) )
272 char *s2 = SSPop( st );
273 char *s1 = SSPop( st );
275 SSPushN( st, strcmp( s1, s2 ) );
279 else if( !strcmp( s, "strncmp" ) )
281 int n = SSPopN( st, vars );
282 char *s2 = SSPop( st );
283 char *s1 = SSPop( st );
285 SSPushN( st, strncmp( s1, s2 , n ) );
289 else if( !strcmp( s, "strsub" ) )
291 int n = SSPopN( st, vars );
292 int m = SSPopN( st, vars );
294 char *s = SSPop( st );
306 str = malloc( i_len + 1 );
308 memcpy( str, s + m - 1, i_len );
315 else if( !strcmp( s, "strlen" ) )
317 char *str = SSPop( st );
319 SSPushN( st, strlen( str ) );
322 else if( !strcmp( s, "str_replace" ) )
324 char *psz_to = SSPop( st );
325 char *psz_from = SSPop( st );
326 char *psz_in = SSPop( st );
327 char *psz_in_current = psz_in;
328 char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );
329 char *psz_out_current = psz_out;
331 while( (p = strstr( psz_in_current, psz_from )) != NULL )
333 memcpy( psz_out_current, psz_in_current, p - psz_in_current );
334 psz_out_current += p - psz_in_current;
335 strcpy( psz_out_current, psz_to );
336 psz_out_current += strlen(psz_to);
337 psz_in_current = p + strlen(psz_from);
339 strcpy( psz_out_current, psz_in_current );
340 psz_out_current += strlen(psz_in_current);
341 *psz_out_current = '\0';
343 SSPush( st, psz_out );
349 else if( !strcmp( s, "url_extract" ) )
351 char *url = mvar_GetValue( vars, "url_value" );
352 char *name = SSPop( st );
353 char *value = ExtractURIString( url, name );
365 else if( !strcmp( s, "url_encode" ) )
367 char *url = SSPop( st );
368 char *value = vlc_UrlEncode( url );
373 else if( !strcmp( s, "xml_encode" ) )
375 char *url = SSPop( st );
376 char *value = convert_xml_special_chars( url );
381 else if( !strcmp( s, "addslashes" ) )
383 char *psz_src = SSPop( st );
387 p = psz_dest = malloc( strlen( str ) * 2 + 1 );
389 while( *str != '\0' )
391 if( *str == '"' || *str == '\'' || *str == '\\' )
400 SSPush( st, psz_dest );
404 else if( !strcmp( s, "stripslashes" ) )
406 char *psz_src = SSPop( st );
410 p = psz_dest = strdup( psz_src );
414 if( *str == '\\' && *(str + 1) )
422 SSPush( st, psz_dest );
426 else if( !strcmp( s, "htmlspecialchars" ) )
428 char *psz_src = SSPop( st );
431 psz_dest = convert_xml_special_chars( psz_src );
433 SSPush( st, psz_dest );
437 else if( !strcmp( s, "realpath" ) )
439 char *psz_src = SSPop( st );
440 char *psz_dir = RealPath( psz_src );
442 SSPush( st, psz_dir );
446 /* 4. stack functions */
447 else if( !strcmp( s, "dup" ) )
449 char *str = SSPop( st );
454 else if( !strcmp( s, "drop" ) )
456 char *str = SSPop( st );
459 else if( !strcmp( s, "swap" ) )
461 char *s1 = SSPop( st );
462 char *s2 = SSPop( st );
469 else if( !strcmp( s, "flush" ) )
474 else if( !strcmp( s, "store" ) )
476 char *value = SSPop( st );
477 char *name = SSPop( st );
479 mvar_PushNewVar( vars, name, value );
483 else if( !strcmp( s, "value" ) )
485 char *name = SSPop( st );
486 char *value = mvar_GetValue( vars, name );
492 /* 5. player control */
493 else if( !strcmp( s, "vlc_play" ) )
495 int i_id = SSPopN( st, vars );
498 vlc_object_lock( p_sys->p_playlist );
499 i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
501 playlist_ItemGetById( p_sys->p_playlist,
503 vlc_object_unlock( p_sys->p_playlist );
504 msg_Dbg( p_intf, "requested playlist item: %i", i_id );
505 SSPushN( st, i_ret );
507 else if( !strcmp( s, "vlc_stop" ) )
509 playlist_Control( p_sys->p_playlist, PLAYLIST_STOP, pl_Unlocked );
510 msg_Dbg( p_intf, "requested playlist stop" );
512 else if( !strcmp( s, "vlc_pause" ) )
514 playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE, pl_Unlocked );
515 msg_Dbg( p_intf, "requested playlist pause" );
517 else if( !strcmp( s, "vlc_next" ) )
519 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, 1 );
520 msg_Dbg( p_intf, "requested playlist next" );
522 else if( !strcmp( s, "vlc_previous" ) )
524 playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, pl_Unlocked, -1 );
525 msg_Dbg( p_intf, "requested playlist previous" );
527 else if( !strcmp( s, "vlc_seek" ) )
529 char *psz_value = SSPop( st );
530 HandleSeek( p_intf, psz_value );
531 msg_Dbg( p_intf, "requested playlist seek: %s", psz_value );
534 else if( !strcmp( s, "vlc_var_type" )
535 || !strcmp( s, "vlc_config_type" ) )
537 vlc_object_t *p_object;
538 const char *psz_type = NULL;
541 if( !strcmp( s, "vlc_var_type" ) )
543 char *psz_object = SSPop( st );
544 char *psz_variable = SSPop( st );
547 p_object = GetVLCObject( p_intf, psz_object, &b_need_release );
549 if( p_object != NULL )
550 i_type = var_Type( p_object, psz_variable );
551 free( psz_variable );
553 if( b_need_release && p_object != NULL )
554 vlc_object_release( p_object );
558 char *psz_variable = SSPop( st );
559 p_object = VLC_OBJECT(p_intf);
560 i_type = config_GetType( p_object, psz_variable );
561 free( psz_variable );
564 if( p_object != NULL )
566 switch( i_type & VLC_VAR_TYPE )
569 psz_type = "VLC_VAR_BOOL";
571 case VLC_VAR_INTEGER:
572 psz_type = "VLC_VAR_INTEGER";
575 psz_type = "VLC_VAR_HOTKEY";
578 psz_type = "VLC_VAR_STRING";
581 psz_type = "VLC_VAR_MODULE";
584 psz_type = "VLC_VAR_FILE";
586 case VLC_VAR_DIRECTORY:
587 psz_type = "VLC_VAR_DIRECTORY";
589 case VLC_VAR_VARIABLE:
590 psz_type = "VLC_VAR_VARIABLE";
593 psz_type = "VLC_VAR_FLOAT";
596 psz_type = "UNDEFINED";
600 psz_type = "INVALID";
602 SSPush( st, psz_type );
604 else if( !strcmp( s, "vlc_var_set" ) )
606 char *psz_object = SSPop( st );
607 char *psz_variable = SSPop( st );
610 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
613 if( p_object != NULL )
615 bool b_error = false;
616 char *psz_value = NULL;
620 i_type = var_Type( p_object, psz_variable );
622 switch( i_type & VLC_VAR_TYPE )
625 val.b_bool = SSPopN( st, vars );
626 msg_Dbg( p_intf, "requested %s var change: %s->%d",
627 psz_object, psz_variable, val.b_bool );
629 case VLC_VAR_INTEGER:
631 val.i_int = SSPopN( st, vars );
632 msg_Dbg( p_intf, "requested %s var change: %s->%d",
633 psz_object, psz_variable, val.i_int );
638 case VLC_VAR_DIRECTORY:
639 case VLC_VAR_VARIABLE:
640 val.psz_string = psz_value = SSPop( st );
641 msg_Dbg( p_intf, "requested %s var change: %s->%s",
642 psz_object, psz_variable, psz_value );
645 psz_value = SSPop( st );
646 val.f_float = atof( psz_value );
647 msg_Dbg( p_intf, "requested %s var change: %s->%f",
648 psz_object, psz_variable, val.f_float );
652 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
653 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
658 var_Set( p_object, psz_variable, val );
659 if( psz_value != NULL )
663 msg_Warn( p_intf, "vlc_var_set called without an object" );
664 free( psz_variable );
667 if( b_need_release && p_object != NULL )
668 vlc_object_release( p_object );
670 else if( !strcmp( s, "vlc_var_get" ) )
672 char *psz_object = SSPop( st );
673 char *psz_variable = SSPop( st );
676 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
679 if( p_object != NULL )
684 i_type = var_Type( p_object, psz_variable );
685 var_Get( p_object, psz_variable, &val );
687 switch( i_type & VLC_VAR_TYPE )
690 SSPushN( st, val.b_bool );
692 case VLC_VAR_INTEGER:
694 SSPushN( st, val.i_int );
699 case VLC_VAR_DIRECTORY:
700 case VLC_VAR_VARIABLE:
701 SSPush( st, val.psz_string );
702 free( val.psz_string );
707 lldiv_t value = lldiv( val.f_float * 1000000, 1000000 );
708 snprintf( psz_value, sizeof(psz_value), "%lld.%06u",
709 value.quot, (unsigned int)value.rem );
710 SSPush( st, psz_value );
714 msg_Warn( p_intf, "invalid %s variable type %d (%s)",
715 psz_object, i_type & VLC_VAR_TYPE, psz_variable );
721 msg_Warn( p_intf, "vlc_var_get called without an object" );
724 free( psz_variable );
727 if( b_need_release && p_object != NULL )
728 vlc_object_release( p_object );
730 else if( !strcmp( s, "vlc_object_exists" ) )
732 char *psz_object = SSPop( st );
735 vlc_object_t *p_object = GetVLCObject( p_intf, psz_object,
737 if( b_need_release && p_object != NULL )
738 vlc_object_release( p_object );
740 if( p_object != NULL )
745 else if( !strcmp( s, "vlc_config_set" ) )
747 char *psz_variable = SSPop( st );
748 int i_type = config_GetType( p_intf, psz_variable );
750 switch( i_type & VLC_VAR_TYPE )
753 case VLC_VAR_INTEGER:
754 config_PutInt( p_intf, psz_variable, SSPopN( st, vars ) );
759 case VLC_VAR_DIRECTORY:
761 char *psz_string = SSPop( st );
762 config_PutPsz( p_intf, psz_variable, psz_string );
768 char *psz_string = SSPop( st );
769 config_PutFloat( p_intf, psz_variable, atof(psz_string) );
774 msg_Warn( p_intf, "vlc_config_set called on unknown var (%s)",
777 free( psz_variable );
779 else if( !strcmp( s, "vlc_config_get" ) )
781 char *psz_variable = SSPop( st );
782 int i_type = config_GetType( p_intf, psz_variable );
784 switch( i_type & VLC_VAR_TYPE )
787 case VLC_VAR_INTEGER:
788 SSPushN( st, config_GetInt( p_intf, psz_variable ) );
793 case VLC_VAR_DIRECTORY:
795 char *psz_string = config_GetPsz( p_intf, psz_variable );
796 SSPush( st, psz_string );
803 lldiv_t value = lldiv( config_GetFloat( p_intf, psz_variable )
804 * 1000000, 1000000 );
805 snprintf( psz_string, sizeof(psz_string), "%lld.%06u",
806 value.quot, (unsigned int)value.rem );
807 SSPush( st, psz_string );
811 msg_Warn( p_intf, "vlc_config_get called on unknown var (%s)",
815 free( psz_variable );
817 else if( !strcmp( s, "vlc_config_save" ) )
819 char *psz_module = SSPop( st );
827 i_result = config_SaveConfigFile( p_intf, psz_module );
829 if( psz_module != NULL )
831 SSPushN( st, i_result );
833 else if( !strcmp( s, "vlc_config_reset" ) )
835 config_ResetAll( p_intf );
837 /* 6. playlist functions */
838 else if( !strcmp( s, "playlist_add" ) )
840 char *psz_name = SSPop( st );
841 char *mrl = SSPop( st );
842 input_item_t *p_input;
845 p_input = MRLParse( p_intf, mrl, psz_name );
847 char *psz_uri = input_item_GetURI( p_input );
848 if( !p_input || !psz_uri || !*psz_uri )
850 i_ret = VLC_EGENERIC;
851 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
855 i_ret = playlist_AddInput( p_sys->p_playlist, p_input,
856 PLAYLIST_APPEND, PLAYLIST_END, true,
858 vlc_gc_decref( p_input );
859 if( i_ret == VLC_SUCCESS )
860 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
862 msg_Warn( p_intf, "adding mrl %s failed", mrl );
865 SSPushN( st, i_ret );
870 else if( !strcmp( s, "playlist_empty" ) )
872 playlist_Clear( p_sys->p_playlist, pl_Unlocked );
873 msg_Dbg( p_intf, "requested playlist empty" );
875 else if( !strcmp( s, "playlist_delete" ) )
877 int i_id = SSPopN( st, vars );
878 playlist_item_t *p_item = playlist_ItemGetById( p_sys->p_playlist,
882 playlist_DeleteFromInput( p_sys->p_playlist,
883 p_item->p_input->i_id, pl_Unlocked );
884 msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
888 msg_Dbg( p_intf, "couldn't find playlist item to delete (%d)",
892 else if( !strcmp( s, "playlist_move" ) )
894 /*int i_newpos =*/ SSPopN( st, vars );
895 /*int i_pos =*/ SSPopN( st, vars );
896 /* FIXME FIXME TODO TODO XXX XXX
897 do not release before fixing this
898 if ( i_pos < i_newpos )
900 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
904 playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
906 msg_Dbg( p_intf, "requested to move playlist item %d to %d",
908 FIXME FIXME TODO TODO XXX XXX */
909 msg_Err( p_intf, "moving using indexes is obsolete. We need to update this function" );
911 else if( !strcmp( s, "playlist_sort" ) )
913 int i_order = SSPopN( st, vars );
914 int i_sort = SSPopN( st, vars );
915 i_order = i_order % 2;
917 /* FIXME FIXME TODO TODO XXX XXX
918 do not release before fixing this
919 playlist_RecursiveNodeSort( p_sys->p_playlist,
920 p_sys->p_playlist->p_general,
922 msg_Dbg( p_intf, "requested sort playlist by : %d in order : %d",
924 FIXME FIXME TODO TODO XXX XXX */
925 msg_Err( p_intf, "this needs to be fixed to use the new playlist framework" );
927 else if( !strcmp( s, "services_discovery_add" ) )
929 char *psz_sd = SSPop( st );
930 playlist_ServicesDiscoveryAdd( p_sys->p_playlist, psz_sd );
933 else if( !strcmp( s, "services_discovery_remove" ) )
935 char *psz_sd = SSPop( st );
936 playlist_ServicesDiscoveryRemove( p_sys->p_playlist, psz_sd );
939 else if( !strcmp( s, "services_discovery_is_loaded" ) )
941 char *psz_sd = SSPop( st );
943 playlist_IsServicesDiscoveryLoaded( p_sys->p_playlist, psz_sd ) );
946 else if( !strcmp( s, "vlc_volume_set" ) )
948 char *psz_vol = SSPop( st );
950 audio_volume_t i_volume;
951 aout_VolumeGet( p_intf, &i_volume );
952 if( psz_vol[0] == '+' )
954 i_value = atoi( psz_vol );
955 if( (i_volume + i_value) > AOUT_VOLUME_MAX )
956 aout_VolumeSet( p_intf, AOUT_VOLUME_MAX );
958 aout_VolumeSet( p_intf, i_volume + i_value );
960 else if( psz_vol[0] == '-' )
962 i_value = atoi( psz_vol );
963 if( (i_volume + i_value) < AOUT_VOLUME_MIN )
964 aout_VolumeSet( p_intf, AOUT_VOLUME_MIN );
966 aout_VolumeSet( p_intf, i_volume + i_value );
968 else if( strstr( psz_vol, "%") != NULL )
970 i_value = atoi( psz_vol );
971 if( i_value < 0 ) i_value = 0;
972 if( i_value > 400 ) i_value = 400;
973 aout_VolumeSet( p_intf, (i_value * (AOUT_VOLUME_MAX - AOUT_VOLUME_MIN))/400+AOUT_VOLUME_MIN);
977 i_value = atoi( psz_vol );
978 if( i_value > AOUT_VOLUME_MAX ) i_value = AOUT_VOLUME_MAX;
979 if( i_value < AOUT_VOLUME_MIN ) i_value = AOUT_VOLUME_MIN;
980 aout_VolumeSet( p_intf, i_value );
982 aout_VolumeGet( p_intf, &i_volume );
985 else if( !strcmp( s, "vlc_get_meta" ) )
987 char *psz_meta = SSPop( st );
988 char *psz_val = NULL;
989 if( p_sys->p_input && input_GetItem(p_sys->p_input) )
991 #define p_item input_GetItem( p_sys->p_input )
992 if( !strcmp( psz_meta, "ARTIST" ) )
994 psz_val = input_item_GetArtist( p_item );
996 else if( !strcmp( psz_meta, "TITLE" ) )
998 psz_val = input_item_GetTitle( p_item );
1000 psz_val = input_item_GetName( p_item );
1002 else if( !strcmp( psz_meta, "ALBUM" ) )
1004 psz_val = input_item_GetAlbum( p_item );
1006 else if( !strcmp( psz_meta, "GENRE" ) )
1008 psz_val = input_item_GetGenre( p_item );
1012 if( psz_val == NULL ) psz_val = strdup( "" );
1013 SSPush( st, psz_val );
1018 else if( !strcmp( s, "vlm_command" ) || !strcmp( s, "vlm_cmd" ) )
1021 char *psz_cmd = strdup( "" );
1023 vlm_message_t *vlm_answer;
1025 /* make sure that we have a vlm object */
1026 if( p_intf->p_sys->p_vlm == NULL )
1027 p_intf->p_sys->p_vlm = vlm_New( p_intf );
1030 /* vlm command uses the ';' delimiter
1031 * (else we can't know when to stop) */
1032 while( strcmp( psz_elt = SSPop( st ), "" )
1033 && strcmp( psz_elt, ";" ) )
1036 (char *)malloc( strlen( psz_cmd ) + strlen( psz_elt ) + 2 );
1037 sprintf( psz_buf, "%s %s", psz_cmd, psz_elt );
1043 msg_Dbg( p_intf, "executing vlm command: %s", psz_cmd );
1044 vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz_cmd, &vlm_answer );
1046 if( vlm_answer->psz_value == NULL )
1048 psz_error = strdup( "" );
1052 psz_error = malloc( strlen(vlm_answer->psz_name) +
1053 strlen(vlm_answer->psz_value) +
1054 strlen( " : ") + 1 );
1055 sprintf( psz_error , "%s : %s" , vlm_answer->psz_name,
1056 vlm_answer->psz_value );
1059 mvar_AppendNewVar( vars, "vlm_error", psz_error );
1060 /* this is kind of a duplicate but we need to have the message
1061 * without the command name for the "export" command */
1062 mvar_AppendNewVar( vars, "vlm_value", vlm_answer->psz_value );
1063 vlm_MessageDelete( vlm_answer );
1068 #endif /* ENABLE_VLM */
1069 else if( !strcmp( s, "snapshot" ) )
1071 if( p_sys->p_input )
1073 vout_thread_t *p_vout;
1074 p_vout = vlc_object_find( p_sys->p_input,
1075 VLC_OBJECT_VOUT, FIND_CHILD );
1079 vout_Control( p_vout, VOUT_SNAPSHOT );
1080 vlc_object_release( p_vout );
1081 msg_Dbg( p_intf, "requested snapshot" );