]> git.sesse.net Git - vlc/blobdiff - modules/control/http/rpn.c
Remove window size parameter.
[vlc] / modules / control / http / rpn.c
index 79ae22ea94bdc968049f4f57abd51f2ac01dd485..6027a15d636d4fd41c1ca092ad0ac3addec7763b 100644 (file)
@@ -24,6 +24,9 @@
  *****************************************************************************/
 
 #include "http.h"
+#include "vlc_url.h"
+#include "vlc_meta.h"
+#include "vlc_strings.h"
 
 static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
                                    const char *psz_object,
@@ -34,10 +37,8 @@ static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,
     vlc_object_t *p_object = NULL;
     *pb_need_release = VLC_FALSE;
 
-    if( !strcmp( psz_object, "VLC_OBJECT_ROOT" ) )
-        i_object_type = VLC_OBJECT_ROOT;
-    else if( !strcmp( psz_object, "VLC_OBJECT_VLC" ) )
-        p_object = VLC_OBJECT(p_intf->p_vlc);
+    if( !strcmp( psz_object, "VLC_OBJECT_LIBVLC" ) )
+        p_object = VLC_OBJECT(p_intf->p_libvlc);
     else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )
         p_object = VLC_OBJECT(p_intf);
     else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )
@@ -117,9 +118,9 @@ int E_(SSPopN)( rpn_stack_t *st, mvar_t  *vars )
 
 void E_(SSPushN)( rpn_stack_t *st, int i )
 {
-    char v[512];
+    char v[12];
 
-    sprintf( v, "%d", i );
+    snprintf( v, sizeof (v), "%d", i );
     E_(SSPush)( st, v );
 }
 
@@ -352,7 +353,7 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             char *tmp;
 
             E_(ExtractURIValue)( url, name, value, 512 );
-            E_(DecodeEncodedURI)( value );
+            decode_URI( value );
             tmp = E_(FromUTF8)( p_intf, value );
             E_(SSPush)( st, tmp );
             free( tmp );
