/*****************************************************************************
* http.c: HTTP input module
*****************************************************************************
- * Copyright (C) 2001-2008 the VideoLAN team
+ * Copyright (C) 2001-2008 VLC authors and VideoLAN
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* RĂ©mi Denis-Courmont <rem # videolan.org>
* Antoine Cellerier <dionoea at videolan dot org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <assert.h>
#include <limits.h>
-#ifdef HAVE_LIBPROXY
-# include <proxy.h>
-#endif
-
-#ifdef WIN32
-# include <windows.h>
-#endif
-
/*****************************************************************************
* Module descriptor
*****************************************************************************/
/* Check proxy */
psz = var_InheritString( p_access, "http-proxy" );
- if( psz )
- {
- p_sys->b_proxy = true;
- vlc_UrlParse( &p_sys->proxy, psz, 0 );
- free( psz );
- }
-#ifdef HAVE_LIBPROXY
- else
+ if( psz == NULL )
{
- pxProxyFactory *pf = px_proxy_factory_new();
- if (pf)
- {
- char *buf;
- int i;
- i=asprintf(&buf, "%s://%s", psz_access, p_access->psz_location);
- if (i >= 0)
- {
- msg_Dbg(p_access, "asking libproxy about url '%s'", buf);
- char **proxies = px_proxy_factory_get_proxies(pf, buf);
- if (proxies[0])
- {
- msg_Dbg(p_access, "libproxy suggest to use '%s'", proxies[0]);
- if(strcmp(proxies[0],"direct://") != 0)
- {
- p_sys->b_proxy = true;
- vlc_UrlParse( &p_sys->proxy, proxies[0], 0);
- }
- }
- for(i=0;proxies[i];i++) free(proxies[i]);
- free(proxies);
- free(buf);
- }
- px_proxy_factory_free(pf);
- }
- else
+ char *url;
+
+ if (likely(asprintf(&url, "%s://%s", psz_access,
+ p_access->psz_location) != -1))
{
- msg_Err(p_access, "Allocating memory for libproxy failed");
+ msg_Dbg(p_access, "querying proxy for %s", url);
+ psz = vlc_getProxyUrl(url);
+ free(url);
}
- }
-#elif (0) // defined( WIN32 ) The parsing is not complete enough
- else
- {
- /* Try to get the proxy server address from Windows internet settings using registry. */
- HKEY h_key;
- /* Open the key */
- if( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft"
- "\\Windows\\CurrentVersion\\Internet Settings",
- 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
- {
- DWORD len = sizeof( DWORD );
- BYTE proxyEnable;
- /* Get the proxy enable value */
- if( RegQueryValueEx( h_key, "ProxyEnable", NULL, NULL,
- &proxyEnable, &len ) == ERROR_SUCCESS
- && proxyEnable )
- {
- /* Proxy is enabled */
- /* Get the proxy URL :
- Proxy server value in the registry can be something like "address:port"
- or "ftp=address1:port1;http=address2:port2 ..." depending of the
- confirguration. */
- unsigned char key[256];
-
- len = sizeof( key );
- if( RegQueryValueEx( h_key, "ProxyServer", NULL, NULL,
- key, &len ) == ERROR_SUCCESS )
- {
- /* FIXME: This is lame. The string should be tokenized. */
-#warning FIXME.
- char *psz_proxy = strstr( (char *)key, "http=" );
- if( psz_proxy != NULL )
- {
- psz_proxy += 5;
- char *end = strchr( psz_proxy, ';' );
- if( end != NULL )
- *end = '\0';
- }
- else
- psz_proxy = (char *)key;
- /* Set proxy enable for this connection. */
- p_sys->b_proxy = true;
- vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
- }
- }
- else
- msg_Dbg( p_access, "HTTP proxy disabled (MSIE)" );
- RegCloseKey( h_key );
- }
+ if (psz != NULL)
+ msg_Dbg(p_access, "proxy: %s", psz);
+ else
+ msg_Dbg(p_access, "no proxy");
}
-#else
- else
+ if( psz != NULL )
{
- psz = getenv( "http_proxy" );
- if( psz )
- {
- p_sys->b_proxy = true;
- vlc_UrlParse( &p_sys->proxy, psz, 0 );
- }
- }
-#endif
+ p_sys->b_proxy = true;
+ vlc_UrlParse( &p_sys->proxy, psz, 0 );
+ free( psz );
- if( psz ) /* No, this is NOT a use-after-free error */
- {
psz = var_InheritString( p_access, "http-proxy-pwd" );
if( psz )
p_sys->proxy.psz_password = p_sys->psz_proxy_passbuf = psz;
- }
- if( p_sys->b_proxy )
- {
if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )
{
msg_Warn( p_access, "invalid proxy host" );
if( p_sys->i_code == 401 )
{
+ if( p_sys->auth.psz_realm == NULL )
+ {
+ msg_Err( p_access, "authentication failed without realm" );
+ goto error;
+ }
char *psz_login, *psz_password;
/* FIXME ? */
if( p_sys->url.psz_username && p_sys->url.psz_password &&
goto error;
}
-
- /* Do not accept redirection outside of HTTP works */
const char *psz_protocol;
- if( !strncmp( p_sys->psz_location, "http:", 5 ) )
+ if( !strncmp( p_sys->psz_location, "http://", 7 ) )
psz_protocol = "http";
- else if( !strncmp( p_sys->psz_location, "https:", 6 ) )
+ else if( !strncmp( p_sys->psz_location, "https://", 8 ) )
psz_protocol = "https";
else
- {
- msg_Err( p_access, "insecure redirection ignored" );
+ { /* Do not accept redirection outside of HTTP */
+ msg_Err( p_access, "unsupported redirection ignored" );
goto error;
}
free( p_access->psz_location );
- p_access->psz_location = strdup( p_sys->psz_location );
+ p_access->psz_location = strdup( p_sys->psz_location
+ + strlen( psz_protocol ) + 3 );
/* Clean up current Open() run */
vlc_UrlClean( &p_sys->url );
http_auth_Reset( &p_sys->auth );
p_sys->inflate.stream.next_out = p_buffer;
i_ret = inflate( &p_sys->inflate.stream, Z_SYNC_FLUSH );
- msg_Warn( p_access, "inflate return value: %d, %s", i_ret, p_sys->inflate.stream.msg );
+ if ( i_ret != Z_OK && i_ret != Z_STREAM_END )
+ msg_Warn( p_access, "inflate return value: %d, %s", i_ret, p_sys->inflate.stream.msg );
return i_len - p_sys->inflate.stream.avail_out;
}
/* TLS/SSL handshake */
p_sys->p_tls = vlc_tls_ClientSessionCreate( p_sys->p_creds, p_sys->fd,
- p_sys->url.psz_host );
+ p_sys->url.psz_host, "https" );
if( p_sys->p_tls == NULL )
{
msg_Err( p_access, "cannot establish HTTP/TLS session" );
net_Printf( p_access, p_sys->fd, pvs, "Referer: %s\r\n",
p_sys->psz_referrer);
}
-#ifdef HAVE_ZLIB_H
- net_Printf( p_access, p_sys->fd, pvs, "Accept-Encoding: gzip, deflate\r\n" );
-#endif
/* Offset */
if( p_sys->i_version == 1 && ! p_sys->b_continuous )
{
{
char *psz = net_Gets( p_access, p_sys->fd, pvs );
char *p;
+ char *p_trailing;
if( psz == NULL )
{
goto error;
}
*p++ = '\0';
- while( *p == ' ' ) p++;
+ p += strspn( p, " \t" );
+
+ /* trim trailing white space */
+ p_trailing = p + strlen( p );
+ if( p_trailing > p )
+ {
+ p_trailing--;
+ while( ( *p_trailing == ' ' || *p_trailing == '\t' ) && p_trailing > p )
+ {
+ *p_trailing = '\0';
+ p_trailing--;
+ }
+ }
if( !strcasecmp( psz, "Content-Length" ) )
{