# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
#include <vlc_plugin.h>
# include <zlib.h>
#endif
+#include <assert.h>
+
+#ifdef HAVE_PROXY_H
+# include "proxy.h"
+#endif
/*****************************************************************************
* Module descriptor
*****************************************************************************/
#define PROXY_TEXT N_("HTTP proxy")
#define PROXY_LONGTEXT N_( \
"HTTP proxy to be used It must be of the form " \
- "http://[user[:pass]@]myproxy.mydomain:myport/ ; " \
+ "http://[user@]myproxy.mydomain:myport/ ; " \
"if empty, the http_proxy environment variable will be tried." )
+#define PROXY_PASS_TEXT N_("HTTP proxy password")
+#define PROXY_PASS_LONGTEXT N_( \
+ "If your HTTP proxy requires a password, set it here." )
+
#define CACHING_TEXT N_("Caching value in ms")
#define CACHING_LONGTEXT N_( \
"Caching value for HTTP streams. This " \
add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT,
false );
+ add_password( "http-proxy-pwd", NULL, NULL,
+ PROXY_PASS_TEXT, PROXY_PASS_LONGTEXT, false );
add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
CACHING_TEXT, CACHING_LONGTEXT, true );
add_string( "http-user-agent", COPYRIGHT_MESSAGE , NULL, AGENT_TEXT,
bool b_proxy;
vlc_url_t proxy;
http_auth_t proxy_auth;
+ char *psz_proxy_passbuf;
/* */
int i_code;
#endif
p_sys->fd = -1;
p_sys->b_proxy = false;
+ p_sys->psz_proxy_passbuf = NULL;
p_sys->i_version = 1;
p_sys->b_seekable = true;
p_sys->psz_mime = NULL;
p_sys->psz_user_agent = var_CreateGetString( p_access, "http-user-agent" );
/* Check proxy */
- psz = var_CreateGetString( p_access, "http-proxy" );
- if( *psz )
+ psz = var_CreateGetNonEmptyString( p_access, "http-proxy" );
+ if( psz )
{
p_sys->b_proxy = true;
vlc_UrlParse( &p_sys->proxy, psz, 0 );
+ free( psz );
}
-#ifdef HAVE_GETENV
+#ifdef HAVE_PROXY_H
else
{
- char *psz_proxy = getenv( "http_proxy" );
- if( psz_proxy && *psz_proxy )
+ pxProxyFactory *pf = px_proxy_factory_new();
+ if (pf)
+ {
+ char *buf;
+ int i;
+ i=asprintf(&buf, "%s://%s", p_access->psz_access, p_access->psz_path);
+ 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
+ {
+ msg_Err(p_access, "Allocating memory for libproxy failed");
+ }
+ }
+#elif HAVE_GETENV
+ else
+ {
+ psz = getenv( "http_proxy" );
+ if( psz )
{
p_sys->b_proxy = true;
- vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
+ vlc_UrlParse( &p_sys->proxy, psz, 0 );
}
}
#endif
- free( psz );
+ if( psz ) /* No, this is NOT a use-after-free error */
+ {
+ psz = var_CreateGetNonEmptyString( 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->url.psz_username && *p_sys->url.psz_username )
{
- msg_Dbg( p_access, " user='%s', pwd='%s'",
- p_sys->url.psz_username, p_sys->url.psz_password );
+ msg_Dbg( p_access, " user='%s'", p_sys->url.psz_username );
}
p_sys->b_reconnect = var_CreateGetBool( p_access, "http-reconnect" );
if( p_sys->i_code == 401 )
{
- char *psz_login = NULL; char *psz_password = NULL;
+ char *psz_login = NULL, *psz_password = NULL;
char psz_msg[250];
int i_ret;
/* FIXME ? */
vlc_UrlClean( &p_sys->url );
AuthReset( &p_sys->auth );
vlc_UrlClean( &p_sys->proxy );
+ free( p_sys->psz_proxy_passbuf );
AuthReset( &p_sys->proxy_auth );
free( p_sys->psz_mime );
free( p_sys->psz_pragma );
error:
vlc_UrlClean( &p_sys->url );
vlc_UrlClean( &p_sys->proxy );
+ free( p_sys->psz_proxy_passbuf );
free( p_sys->psz_mime );
free( p_sys->psz_pragma );
free( p_sys->psz_location );
Disconnect( p_access );
+ if( p_access->info.i_size
+ && (uint64_t)i_pos >= (uint64_t)p_access->info.i_size ) {
+ msg_Err( p_access, "seek to far" );
+ int retval = Seek( p_access, p_access->info.i_size - 1 );
+ if( retval == VLC_SUCCESS ) {
+ uint8_t p_buffer[2];
+ Read( p_access, p_buffer, 1);
+ p_access->info.b_eof = false;
+ }
+ return retval;
+ }
if( Connect( p_access, i_pos ) )
{
msg_Err( p_access, "seek failed" );
if( p_sys->i_version == 1 )
{
net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs,
- "Range: bytes=%"PRId64"-\r\n", i_tell );
+ "Range: bytes=%"PRIu64"-\r\n", i_tell );
}
/* Cookies */