X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fhttp.c;h=46e8dd434bd251d8648d41e25f3f24e8db134edc;hb=8ad60e05cdb9509e329ece1d8f4cd5b91306d811;hp=c59fde7cbd25069b9b509f41ccf519c468fbd79d;hpb=e55b8a6f199d250d264ae5e2cdc9275cfb5631b9;p=vlc diff --git a/modules/access/http.c b/modules/access/http.c index c59fde7cbd..46e8dd434b 100644 --- a/modules/access/http.c +++ b/modules/access/http.c @@ -1,7 +1,7 @@ /***************************************************************************** * http.c: HTTP input module ***************************************************************************** - * Copyright (C) 2001-2004 VideoLAN + * Copyright (C) 2001-2005 VideoLAN * $Id$ * * Authors: Laurent Aimar @@ -227,7 +227,21 @@ static int Open( vlc_object_t *p_this ) 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" ); @@ -261,17 +275,17 @@ static int Open( vlc_object_t *p_this ) 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 ) @@ -371,9 +385,9 @@ static int Open( vlc_object_t *p_this ) 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" ) ) @@ -397,6 +411,13 @@ static int Open( vlc_object_t *p_this ) } /* 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" ); @@ -625,7 +646,7 @@ static int ReadICYMeta( access_t *p_access ) 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 ); @@ -735,13 +756,13 @@ static int Control( access_t *p_access, int i_query, va_list args ) 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; @@ -850,27 +871,76 @@ static int Connect( access_t *p_access, int64_t i_tell ) } /* 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 ); } @@ -882,6 +952,7 @@ static int Request( access_t *p_access, int64_t 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, @@ -938,6 +1009,7 @@ static int Request( access_t *p_access, int64_t i_tell ) 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 );