]> 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 75f24c2af4c1a22239a57f6ff1d067f1005e0bd5..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", "" );
@@ -582,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 );
     }
 
@@ -616,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 );
     }
 
@@ -644,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';
             }
@@ -655,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';
             }
@@ -674,7 +688,8 @@ int  HandlerCallback( httpd_handler_sys_t *p_args,
     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,
@@ -787,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;
@@ -817,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 );