changeset 4146:925046ea34ec

Added support for the environment variable http_proxy.
author bertrand
date Mon, 14 Jan 2002 06:44:30 +0000
parents c66fddd8867c
children 4bbdda22003d
files libmpdemux/network.c libmpdemux/network.h libmpdemux/open.c
diffstat 3 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/network.c	Mon Jan 14 01:12:44 2002 +0000
+++ b/libmpdemux/network.c	Mon Jan 14 06:44:30 2002 +0000
@@ -173,6 +173,49 @@
 	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 @@
 
 		// 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;
--- a/libmpdemux/network.h	Mon Jan 14 01:12:44 2002 +0000
+++ b/libmpdemux/network.h	Mon Jan 14 06:44:30 2002 +0000
@@ -42,6 +42,7 @@
 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 );
 
--- a/libmpdemux/open.c	Mon Jan 14 01:12:44 2002 +0000
+++ b/libmpdemux/open.c	Mon Jan 14 06:44:30 2002 +0000
@@ -375,6 +375,7 @@
 	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 );