]> git.sesse.net Git - vlc/blobdiff - modules/control/http/macro.c
Merge commit 'origin/1.0-bugfix'
[vlc] / modules / control / http / macro.c
index 2b6aff03fc332a45b89b1f438fd3de049d596fe4..4d55c8df273deed99637f43be6ebc2f4356fa181 100644 (file)
@@ -199,10 +199,11 @@ static void MacroDo( httpd_file_sys_t *p_args,
                         msg_Dbg( p_intf, "requested playlist play" );
                         break;
                     }
+                    //TODO: really locked here ?
                     playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
                                       true, NULL,
                                       playlist_ItemGetById( p_sys->p_playlist,
-                                      i_item, true ) );
+                                      i_item ) );
                     msg_Dbg( p_intf, "requested playlist item: %i", i_item );
                     break;
                 }
@@ -230,9 +231,8 @@ static void MacroDo( httpd_file_sys_t *p_args,
                     if( p_sys->p_input )
                     {
                         vout_thread_t *p_vout;
-                        p_vout = vlc_object_find( p_sys->p_input,
-                                                  VLC_OBJECT_VOUT, FIND_CHILD );
 
+                        p_vout = input_GetVout( p_sys->p_input );
                         if( p_vout )
                         {
                             p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
@@ -338,30 +338,23 @@ static void MacroDo( httpd_file_sys_t *p_args,
 
                     p_input = MRLParse( p_intf, mrl, psz_name );
 
-                    char *psz_uri = input_item_GetURI( p_input );
-                    if( !p_input || !psz_uri || !*psz_uri )
-                    {
-                        msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
-                    }
+                    char *psz_uri = p_input ? input_item_GetURI( p_input ) : NULL;
+                    if( psz_uri && *psz_uri &&
+                        playlist_AddInput( p_sys->p_playlist, p_input,
+                                           PLAYLIST_APPEND, PLAYLIST_END,
+                                           true, false) == VLC_SUCCESS )
+                        msg_Dbg( p_intf, "requested mrl add: %s", mrl );
                     else
-                    {
-                        int i_ret = playlist_AddInput( p_sys->p_playlist,
-                                     p_input,
-                                     PLAYLIST_APPEND, PLAYLIST_END, true,
-                                     false);
-                        vlc_gc_decref( p_input );
-                        if( i_ret == VLC_SUCCESS )
-                            msg_Dbg( p_intf, "requested mrl add: %s", mrl );
-                        else
-                            msg_Warn( p_intf, "adding mrl %s failed", mrl );
-                    }
+                        msg_Warn( p_intf, "adding mrl failed: %s", mrl );
                     free( psz_uri );
-
+                    if( p_input )
+                        vlc_gc_decref( p_input );
                     break;
                 }
                 case MVLC_DEL:
                 {
-                    int i_item, *p_items = NULL, i_nb_items = 0;
+                    int *p_items = NULL;
+                    size_t i_nb_items = 0;
                     char item[512];
                     const char *p_parser = p_request;
 
@@ -371,24 +364,25 @@ static void MacroDo( httpd_file_sys_t *p_args,
                     {
                         if( !*item ) continue;
 
-                        i_item = atoi( item );
+                        int i_item = atoi( item );
                         p_items = realloc( p_items, (i_nb_items + 1) *
-                                           sizeof(int) );
+                                           sizeof(*p_items) );
                         p_items[i_nb_items] = i_item;
                         i_nb_items++;
                     }
 
-                    if( i_nb_items )
+                    for( size_t i = 0; i < i_nb_items; i++ )
                     {
-                        int i;
-                        for( i = 0; i < i_nb_items; i++ )
-                        {
+                        playlist_item_t *p_item;
+
+                        msg_Dbg( p_intf, "requested playlist delete: %d",
+                                 p_items[i] );
+                        p_item = playlist_ItemGetById( p_sys->p_playlist,
+                                                       p_items[i] );
+                        if( p_item )
                             playlist_DeleteFromInput( p_sys->p_playlist,
-                                                      p_items[i], false );
-                            msg_Dbg( p_intf, "requested playlist delete: %d",
-                                     p_items[i] );
-                            p_items[i] = -1;
-                        }
+                                                      p_item->p_input,
+                                                      false );
                     }
 
                     free( p_items );
@@ -396,10 +390,10 @@ static void MacroDo( httpd_file_sys_t *p_args,
                 }
                 case MVLC_KEEP:
                 {
-                    int i_item, *p_items = NULL, i_nb_items = 0;
+                    int *p_items = NULL;
+                    size_t i_nb_items = 0, i;
                     char item[512];
                     const char *p_parser = p_request;
-                    int i,j;
 
                     /* Get the list of items to keep */
                     while( (p_parser =
@@ -407,30 +401,31 @@ static void MacroDo( httpd_file_sys_t *p_args,
                     {
                         if( !*item ) continue;
 
-                        i_item = atoi( item );
+                        int i_item = atoi( item );
                         p_items = realloc( p_items, (i_nb_items + 1) *
-                                           sizeof(int) );
+                                           sizeof(*p_items) );
                         p_items[i_nb_items] = i_item;
                         i_nb_items++;
                     }
 
-                    for( i = p_sys->p_playlist->items.i_size - 1 ; i >= 0; i-- )
+                    for( i = 0; i < p_sys->p_playlist->items.i_size; i++ )
                     {
+                        size_t j;
+
                         /* Check if the item is in the keep list */
                         for( j = 0 ; j < i_nb_items ; j++ )
                         {
                             if( p_items[j] ==
-                                 ARRAY_VAL(p_sys->p_playlist->items,i)
-                                                ->i_id)
+                                ARRAY_VAL(p_sys->p_playlist->items,i)->i_id)
                                 break;
                         }
                         if( j == i_nb_items )
                         {
+                            msg_Dbg( p_intf, "requested playlist delete: %d",
+                                   p_sys->p_playlist->items.p_elems[i]->i_id );
                             playlist_DeleteFromInput( p_sys->p_playlist,
-                                     p_sys->p_playlist->items.p_elems[i]->i_id,
+                                p_sys->p_playlist->items.p_elems[i]->p_input,
                                                       false );
-                            msg_Dbg( p_intf, "requested playlist delete: %d",
-                                     i );
                         }
                     }
 
@@ -529,7 +524,7 @@ static void MacroDo( httpd_file_sys_t *p_args,
                 case MVLC_SHUTDOWN:
                 {
                     msg_Dbg( p_intf, "requested shutdown" );
-                    vlc_object_kill( p_intf->p_libvlc );
+                    libvlc_Quit( p_intf->p_libvlc );
                     break;
                 }
 #ifdef ENABLE_VLM
@@ -555,7 +550,11 @@ static void MacroDo( httpd_file_sys_t *p_args,
                     if( p_intf->p_sys->p_vlm == NULL )
                         p_intf->p_sys->p_vlm = vlm_New( p_intf );
 
-                    if( p_intf->p_sys->p_vlm == NULL ) break;
+                    if( p_intf->p_sys->p_vlm == NULL )
+                    {
+                        free( psz );
+                        break;
+                    }
 
                     ExtractURIValue( p_request, "name", name, 512 );
                     if( StrToMacroType( control ) == MVLC_VLM_NEW )
@@ -591,11 +590,10 @@ static void MacroDo( httpd_file_sys_t *p_args,
                     }
                     else
                     {
-                        vlm_error = malloc( strlen(vlm_answer->psz_name) +
-                                            strlen(vlm_answer->psz_value) +
-                                            strlen( " : ") + 1 );
-                        sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
-                                                         vlm_answer->psz_value );
+                        if( asprintf( &vlm_error , "%s : %s" ,
+                                      vlm_answer->psz_name,
+                                      vlm_answer->psz_value ) == -1 )
+                            vlm_error = NULL;
                     }
 
                     mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );