]> git.sesse.net Git - vlc/blobdiff - modules/control/http/macro.c
Input access locking, part 3 (final).
[vlc] / modules / control / http / macro.c
index 7ea5cf193a334f7fffdb2a1ce9812e4247b6e6c4..89ed3c102a114f8cfe113f0868376589d6d9860c 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "http.h"
 #include "macros.h"
+#include "vlc_url.h"
 
 int E_(MacroParse)( macro_t *m, char *psz_src )
 {
@@ -195,26 +196,31 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                         msg_Dbg( p_intf, "requested playlist play" );
                         break;
                     }
-                    playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY,
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
+                                      VLC_TRUE, NULL,
                                       playlist_ItemGetById( p_sys->p_playlist,
-                                      i_item ) );
+                                      i_item, VLC_TRUE ) );
                     msg_Dbg( p_intf, "requested playlist item: %i", i_item );
                     break;
                 }
                 case MVLC_STOP:
-                    playlist_Control( p_sys->p_playlist, PLAYLIST_STOP );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_STOP,
+                                      VLC_TRUE );
                     msg_Dbg( p_intf, "requested playlist stop" );
                     break;
                 case MVLC_PAUSE:
-                    playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE,
+                                      VLC_TRUE );
                     msg_Dbg( p_intf, "requested playlist pause" );
                     break;
                 case MVLC_NEXT:
-                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,
+                                      VLC_TRUE, 1 );
                     msg_Dbg( p_intf, "requested playlist next" );
                     break;
                 case MVLC_PREVIOUS:
-                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1 );
+                    playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP,
+                                      VLC_TRUE, -1 );
                     msg_Dbg( p_intf, "requested playlist previous" );
                     break;
                 case MVLC_FULLSCREEN:
@@ -301,30 +307,47 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 /* playlist management */
                 case MVLC_ADD:
                 {
-                    char mrl[1024], psz_name[1024];
-                    playlist_item_t *p_item;
+                    char mrl[1024], psz_name[1024], tmp[1024];
+                    char *p, *str;
+                    input_item_t *p_input;
 
-                    E_(ExtractURIValue)( p_request, "mrl", mrl, 1024 );
-                    decode_URI( mrl );
+                    E_(ExtractURIValue)( p_request, "mrl", tmp, 1024 );
+                    decode_URI( tmp );
                     E_(ExtractURIValue)( p_request, "name", psz_name, 1024 );
                     decode_URI( psz_name );
                     if( !*psz_name )
                     {
-                        memcpy( psz_name, mrl, 1024 );
+                        memcpy( psz_name, tmp, 1024 );
                     }
-                    p_item = E_(MRLParse)( p_intf, mrl, psz_name );
+                    /* addslashes for backward compatibility with the old
+                     * http intf */
+                    p = mrl; str = tmp;
+                    while( *str != '\0' )
+                    {
+                        if( *str == '"' || *str == '\'' || *str == '\\' )
+                        {
+                            *p++ = '\\';
+                        }
+                        *p++ = *str;
+                        str++;
+                    }
+                    *p = '\0';
+
+                    p_input = E_(MRLParse)( p_intf, mrl, psz_name );
 
-                    if( !p_item || !p_item->input.psz_uri ||
-                        !*p_item->input.psz_uri )
+                    char *psz_uri = input_item_GetURI( p_input );
+                    if( !p_input || !psz_uri || !*psz_uri )
                     {
                         msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
                     }
                     else
                     {
-                        playlist_AddItem( p_sys->p_playlist, p_item,
-                                          PLAYLIST_APPEND, PLAYLIST_END );
+                        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 );
                     }
+                    free( psz_uri );
 
                     break;
                 }
@@ -351,7 +374,8 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                         int i;
                         for( i = 0; i < i_nb_items; i++ )
                         {
-                            playlist_LockDelete( p_sys->p_playlist, p_items[i] );
+                            playlist_DeleteFromInput( p_sys->p_playlist,
+                                                      p_items[i], VLC_FALSE );
                             msg_Dbg( p_intf, "requested playlist delete: %d",
                                      p_items[i] );
                             p_items[i] = -1;
@@ -380,17 +404,21 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                         i_nb_items++;
                     }
 
