]> git.sesse.net Git - vlc/blobdiff - modules/control/http/http.c
Add --data-path option. Access the src share directory now works from build tree.
[vlc] / modules / control / http / http.c
index 518c1cb06e765d2c76ab38a443e3ffa7c24805ea..ec762d0bbe652816d07bb182ddd3c617efcca409 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "http.h"
 #include <vlc_plugin.h>
+#include <vlc_url.h>
 
 #include <assert.h>
 
@@ -231,9 +232,10 @@ static int Open( vlc_object_t *p_this )
     psz_src = config_GetPsz( p_intf, "http-src" );
     if( ( psz_src == NULL ) || ( *psz_src == '\0' ) )
     {
-        const char *data_path = config_GetDataDir ();
+        char *data_path = config_GetDataDir( p_intf );
         if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 )
             psz_src = NULL;
+        free( data_path );
     }
 
     if( !psz_src || *psz_src == '\0' )
@@ -417,7 +419,7 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
         state = "stop";
     }
 
-    aout_VolumeGet( p_args->p_intf, &i_volume );
+    aout_VolumeGet( p_sys->p_playlist, &i_volume );
     sprintf( volume, "%d", (int)i_volume );
 
     p_args->vars = mvar_New( "variables", "" );
@@ -432,7 +434,6 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
     mvar_AppendNewVar( p_args->vars, "vlc_compile_domain",
                            VLC_CompileDomain() );
     mvar_AppendNewVar( p_args->vars, "vlc_compiler", VLC_Compiler() );
-    mvar_AppendNewVar( p_args->vars, "vlc_changeset", VLC_Changeset() );
     mvar_AppendNewVar( p_args->vars, "stream_position", position );
     mvar_AppendNewVar( p_args->vars, "stream_time", time );
     mvar_AppendNewVar( p_args->vars, "stream_length", length );
@@ -556,18 +557,11 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
     int i_env = 0;
     char **ppsz_env = NULL;
     char *psz_tmp;
-    char sep;
     size_t i_buffer;
     char *p_buffer;
     char *psz_cwd, *psz_file = NULL;
     int i_ret;
 
-#ifdef WIN32
-    sep = '\\';
-#else
-    sep = '/';
-#endif
-
     /* Create environment for the CGI */
     TAB_APPEND( i_env, ppsz_env, strdup("GATEWAY_INTERFACE=CGI/1.1") );
     TAB_APPEND( i_env, ppsz_env, strdup("SERVER_PROTOCOL=HTTP/1.1") );
