changeset 32553:c44141d4e443

Do not keep authentication in URL on connection through a proxy
author cboesch
date Sun, 21 Nov 2010 16:52:22 +0000
parents 2e4da7887fd1
children 8fffd26d06ae
files stream/network.c stream/url.c stream/url.h
diffstat 3 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/stream/network.c	Sun Nov 21 12:25:44 2010 +0000
+++ b/stream/network.c	Sun Nov 21 16:52:22 2010 +0000
@@ -209,7 +209,7 @@
 			mp_msg(MSGT_NETWORK, MSGL_ERR, "Invalid URL '%s' to proxify\n", url->file+1);
 			goto err_out;
 		}
-		http_set_uri( http_hdr, server_url->url );
+		http_set_uri( http_hdr, server_url->noauth_url );
 	} else {
 		server_url = url;
 		http_set_uri( http_hdr, server_url->file );
--- a/stream/url.c	Sun Nov 21 12:25:44 2010 +0000
+++ b/stream/url.c	Sun Nov 21 16:52:22 2010 +0000
@@ -58,9 +58,19 @@
   return res;
 }
 
+static int make_noauth_url(URL_t *url, char *dst, int dst_size)
+{
+    if (url->port)
+        return snprintf(dst, dst_size, "%s://%s:%d%s", url->protocol,
+                        url->hostname, url->port, url->file);
+    else
+        return snprintf(dst, dst_size, "%s://%s%s", url->protocol,
+                        url->hostname, url->file);
+}
+
 URL_t*
 url_new(const char* url) {
-	int pos1, pos2,v6addr = 0;
+	int pos1, pos2,v6addr = 0, noauth_len;
 	URL_t* Curl = NULL;
         char *escfilename=NULL;
 	char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL, *ptr4=NULL;
@@ -232,6 +242,17 @@
 		strcpy(Curl->file, "/");
 	}
 
+	noauth_len = make_noauth_url(Curl, NULL, 0);
+	if (noauth_len > 0) {
+		noauth_len++;
+		Curl->noauth_url = malloc(noauth_len);
+		if (!Curl->noauth_url) {
+			mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MemAllocFailed);
+			goto err_out;
+		}
+		make_noauth_url(Curl, Curl->noauth_url, noauth_len);
+	}
+
         free(escfilename);
 	return Curl;
 err_out:
--- a/stream/url.h	Sun Nov 21 12:25:44 2010 +0000
+++ b/stream/url.h	Sun Nov 21 16:52:22 2010 +0000
@@ -27,6 +27,7 @@
 
 typedef struct {
 	char *url;
+	char *noauth_url;
 	char *protocol;
 	char *hostname;
 	char *file;