[MPlayer-cvslog] r32634 - in trunk/stream: http.c http.h network.c

cboesch subversion at mplayerhq.hu
Thu Nov 18 21:20:39 CET 2010


Author: cboesch
Date: Thu Nov 18 21:20:39 2010
New Revision: 32634

Log:
Add Proxy-Authorization header to authenticate on proxies

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

Modified: trunk/stream/http.c
==============================================================================
--- trunk/stream/http.c	Thu Nov 18 21:18:44 2010	(r32633)
+++ trunk/stream/http.c	Thu Nov 18 21:20:39 2010	(r32634)
@@ -602,10 +602,11 @@ http_set_uri( HTTP_header_t *http_hdr, c
 	strcpy( http_hdr->uri, uri );
 }
 
-int
-http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) {
+static int
+http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) {
 	char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL;
 	int encoded_len, pass_len=0, out_len;
+	size_t auth_len;
 	int res = -1;
 	if( http_hdr==NULL || username==NULL ) return -1;
 
@@ -637,13 +638,14 @@ http_add_basic_authentication( HTTP_head
 
 	b64_usr_pass[out_len]='\0';
 
-	auth = malloc(encoded_len+22);
+	auth_len = encoded_len + 100;
+	auth = malloc(auth_len);
 	if( auth==NULL ) {
 		mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
 		goto out;
 	}
 
-	sprintf( auth, "Authorization: Basic %s", b64_usr_pass);
+	snprintf(auth, auth_len, "%s: Basic %s", auth_str, b64_usr_pass);
 	http_set_field( http_hdr, auth );
 	res = 0;
 
@@ -655,6 +657,16 @@ out:
 	return res;
 }
 
+int
+http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) {
+	return http_add_authentication(http_hdr, username, password, "Authorization");
+}
+
+int
+http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) {
+	return http_add_authentication(http_hdr, username, password, "Proxy-Authorization");
+}
+
 void
 http_debug_hdr( HTTP_header_t *http_hdr ) {
 	HTTP_field_t *field;

Modified: trunk/stream/http.h
==============================================================================
--- trunk/stream/http.h	Thu Nov 18 21:18:44 2010	(r32633)
+++ trunk/stream/http.h	Thu Nov 18 21:20:39 2010	(r32634)
@@ -63,6 +63,7 @@ void		http_set_field( HTTP_header_t *htt
 void		http_set_method( HTTP_header_t *http_hdr, const char *method );
 void		http_set_uri( HTTP_header_t *http_hdr, const char *uri );
 int		http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password );
+int		http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password );
 
 void		http_debug_hdr( HTTP_header_t *http_hdr );
 

Modified: trunk/stream/network.c
==============================================================================
--- trunk/stream/network.c	Thu Nov 18 21:18:44 2010	(r32633)
+++ trunk/stream/network.c	Thu Nov 18 21:20:39 2010	(r32634)
@@ -254,6 +254,8 @@ http_send_request( URL_t *url, off_t pos
 	if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url );
 
 	http_set_field( http_hdr, "Connection: close");
+	if (proxy)
+		http_add_basic_proxy_authentication(http_hdr, url->username, url->password);
 	http_add_basic_authentication(http_hdr, server_url->username, server_url->password);
 	if( http_build_request( http_hdr )==NULL ) {
 		goto err_out;


More information about the MPlayer-cvslog mailing list