diff options
author | bertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-01-14 06:44:30 +0000 |
---|---|---|
committer | bertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-01-14 06:44:30 +0000 |
commit | 8629e9e819cfce49406f55c2655bd1ad6f72d0df (patch) | |
tree | 71d1ab0ec4cb3ed842755f8c10d4ed807ec31588 /libmpdemux | |
parent | 32d1e1014ff45f4955ee0315b10b81eea117a8c2 (diff) | |
download | mpv-8629e9e819cfce49406f55c2655bd1ad6f72d0df.tar.bz2 mpv-8629e9e819cfce49406f55c2655bd1ad6f72d0df.tar.xz |
Added support for the environment variable http_proxy.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4147 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r-- | libmpdemux/network.c | 45 | ||||
-rw-r--r-- | libmpdemux/network.h | 1 | ||||
-rw-r--r-- | libmpdemux/open.c | 1 |
3 files changed, 45 insertions, 2 deletions
diff --git a/libmpdemux/network.c b/libmpdemux/network.c index ecd22acd92..d24dbd2189 100644 --- a/libmpdemux/network.c +++ b/libmpdemux/network.c @@ -173,6 +173,49 @@ connect2Server(char *host, int port) { return socket_server_fd; } +URL_t* +check4proxies( URL_t *url ) { + if( !strcasecmp(url->protocol, "http_proxy") ) { + printf("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); + return url; + } + // Check if the http_proxy environment variable is set. + if( !strcasecmp(url->protocol, "http") ) { + char *proxy; + proxy = getenv("http_proxy"); + if( proxy!=NULL ) { + // We got a proxy, build the URL to use it + int len; + char *new_url; + URL_t *tmp_url; + URL_t *proxy_url = url_new( proxy ); + + if( proxy_url==NULL ) { + printf("Invalid proxy setting...Trying without proxy.\n"); + return url; + } + + printf("Using HTTP proxy: %s\n", proxy_url->url ); + len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port + new_url = malloc( len+1 ); + if( new_url==NULL ) { + printf("Memory allocation failed\n"); + return url; + } + sprintf( new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url); + tmp_url = url_new( new_url ); + if( tmp_url==NULL ) { + return url; + } + url_free( url ); + url = tmp_url; + free( new_url ); + url_free( proxy_url ); + } + } + return url; +} + int http_send_request( URL_t *url ) { HTTP_header_t *http_hdr; @@ -326,8 +369,6 @@ extension=NULL; // HTTP based protocol if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "http_proxy") ) { - //if( url->port==0 ) url->port = 80; - fd = http_send_request( url ); if( fd<0 ) { return -1; diff --git a/libmpdemux/network.h b/libmpdemux/network.h index 02615e7000..e1ead7f19c 100644 --- a/libmpdemux/network.h +++ b/libmpdemux/network.h @@ -42,6 +42,7 @@ streaming_ctrl_t *streaming_ctrl_new(); void streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ); int autodetectProtocol( streaming_ctrl_t *streaming_ctrl, int *fd_out, int *file_format ); +URL_t* check4proxies( URL_t *url ); //int streaming_start( stream_t *stream, int demuxer_type ); diff --git a/libmpdemux/open.c b/libmpdemux/open.c index e4d8177035..7af6221f3b 100644 --- a/libmpdemux/open.c +++ b/libmpdemux/open.c @@ -375,6 +375,7 @@ tv_err: streaming_ctrl_t *streaming_ctrl; streaming_ctrl = streaming_ctrl_new(); if( streaming_ctrl==NULL ) return NULL; + url = check4proxies( url ); streaming_ctrl->url = url_copy( url ); if( autodetectProtocol( streaming_ctrl, &f, file_format )<0 ) { mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_UnableOpenURL, filename ); |