+
+int ArtCallback( httpd_handler_sys_t *p_args,
+ httpd_handler_t *p_handler, char *_p_url,
+ uint8_t *p_request, int i_type,
+ uint8_t *p_in, int i_in,
+ char *psz_remote_addr, char *psz_remote_host,
+ uint8_t **pp_data, int *pi_data )
+{
+ VLC_UNUSED(p_handler); VLC_UNUSED(_p_url); VLC_UNUSED(i_type);
+ VLC_UNUSED(p_in); VLC_UNUSED(i_in); VLC_UNUSED(psz_remote_addr);
+ VLC_UNUSED(psz_remote_host);
+
+ char *psz_art = NULL;
+ intf_thread_t *p_intf = p_args->file.p_intf;
+ intf_sys_t *p_sys = p_intf->p_sys;
+ char psz_id[16];
+ input_item_t *p_item = NULL;
+ int i_id;
+
+ psz_id[0] = '\0';
+ if( p_request )
+ ExtractURIValue( (char *)p_request, "id", psz_id, 15 );
+ i_id = atoi( psz_id );
+ if( i_id )
+ {
+ playlist_item_t *p_pl_item = playlist_ItemGetById( p_sys->p_playlist,
+ i_id, false );
+ if( p_pl_item )
+ p_item = p_pl_item->p_input;
+ }
+ else
+ {
+ /* FIXME: Workarround a stupid assert in input_GetItem */
+ if( p_sys->p_input && p_sys->p_input->p )
+ p_item = input_GetItem( p_sys->p_input );
+ }
+
+ if( p_item )
+ {
+ psz_art = input_item_GetArtURL( p_item );
+ }
+
+ if( psz_art && !strncmp( psz_art, "file://", strlen( "file://" ) ) )
+ {
+ FILE *f;
+ char *psz_ext;
+ char *psz_header;
+ char *p_data = NULL;
+ int i_header_size, i_data;
+
+ 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;
+ }
+
+ FileLoad( f, &p_data, &i_data );
+
+ fclose( f );
+
+ 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 );
+#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
+ {
+ msg_Dbg( p_intf, "No album art found" );
+ Callback404( &p_args->file, (char**)pp_data, pi_data );
+ }
+
+ free( psz_art );
+
+ return VLC_SUCCESS;
+}