@@ -590,33 +584,40 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
 
     if( i_request )
     {
-        asprintf( &psz_tmp, "QUERY_STRING=%s", p_request );
+        if( -1==asprintf( &psz_tmp, "QUERY_STRING=%s", p_request ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
 
-        asprintf( &psz_tmp, "REQUEST_URI=%s?%s", p_url, p_request );
+        if( -1==asprintf( &psz_tmp, "REQUEST_URI=%s?%s", p_url, p_request ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
     else
     {
-        asprintf( &psz_tmp, "REQUEST_URI=%s", p_url );
+        if( -1==asprintf( &psz_tmp, "REQUEST_URI=%s", p_url ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
 
-    asprintf( &psz_tmp, "SCRIPT_NAME=%s", p_url );
+    if( -1==asprintf( &psz_tmp, "SCRIPT_NAME=%s", p_url ) )
+        psz_tmp = NULL;
     TAB_APPEND( i_env, ppsz_env, psz_tmp );
 
 #define p_sys p_args->file.p_intf->p_sys
-    asprintf( &psz_tmp, "SERVER_NAME=%s", p_sys->psz_address );
+    if( -1==asprintf( &psz_tmp, "SERVER_NAME=%s", p_sys->psz_address ) )
+        psz_tmp = NULL;
     TAB_APPEND( i_env, ppsz_env, psz_tmp );
 
-    asprintf( &psz_tmp, "SERVER_PORT=%u", p_sys->i_port );
+    if( -1==asprintf( &psz_tmp, "SERVER_PORT=%u", p_sys->i_port ) )
+        psz_tmp = NULL;
     TAB_APPEND( i_env, ppsz_env, psz_tmp );
 #undef p_sys
 
     p = getenv( "PATH" );
     if( p != NULL )
     {
-        asprintf( &psz_tmp, "PATH=%s", p );
+        if( -1==asprintf( &psz_tmp, "PATH=%s", p ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
 
@@ -624,20 +625,23 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
     p = getenv( "windir" );
     if( p != NULL )
     {
-        asprintf( &psz_tmp, "SYSTEMROOT=%s", p );
+        if( -1==asprintf( &psz_tmp, "SYSTEMROOT=%s", p ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
 #endif
 
     if( psz_remote_addr != NULL && *psz_remote_addr )
     {
-        asprintf( &psz_tmp, "REMOTE_ADDR=%s", psz_remote_addr );
+        if( -1==asprintf( &psz_tmp, "REMOTE_ADDR=%s", psz_remote_addr ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
 
     if( psz_remote_host != NULL && *psz_remote_host )
     {
-        asprintf( &psz_tmp, "REMOTE_HOST=%s", psz_remote_host );
+        if( -1==asprintf( &psz_tmp, "REMOTE_HOST=%s", psz_remote_host ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
     }
 
@@ -652,7 +656,8 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
                 if( end == NULL )
                     break;
                 *end = '\0';
-                asprintf( &psz_tmp, "CONTENT_TYPE=%s", p );
+                if( -1==asprintf( &psz_tmp, "CONTENT_TYPE=%s", p ) )
+                    psz_tmp = NULL;
                 TAB_APPEND( i_env, ppsz_env, psz_tmp );
                 *end = '\r';
             }
@@ -663,7 +668,8 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
                 if( end == NULL )
                     break;
                 *end = '\0';
-                asprintf( &psz_tmp, "CONTENT_LENGTH=%s", p );
+                if( -1==asprintf( &psz_tmp, "CONTENT_LENGTH=%s", p ) )
+                    psz_tmp = NULL;
                 TAB_APPEND( i_env, ppsz_env, psz_tmp );
                 *end = '\r';
             }
@@ -678,11 +684,12 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
         }
     }
 
-    psz_file = strrchr( p_args->file.file, sep );
+    psz_file = strrchr( p_args->file.file, DIR_SEP_CHAR );
     if( psz_file != NULL )
     {
         psz_file++;
-        asprintf( &psz_tmp, "SCRIPT_FILENAME=%s", psz_file );
+        if( -1==asprintf( &psz_tmp, "SCRIPT_FILENAME=%s", psz_file ) )
+            psz_tmp = NULL;
         TAB_APPEND( i_env, ppsz_env, psz_tmp );
 
         TAB_APPEND( p_args->p_association->i_argc,
@@ -695,7 +702,7 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
                 NULL );
 
     psz_tmp = strdup( p_args->file.file );
-    p = strrchr( psz_tmp, sep );
+    p = strrchr( psz_tmp, DIR_SEP_CHAR );
     if( p != NULL )
     {
         *p = '\0';
@@ -776,10 +783,12 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
     i_id = atoi( psz_id );
     if( i_id )
     {
+        playlist_Lock( p_sys->p_playlist );
         playlist_item_t *p_pl_item = playlist_ItemGetById( p_sys->p_playlist,
-                                                           i_id, false );
+                                                           i_id );
         if( p_pl_item )
             p_item = p_pl_item->p_input;
+        playlist_Unlock( p_sys->p_playlist );
     }
     else
     {
@@ -793,7 +802,8 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
         psz_art = input_item_GetArtURL( p_item );
     }
 
-    if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) )
+    if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) &&
+        decode_URI( psz_art + 7 ) )
     {
         FILE *f;
         char *psz_ext;
@@ -823,6 +833,8 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
         i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data );
 #undef HEADER
 
+        assert( i_header_size != -1 );
+
         *pi_data = i_header_size + i_data;
         *pp_data = (uint8_t*)malloc( *pi_data );
         memcpy( *pp_data, psz_header, i_header_size );