1 /*****************************************************************************
2 * http.c : HTTP/HTTPS Remote control interface
3 *****************************************************************************
4 * Copyright (C) 2001-2006 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
30 #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 /*****************************************************************************
101 *****************************************************************************/
102 #if !defined(__APPLE__) && !defined(SYS_BEOS) && !defined(WIN32)
103 static int DirectoryCheck( const char *psz_dir )
105 struct stat stat_info;
107 if( ( utf8_stat( psz_dir, &stat_info ) == -1 )
108 || !S_ISDIR( stat_info.st_mode ) )
117 /*****************************************************************************
118 * Activate: initialize and create stuff
119 *****************************************************************************/
120 static int Open( vlc_object_t *p_this )
122 intf_thread_t *p_intf = (intf_thread_t*)p_this;
125 const char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
128 char *psz_src = NULL;
130 psz_address = var_CreateGetNonEmptyString( p_intf, "http-host" );
131 if( psz_address != NULL )
133 char *psz_parser = strchr( psz_address, ':' );
136 *psz_parser++ = '\0';
137 i_port = atoi( psz_parser );
141 psz_address = strdup("");
143 p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
146 return( VLC_ENOMEM );
149 p_sys->p_playlist = pl_Yield( p_this );
150 p_sys->p_input = NULL;
152 p_sys->psz_address = psz_address;
153 p_sys->i_port = i_port;
154 p_sys->p_art_handler = NULL;
156 /* determine file handler associations */
157 p_sys->i_handlers = 0;
158 p_sys->pp_handlers = NULL;
159 #if defined( HAVE_FORK ) || defined( WIN32 )
160 psz_src = config_GetPsz( p_intf, "http-handlers" );
161 if( psz_src != NULL && *psz_src )
166 http_association_t *p_handler;
168 char *psz_program, *psz_options;
169 p = strchr( p, '=' );
170 if( p == NULL ) break;
173 p = strchr( p, ',' );
177 p_handler = malloc( sizeof( http_association_t ) );
178 p_handler->psz_ext = strdup( psz_ext );
179 psz_options = FirstWord( psz_program, psz_program );
180 p_handler->i_argc = 0;
181 p_handler->ppsz_argv = NULL;
182 TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
183 strdup( psz_program ) );
184 while( psz_options != NULL && *psz_options )
186 char *psz_next = FirstWord( psz_options, psz_options );
187 TAB_APPEND( p_handler->i_argc, p_handler->ppsz_argv,
188 strdup( psz_options ) );
189 psz_options = psz_next;
191 /* NULL will be appended later on */
193 TAB_APPEND( p_sys->i_handlers, p_sys->pp_handlers, p_handler );
199 /* determine SSL configuration */
200 psz_cert = config_GetPsz( p_intf, "http-intf-cert" );
201 if ( psz_cert != NULL )
203 msg_Dbg( p_intf, "enabling TLS for HTTP interface (cert file: %s)",
205 psz_key = var_GetNonEmptyString( p_intf, "http-intf-key" );
206 psz_ca = var_GetNonEmptyString( p_intf, "http-intf-ca" );
207 psz_crl = var_GetNonEmptyString( p_intf, "http-intf-crl" );
218 msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
220 p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
221 i_port, psz_cert, psz_key, psz_ca,
223 if( p_sys->p_httpd_host == NULL )
225 msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
226 pl_Release( p_this );
227 free( p_sys->psz_address );
233 char psz_tmp[NI_MAXHOST + 6];
235 /* Ugly hack to run several HTTP servers on different ports */
236 snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 );
237 var_Create(p_intf->p_libvlc, "http-host", VLC_VAR_STRING );
238 var_SetString( p_intf->p_libvlc, "http-host", psz_tmp );
242 p_sys->pp_files = NULL;
244 #if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
245 if ( ( psz_src = config_GetPsz( p_intf, "http-src" )) == NULL )
247 const char * psz_vlcpath = config_GetDataDir();
248 psz_src = malloc( strlen(psz_vlcpath) + strlen("/http" ) + 1 );
249 if( !psz_src ) return VLC_ENOMEM;
250 sprintf( psz_src, "%s/http", psz_vlcpath );
253 psz_src = config_GetPsz( p_intf, "http-src" );
255 if( ( psz_src == NULL ) || ( *psz_src == '\0' ) )
257 const char *data_path = config_GetDataDir ();
258 char buf[strlen (data_path) + sizeof ("/http")];
259 snprintf (buf, sizeof (buf), "%s/http", data_path);
261 const char const* ppsz_paths[] = {
272 for( i = 0; ppsz_paths[i] != NULL; i++ )
273 if( !DirectoryCheck( ppsz_paths[i] ) )
275 psz_src = strdup( ppsz_paths[i] );
281 if( !psz_src || *psz_src == '\0' )
283 msg_Err( p_intf, "invalid web interface source directory" );
287 /* remove trainling \ or / */
288 if( psz_src[strlen( psz_src ) - 1] == '\\' ||
289 psz_src[strlen( psz_src ) - 1] == '/' )
291 psz_src[strlen( psz_src ) - 1] = '\0';
294 ParseDirectory( p_intf, psz_src, psz_src );
295 if( p_sys->i_files <= 0 )
297 msg_Err( p_intf, "cannot find any file in directory %s", psz_src );
303 if( config_GetInt( p_intf, "http-album-art" ) )
305 /* FIXME: we're leaking h */
306 httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) );
309 msg_Err( p_intf, "not enough memory to allocate album art handler" );
312 h->file.p_intf = p_intf;
315 /* TODO: use ACL and login/password stuff here too */
316 h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
317 "/art", NULL, NULL, NULL,
319 p_sys->p_art_handler = h->p_handler;
326 free( p_sys->pp_files );
327 httpd_HostDelete( p_sys->p_httpd_host );
328 free( p_sys->psz_address );
330 pl_Release( p_this );
334 /*****************************************************************************
335 * Close: destroy interface
336 *****************************************************************************/
337 static void Close ( vlc_object_t *p_this )
339 intf_thread_t *p_intf = (intf_thread_t *)p_this;
340 intf_sys_t *p_sys = p_intf->p_sys;
346 vlm_Delete( p_sys->p_vlm );
348 for( i = 0; i < p_sys->i_files; i++ )
350 if( p_sys->pp_files[i]->b_handler )
351 httpd_HandlerDelete( ((httpd_handler_sys_t *)p_sys->pp_files[i])->p_handler );
353 httpd_FileDelete( p_sys->pp_files[i]->p_file );
354 if( p_sys->pp_files[i]->p_redir )
355 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
356 if( p_sys->pp_files[i]->p_redir2 )
357 httpd_RedirectDelete( p_sys->pp_files[i]->p_redir2 );
359 free( p_sys->pp_files[i]->file );
360 free( p_sys->pp_files[i]->name );
361 free( p_sys->pp_files[i] );
363 free( p_sys->pp_files );
364 for( i = 0; i < p_sys->i_handlers; i++ )
366 http_association_t *p_handler = p_sys->pp_handlers[i];
368 free( p_handler->psz_ext );
369 for( j = 0; j < p_handler->i_argc; j++ )
370 free( p_handler->ppsz_argv[j] );
371 if( p_handler->i_argc )
372 free( p_handler->ppsz_argv );
375 if( p_sys->i_handlers )
376 free( p_sys->pp_handlers );
377 if( p_sys->p_art_handler )
378 httpd_HandlerDelete( p_sys->p_art_handler );
379 httpd_HostDelete( p_sys->p_httpd_host );
380 free( p_sys->psz_address );
382 pl_Release( p_this );
385 /****************************************************************************
387 ****************************************************************************
388 * a file with b_html is parsed and all "macro" replaced
389 ****************************************************************************/
390 static void Callback404( httpd_file_sys_t *p_args, char **pp_data,
393 char *p = *pp_data = malloc( 10240 );
398 p += sprintf( p, "Content-Type: text/html\n" );
399 p += sprintf( p, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" );
400 p += sprintf( p, "<head>\n" );
401 p += sprintf( p, "<title>Error loading %s</title>\n", p_args->file );
402 p += sprintf( p, "</head>\n" );
403 p += sprintf( p, "<body>\n" );
404 p += sprintf( p, "<h1><center>Error loading %s for %s</center></h1>\n", p_args->file, p_args->name );
405 p += sprintf( p, "<a href=\"http://www.videolan.org/\">VideoLAN</a>\n" );
406 p += sprintf( p, "</body>\n" );
407 p += sprintf( p, "</html>\n" );
409 *pi_data = strlen( *pp_data );
412 static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
413 int i_buffer, char *p_request,
414 char **pp_data, int *pi_data )
416 intf_sys_t *p_sys = p_args->p_intf->p_sys;
417 int i_request = p_request != NULL ? strlen( p_request ) : 0;
420 char position[4]; /* percentage */
421 char time[12]; /* in seconds */
422 char length[12]; /* in seconds */
423 audio_volume_t i_volume;
428 assert( p_sys->p_input == NULL );
429 /* FIXME: proper locking anyone? */
430 p_sys->p_input = p_sys->p_playlist->p_input;
433 vlc_object_yield( p_sys->p_input );
434 var_Get( p_sys->p_input, "position", &val);
435 sprintf( position, "%d" , (int)((val.f_float) * 100.0));
436 var_Get( p_sys->p_input, "time", &val);
437 sprintf( time, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) );
438 var_Get( p_sys->p_input, "length", &val);
439 sprintf( length, "%"PRIi64, (int64_t)val.i_time / INT64_C(1000000) );
441 var_Get( p_sys->p_input, "state", &val );
442 if( val.i_int == PLAYING_S )
446 else if( val.i_int == OPENING_S )
448 state = "opening/connecting";
450 else if( val.i_int == BUFFERING_S )
454 else if( val.i_int == PAUSE_S )
465 sprintf( position, "%d", 0 );
466 sprintf( time, "%d", 0 );
467 sprintf( length, "%d", 0 );
471 aout_VolumeGet( p_args->p_intf, &i_volume );
472 sprintf( volume, "%d", (int)i_volume );
474 p_args->vars = mvar_New( "variables", "" );
475 mvar_AppendNewVar( p_args->vars, "url_param",
476 i_request > 0 ? "1" : "0" );
477 mvar_AppendNewVar( p_args->vars, "url_value", p_request );
478 mvar_AppendNewVar( p_args->vars, "version", VLC_Version() );
479 mvar_AppendNewVar( p_args->vars, "copyright", COPYRIGHT_MESSAGE );
480 mvar_AppendNewVar( p_args->vars, "vlc_compile_by", VLC_CompileBy() );
481 mvar_AppendNewVar( p_args->vars, "vlc_compile_host",
483 mvar_AppendNewVar( p_args->vars, "vlc_compile_domain",
484 VLC_CompileDomain() );
485 mvar_AppendNewVar( p_args->vars, "vlc_compiler", VLC_Compiler() );
486 mvar_AppendNewVar( p_args->vars, "vlc_changeset", VLC_Changeset() );
487 mvar_AppendNewVar( p_args->vars, "stream_position", position );
488 mvar_AppendNewVar( p_args->vars, "stream_time", time );
489 mvar_AppendNewVar( p_args->vars, "stream_length", length );
490 mvar_AppendNewVar( p_args->vars, "volume", volume );
491 mvar_AppendNewVar( p_args->vars, "stream_state", state );
492 mvar_AppendNewVar( p_args->vars, "charset", "UTF-8" );
497 /* FIXME: Workarround a stupid assert in input_GetItem */
498 input_item_t *p_item = p_sys->p_input && p_sys->p_input->p
499 ? input_GetItem( p_sys->p_input )
504 vlc_mutex_lock( &p_item->p_stats->lock );
505 #define STATS_INT( n ) sprintf( stats, "%d", p_item->p_stats->i_ ## n ); \
506 mvar_AppendNewVar( p_args->vars, #n, stats );
507 #define STATS_FLOAT( n ) sprintf( stats, "%f", p_item->p_stats->f_ ## n ); \
508 mvar_AppendNewVar( p_args->vars, #n, stats );
509 STATS_INT( read_bytes )
510 STATS_FLOAT( input_bitrate )
511 STATS_INT( demux_read_bytes )
512 STATS_FLOAT( demux_bitrate )
513 STATS_INT( decoded_video )
514 STATS_INT( displayed_pictures )
515 STATS_INT( lost_pictures )
516 STATS_INT( decoded_audio )
517 STATS_INT( played_abuffers )
518 STATS_INT( lost_abuffers )
519 STATS_INT( sent_packets )
520 STATS_INT( sent_bytes )
521 STATS_FLOAT( send_bitrate )
524 vlc_mutex_unlock( &p_item->p_stats->lock );
528 SSInit( &p_args->stack );
530 /* allocate output */
531 *pi_data = i_buffer + 1000;
532 dst = *pp_data = malloc( *pi_data );
534 /* we parse executing all <vlc /> macros */
535 Execute( p_args, p_request, i_request, pp_data, pi_data, &dst,
536 &p_buffer[0], &p_buffer[i_buffer] );
539 *pi_data = dst - *pp_data;
541 if( p_sys->p_input != NULL )
543 vlc_object_release( p_sys->p_input );
544 p_sys->p_input = NULL;
546 SSClean( &p_args->stack );
547 mvar_Delete( p_args->vars );
550 int HttpCallback( httpd_file_sys_t *p_args,
551 httpd_file_t *p_file,
553 uint8_t **_pp_data, int *pi_data )
556 char *p_request = (char *)_p_request;
557 char **pp_data = (char **)_pp_data;
560 if( ( f = utf8_fopen( p_args->file, "r" ) ) == NULL )
562 Callback404( p_args, pp_data, pi_data );
566 if( !p_args->b_html )
568 FileLoad( f, pp_data, pi_data );
575 /* first we load in a temporary buffer */
576 FileLoad( f, &p_buffer, &i_buffer );
578 ParseExecute( p_args, p_buffer, i_buffer, p_request, pp_data, pi_data );
588 /****************************************************************************
590 ****************************************************************************
591 * call the external handler and parse vlc macros if Content-Type is HTML
592 ****************************************************************************/
593 int HandlerCallback( httpd_handler_sys_t *p_args,
594 httpd_handler_t *p_handler, char *_p_url,
595 uint8_t *_p_request, int i_type,
596 uint8_t *_p_in, int i_in,
597 char *psz_remote_addr, char *psz_remote_host,
598 uint8_t **_pp_data, int *pi_data )
600 VLC_UNUSED(p_handler); VLC_UNUSED(_p_in);
601 char *p_url = (char *)_p_url;
602 char *p_request = (char *)_p_request;
603 char **pp_data = (char **)_pp_data;
604 char *p_in = (char *)p_in;
605 int i_request = p_request != NULL ? strlen( p_request ) : 0;
608 char **ppsz_env = NULL;
613 char *psz_cwd, *psz_file = NULL;
622 /* Create environment for the CGI */
623 TAB_APPEND( i_env, ppsz_env, strdup("GATEWAY_INTERFACE=CGI/1.1") );
624 TAB_APPEND( i_env, ppsz_env, strdup("SERVER_PROTOCOL=HTTP/1.1") );
625 TAB_APPEND( i_env, ppsz_env, strdup("SERVER_SOFTWARE=" COPYRIGHT_MESSAGE) );
630 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=GET") );
633 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=POST") );
636 TAB_APPEND( i_env, ppsz_env, strdup("REQUEST_METHOD=HEAD") );
644 psz_tmp = malloc( sizeof("QUERY_STRING=") + i_request );
645 sprintf( psz_tmp, "QUERY_STRING=%s", p_request );
646 TAB_APPEND( i_env, ppsz_env, psz_tmp );
648 psz_tmp = malloc( sizeof("REQUEST_URI=?") + strlen(p_url)
650 sprintf( psz_tmp, "REQUEST_URI=%s?%s", p_url, p_request );
651 TAB_APPEND( i_env, ppsz_env, psz_tmp );
655 psz_tmp = malloc( sizeof("REQUEST_URI=") + strlen(p_url) );
656 sprintf( psz_tmp, "REQUEST_URI=%s", p_url );
657 TAB_APPEND( i_env, ppsz_env, psz_tmp );
660 psz_tmp = malloc( sizeof("SCRIPT_NAME=") + strlen(p_url) );
661 sprintf( psz_tmp, "SCRIPT_NAME=%s", p_url );
662 TAB_APPEND( i_env, ppsz_env, psz_tmp );
664 #define p_sys p_args->file.p_intf->p_sys
665 psz_tmp = malloc( sizeof("SERVER_NAME=") + strlen(p_sys->psz_address) );
666 sprintf( psz_tmp, "SERVER_NAME=%s", p_sys->psz_address );
667 TAB_APPEND( i_env, ppsz_env, psz_tmp );
669 psz_tmp = malloc( sizeof("SERVER_PORT=") + 5 );
670 sprintf( psz_tmp, "SERVER_PORT=%u", p_sys->i_port );
671 TAB_APPEND( i_env, ppsz_env, psz_tmp );
674 p = getenv( "PATH" );
677 psz_tmp = malloc( sizeof("PATH=") + strlen(p) );
678 sprintf( psz_tmp, "PATH=%s", p );
679 TAB_APPEND( i_env, ppsz_env, psz_tmp );
683 p = getenv( "windir" );
686 psz_tmp = malloc( sizeof("SYSTEMROOT=") + strlen(p) );
687 sprintf( psz_tmp, "SYSTEMROOT=%s", p );
688 TAB_APPEND( i_env, ppsz_env, psz_tmp );
692 if( psz_remote_addr != NULL && *psz_remote_addr )
694 psz_tmp = malloc( sizeof("REMOTE_ADDR=") + strlen(psz_remote_addr) );
695 sprintf( psz_tmp, "REMOTE_ADDR=%s", psz_remote_addr );
696 TAB_APPEND( i_env, ppsz_env, psz_tmp );
699 if( psz_remote_host != NULL && *psz_remote_host )
701 psz_tmp = malloc( sizeof("REMOTE_HOST=") + strlen(psz_remote_host) );
702 sprintf( psz_tmp, "REMOTE_HOST=%s", psz_remote_host );
703 TAB_APPEND( i_env, ppsz_env, psz_tmp );
711 if( !strncasecmp( p, "Content-Type: ", strlen("Content-Type: ") ) )
713 char *end = strchr( p, '\r' );
717 psz_tmp = malloc( sizeof("CONTENT_TYPE=") + strlen(p) );
718 sprintf( psz_tmp, "CONTENT_TYPE=%s", p );
719 TAB_APPEND( i_env, ppsz_env, psz_tmp );
722 if( !strncasecmp( p, "Content-Length: ",
723 strlen("Content-Length: ") ) )
725 char *end = strchr( p, '\r' );
729 psz_tmp = malloc( sizeof("CONTENT_LENGTH=") + strlen(p) );
730 sprintf( psz_tmp, "CONTENT_LENGTH=%s", p );
731 TAB_APPEND( i_env, ppsz_env, psz_tmp );
735 p = strchr( p, '\n' );
736 if( p == NULL || p[1] == '\r' )
745 psz_file = strrchr( p_args->file.file, sep );
746 if( psz_file != NULL )
749 psz_tmp = malloc( sizeof("SCRIPT_FILENAME=") + strlen(psz_file) );
750 sprintf( psz_tmp, "SCRIPT_FILENAME=%s", psz_file );
751 TAB_APPEND( i_env, ppsz_env, psz_tmp );
753 TAB_APPEND( p_args->p_association->i_argc,
754 p_args->p_association->ppsz_argv, psz_file );
757 TAB_APPEND( i_env, ppsz_env, NULL );
759 TAB_APPEND( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
762 psz_tmp = strdup( p_args->file.file );
763 p = strrchr( psz_tmp, sep );
775 i_ret = vlc_execve( p_args->file.p_intf, p_args->p_association->i_argc,
776 p_args->p_association->ppsz_argv, ppsz_env, psz_cwd,
777 (char *)p_in, i_in, &p_buffer, &i_buffer );
778 TAB_REMOVE( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
780 TAB_REMOVE( p_args->p_association->i_argc, p_args->p_association->ppsz_argv,
784 TAB_REMOVE( i_env, ppsz_env, ppsz_env[0] );
788 Callback404( (httpd_file_sys_t *)p_args, pp_data, pi_data );
792 while( strncasecmp( p, "Content-Type: text/html",
793 strlen("Content-Type: text/html") ) )
795 p = strchr( p, '\n' );
796 if( p == NULL || p[1] == '\r' )
811 ParseExecute( (httpd_file_sys_t *)p_args, p_buffer, i_buffer,
812 p_request, pp_data, pi_data );
820 int ArtCallback( httpd_handler_sys_t *p_args,
821 httpd_handler_t *p_handler, char *_p_url,
822 uint8_t *p_request, int i_type,
823 uint8_t *p_in, int i_in,
824 char *psz_remote_addr, char *psz_remote_host,
825 uint8_t **pp_data, int *pi_data )
827 VLC_UNUSED(p_handler); VLC_UNUSED(_p_url); VLC_UNUSED(i_type);
828 VLC_UNUSED(p_in); VLC_UNUSED(i_in); VLC_UNUSED(psz_remote_addr);
829 VLC_UNUSED(psz_remote_host);
831 char *psz_art = NULL;
832 intf_thread_t *p_intf = p_args->file.p_intf;
833 intf_sys_t *p_sys = p_intf->p_sys;
835 input_item_t *p_item = NULL;
840 ExtractURIValue( (char *)p_request, "id", psz_id, 15 );
841 i_id = atoi( psz_id );
844 playlist_item_t *p_pl_item = playlist_ItemGetById( p_sys->p_playlist,
847 p_item = p_pl_item->p_input;
851 /* FIXME: Workarround a stupid assert in input_GetItem */
852 if( p_sys->p_input && p_sys->p_input->p )
853 p_item = input_GetItem( p_sys->p_input );
858 psz_art = input_item_GetArtURL( p_item );
861 if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) )
867 int i_header_size, i_data;
869 if( ( f = utf8_fopen( psz_art + strlen( "file://" ), "r" ) ) == NULL )
871 msg_Dbg( p_intf, "Couldn't open album art file %s",
872 psz_art + strlen( "file://" ) );
873 Callback404( &p_args->file, (char**)pp_data, pi_data );
878 FileLoad( f, &p_data, &i_data );
882 psz_ext = strrchr( psz_art, '.' );
883 if( psz_ext ) psz_ext++;
885 #define HEADER "Content-Type: image/%s\n" \
886 "Content-Length: %d\n" \
888 i_header_size = asprintf( &psz_header, HEADER, psz_ext, i_data );
891 *pi_data = i_header_size + i_data;
892 *pp_data = (uint8_t*)malloc( *pi_data );
893 memcpy( *pp_data, psz_header, i_header_size );
894 memcpy( *pp_data+i_header_size, p_data, i_data );
900 msg_Dbg( p_intf, "No album art found" );
901 Callback404( &p_args->file, (char**)pp_data, pi_data );