[Mplayer-cvslog] CVS: main/libmpdemux network.c,1.49,1.50

Bertrand Baudet bertrand at mplayerhq.hu
Sun Jun 23 11:17:55 CEST 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv8919

Modified Files:
	network.c 
Log Message:
Added HTTP basic authentication support


Index: network.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- network.c	21 Jun 2002 07:06:46 -0000	1.49
+++ network.c	23 Jun 2002 09:17:52 -0000	1.50
@@ -275,6 +275,7 @@
 	http_set_field( http_hdr, str);
 	http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION);
 	http_set_field( http_hdr, "Connection: closed");
+	http_add_basic_authentication( http_hdr, url->username, url->password );
 	if( http_build_request( http_hdr )==NULL ) {
 		return -1;
 	}
@@ -492,6 +493,42 @@
 						redirect = 1;	
 					}
 					break;
+				case 401: // Authorization required
+					{
+					char username[50], password[50];
+					char *aut;
+					aut = http_get_field(http_hdr, "WWW-Authenticate");
+					if( aut!=NULL ) {
+						char *aut_space;
+						aut_space = strstr(aut, "realm=");
+						if( aut_space!=NULL ) aut_space += 6;
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Authorization required for %s, please enter:\n", aut_space);
+					} else {
+						mp_msg(MSGT_NETWORK,MSGL_ERR,"Authorization required, please enter:\n");
+					}
+					mp_msg(MSGT_NETWORK,MSGL_ERR,"username: ");
+					// FIXME
+					scanf("%s", username);
+					printf("%s\n", username);
+					mp_msg(MSGT_NETWORK,MSGL_ERR,"password: ");
+					// FIXME
+					scanf("%s", password);
+					printf("%s\n", password);
+					url->username = (char*)malloc(strlen(username)+1);
+					if( url->username==NULL ) {
+						mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+						return -1;
+					}
+					strcpy(url->username, username);
+					url->password = (char*)malloc(strlen(password)+1);
+					if( url->password==NULL ) {
+						mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+						return -1;
+					}
+					strcpy(url->password, password);
+					redirect = 1;
+					break;
+					}
 				default:
 					mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
 					return -1;




More information about the MPlayer-cvslog mailing list