From 1737297b581eca0ebcb7a399253771450cc24176 Mon Sep 17 00:00:00 2001 From: cboesch Date: Fri, 3 Dec 2010 23:10:36 +0000 Subject: stream/http: Add support for login/password in http_proxy env variable git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32673 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/network.c | 6 +++--- stream/url.c | 13 +++++++++++++ stream/url.h | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'stream') diff --git a/stream/network.c b/stream/network.c index c8667686ec..c6776ac29a 100644 --- a/stream/network.c +++ b/stream/network.c @@ -165,14 +165,14 @@ check4proxies( URL_t *url ) { #endif mp_msg(MSGT_NETWORK,MSGL_V,"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 ); + len = make_http_proxy_url(proxy_url, url->url, NULL, 0) + 1; + new_url = malloc(len); if( new_url==NULL ) { mp_tmsg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed.\n"); url_free(proxy_url); return url_out; } - sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url ); + make_http_proxy_url(proxy_url, url->url, new_url, len); tmp_url = url_new( new_url ); if( tmp_url==NULL ) { free( new_url ); diff --git a/stream/url.c b/stream/url.c index 92ea058831..c898d092b5 100644 --- a/stream/url.c +++ b/stream/url.c @@ -67,6 +67,19 @@ static int make_noauth_url(URL_t *url, char *dst, int dst_size) url->hostname, url->file); } +int make_http_proxy_url(URL_t *proxy, const char *host_url, char *dst, + int dst_size) +{ + if (proxy->username) + return snprintf(dst, dst_size, "http_proxy://%s:%s@%s:%d/%s", + proxy->username, + proxy->password ? proxy->password : "", + proxy->hostname, proxy->port, host_url); + else + return snprintf(dst, dst_size, "http_proxy://%s:%d/%s", + proxy->hostname, proxy->port, host_url); +} + URL_t* url_new(const char* url) { int pos1, pos2,v6addr = 0, noauth_len; diff --git a/stream/url.h b/stream/url.h index c89d91a663..b75978af2c 100644 --- a/stream/url.h +++ b/stream/url.h @@ -37,6 +37,9 @@ typedef struct { } URL_t; URL_t *url_redirect(URL_t **url, const char *redir); + +int make_http_proxy_url(URL_t *proxy, const char *host_url, char *dst, int dst_size); + URL_t* url_new(const char* url); void url_free(URL_t* url); -- cgit v1.2.3