]> git.sesse.net Git - vlc/blobdiff - modules/control/http.c
* modules/control/http.c: fixed segfault when deleting items and prevent adding empty...
[vlc] / modules / control / http.c
index 4235800686630d8dcd4ef860cbe0eed2f72adbeb..d0cb9ca73bf4f5dd73198980a8b138b410d3be62 100644 (file)
@@ -2,7 +2,7 @@
  * http.c :  http mini-server ;)
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.34 2003/11/16 20:41:36 garf Exp $
+ * $Id: http.c,v 1.39 2003/11/23 17:46:06 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -1754,7 +1754,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                     uri_decode_url_encoded( mrl );
                     p_item = parse_MRL( mrl );
 
-                    if( p_item == NULL )
+                    if( !p_item || !*p_item )
                     {
                         msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
                     } else
@@ -1812,7 +1812,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 {
                     int i_item, *p_items = NULL, i_nb_items = 0;
                     char item[512], *p_parser = p_request;
-                    int i,j,temp;
+                    int i,j;
 
                     /* Get the list of items to keep */
                     while( (p_parser =
@@ -1821,40 +1821,27 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                         if( !*item ) continue;
 
                         i_item = atoi( item );
-                        p_items = realloc( p_items, (i_nb_items + 3) *
+                        p_items = realloc( p_items, (i_nb_items + 1) *
                                            sizeof(int) );
-                        p_items[i_nb_items + 1] = i_item;
+                        p_items[i_nb_items] = i_item;
                         i_nb_items++;
                     }
 
-                    /* sort item list */
-                    for( i=1 ; i < (i_nb_items + 1) ; i++)
+                    /* The items need to be deleted from in reversed order */
+                    for( i = p_sys->p_playlist->i_size - 1; i >= 0 ; i-- )
                     {
-                        for( j=(i+1) ; j < (i_nb_items + 1) ; j++)
+                        /* Check if the item is in the keep list */
+                        for( j = 0 ; j < i_nb_items ; j++ )
                         {
-                            if( p_items[j] > p_items[i] )
-                            {
-                                temp = p_items[j];
-                                p_items[j] = p_items[i];
-                                p_items[i] = temp;
-                            }
+                            if( p_items[j] == i ) break;
                         }
-                    }
-
-                    p_items[0] = p_sys->p_playlist->i_size;
-                    p_items[ i_nb_items + 1 ] = -1;
-
-                    /* The items need to be deleted from in reversed order */
-                        for( i=0 ; i <= i_nb_items ; i++ )
+                        if( j == i_nb_items )
                         {
-                            for( j = (p_items[i] - 1) ; j > p_items[i + 1] ; j-- )
-                            {
-                                playlist_Delete( p_sys->p_playlist,
-                                                 j );
-                                msg_Dbg( p_intf, "requested playlist delete: %d",
-                                         j );
-                            }
+                            playlist_Delete( p_sys->p_playlist, i );
+                            msg_Dbg( p_intf, "requested playlist delete: %d",
+                                     i );
                         }
+                    }
 
                     if( p_items ) free( p_items );
                     break;
@@ -2878,11 +2865,17 @@ playlist_item_t * parse_MRL( char *psz )
     }
 
     /* extract the mrl */
-    s_temp = Find_end_MRL( s_mrl );
-
+    s_temp = strstr( s_mrl , " :" );
     if( s_temp == NULL )
     {
-        return NULL;
+        s_temp = s_mrl + strlen( s_mrl );
+    } else
+    {
+        while( (*s_temp == ' ') && (s_temp != s_mrl ) )
+        {
+            s_temp--;
+        }
+        s_temp++;
     }
 
     /* if the mrl is between " or ', we must remove them */