X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fhttp%2Fhttp.c;h=b53c557cdf4c176649508b2ebfec364bebe8b14f;hb=7cfe1ace0115068dcdb157671aa4222a2f68b26d;hp=92d08392aea02f54622ea749a924a4d68c305216;hpb=31bf9857bf400f283e072f053d33f6e210f698b9;p=vlc diff --git a/modules/control/http/http.c b/modules/control/http/http.c index 92d08392ae..b53c557cdf 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,10 @@ #include "http.h" #include +#include +#include + +#include /***************************************************************************** * Module descriptor @@ -47,7 +50,7 @@ static void Close( vlc_object_t * ); #define HANDLERS_LONGTEXT N_( \ "List of handler extensions and executable paths (for instance: " \ "php=/usr/bin/php,pl=/usr/bin/perl)." ) -#define ART_TEXT N_( "Export album art as /art." ) +#define ART_TEXT N_( "Export album art as /art" ) #define ART_LONGTEXT N_( \ "Allow exporting album art for current playlist items at the " \ "/art and /art?id= URLs." ) @@ -62,26 +65,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, HOST_TEXT, HOST_LONGTEXT, true ) + add_string ( "http-src", NULL, SRC_TEXT, SRC_LONGTEXT, true ) #if defined( HAVE_FORK ) || defined( WIN32 ) - add_string ( "http-handlers", NULL, NULL, HANDLERS_TEXT, HANDLERS_LONGTEXT, true ); + add_string ( "http-handlers", 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, ART_TEXT, ART_LONGTEXT, true ) + set_section( N_("HTTP SSL" ), 0 ) + add_loadfile ( "http-intf-cert", NULL, CERT_TEXT, CERT_LONGTEXT, true ) + add_loadfile ( "http-intf-key", NULL, KEY_TEXT, KEY_LONGTEXT, true ) + add_loadfile ( "http-intf-ca", NULL, CA_TEXT, CA_LONGTEXT, true ) + add_loadfile ( "http-intf-crl", NULL, CRL_TEXT, CRL_LONGTEXT, true ) + set_capability( "interface", 0 ) + set_callbacks( Open, Close ) + add_shortcut( "http" ) +vlc_module_end () /***************************************************************************** @@ -94,24 +97,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 ) -{ - struct stat stat_info; - - if( ( utf8_stat( psz_dir, &stat_info ) == -1 ) - || !S_ISDIR( stat_info.st_mode ) ) - { - return VLC_EGENERIC; - } - return VLC_SUCCESS; -} -#endif - - /***************************************************************************** * Activate: initialize and create stuff *****************************************************************************/ @@ -120,7 +105,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; @@ -128,7 +113,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'; @@ -141,10 +126,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_Get( p_this ); p_sys->p_input = NULL; p_sys->p_vlm = NULL; p_sys->psz_address = psz_address; @@ -155,8 +141,8 @@ static int Open( vlc_object_t *p_this ) p_sys->i_handlers = 0; p_sys->pp_handlers = NULL; #if defined( HAVE_FORK ) || defined( WIN32 ) - psz_src = config_GetPsz( p_intf, "http-handlers" ); - if( psz_src != NULL && *psz_src ) + psz_src = var_InheritString( p_intf, "http-handlers" ); + if( psz_src != NULL ) { char *p = psz_src; while( p != NULL ) @@ -190,19 +176,19 @@ static int Open( vlc_object_t *p_this ) TAB_APPEND( p_sys->i_handlers, p_sys->pp_handlers, p_handler ); } + free( psz_src ); } - free( psz_src ); #endif /* determine SSL configuration */ - psz_cert = config_GetPsz( p_intf, "http-intf-cert" ); + psz_cert = var_InheritString( p_intf, "http-intf-cert" ); if ( psz_cert != NULL ) { msg_Dbg( p_intf, "enabling TLS for HTTP interface (cert file: %s)", psz_cert ); - psz_key = var_GetNonEmptyString( p_intf, "http-intf-key" ); - psz_ca = var_GetNonEmptyString( p_intf, "http-intf-ca" ); - psz_crl = var_GetNonEmptyString( p_intf, "http-intf-crl" ); + psz_key = var_InheritString( p_intf, "http-intf-key" ); + psz_ca = var_InheritString( p_intf, "http-intf-ca" ); + psz_crl = var_InheritString( p_intf, "http-intf-crl" ); if( i_port <= 0 ) i_port = 8443; @@ -218,10 +204,14 @@ 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 ); - pl_Release( p_this ); free( p_sys->psz_address ); free( p_sys ); return VLC_EGENERIC; @@ -239,44 +229,16 @@ 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 ) + psz_src = var_InheritString( p_intf, "http-src" ); + if( psz_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 ); + char *data_path = config_GetDataDir( p_intf ); + if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 ) + psz_src = NULL; + free( data_path ); } -#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; - } - } -#endif - - if( !psz_src || *psz_src == '\0' ) + if( psz_src == NULL ) { msg_Err( p_intf, "invalid web interface source directory" ); goto failed; @@ -296,17 +258,12 @@ static int Open( vlc_object_t *p_this ) goto failed; } - free( psz_src ); - - if( config_GetInt( p_intf, "http-album-art" ) ) + if( var_InheritBool( p_intf, "http-album-art" ) ) { /* 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; @@ -317,6 +274,7 @@ static int Open( vlc_object_t *p_this ) p_sys->p_art_handler = h->p_handler; } + free( psz_src ); return VLC_SUCCESS; failed: @@ -325,7 +283,6 @@ failed: httpd_HostDelete( p_sys->p_httpd_host ); free( p_sys->psz_address ); free( p_sys ); - pl_Release( p_this ); return VLC_EGENERIC; } @@ -336,13 +293,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 ) @@ -377,7 +333,6 @@ static void Close ( vlc_object_t *p_this ) httpd_HostDelete( p_sys->p_httpd_host ); free( p_sys->psz_address ); free( p_sys ); - pl_Release( p_this ); } /**************************************************************************** @@ -414,7 +369,6 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer, intf_sys_t *p_sys = p_args->p_intf->p_sys; int i_request = p_request != NULL ? strlen( p_request ) : 0; char *dst; - vlc_value_t val; char position[4]; /* percentage */ char time[12]; /* in seconds */ char length[12]; /* in seconds */ @@ -425,63 +379,45 @@ 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); - sprintf( time, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) ); - var_Get( p_sys->p_input, "length", &val); - sprintf( length, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) ); + snprintf( position, sizeof(position), "%d", + (int)(var_GetFloat( p_sys->p_input, "position" ) * 100.)); + snprintf( time, sizeof(time), "%"PRIi64, + var_GetTime( p_sys->p_input, "time" ) / CLOCK_FREQ ); + snprintf( length, sizeof(length), "%"PRIi64, + var_GetTime( p_sys->p_input, "length" ) / CLOCK_FREQ ); - var_Get( p_sys->p_input, "state", &val ); - if( val.i_int == PLAYING_S ) + switch( var_GetInteger( p_sys->p_input, "state" ) ) { - state = "playing"; - } - else if( val.i_int == OPENING_S ) - { - state = "opening/connecting"; - } - else if( val.i_int == BUFFERING_S ) - { - state = "buffering"; - } - else if( val.i_int == PAUSE_S ) - { - state = "paused"; - } - else - { - state = "stop"; + case PLAYING_S: state = "playing"; break; + case OPENING_S: state = "opening/connecting"; break; + case PAUSE_S: state = "paused"; break; + default: state = "stop"; break; } } else { - sprintf( position, "%d", 0 ); - sprintf( time, "%d", 0 ); - sprintf( length, "%d", 0 ); + strcpy( position, "0" ); + strcpy( time, "0" ); + strcpy( length, "0" ); state = "stop"; } - aout_VolumeGet( p_args->p_intf, &i_volume ); - sprintf( volume, "%d", (int)i_volume ); + i_volume = aout_VolumeGet( p_sys->p_playlist ); + snprintf( volume, sizeof(volume), "%d", (int)i_volume ); p_args->vars = mvar_New( "variables", "" ); mvar_AppendNewVar( p_args->vars, "url_param", i_request > 0 ? "1" : "0" ); mvar_AppendNewVar( p_args->vars, "url_value", p_request ); - mvar_AppendNewVar( p_args->vars, "version", VLC_Version() ); + mvar_AppendNewVar( p_args->vars, "version", VERSION_MESSAGE ); mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE ); mvar_AppendNewVar( p_args->vars, "vlc_compile_by", VLC_CompileBy() ); mvar_AppendNewVar( p_args->vars, "vlc_compile_host", VLC_CompileHost() ); - 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 ); @@ -500,7 +436,7 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer, if( p_item ) { vlc_mutex_lock( &p_item->p_stats->lock ); -#define STATS_INT( n ) sprintf( stats, "%d", p_item->p_stats->i_ ## n ); \ +#define STATS_INT( n ) sprintf( stats, "%"PRIi64, p_item->p_stats->i_ ## n ); \ mvar_AppendNewVar( p_args->vars, #n, stats ); #define STATS_FLOAT( n ) sprintf( stats, "%f", p_item->p_stats->f_ ## n ); \ mvar_AppendNewVar( p_args->vars, #n, stats ); @@ -555,7 +491,7 @@ int HttpCallback( httpd_file_sys_t *p_args, char **pp_data = (char **)_pp_data; FILE *f; - if( ( f = utf8_fopen( p_args->file, "r" ) ) == NULL ) + if( ( f = vlc_fopen( p_args->file, "r" ) ) == NULL ) { Callback404( p_args, pp_data, pi_data ); return VLC_SUCCESS; @@ -599,28 +535,21 @@ 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") ); - TAB_APPEND( i_env, ppsz_env, strdup("SERVER_SOFTWARE=" COPYRIGHT_MESSAGE) ); + TAB_APPEND( i_env, ppsz_env, strdup("SERVER_SOFTWARE=VLC "VERSION) ); switch( i_type ) { @@ -639,41 +568,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 ); } @@ -681,23 +609,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 ); } @@ -712,8 +640,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'; } @@ -724,8 +652,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'; } @@ -740,12 +668,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, @@ -758,7 +686,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'; @@ -839,10 +767,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 { @@ -856,50 +786,56 @@ 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 ) { - FILE *f; - char *psz_ext; - char *psz_header; - char *p_data = NULL; - int i_header_size, i_data; + char *psz = make_path( psz_art ); + free( psz_art ); + psz_art = psz; + } - if( ( f = utf8_fopen( psz_art + strlen( "file://" ), "r" ) ) == NULL ) - { - msg_Dbg( p_intf, "Couldn't open album art file %s", - psz_art + strlen( "file://" ) ); - Callback404( &p_args->file, (char**)pp_data, pi_data ); - free( psz_art ); - return VLC_SUCCESS; - } + if( psz_art == NULL ) + { + msg_Dbg( p_intf, "No album art found" ); + Callback404( &p_args->file, (char**)pp_data, pi_data ); + return VLC_SUCCESS; + } - FileLoad( f, &p_data, &i_data ); + FILE *f = vlc_fopen( psz_art, "r" ); + if( f == NULL ) + { + msg_Dbg( p_intf, "Couldn't open album art file %s", psz_art ); + Callback404( &p_args->file, (char**)pp_data, pi_data ); + free( psz_art ); + return VLC_SUCCESS; + } + free( psz_art ); - fclose( f ); + char *p_data = NULL; + int i_data; + FileLoad( f, &p_data, &i_data ); + fclose( f ); - psz_ext = strrchr( psz_art, '.' ); - if( psz_ext ) psz_ext++; + char *psz_ext = strrchr( psz_art, '.' ); + if( psz_ext ) psz_ext++; #define HEADER "Content-Type: image/%s\n" \ "Content-Length: %d\n" \ "\n" - i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data ); + char *psz_header; + int i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data ); #undef HEADER - - *pi_data = i_header_size + i_data; - *pp_data = (uint8_t*)malloc( *pi_data ); - memcpy( *pp_data, psz_header, i_header_size ); - memcpy( *pp_data+i_header_size, p_data, i_data ); - free( psz_header ); - free( p_data ); - } - else + if( likely(i_header_size != -1) ) { - msg_Dbg( p_intf, "No album art found" ); - Callback404( &p_args->file, (char**)pp_data, pi_data ); + *pp_data = malloc( i_header_size + i_data ); + if( likely(*pp_data != NULL) ) + { + *pi_data = i_header_size + i_data; + memcpy( *pp_data, psz_header, i_header_size ); + memcpy( *pp_data+i_header_size, p_data, i_data ); + } + free( psz_header ); } - - free( psz_art ); + free( p_data ); return VLC_SUCCESS; }