]> git.sesse.net Git - vlc/blobdiff - modules/control/http/macro.c
Don't include config.h from the headers - refs #297.
[vlc] / modules / control / http / macro.c
index 34795bb65ccbec37b09245a661f96941ab730eeb..450a0e4106b212552978f6c47349c4cdc80c98bb 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "http.h"
 #include "macros.h"
+#include "vlc_url.h"
 
-int E_(MacroParse)( macro_t *m, char *psz_src )
+static int MacroParse( macro_t *m, char *psz_src )
 {
     char *dup = strdup( (char *)psz_src );
     char *src = dup;
@@ -106,14 +110,14 @@ int E_(MacroParse)( macro_t *m, char *psz_src )
 #undef EXTRACT
 }
 
-void E_(MacroClean)( macro_t *m )
+static void MacroClean( macro_t *m )
 {
     free( m->id );
     free( m->param1 );
     free( m->param2 );
 }
 
-int E_(StrToMacroType)( char *name )
+static int StrToMacroType( const char *name )
 {
     int i;
 
@@ -131,7 +135,7 @@ int E_(StrToMacroType)( char *name )
     return MVLC_UNKNOWN;
 }
 
-void E_(MacroDo)( httpd_file_sys_t *p_args,
+static void MacroDo( httpd_file_sys_t *p_args,
                      macro_t *m,
                      char *p_request, int i_request,
                      char **pp_data,  int *pi_data,
@@ -166,7 +170,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
         } \
     }
 
-    switch( E_(StrToMacroType)( m->id ) )
+    switch( StrToMacroType( m->id ) )
     {
         case MVLC_CONTROL:
             if( i_request <= 0 )
@@ -179,7 +183,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 msg_Warn( p_intf, "unauthorized control=%s", control );
                 break;
             }
-            switch( E_(StrToMacroType)( control ) )
+            switch( StrToMacroType( control ) )
             {
                 case MVLC_PLAY:
                 {
@@ -195,26 +199,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:
@@ -329,17 +338,20 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
 
                     p_input = E_(MRLParse)( p_intf, mrl, psz_name );
 
-                    if( !p_input || p_input->psz_uri ||
-                        !*p_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_PlaylistAddInput( p_sys->p_playlist, p_input,
-                                          PLAYLIST_APPEND, PLAYLIST_END );
+                        playlist_AddInput( p_sys->p_playlist, p_input,
+                                     PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
+                                     VLC_FALSE);
+                        vlc_gc_decref( p_input );
                         msg_Dbg( p_intf, "requested mrl add: %s", mrl );
                     }
+                    free( psz_uri );
 
                     break;
                 }
@@ -366,7 +378,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;
@@ -395,19 +408,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]->p_input->i_id )
+                                 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]->p_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 );
                         }
@@ -418,7 +433,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;
                 }