@@ -398,16 +399,17 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
         {
             char *psz_src = E_(SSPop)( st );
             char *psz_dest;
+            char *str = psz_src;
 
             p = psz_dest = strdup( psz_src );
 
-            while( *psz_src )
+            while( *str )
             {
-                if( *psz_src == '\\' && *(psz_src + 1) )
+                if( *str == '\\' && *(str + 1) )
                 {
-                    psz_src++;
+                    str++;
                 }
-                *p++ = *psz_src++;
+                *p++ = *str++;
             }
             *p = '\0';
 
@@ -419,44 +421,8 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
         {
             char *psz_src = E_(SSPop)( st );
             char *psz_dest;
-            char *str = psz_src;
 
-            p = psz_dest = malloc( strlen( str ) * 6 + 1 );
-
-            while( *str != '\0' )
-            {
-                if( *str == '&' )
-                {
-                    strcpy( p, "&" );
-                    p += 5;
-                }
-                else if( *str == '\"' )
-                {
-                    strcpy( p, """ );
-                    p += 6;
-                }
-                else if( *str == '\'' )
-                {
-                    strcpy( p, "'" );
-                    p += 6;
-                }
-                else if( *str == '<' )
-                {
-                    strcpy( p, "&lt;" );
-                    p += 4;
-                }
-                else if( *str == '>' )
-                {
-                    strcpy( p, "&gt;" );
-                    p += 4;
-                }
-                else
-                {
-                    *p++ = *str;
-                }
-                str++;
-            }
-            *p = '\0';
+            psz_dest = convert_xml_special_chars( psz_src );
 
             E_(SSPush)( st, psz_dest );
             free( psz_src );
@@ -523,30 +489,31 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             int i_id = E_(SSPopN)( st, vars );
             int i_ret;
 
-            i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
+            i_ret = playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
+                                      NULL,
                                       playlist_ItemGetById( p_sys->p_playlist,
-                                      i_id ) );
+                                      i_id, VLC_TRUE ) );
             msg_Dbg( p_intf, "requested playlist item: %i", i_id );
             E_(SSPushN)( st, i_ret );
         }
         else if( !strcmp( s, "vlc_stop" ) )
         {
-            playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
+            playlist_Control( p_sys->p_playlist, VLC_TRUE, PLAYLIST_STOP );
             msg_Dbg( p_intf, "requested playlist stop" );
         }
         else if( !strcmp( s, "vlc_pause" ) )
         {
-            playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
+            playlist_Control( p_sys->p_playlist, VLC_TRUE, PLAYLIST_PAUSE );
             msg_Dbg( p_intf, "requested playlist pause" );
         }
         else if( !strcmp( s, "vlc_next" ) )
         {
-            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
+            playlist_Control( p_sys->p_playlist, VLC_TRUE, PLAYLIST_SKIP, 1 );
             msg_Dbg( p_intf, "requested playlist next" );
         }
         else if( !strcmp( s, "vlc_previous" ) )
         {
-            playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
+            playlist_Control( p_sys->p_playlist, VLC_TRUE, PLAYLIST_SKIP, -1 );
             msg_Dbg( p_intf, "requested playlist previous" );
         }
         else if( !strcmp( s, "vlc_seek" ) )
@@ -729,7 +696,9 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
                 case VLC_VAR_FLOAT:
                 {
                     char psz_value[20];
-                    snprintf( psz_value, sizeof(psz_value), "%f", val.f_float );
+                    lldiv_t value = lldiv( val.f_float * 1000000, 1000000 );
+                    snprintf( psz_value, sizeof(psz_value), "%lld.%06u",
+                                    value.quot, (unsigned int)value.rem );
                     E_(SSPush)( st, psz_value );
                     break;
                 }
@@ -823,8 +792,10 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             case VLC_VAR_FLOAT:
             {
                 char psz_string[20];
-                snprintf( psz_string, sizeof(psz_string), "%f",
-                          config_GetFloat( p_intf, psz_variable ) );
+                lldiv_t value = lldiv( config_GetFloat( p_intf, psz_variable )
+                                       * 1000000, 1000000 );
+                snprintf( psz_string, sizeof(psz_string), "%lld.%06u",
+                          value.quot, (unsigned int)value.rem );
                 E_(SSPush)( st, psz_string );
                 break;
             }
@@ -860,7 +831,7 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             char *psz_name = E_(SSPop)( st );
             char *mrl = E_(SSPop)( st );
             char *tmp;
-            playlist_item_t *p_item;
+            input_item_t *p_input;
             int i_id;
 
             tmp = E_(ToUTF8)( p_intf, psz_name );
@@ -870,25 +841,18 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             free( mrl );
             mrl = tmp;
 
-            if( !*psz_name )
-            {
-                p_item = E_(MRLParse)( p_intf, mrl, mrl );
-            }
-            else
-            {
-                p_item = E_(MRLParse)( p_intf, mrl, psz_name );
-            }
+            p_input = E_(MRLParse)( p_intf, mrl, psz_name );
 
-            if( p_item == NULL || p_item->input.psz_uri == NULL ||
-                 !*p_item->input.psz_uri )
+            if( !p_input || !p_input->psz_uri || !*p_input->psz_uri )
             {
                 i_id = VLC_EGENERIC;
                 msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
             }
             else
             {
-                i_id = playlist_AddItem( p_sys->p_playlist, p_item,
-                                         PLAYLIST_APPEND, PLAYLIST_END );
+                i_id = playlist_AddInput( p_sys->p_playlist, p_input,
+                                   PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                                   VLC_FALSE);
                 msg_Dbg( p_intf, "requested mrl add: %s", mrl );
             }
             E_(SSPushN)( st, i_id );
@@ -898,19 +862,21 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
         }
         else if( !strcmp( s, "playlist_empty" ) )
         {
-            playlist_LockClear( p_sys->p_playlist );
+            playlist_Clear( p_sys->p_playlist, VLC_FALSE );
             msg_Dbg( p_intf, "requested playlist empty" );
         }
         else if( !strcmp( s, "playlist_delete" ) )
         {
             int i_id = E_(SSPopN)( st, vars );
-            playlist_LockDelete( p_sys->p_playlist, i_id );
+            playlist_DeleteFromInput( p_sys->p_playlist, i_id, VLC_FALSE );
             msg_Dbg( p_intf, "requested playlist delete: %d", i_id );
         }
         else if( !strcmp( s, "playlist_move" ) )
         {
-            int i_newpos = E_(SSPopN)( st, vars );
-            int i_pos = E_(SSPopN)( st, vars );
+            /*int i_newpos =*/ E_(SSPopN)( st, vars );
+            /*int i_pos =*/ E_(SSPopN)( st, vars );
+            /* FIXME FIXME TODO TODO XXX XXX
+            do not release before fixing this
             if ( i_pos < i_newpos )
             {
                 playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
@@ -921,6 +887,43 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             }
             msg_Dbg( p_intf, "requested to move playlist item %d to %d",
                      i_pos, i_newpos);
+               FIXME FIXME TODO TODO XXX XXX */
+            msg_Err( p_intf, "moving using indexes is obsolete. We need to update this function" );
+        }
+        else if( !strcmp( s, "playlist_sort" ) )
+        {
+            int i_order = E_(SSPopN)( st, vars );
+            int i_sort = E_(SSPopN)( st, vars );
+            i_order = i_order % 2;
+            i_sort = i_sort % 9;
+            /* FIXME FIXME TODO TODO XXX XXX
+            do not release before fixing this
+            playlist_RecursiveNodeSort(  p_sys->p_playlist,
+                                         p_sys->p_playlist->p_general,
+                                         i_sort, i_order );
+            msg_Dbg( p_intf, "requested sort playlist by : %d in order : %d",
+                     i_sort, i_order );
+               FIXME FIXME TODO TODO XXX XXX */
+            msg_Err( p_intf, "this needs to be fixed to use the new playlist framework" );
+        }
+        else if( !strcmp( s, "services_discovery_add" ) )
+        {
+            char *psz_sd = E_(SSPop)( st );
+            playlist_ServicesDiscoveryAdd( p_sys->p_playlist, psz_sd );
+            free( psz_sd );
+        }
+        else if( !strcmp( s, "services_discovery_remove" ) )
+        {
+            char *psz_sd = E_(SSPop)( st );
+            playlist_ServicesDiscoveryRemove( p_sys->p_playlist, psz_sd );
+            free( psz_sd );
+        }
+        else if( !strcmp( s, "services_discovery_is_loaded" ) )
+        {
+            char *psz_sd = E_(SSPop)( st );
+            E_(SSPushN)( st,
+            playlist_IsServicesDiscoveryLoaded( p_sys->p_playlist, psz_sd ) );
+            free( psz_sd );
         }
         else if( !strcmp( s, "vlc_volume_set" ) )
         {
@@ -959,6 +962,48 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
                 aout_VolumeSet( p_intf, i_value );
             }
             aout_VolumeGet( p_intf, &i_volume );
+            free( psz_vol );
+        }
+        else if( !strcmp( s, "vlc_get_meta" ) )
+        {
+            char *psz_meta = E_(SSPop)( st );
+            char *psz_val = NULL;
+            if( p_sys->p_input && input_GetItem(p_sys->p_input) )
+            {
+#define p_item input_GetItem( p_sys->p_input )
+                if( !strcmp( psz_meta, "ARTIST" ) )
+                {
+                    psz_val = input_ItemGetInfo( p_item,
+                                _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
+                }
+                else if( !strcmp( psz_meta, "TITLE" ) )
+                {
+                    psz_val = input_ItemGetInfo( p_item,
+                                _(VLC_META_INFO_CAT), _(VLC_META_TITLE) );
+                    if( psz_val == NULL )
+                        psz_val = strdup( p_item->psz_name );
+                }
+                else if( !strcmp( psz_meta, "ALBUM" ) )
+                {
+                    psz_val = input_ItemGetInfo( p_item,
+                                _(VLC_META_INFO_CAT), _(VLC_META_COLLECTION) );
+                }
+                else if( !strcmp( psz_meta, "GENRE" ) )
+                {
+                    psz_val = input_ItemGetInfo( p_item,
+                                _(VLC_META_INFO_CAT), _(VLC_META_GENRE) );
+                }
+                else
+                {
+                    psz_val = input_ItemGetInfo( p_item,
+                                            _(VLC_META_INFO_CAT), psz_meta );
+                }
+#undef p_item
+            }
+            if( psz_val == NULL ) psz_val = strdup( "" );
+            E_(SSPush)( st, psz_val );
+            free( psz_meta );
+            free( psz_val );
         }
         else if( !strcmp( s, "vlm_command" ) || !strcmp( s, "vlm_cmd" ) )
         {
@@ -977,7 +1022,6 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             while( strcmp( psz_elt = E_(SSPop)( st ), "" )
                    && strcmp( psz_elt, ";" ) )
             {
-                printf( "\npsz_elt : %s", psz_elt );
                 char *psz_buf =
                     (char *)malloc( strlen( psz_cmd ) + strlen( psz_elt ) + 2 );
                 sprintf( psz_buf, "%s %s", psz_cmd, psz_elt );
@@ -986,8 +1030,7 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
                 psz_cmd = psz_buf;
             }
 
-            printf( "\nVLM command : %s\n\n", psz_cmd );
-
+            msg_Dbg( p_intf, "executing vlm command: %s", psz_cmd );
             vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz_cmd, &vlm_answer );
 
             if( vlm_answer->psz_value == NULL )
@@ -1004,11 +1047,32 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,
             }
 
             E_(mvar_AppendNewVar)( vars, "vlm_error", psz_error );
+            /* this is kind of a duplicate but we need to have the message
+             * without the command name for the "export" command */
+            E_(mvar_AppendNewVar)( vars, "vlm_value", vlm_answer->psz_value );
             vlm_MessageDelete( vlm_answer );
 
             free( psz_cmd );
             free( psz_error );
         }
+        else if( !strcmp( s, "snapshot" ) )
+        {
+            if( p_sys->p_input )
+            {
+                vout_thread_t *p_vout;
+                p_vout = vlc_object_find( p_sys->p_input,
+                                          VLC_OBJECT_VOUT, FIND_CHILD );
+
+                if( p_vout )
+                {
+                    vout_Control( p_vout, VOUT_SNAPSHOT );
+                    vlc_object_release( p_vout );
+                    msg_Dbg( p_intf, "requested snapshot" );
+                }
+            }
+            break;
+
+        }
         else
         {
             E_(SSPush)( st, s );