/*****************************************************************************
* http.c: HTTP input module
*****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2005 VideoLAN
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
p_sys->i_remaining = 0;
/* Parse URI */
- ParseURL( p_sys, p_access->psz_path );
+ if( vlc_UrlIsNotEncoded( p_access->psz_path ) )
+ {
+ psz = vlc_UrlEncode( p_access->psz_path );
+ if( psz == NULL )
+ {
+ free( p_sys );
+ return VLC_ENOMEM;
+ }
+
+ ParseURL( p_sys, psz );
+ free( psz );
+ }
+ else
+ ParseURL( p_sys, p_access->psz_path );
+
if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
{
msg_Warn( p_access, "invalid host" );
p_sys->b_proxy = VLC_TRUE;
vlc_UrlParse( &p_sys->proxy, psz, 0 );
}
+#ifdef HAVE_GETENV
else
{
- char *psz_proxy = getenv( "http_proxy" );
+ char *psz_proxy = getenv( "HTTP_PROXY" );
if( psz_proxy && *psz_proxy )
{
p_sys->b_proxy = VLC_TRUE;
vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
}
- if( psz_proxy )
- free( psz_proxy );
}
+#endif
free( psz );
if( p_sys->b_proxy )
if( !strcmp( p_sys->psz_protocol, "ICY" ) || p_sys->b_icecast )
{
if( p_sys->psz_mime && strcasecmp( p_sys->psz_mime, "application/ogg" ) )
- {
+ {
if( !strcasecmp( p_sys->psz_mime, "video/nsv" ) ||
- !strcasecmp( p_sys->psz_mime, "video/nsa") )
+ !strcasecmp( p_sys->psz_mime, "video/nsa" ) )
p_access->psz_demux = strdup( "nsv" );
else if( !strcasecmp( p_sys->psz_mime, "audio/aac" ) ||
!strcasecmp( p_sys->psz_mime, "audio/aacp" ) )
}
/* else probably Ogg Vorbis */
}
+ else if( !strcasecmp( p_access->psz_access, "unsv" ) &&
+ p_sys->psz_mime &&
+ !strcasecmp( p_sys->psz_mime, "misc/ultravox" ) )
+ {
+ /* Grrrr! detect ultravox server and force NSV demuxer */
+ p_access->psz_demux = strdup( "nsv" );
+ }
if( p_sys->b_reconnect ) msg_Dbg( p_access, "auto re-connect enabled" );
if( i_read != buffer[0] * 16 )
return VLC_EGENERIC;
- psz_meta[buffer[0]*16 + 1] = '\0'; /* Just in case */
+ psz_meta[buffer[0]*16] = '\0'; /* Just in case */
msg_Dbg( p_access, "icy-meta=%s", psz_meta );
msg_Dbg( p_access, "GET META %s %s %s",
p_sys->psz_icy_name, p_sys->psz_icy_genre, p_sys->psz_icy_title );
if( p_sys->psz_icy_name )
- vlc_meta_Add( *pp_meta, VLC_META_DESCRIPTION,
+ vlc_meta_Add( *pp_meta, VLC_META_TITLE,
p_sys->psz_icy_name );
if( p_sys->psz_icy_genre )
vlc_meta_Add( *pp_meta, VLC_META_GENRE,
p_sys->psz_icy_genre );
if( p_sys->psz_icy_title )
- vlc_meta_Add( *pp_meta, VLC_META_TITLE,
+ vlc_meta_Add( *pp_meta, VLC_META_NOW_PLAYING,
p_sys->psz_icy_title );
break;
}
/* Initialize TLS/SSL session */
- /* FIXME: support proxy CONNECT for HTTP/SSL */
if( p_sys->b_ssl == VLC_TRUE )
{
+ /* CONNECT to establish TLS tunnel through HTTP proxy */
if( p_sys->b_proxy )
{
- msg_Err( p_access, "HTTP/SSL through HTTP proxy not supported yet" );
- Disconnect( p_access );
- return VLC_EGENERIC;
+ char *psz;
+ unsigned i_status = 0;
+
+ if( p_sys->i_version == 0 )
+ {
+ /* CONNECT is not in HTTP/1.0 */
+ Disconnect( p_access );
+ return VLC_EGENERIC;
+ }
+
+ net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
+ "CONNECT %s:%d HTTP/1.%d\r\nHost: %s:%d\r\n\r\n",
+ p_sys->url.psz_host, p_sys->url.i_port,
+ p_sys->i_version,
+ p_sys->url.psz_host, p_sys->url.i_port);
+
+ psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+ if( psz == NULL )
+ {
+ msg_Err( p_access, "cannot establish HTTP/TLS tunnel" );
+ Disconnect( p_access );
+ return VLC_EGENERIC;
+ }
+
+ sscanf( psz, "HTTP/%*u.%*u %3u", &i_status );
+ free( psz );
+
+ if( ( i_status / 100 ) != 2 )
+ {
+ msg_Err( p_access, "HTTP/TLS tunnel through proxy denied" );
+ Disconnect( p_access );
+ return VLC_EGENERIC;
+ }
+
+ do
+ {
+ psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+ if( psz == NULL )
+ {
+ msg_Err( p_access, "HTTP proxy connection failed" );
+ Disconnect( p_access );
+ return VLC_EGENERIC;
+ }
+
+ if( *psz == '\0' )
+ i_status = 0;
+
+ free( psz );
+ }
+ while( i_status );
}
- p_sys->p_tls = tls_ClientCreate( VLC_OBJECT(p_access), NULL, p_sys->fd );
+ /* TLS/SSL handshake */
+ p_sys->p_tls = tls_ClientCreate( VLC_OBJECT(p_access), p_sys->fd,
+ srv.psz_host );
if( p_sys->p_tls == NULL )
{
- msg_Err( p_access, "cannot establish HTTP/SSL session" );
+ msg_Err( p_access, "cannot establish HTTP/TLS session" );
Disconnect( p_access );
return VLC_EGENERIC;
}
p_sys->p_vs = &p_sys->p_tls->sock;
}
- return Request( p_access,i_tell );
+ return Request( p_access, i_tell );
}
if( p_sys->b_proxy )
{
+ /* FIXME: support SSL proxies */
if( p_sys->url.psz_path )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
p_sys->psz_passwd ? p_sys->psz_passwd : "" );
b64 = vlc_b64_encode( buf );
+ free( buf );
net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs,
"Authorization: Basic %s\r\n", b64 );