-                    for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- )
+                    for( i = p_sys->p_playlist->items.i_size - 1 ; i >= 0; i-- )
                     {
                         /* Check if the item is in the keep list */
                         for( j = 0 ; j < i_nb_items ; j++ )
                         {
                             if( p_items[j] ==
-                                p_sys->p_playlist->pp_items[i]->input.i_id ) break;
+                                 ARRAY_VAL(p_sys->p_playlist->items,i)
+                                                ->i_id)
+                                break;
                         }
                         if( j == i_nb_items )
                         {
-                            playlist_LockDelete( p_sys->p_playlist, p_sys->p_playlist->pp_items[i]->input.i_id );
+                            playlist_DeleteFromInput( p_sys->p_playlist,
+                                     p_sys->p_playlist->items.p_elems[i]->i_id,
+                                                      VLC_FALSE );
                             msg_Dbg( p_intf, "requested playlist delete: %d",
                                      i );
                         }
@@ -401,7 +429,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 }
                 case MVLC_EMPTY:
                 {
-                    playlist_LockClear( p_sys->p_playlist );
+                    playlist_Clear( p_sys->p_playlist, VLC_FALSE );
                     msg_Dbg( p_intf, "requested playlist empty" );
                     break;
                 }
@@ -423,8 +451,9 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
 
                     if( !strcmp( type , "title" ) )
                     {
-                        playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
-                                                    p_sys->p_playlist->pp_views[0]->p_root,
+                        playlist_RecursiveNodeSort( p_sys->p_playlist,
+                                                    /* Ugly hack,but not worse than before ... */
+                                                    p_sys->p_playlist->p_root_onelevel,
                                                     SORT_TITLE_NODES_FIRST,
                                                     ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist sort by title (%d)" , i_order );
@@ -432,15 +461,15 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     else if( !strcmp( type , "author" ) )
                     {
                         playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
-                                                    p_sys->p_playlist->pp_views[0]->p_root,
-                                                    SORT_AUTHOR,
+                                                    p_sys->p_playlist->p_root_onelevel,
+                                                    SORT_ARTIST,
                                                     ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
                     }
                     else if( !strcmp( type , "shuffle" ) )
                     {
                         playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
-                                                    p_sys->p_playlist->pp_views[0]->p_root,
+                                                    p_sys->p_playlist->p_root_onelevel,
                                                     SORT_RANDOM,
                                                     ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist shuffle");
@@ -458,6 +487,8 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     E_(ExtractURIValue)( p_request, "psz_newpos", psz_newpos, 6 );
                     i_pos = atoi( psz_pos );
                     i_newpos = atoi( psz_newpos );
+                    /* FIXME FIXME TODO TODO XXX XXX
+                    ( duplicate from rpn.c )
                     if ( i_pos < i_newpos )
                     {
                         playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
@@ -467,6 +498,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                         playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
                     }
                     msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
+                    FIXME FIXME TODO TODO XXX XXX */
                     break;
                 }
 
@@ -487,7 +519,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 case MVLC_SHUTDOWN:
                 {
                     msg_Dbg( p_intf, "requested shutdown" );
-                    p_intf->p_vlc->b_die = VLC_TRUE;
+                    vlc_object_kill( p_intf->p_libvlc );
                     break;
                 }
                 /* vlm */
@@ -703,16 +735,15 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 case MVLC_FLOAT:
                     f = config_GetFloat( p_intf, m->param1 );
                     div = lldiv( f * 1000000 , 1000000 );
-                    sprintf( value, I64Fd".%06u", div.quot,
+                    sprintf( value, "%lld.%06u", div.quot,
                             (unsigned int)div.rem );
                     break;
                 case MVLC_STRING:
                     psz = config_GetPsz( p_intf, m->param1 );
                     if( psz != NULL )
                     {
-                        strncpy( value, psz,sizeof( value ) );
+                        strlcpy( value, psz,sizeof( value ) );
                         free( psz );
-                        value[sizeof( value ) - 1] = '\0';
                     }
                     else
                         *value = '\0';
@@ -721,7 +752,6 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 default:
                     snprintf( value, sizeof( value ),
                               "invalid type(%s) in set", m->param2 );
-                    value[sizeof( value ) - 1] = '\0';
                     break;
             }
             PRINTS( "%s", value );