summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
authorbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-06-25 08:04:52 +0000
committerbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-06-25 08:04:52 +0000
commitf7f0dc084cf0086266ee242f0e01e48709afe0b7 (patch)
tree53a8001ccb7f7f197d095e902a50d56dc6eaac35 /libmpdemux
parentc41fe8144afbcb24fae53dde685b54b29a7efb1d (diff)
downloadmpv-f7f0dc084cf0086266ee242f0e01e48709afe0b7.tar.bz2
mpv-f7f0dc084cf0086266ee242f0e01e48709afe0b7.tar.xz
Read username/password from the -user -pass command line options.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6559 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/network.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/libmpdemux/network.c b/libmpdemux/network.c
index 16bc52b46f..5fb7cfa0b4 100644
--- a/libmpdemux/network.c
+++ b/libmpdemux/network.c
@@ -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 @@ http_read_response( int fd ) {
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 @@ http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) {
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 @@ return -1;
}
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 @@ extension=NULL;
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;