[vlc-devel] [RFC PATCH 8/8] http: use vlc_credential
Thomas Guillem
thomas at gllm.fr
Wed Dec 30 19:37:05 CET 2015
---
modules/access/http.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/modules/access/http.c b/modules/access/http.c
index e27a986..9cc793f6 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -46,6 +46,7 @@
#include <vlc_input.h>
#include <vlc_http.h>
#include <vlc_interrupt.h>
+#include <vlc_keystore.h>
#ifdef HAVE_ZLIB_H
# include <zlib.h>
@@ -212,6 +213,7 @@ static int Open( vlc_object_t *p_this )
const char *psz_url = p_access->psz_url;
char *psz;
int ret = VLC_EGENERIC;
+ vlc_credential *p_credential = NULL;
access_sys_t *p_sys = malloc( sizeof(*p_sys) );
if( unlikely(p_sys == NULL) )
@@ -385,7 +387,7 @@ connect:
msg_Err( p_access, "authentication failed without realm" );
goto error;
}
- char *psz_login, *psz_password;
+ const char *psz_login, *psz_password;
/* FIXME ? */
if( p_sys->url.psz_username && p_sys->url.psz_password &&
p_sys->auth.psz_nonce && p_sys->auth.i_nonce == 0 )
@@ -395,25 +397,36 @@ connect:
}
msg_Dbg( p_access, "authentication failed for realm %s",
p_sys->auth.psz_realm );
- dialog_Login( p_access, &psz_login, &psz_password,
- _("HTTP authentication"),
- _("Please enter a valid login name and a password for realm %s."),
- p_sys->auth.psz_realm );
- if( psz_login != NULL && psz_password != NULL )
+ if (p_credential == NULL)
+ {
+ p_credential =
+ vlc_credential_create( p_access, psz_url,
+ p_sys->auth.psz_realm,
+ "Basic", /* TODO */
+ _("HTTP authentication"),
+ _("Please enter a valid login name and a password for realm %s."),
+ p_sys->auth.psz_realm );
+ if (p_credential == NULL)
+ goto error;
+ }
+ if (vlc_credential_get(p_credential, &psz_login, &psz_password))
{
msg_Dbg( p_access, "retrying with user=%s", psz_login );
- p_sys->url.psz_username = psz_login;
- p_sys->url.psz_password = psz_password;
+ p_sys->url.psz_username = (char *) psz_login;
+ p_sys->url.psz_password = (char *) psz_password;
Disconnect( p_access );
goto connect;
}
else
{
- free( psz_login );
- free( psz_password );
goto error;
}
}
+ else if (p_credential != NULL)
+ {
+ vlc_credential_release(p_credential, true);
+ p_credential = NULL;
+ }
if( ( p_sys->i_code == 301 || p_sys->i_code == 302 ||
p_sys->i_code == 303 || p_sys->i_code == 307 ) &&
@@ -450,6 +463,8 @@ connect:
return VLC_SUCCESS;
error:
+ if (p_credential)
+ vlc_credential_release(p_credential, false);
vlc_UrlClean( &p_sys->url );
if( p_sys->b_proxy )
vlc_UrlClean( &p_sys->proxy );
--
2.1.4
More information about the vlc-devel
mailing list