X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fhttp%2Fhttp.c;h=ec762d0bbe652816d07bb182ddd3c617efcca409;hb=28e52ddb9b8a1ae76eba086114ecf0bca90383ee;hp=17377229f40be4fe9ae91d7d5362e7fc5239ec43;hpb=630076053112b47b2f6279b1e67a4031d2ca45b2;p=vlc diff --git a/modules/control/http/http.c b/modules/control/http/http.c index 17377229f4..ec762d0bbe 100644 --- a/modules/control/http/http.c +++ b/modules/control/http/http.c @@ -2,7 +2,6 @@ * http.c : HTTP/HTTPS Remote control interface ***************************************************************************** * Copyright (C) 2001-2006 the VideoLAN team - * $Id$ * * Authors: Gildas Bazin * Laurent Aimar @@ -28,6 +27,9 @@ #include "http.h" #include +#include + +#include /***************************************************************************** * Module descriptor @@ -62,26 +64,26 @@ static void Close( vlc_object_t * ); #define CRL_TEXT N_( "CRL file" ) #define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file." ) -vlc_module_begin(); - set_shortname( _("HTTP")); - set_description( _("HTTP remote control interface") ); - set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_MAIN ); - add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true ); - add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, true ); - add_obsolete_string ( "http-charset" ); +vlc_module_begin () + set_shortname( N_("HTTP")) + set_description( N_("HTTP remote control interface") ) + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_MAIN ) + add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true ) + add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, true ) + add_obsolete_string ( "http-charset" ) #if defined( HAVE_FORK ) || defined( WIN32 ) - add_string ( "http-handlers", NULL, NULL, HANDLERS_TEXT, HANDLERS_LONGTEXT, true ); + add_string ( "http-handlers", NULL, NULL, HANDLERS_TEXT, HANDLERS_LONGTEXT, true ) #endif - add_bool ( "http-album-art", false, NULL, ART_TEXT, ART_LONGTEXT, true ); - set_section( N_("HTTP SSL" ), 0 ); - add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, true ); - add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, true ); - add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, true ); - add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, true ); - set_capability( "interface", 0 ); - set_callbacks( Open, Close ); -vlc_module_end(); + add_bool ( "http-album-art", false, NULL, ART_TEXT, ART_LONGTEXT, true ) + set_section( N_("HTTP SSL" ), 0 ) + add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, true ) + add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, true ) + add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, true ) + add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, true ) + set_capability( "interface", 0 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** @@ -94,35 +96,6 @@ int ArtCallback( httpd_handler_sys_t *p_args, char *psz_remote_addr, char *psz_remote_host, uint8_t **pp_data, int *pi_data ); -/***************************************************************************** - * Local functions - *****************************************************************************/ -#if !defined(__APPLE__) && !defined(SYS_BEOS) && !defined(WIN32) -static int DirectoryCheck( const char *psz_dir ) -{ - DIR *p_dir; - -#ifdef HAVE_SYS_STAT_H - struct stat stat_info; - - if( ( utf8_stat( psz_dir, &stat_info ) == -1 ) - || !S_ISDIR( stat_info.st_mode ) ) - { - return VLC_EGENERIC; - } -#endif - - if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL ) - { - return VLC_EGENERIC; - } - closedir( p_dir ); - - return VLC_SUCCESS; -} -#endif - - /***************************************************************************** * Activate: initialize and create stuff *****************************************************************************/ @@ -131,7 +104,7 @@ static int Open( vlc_object_t *p_this ) intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_sys_t *p_sys; char *psz_address; - const char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL, + char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL, *psz_crl = NULL; int i_port = 0; char *psz_src = NULL; @@ -139,7 +112,7 @@ static int Open( vlc_object_t *p_this ) psz_address = var_CreateGetNonEmptyString( p_intf, "http-host" ); if( psz_address != NULL ) { - char *psz_parser = strchr( psz_address, ':' ); + char *psz_parser = strrchr( psz_address, ':' ); if( psz_parser ) { *psz_parser++ = '\0'; @@ -152,10 +125,11 @@ static int Open( vlc_object_t *p_this ) p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) ); if( !p_intf->p_sys ) { + free( psz_address ); return( VLC_ENOMEM ); } - p_sys->p_playlist = pl_Yield( p_this ); + p_sys->p_playlist = pl_Hold( p_this ); p_sys->p_input = NULL; p_sys->p_vlm = NULL; p_sys->psz_address = psz_address; @@ -229,6 +203,11 @@ static int Open( vlc_object_t *p_this ) p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address, i_port, psz_cert, psz_key, psz_ca, psz_crl ); + free( psz_cert ); + free( psz_key ); + free( psz_ca ); + free( psz_crl ); + if( p_sys->p_httpd_host == NULL ) { msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port ); @@ -250,42 +229,14 @@ static int Open( vlc_object_t *p_this ) p_sys->i_files = 0; p_sys->pp_files = NULL; -#if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32) - if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL ) - { - const char * psz_vlcpath = config_GetDataDir(); - psz_src = malloc( strlen(psz_vlcpath) + strlen("/http" ) + 1 ); - if( !psz_src ) return VLC_ENOMEM; - sprintf( psz_src, "%s/http", psz_vlcpath ); - } -#else psz_src = config_GetPsz( p_intf, "http-src" ); - if( ( psz_src == NULL ) || ( *psz_src == '\0' ) ) { - const char *data_path = config_GetDataDir (); - char buf[strlen (data_path) + sizeof ("/http")]; - snprintf (buf, sizeof (buf), "%s/http", data_path); - - const char const* ppsz_paths[] = { - "share/http", - "../share/http", - buf, - NULL - }; - unsigned i; - - free( psz_src ); - psz_src = NULL; - - for( i = 0; ppsz_paths[i] != NULL; i++ ) - if( !DirectoryCheck( ppsz_paths[i] ) ) - { - psz_src = strdup( ppsz_paths[i] ); - break; - } + char *data_path = config_GetDataDir( p_intf ); + if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 ) + psz_src = NULL; + free( data_path ); } -#endif if( !psz_src || *psz_src == '\0' ) { @@ -314,10 +265,7 @@ static int Open( vlc_object_t *p_this ) /* FIXME: we're leaking h */ httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) ); if( !h ) - { - msg_Err( p_intf, "not enough memory to allocate album art handler" ); goto failed; - } h->file.p_intf = p_intf; h->file.file = NULL; h->file.name = NULL; @@ -347,13 +295,12 @@ static void Close ( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys = p_intf->p_sys; - int i; +#ifdef ENABLE_VLM if( p_sys->p_vlm ) - { vlm_Delete( p_sys->p_vlm ); - } +#endif for( i = 0; i < p_sys->i_files; i++ ) { if( p_sys->pp_files[i]->b_handler ) @@ -436,10 +383,9 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer, assert( p_sys->p_input == NULL ); /* FIXME: proper locking anyone? */ - p_sys->p_input = p_sys->p_playlist->p_input; + p_sys->p_input = playlist_CurrentInput( p_sys->p_playlist ); if( p_sys->p_input ) { - vlc_object_yield( p_sys->p_input ); var_Get( p_sys->p_input, "position", &val); sprintf( position, "%d" , (int)((val.f_float) * 100.0)); var_Get( p_sys->p_input, "time", &val); @@ -456,10 +402,6 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer, { state = "opening/connecting"; } - else if( val.i_int == BUFFERING_S ) - { - state = "buffering"; - } else if( val.i_int == PAUSE_S ) { state = "paused"; @@ -477,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", "" ); @@ -492,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 ); @@ -610,24 +551,17 @@ int HandlerCallback( httpd_handler_sys_t *p_args, char *p_url = (char *)_p_url; char *p_request = (char *)_p_request; char **pp_data = (char **)_pp_data; - char *p_in = (char *)p_in; + char *p_in = (char *)_p_in; int i_request = p_request != NULL ? strlen( p_request ) : 0; char *p; 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") ); @@ -650,41 +584,40 @@ int HandlerCallback( httpd_handler_sys_t *p_args, if( i_request ) { - psz_tmp = malloc( sizeof("QUERY_STRING=") + i_request ); - sprintf( 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 ); - psz_tmp = malloc( sizeof("REQUEST_URI=?") + strlen(p_url) - + i_request ); - sprintf( 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 { - psz_tmp = malloc( sizeof("REQUEST_URI=") + strlen(p_url) ); - sprintf( 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 ); } - psz_tmp = malloc( sizeof("SCRIPT_NAME=") + strlen(p_url) ); - sprintf( 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 - psz_tmp = malloc( sizeof("SERVER_NAME=") + strlen(p_sys->psz_address) ); - sprintf( 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 ); - psz_tmp = malloc( sizeof("SERVER_PORT=") + 5 ); - sprintf( 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 ) { - psz_tmp = malloc( sizeof("PATH=") + strlen(p) ); - sprintf( psz_tmp, "PATH=%s", p ); + if( -1==asprintf( &psz_tmp, "PATH=%s", p ) ) + psz_tmp = NULL; TAB_APPEND( i_env, ppsz_env, psz_tmp ); } @@ -692,23 +625,23 @@ int HandlerCallback( httpd_handler_sys_t *p_args, p = getenv( "windir" ); if( p != NULL ) { - psz_tmp = malloc( sizeof("SYSTEMROOT=") + strlen(p) ); - sprintf( 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 ) { - psz_tmp = malloc( sizeof("REMOTE_ADDR=") + strlen(psz_remote_addr) ); - sprintf( 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 ) { - psz_tmp = malloc( sizeof("REMOTE_HOST=") + strlen(psz_remote_host) ); - sprintf( 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 ); } @@ -723,8 +656,8 @@ int HandlerCallback( httpd_handler_sys_t *p_args, if( end == NULL ) break; *end = '\0'; - psz_tmp = malloc( sizeof("CONTENT_TYPE=") + strlen(p) ); - sprintf( 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'; } @@ -735,8 +668,8 @@ int HandlerCallback( httpd_handler_sys_t *p_args, if( end == NULL ) break; *end = '\0'; - psz_tmp = malloc( sizeof("CONTENT_LENGTH=") + strlen(p) ); - sprintf( 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'; } @@ -751,12 +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++; - psz_tmp = malloc( sizeof("SCRIPT_FILENAME=") + strlen(psz_file) ); - sprintf( 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, @@ -769,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'; @@ -850,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 { @@ -867,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; @@ -897,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 );