[Mplayer-cvslog] CVS: main/libmpdemux network.c,1.52,1.53
Bertrand Baudet
bertrand at mplayerhq.hu
Tue Jun 25 10:04:55 CEST 2002
Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv25048
Modified Files:
network.c
Log Message:
Read username/password from the -user -pass command line options.
Index: network.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- network.c 24 Jun 2002 20:12:18 -0000 1.52
+++ network.c 25 Jun 2002 08:04:52 -0000 1.53
@@ -32,6 +32,11 @@
extern int verbose;
extern m_config_t *mconfig;
+/* Variables for the command line option -user & -pass */
+char *network_username;
+char *network_password;
+
+
static struct {
char *mime_type;
int demuxer_type;
@@ -335,10 +340,12 @@
int
http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) {
- char username[50], password[50];
char *aut;
- if( *auth_retry>3 ) {
+ int ret;
+ if( *auth_retry==1 ) {
mp_msg(MSGT_NETWORK,MSGL_ERR,"Authentication failed\n");
+ mp_msg(MSGT_NETWORK,MSGL_ERR,"Please use the option -user and -pass to provide your username/password for a list of URLs,\n");
+ mp_msg(MSGT_NETWORK,MSGL_ERR,"or form an URL like: http://username:password@hostname/file\n");
return -1;
}
if( *auth_retry>0 ) {
@@ -351,24 +358,21 @@
url->password = NULL;
}
}
+
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_INFO,"Authorization required for %s, please enter:\n", aut_space);
- mp_msg(MSGT_NETWORK,MSGL_INFO,"Authorization required for %s\n", aut_space);
+ mp_msg(MSGT_NETWORK,MSGL_INFO,"Authentication required for %s\n", aut_space);
} else {
-// mp_msg(MSGT_NETWORK,MSGL_INFO,"Authorization required, please enter:\n");
- mp_msg(MSGT_NETWORK,MSGL_INFO,"Authorization required\n");
+ mp_msg(MSGT_NETWORK,MSGL_INFO,"Authentication required\n");
}
-return -1;
- if( url->username==NULL ) {
- mp_msg(MSGT_NETWORK,MSGL_INFO,"username: ");
- // FIXME
- scanf("%s", username);
- printf("%s\n", username);
-
+ ret = m_config_is_option_set(mconfig,"user");
+ if( ret==1 ) {
+ char *username;
+ username = *((char**)m_config_get_option_ptr(mconfig, "user"));
+ if( username==NULL ) return -1;
url->username = (char*)malloc(strlen(username)+1);
if( url->username==NULL ) {
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
@@ -376,22 +380,25 @@
}
strcpy(url->username, username);
} else {
- mp_msg(MSGT_NETWORK,MSGL_INFO,"%s ", url->username );
- }
- mp_msg(MSGT_NETWORK,MSGL_INFO,"password: ");
- // FIXME
- scanf("%s", password);
- printf("%s\n", password);
- if( url->password ) {
- free( url->password );
- url->password = NULL;
- }
- url->password = (char*)malloc(strlen(password)+1);
- if( url->password==NULL ) {
- mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ mp_msg(MSGT_NETWORK,MSGL_ERR,"Unable to read the username\n");
+ mp_msg(MSGT_NETWORK,MSGL_ERR,"Please use the option -user and -pass to provide your username/password for a list of URLs,\n");
+ mp_msg(MSGT_NETWORK,MSGL_ERR,"or form an URL like: http://username:password@hostname/file\n");
return -1;
}
- strcpy(url->password, password);
+ ret = m_config_is_option_set(mconfig,"pass");
+ if( ret==1 ) {
+ char *password;
+ password = *((char**)m_config_get_option_ptr(mconfig, "pass"));
+ if( password==NULL ) return -1;
+ 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);
+ } else {
+ mp_msg(MSGT_NETWORK,MSGL_INFO,"No password provided, trying blank password\n");
+ }
(*auth_retry)++;
return 0;
}
@@ -557,7 +564,7 @@
redirect = 1;
}
break;
- case 401: // Authorization required
+ case 401: // Authentication required
if( http_authenticate(http_hdr, url, &auth_retry)<0 ) return -1;
redirect = 1;
break;
More information about the MPlayer-cvslog
mailing list