[MPlayer-cvslog] r32673 - in trunk/stream: network.c url.c url.h

cboesch subversion at mplayerhq.hu
Sat Dec 4 00:10:36 CET 2010


Author: cboesch
Date: Sat Dec  4 00:10:36 2010
New Revision: 32673

Log:
Add support for login/password in http_proxy env variable.

Modified:
   trunk/stream/network.c
   trunk/stream/url.c
   trunk/stream/url.h

Modified: trunk/stream/network.c
==============================================================================
--- trunk/stream/network.c	Fri Dec  3 20:52:10 2010	(r32672)
+++ trunk/stream/network.c	Sat Dec  4 00:10:36 2010	(r32673)
@@ -164,14 +164,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_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
 				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 );

Modified: trunk/stream/url.c
==============================================================================
--- trunk/stream/url.c	Fri Dec  3 20:52:10 2010	(r32672)
+++ trunk/stream/url.c	Sat Dec  4 00:10:36 2010	(r32673)
@@ -68,6 +68,19 @@ static int make_noauth_url(URL_t *url, c
                         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;

Modified: trunk/stream/url.h
==============================================================================
--- trunk/stream/url.h	Fri Dec  3 20:52:10 2010	(r32672)
+++ trunk/stream/url.h	Sat Dec  4 00:10:36 2010	(r32673)
@@ -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);
 


More information about the MPlayer-cvslog mailing list