1 /*****************************************************************************
2 * http.c : HTTP/HTTPS Remote control interface
3 *****************************************************************************
4 * Copyright (C) 2001-2006 the VideoLAN team
6 * Authors: Gildas Bazin <gbazin@netcourrier.com>
7 * Laurent Aimar <fenrir@via.ecp.fr>
8 * Christophe Massiot <massiot@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_plugin.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
40 #define HOST_TEXT N_( "Host address" )
41 #define HOST_LONGTEXT N_( \
42 "Address and port the HTTP interface will listen on. It defaults to " \
43 "all network interfaces (0.0.0.0)." \
44 " If you want the HTTP interface to be available only on the local " \
45 "machine, enter 127.0.0.1" )
46 #define SRC_TEXT N_( "Source directory" )
47 #define SRC_LONGTEXT N_( "Source directory" )
48 #define HANDLERS_TEXT N_( "Handlers" )
49 #define HANDLERS_LONGTEXT N_( \
50 "List of handler extensions and executable paths (for instance: " \
51 "php=/usr/bin/php,pl=/usr/bin/perl)." )
52 #define ART_TEXT N_( "Export album art as /art." )
53 #define ART_LONGTEXT N_( \
54 "Allow exporting album art for current playlist items at the " \
55 "/art and /art?id=<id> URLs." )
56 #define CERT_TEXT N_( "Certificate file" )
57 #define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
59 #define KEY_TEXT N_( "Private key file" )
60 #define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file." )
61 #define CA_TEXT N_( "Root CA file" )
62 #define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
63 "certificates file." )
64 #define CRL_TEXT N_( "CRL file" )
65 #define CRL_LONGTEXT N_( "HTTP interace Certificates Revocation List file." )
68 set_shortname( N_("HTTP"))
69 set_description( N_("HTTP remote control interface") )
70 set_category( CAT_INTERFACE )
71 set_subcategory( SUBCAT_INTERFACE_MAIN )
72 add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true )
73 add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, true )
74 add_obsolete_string ( "http-charset" )
75 #if defined( HAVE_FORK ) || defined( WIN32 )
76 add_string ( "http-handlers", NULL, NULL, HANDLERS_TEXT, HANDLERS_LONGTEXT, true )
78 add_bool ( "http-album-art", false, NULL, ART_TEXT, ART_LONGTEXT, true )
79 set_section( N_("HTTP SSL" ), 0 )
80 add_string ( "http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT, true )
81 add_string ( "http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT, true )
82 add_string ( "http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT, true )
83 add_string ( "http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT, true )
84 set_capability( "interface", 0 )
85 set_callbacks( Open, Close )
89 /*****************************************************************************
91 *****************************************************************************/
92 int ArtCallback( httpd_handler_sys_t *p_args,
93 httpd_handler_t *p_handler, char *_p_url,
94 uint8_t *_p_request, int i_type,
95 uint8_t *_p_in, int i_in,
96 char *psz_remote_addr, char *psz_remote_host,
97 uint8_t **pp_data, int *pi_data );
99 /*****************************************************************************
100 * Activate: initialize and create stuff
101 *****************************************************************************/
102 static int Open( vlc_object_t *p_this )
104 intf_thread_t *p_intf = (intf_thread_t*)p_this;
107 char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
110 char *psz_src = NULL;
112 psz_address = var_CreateGetNonEmptyString( p_intf, "http-host" );
113 if( psz_address != NULL )
115 char *psz_parser = strrchr( psz_address, ':' );
118 *psz_parser++ = '\0';
119 i_port = atoi( psz_parser );
123 psz_address = strdup("");
125 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
129 return( VLC_ENOMEM );
132 p_sys->p_playlist = pl_Hold( p_this );
133 p_sys->p_input = NULL;
135 p_sys->psz_address = psz_address;
136 p_sys->i_port = i_port;
137 p_sys->p_art_handler = NULL;
139 /* determine file handler associations */
140 p_sys->i_handlers = 0;
141 p_sys->pp_handlers = NULL;
142 #if defined( HAVE_FORK ) || defined( WIN32 )
143 psz_src = config_GetPsz( p_intf, "http-handlers" );
144 if( psz_src != NULL && *psz_src )
149 http_association_t *p_handler;
151 char *psz_program, *psz_options;
152 p = strchr( p, '=' );
153 if( p == NULL ) break;
156 p = strchr( p, ',' );
160 p_handler = malloc( sizeof( http_association_t ) );
161 p_handler->psz_ext = strdup( psz_ext );
162 psz_options = FirstWord( psz_program, psz_program );
163 p_handler->i_argc = 0;
164 p_handler->ppsz_argv = NULL;
165 TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
166 strdup( psz_program ) );
167 while( psz_options != NULL && *psz_options )
169 char *psz_next = FirstWord( psz_options, psz_options );
170 TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
171 strdup( psz_options ) );
172 psz_options = psz_next;
174 /* NULL will be appended later on */
176 TAB_APPEND( p_sys->i_handlers, p_sys->pp_handlers, p_handler );
182 /* determine SSL configuration */
183 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
184 if ( psz_cert != NULL )
186 msg_Dbg( p_intf, "enabling TLS for HTTP interface (cert file: %s)",
188 psz_key = var_GetNonEmptyString( p_intf, "http-intf-key" );
189 psz_ca = var_GetNonEmptyString( p_intf, "http-intf-ca" );
190 psz_crl = var_GetNonEmptyString( p_intf, "http-intf-crl" );
201 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
203 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
204 i_port, psz_cert, psz_key, psz_ca,
211 if( p_sys->p_httpd_host == NULL )
213 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
214 pl_Release( p_this );
215 free( p_sys->psz_address );
221 char psz_tmp[NI_MAXHOST + 6];
223 /* Ugly hack to run several HTTP servers on different ports */
224 snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 );
225 var_Create(p_intf->p_libvlc, "http-host", VLC_VAR_STRING );
226 var_SetString( p_intf->p_libvlc, "http-host", psz_tmp );
230 p_sys->pp_files = NULL;
232 psz_src = config_GetPsz( p_intf, "http-src" );
233 if( ( psz_src == NULL ) || ( *psz_src == '\0' ) )
235 const char *data_path = config_GetDataDir ();
236 if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 )
240 if( !psz_src || *psz_src == '\0' )
242 msg_Err( p_intf, "invalid web interface source directory" );
246 /* remove trainling \ or / */
247 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
248 psz_src[strlen( psz_src ) - 1] == '/' )
250 psz_src[strlen( psz_src ) - 1] = '\0';
253 ParseDirectory( p_intf, psz_src, psz_src );
254 if( p_sys->i_files <= 0 )
256 msg_Err( p_intf, "cannot find any file in directory %s", psz_src );
262 if( config_GetInt( p_intf, "http-album-art" ) )
264 /* FIXME: we're leaking h */
265 httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) );
268 h->file.p_intf = p_intf;
271 /* TODO: use ACL and login/password stuff here too */
272 h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
273 "/art", NULL, NULL, NULL,
275 p_sys->p_art_handler = h->p_handler;
282 free( p_sys->pp_files );
283 httpd_HostDelete( p_sys->p_httpd_host );
284 free( p_sys->psz_address );
286 pl_Release( p_this );
290 /*****************************************************************************
291 * Close: destroy interface
292 *****************************************************************************/
293 static void Close ( vlc_object_t *p_this )
295 intf_thread_t *p_intf = (intf_thread_t *)p_this;
296 intf_sys_t *p_sys = p_intf->p_sys;
301 vlm_Delete( p_sys->p_vlm );
303 for( i = 0; i < p_sys->i_files; i++ )
305 if( p_sys->pp_files[i]->b_handler )
306 httpd_HandlerDelete( ((httpd_handler_sys_t *)p_sys->pp_files[i])->p_handler );
308 httpd_FileDelete( p_sys->pp_files[i]->p_file );
309 if( p_sys->pp_files[i]->p_redir )
310 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
311 if( p_sys->pp_files[i]->p_redir2 )
312 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
314 free( p_sys->pp_files[i]->file );
315 free( p_sys->pp_files[i]->name );
316 free( p_sys->pp_files[i] );
318 free( p_sys->pp_files );
319 for( i = 0; i < p_sys->i_handlers; i++ )
321 http_association_t *p_handler = p_sys->pp_handlers[i];
323 free( p_handler->psz_ext );
324 for( j = 0; j < p_handler->i_argc; j++ )
325 free( p_handler->ppsz_argv[j] );
326 if( p_handler->i_argc )
327 free( p_handler->ppsz_argv );
330 if( p_sys->i_handlers )
331 free( p_sys->pp_handlers );
332 if( p_sys->p_art_handler )
333 httpd_HandlerDelete( p_sys->p_art_handler );
334 httpd_HostDelete( p_sys->p_httpd_host );
335 free( p_sys->psz_address );
337 pl_Release( p_this );
340 /****************************************************************************
342 ****************************************************************************
343 * a file with b_html is parsed and all "macro" replaced
344 ****************************************************************************/
345 static void Callback404( httpd_file_sys_t *p_args, char **pp_data,
348 char *p = *pp_data = malloc( 10240 );
353 p += sprintf( p, "Content-Type: text/html\n" );
354 p += sprintf( p, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" );
355 p += sprintf( p, "<head>\n" );
356 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
357 p += sprintf( p, "</head>\n" );
358 p += sprintf( p, "<body>\n" );
359 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
360 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
361 p += sprintf( p, "</body>\n" );
362 p += sprintf( p, "</html>\n" );
364 *pi_data = strlen( *pp_data );
367 static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
368 int i_buffer, char *p_request,
369 char **pp_data, int *pi_data )
371 intf_sys_t *p_sys = p_args->p_intf->p_sys;
372 int i_request = p_request != NULL ? strlen( p_request ) : 0;
375 char position[4]; /* percentage */
376 char time[12]; /* in seconds */
377 char length[12]; /* in seconds */
378 audio_volume_t i_volume;
383 assert( p_sys->p_input == NULL );
384 /* FIXME: proper locking anyone? */
385 p_sys->p_input = playlist_CurrentInput( p_sys->p_playlist );
388 var_Get( p_sys->p_input, "position", &val);
389 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
390 var_Get( p_sys->p_input, "time", &val);
391 sprintf( time, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) );
392 var_Get( p_sys->p_input, "length", &val);
393 sprintf( length, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) );
395 var_Get( p_sys->p_input, "state", &val );
396 if( val.i_int == PLAYING_S )
400 else if( val.i_int == OPENING_S )
402 state = "opening/connecting";
404 else if( val.i_int == PAUSE_S )
415 sprintf( position, "%d", 0 );
416 sprintf( time, "%d", 0 );
417 sprintf( length, "%d", 0 );
421 aout_VolumeGet( p_args->p_intf, &i_volume );
422 sprintf( volume, "%d", (int)i_volume );
424 p_args->vars = mvar_New( "variables", "" );
425 mvar_AppendNewVar( p_args->vars, "url_param",
426 i_request > 0 ? "1" : "0" );
427 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
428 mvar_AppendNewVar( p_args->vars, "version", VLC_Version() );
429 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
430 mvar_AppendNewVar( p_args->vars, "vlc_compile_by", VLC_CompileBy() );
431 mvar_AppendNewVar( p_args->vars, "vlc_compile_host",
433 mvar_AppendNewVar( p_args->vars, "vlc_compile_domain",
434 VLC_CompileDomain() );
435 mvar_AppendNewVar( p_args->vars, "vlc_compiler", VLC_Compiler() );
436 mvar_AppendNewVar( p_args->vars, "stream_position", position );
437 mvar_AppendNewVar( p_args->vars, "stream_time", time );
438 mvar_AppendNewVar( p_args->vars, "stream_length", length );
439 mvar_AppendNewVar( p_args->vars, "volume", volume );
440 mvar_AppendNewVar( p_args->vars, "stream_state", state );
441 mvar_AppendNewVar( p_args->vars, "charset", "UTF-8" );
446 /* FIXME: Workarround a stupid assert in input_GetItem */
447 input_item_t *p_item = p_sys->p_input && p_sys->p_input->p
448 ? input_GetItem( p_sys->p_input )
453 vlc_mutex_lock( &p_item->p_stats->lock );
454 #define STATS_INT( n ) sprintf( stats, "%d", p_item->p_stats->i_ ## n ); \
455 mvar_AppendNewVar( p_args->vars, #n, stats );
456 #define STATS_FLOAT( n ) sprintf( stats, "%f", p_item->p_stats->f_ ## n ); \
457 mvar_AppendNewVar( p_args->vars, #n, stats );
458 STATS_INT( read_bytes )
459 STATS_FLOAT( input_bitrate )
460 STATS_INT( demux_read_bytes )
461 STATS_FLOAT( demux_bitrate )
462 STATS_INT( decoded_video )
463 STATS_INT( displayed_pictures )
464 STATS_INT( lost_pictures )
465 STATS_INT( decoded_audio )
466 STATS_INT( played_abuffers )
467 STATS_INT( lost_abuffers )
468 STATS_INT( sent_packets )
469 STATS_INT( sent_bytes )
470 STATS_FLOAT( send_bitrate )
473 vlc_mutex_unlock( &p_item->p_stats->lock );
477 SSInit( &p_args->stack );
479 /* allocate output */
480 *pi_data = i_buffer + 1000;
481 dst = *pp_data = malloc( *pi_data );
483 /* we parse executing all <vlc /> macros */
484 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst,
485 &p_buffer[0], &p_buffer[i_buffer] );
488 *pi_data = dst - *pp_data;
490 if( p_sys->p_input != NULL )
492 vlc_object_release( p_sys->p_input );
493 p_sys->p_input = NULL;
495 SSClean( &p_args->stack );
496 mvar_Delete( p_args->vars );
499 int HttpCallback( httpd_file_sys_t *p_args,
500 httpd_file_t *p_file,
502 uint8_t **_pp_data, int *pi_data )
505 char *p_request = (char *)_p_request;
506 char **pp_data = (char **)_pp_data;
509 if( ( f = utf8_fopen( p_args->file, "r" ) ) == NULL )
511 Callback404( p_args, pp_data, pi_data );
515 if( !p_args->b_html )
517 FileLoad( f, pp_data, pi_data );
524 /* first we load in a temporary buffer */
525 FileLoad( f, &p_buffer, &i_buffer );
527 ParseExecute( p_args, p_buffer, i_buffer, p_request, pp_data, pi_data );
537 /****************************************************************************
539 ****************************************************************************
540 * call the external handler and parse vlc macros if Content-Type is HTML
541 ****************************************************************************/
542 int HandlerCallback( httpd_handler_sys_t *p_args,
543 httpd_handler_t *p_handler, char *_p_url,
544 uint8_t *_p_request, int i_type,
545 uint8_t *_p_in, int i_in,
546 char *psz_remote_addr, char *psz_remote_host,
547 uint8_t **_pp_data, int *pi_data )
549 VLC_UNUSED(p_handler); VLC_UNUSED(_p_in);
550 char *p_url = (char *)_p_url;
551 char *p_request = (char *)_p_request;
552 char **pp_data = (char **)_pp_data;
553 char *p_in = (char *)_p_in;
554 int i_request = p_request != NULL ? strlen( p_request ) : 0;
557 char **ppsz_env = NULL;
561 char *psz_cwd, *psz_file = NULL;
564 /* Create environment for the CGI */
565 TAB_APPEND( i_env, ppsz_env, strdup("GATEWAY_INTERFACE=CGI/1.1") );
566 TAB_APPEND( i_env, ppsz_env, strdup("SERVER_PROTOCOL=HTTP/1.1") );
567 TAB_APPEND( i_env, ppsz_env, strdup("SERVER_SOFTWARE=" COPYRIGHT_MESSAGE) );
572 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=GET") );
575 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=POST") );
578 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=HEAD") );
586 asprintf( &psz_tmp, "QUERY_STRING=%s", p_request );
587 TAB_APPEND( i_env, ppsz_env, psz_tmp );
589 asprintf( &psz_tmp, "REQUEST_URI=%s?%s", p_url, p_request );
590 TAB_APPEND( i_env, ppsz_env, psz_tmp );
594 asprintf( &psz_tmp, "REQUEST_URI=%s", p_url );
595 TAB_APPEND( i_env, ppsz_env, psz_tmp );
598 asprintf( &psz_tmp, "SCRIPT_NAME=%s", p_url );
599 TAB_APPEND( i_env, ppsz_env, psz_tmp );
601 #define p_sys p_args->file.p_intf->p_sys
602 asprintf( &psz_tmp, "SERVER_NAME=%s", p_sys->psz_address );
603 TAB_APPEND( i_env, ppsz_env, psz_tmp );
605 asprintf( &psz_tmp, "SERVER_PORT=%u", p_sys->i_port );
606 TAB_APPEND( i_env, ppsz_env, psz_tmp );
609 p = getenv( "PATH" );
612 asprintf( &psz_tmp, "PATH=%s", p );
613 TAB_APPEND( i_env, ppsz_env, psz_tmp );
617 p = getenv( "windir" );
620 asprintf( &psz_tmp, "SYSTEMROOT=%s", p );
621 TAB_APPEND( i_env, ppsz_env, psz_tmp );
625 if( psz_remote_addr != NULL && *psz_remote_addr )
627 asprintf( &psz_tmp, "REMOTE_ADDR=%s", psz_remote_addr );
628 TAB_APPEND( i_env, ppsz_env, psz_tmp );
631 if( psz_remote_host != NULL && *psz_remote_host )
633 asprintf( &psz_tmp, "REMOTE_HOST=%s", psz_remote_host );
634 TAB_APPEND( i_env, ppsz_env, psz_tmp );
642 if( !strncasecmp( p, "Content-Type: ", strlen("Content-Type: ") ) )
644 char *end = strchr( p, '\r' );
648 asprintf( &psz_tmp, "CONTENT_TYPE=%s", p );
649 TAB_APPEND( i_env, ppsz_env, psz_tmp );
652 if( !strncasecmp( p, "Content-Length: ",
653 strlen("Content-Length: ") ) )
655 char *end = strchr( p, '\r' );
659 asprintf( &psz_tmp, "CONTENT_LENGTH=%s", p );
660 TAB_APPEND( i_env, ppsz_env, psz_tmp );
664 p = strchr( p, '\n' );
665 if( p == NULL || p[1] == '\r' )
674 psz_file = strrchr( p_args->file.file, DIR_SEP_CHAR );
675 if( psz_file != NULL )
678 asprintf( &psz_tmp, "SCRIPT_FILENAME=%s", psz_file );
679 TAB_APPEND( i_env, ppsz_env, psz_tmp );
681 TAB_APPEND( p_args->p_association->i_argc,
682 p_args->p_association->ppsz_argv, psz_file );
685 TAB_APPEND( i_env, ppsz_env, NULL );
687 TAB_APPEND( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
690 psz_tmp = strdup( p_args->file.file );
691 p = strrchr( psz_tmp, DIR_SEP_CHAR );
703 i_ret = vlc_execve( p_args->file.p_intf, p_args->p_association->i_argc,
704 p_args->p_association->ppsz_argv, ppsz_env, psz_cwd,
705 (char *)p_in, i_in, &p_buffer, &i_buffer );
706 TAB_REMOVE( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
708 TAB_REMOVE( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
712 TAB_REMOVE( i_env, ppsz_env, ppsz_env[0] );
716 Callback404( (httpd_file_sys_t *)p_args, pp_data, pi_data );
720 while( strncasecmp( p, "Content-Type: text/html",
721 strlen("Content-Type: text/html") ) )
723 p = strchr( p, '\n' );
724 if( p == NULL || p[1] == '\r' )
739 ParseExecute( (httpd_file_sys_t *)p_args, p_buffer, i_buffer,
740 p_request, pp_data, pi_data );
748 int ArtCallback( httpd_handler_sys_t *p_args,
749 httpd_handler_t *p_handler, char *_p_url,
750 uint8_t *p_request, int i_type,
751 uint8_t *p_in, int i_in,
752 char *psz_remote_addr, char *psz_remote_host,
753 uint8_t **pp_data, int *pi_data )
755 VLC_UNUSED(p_handler); VLC_UNUSED(_p_url); VLC_UNUSED(i_type);
756 VLC_UNUSED(p_in); VLC_UNUSED(i_in); VLC_UNUSED(psz_remote_addr);
757 VLC_UNUSED(psz_remote_host);
759 char *psz_art = NULL;
760 intf_thread_t *p_intf = p_args->file.p_intf;
761 intf_sys_t *p_sys = p_intf->p_sys;
763 input_item_t *p_item = NULL;
768 ExtractURIValue( (char *)p_request, "id", psz_id, 15 );
769 i_id = atoi( psz_id );
772 playlist_Lock( p_sys->p_playlist );
773 playlist_item_t *p_pl_item = playlist_ItemGetById( p_sys->p_playlist,
776 p_item = p_pl_item->p_input;
777 playlist_Unlock( p_sys->p_playlist );
781 /* FIXME: Workarround a stupid assert in input_GetItem */
782 if( p_sys->p_input && p_sys->p_input->p )
783 p_item = input_GetItem( p_sys->p_input );
788 psz_art = input_item_GetArtURL( p_item );
791 if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) &&
792 decode_URI( psz_art + 7 ) )
798 int i_header_size, i_data;
800 if( ( f = utf8_fopen( psz_art + strlen( "file://" ), "r" ) ) == NULL )
802 msg_Dbg( p_intf, "Couldn't open album art file %s",
803 psz_art + strlen( "file://" ) );
804 Callback404( &p_args->file, (char**)pp_data, pi_data );
809 FileLoad( f, &p_data, &i_data );
813 psz_ext = strrchr( psz_art, '.' );
814 if( psz_ext ) psz_ext++;
816 #define HEADER "Content-Type: image/%s\n" \
817 "Content-Length: %d\n" \
819 i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data );
822 *pi_data = i_header_size + i_data;
823 *pp_data = (uint8_t*)malloc( *pi_data );
824 memcpy( *pp_data, psz_header, i_header_size );
825 memcpy( *pp_data+i_header_size, p_data, i_data );
831 msg_Dbg( p_intf, "No album art found" );
832 Callback404( &p_args->file, (char**)pp_data, pi_data );