@@ -440,7 +455,7 @@ 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 ),*/
+                        playlist_RecursiveNodeSort( p_sys->p_playlist,
                                                     /* Ugly hack,but not worse than before ... */
                                                     p_sys->p_playlist->p_root_onelevel,
                                                     SORT_TITLE_NODES_FIRST,
@@ -451,7 +466,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     {
                         playlist_RecursiveNodeSort( p_sys->p_playlist, /*playlist_ItemGetById( p_sys->p_playlist, i_item ),*/
                                                     p_sys->p_playlist->p_root_onelevel,
-                                                    SORT_AUTHOR,
+                                                    SORT_ARTIST,
                                                     ( i_order == 0 ) ? ORDER_NORMAL : ORDER_REVERSE );
                         msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
                     }
@@ -508,7 +523,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 */
@@ -535,7 +550,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     if( p_intf->p_sys->p_vlm == NULL ) break;
 
                     E_(ExtractURIValue)( p_request, "name", name, 512 );
-                    if( E_(StrToMacroType)( control ) == MVLC_VLM_NEW )
+                    if( StrToMacroType( control ) == MVLC_VLM_NEW )
                     {
                         char type[20];
                         E_(ExtractURIValue)( p_request, "type", type, 20 );
@@ -616,13 +631,13 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     if( p_intf->p_sys->p_vlm == NULL ) break;
 
                     E_(ExtractURIValue)( p_request, "name", name, 512 );
-                    if( E_(StrToMacroType)( control ) == MVLC_VLM_PLAY )
+                    if( StrToMacroType( control ) == MVLC_VLM_PLAY )
                         sprintf( psz, "control %s play", name );
-                    else if( E_(StrToMacroType)( control ) == MVLC_VLM_PAUSE )
+                    else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
                         sprintf( psz, "control %s pause", name );
-                    else if( E_(StrToMacroType)( control ) == MVLC_VLM_STOP )
+                    else if( StrToMacroType( control ) == MVLC_VLM_STOP )
                         sprintf( psz, "control %s stop", name );
-                    else if( E_(StrToMacroType)( control ) == MVLC_VLM_SEEK )
+                    else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
                     {
                         char percent[20];
                         E_(ExtractURIValue)( p_request, "percent", percent, 512 );
@@ -649,7 +664,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                     E_(ExtractURIValue)( p_request, "file", file, 512 );
                     decode_URI( file );
 
-                    if( E_(StrToMacroType)( control ) == MVLC_VLM_LOAD )
+                    if( StrToMacroType( control ) == MVLC_VLM_LOAD )
                         sprintf( psz, "load %s", file );
                     else
                         sprintf( psz, "save %s", file );
@@ -684,7 +699,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
             E_(ExtractURIValue)( p_request, m->param1,  value, 512 );
             decode_URI( value );
 
-            switch( E_(StrToMacroType)( m->param2 ) )
+            switch( StrToMacroType( m->param2 ) )
             {
                 case MVLC_INT:
                     i = atoi( value );
@@ -715,7 +730,7 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
                 break;
             }
 
-            switch( E_(StrToMacroType)( m->param2 ) )
+            switch( StrToMacroType( m->param2 ) )
             {
                 case MVLC_INT:
                     i = config_GetInt( p_intf, m->param1 );
@@ -724,7 +739,7 @@ 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:
@@ -790,7 +805,8 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
 #undef ALLOC
 }
 
-char *E_(MacroSearch)( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
+static
+char *MacroSearch( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
 {
     int     i_id;
     int     i_level = 0;
@@ -802,9 +818,9 @@ char *E_(MacroSearch)( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
             int i_skip;
             macro_t m;
 
-            i_skip = E_(MacroParse)( &m, src );
+            i_skip = MacroParse( &m, src );
 
-            i_id = E_(StrToMacroType)( m.id );
+            i_id = StrToMacroType( m.id );
 
             switch( i_id )
             {
@@ -819,7 +835,7 @@ char *E_(MacroSearch)( char *src, char *end, int i_mvlc, vlc_bool_t b_after )
                     break;
             }
 
-            E_(MacroClean)( &m );
+            MacroClean( &m );
 
             if( ( i_mvlc == MVLC_END && i_level == -1 ) ||
                 ( i_mvlc != MVLC_END && i_level == 0 && i_mvlc == i_id ) )
@@ -870,11 +886,11 @@ void E_(Execute)( httpd_file_sys_t *p_args,
         {
             macro_t m;
 
-            src += E_(MacroParse)( &m, src );
+            src += MacroParse( &m, src );
 
             //msg_Dbg( p_intf, "macro_id=%s", m.id );
 
-            switch( E_(StrToMacroType)( m.id ) )
+            switch( StrToMacroType( m.id ) )
             {
                 case MVLC_INCLUDE:
                 {
@@ -910,8 +926,8 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                     if( ( f = fopen( psz_file, "r" ) ) == NULL )
                     {
                         msg_Warn( p_args->p_intf,
-                                  "unable to include file %s (%s)",
-                                  psz_file, strerror(errno) );
+                                  "unable to include file %s (%m)",
+                                  psz_file );
                         break;
                     }
 
@@ -939,15 +955,15 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                     {
                         i_test = 0;
                     }
-                    endif = E_(MacroSearch)( src, end, MVLC_END, VLC_TRUE );
+                    endif = MacroSearch( src, end, MVLC_END, VLC_TRUE );
 
                     if( i_test == 0 )
                     {
-                        char *start = E_(MacroSearch)( src, endif, MVLC_ELSE, VLC_TRUE );
+                        char *start = MacroSearch( src, endif, MVLC_ELSE, VLC_TRUE );
 
                         if( start )
                         {
-                            char *stop  = E_(MacroSearch)( start, endif, MVLC_END, VLC_FALSE );
+                            char *stop  = MacroSearch( start, endif, MVLC_END, VLC_FALSE );
                             if( stop )
                             {
                                 E_(Execute)( p_args, p_request, i_request,
@@ -958,9 +974,9 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                     else if( i_test == 1 )
                     {
                         char *stop;
-                        if( ( stop = E_(MacroSearch)( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
+                        if( ( stop = MacroSearch( src, endif, MVLC_ELSE, VLC_FALSE ) ) == NULL )
                         {
-                            stop = E_(MacroSearch)( src, endif, MVLC_END, VLC_FALSE );
+                            stop = MacroSearch( src, endif, MVLC_END, VLC_FALSE );
                         }
                         if( stop )
                         {
@@ -974,9 +990,9 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                 }
                 case MVLC_FOREACH:
                 {
-                    char *endfor = E_(MacroSearch)( src, end, MVLC_END, VLC_TRUE );
+                    char *endfor = MacroSearch( src, end, MVLC_END, VLC_TRUE );
                     char *start = src;
-                    char *stop = E_(MacroSearch)( src, end, MVLC_END, VLC_FALSE );
+                    char *stop = MacroSearch( src, end, MVLC_END, VLC_FALSE );
 
                     if( stop )
                     {
@@ -1077,12 +1093,12 @@ void E_(Execute)( httpd_file_sys_t *p_args,
                     break;
                 }
                 default:
-                    E_(MacroDo)( p_args, &m, p_request, i_request,
-                                 pp_data, pi_data, &dst );
+                    MacroDo( p_args, &m, p_request, i_request,
+                             pp_data, pi_data, &dst );
                     break;
             }
 
-            E_(MacroClean)( &m );
+            MacroClean( &m );
             continue;
         }