[vlc-commits] ftp: use vlc_credential
Thomas Guillem
git at videolan.org
Thu Jan 7 20:12:44 CET 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jan 7 19:55:35 2016 +0100| [c4e7180cfc3631f2d03e18cf14f390efbe834dca] | committer: Thomas Guillem
ftp: use vlc_credential
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4e7180cfc3631f2d03e18cf14f390efbe834dca
---
modules/access/ftp.c | 66 +++++++++++++++++++++++++-------------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/modules/access/ftp.c b/modules/access/ftp.c
index 3f3e9d8..83f77d2 100644
--- a/modules/access/ftp.c
+++ b/modules/access/ftp.c
@@ -45,6 +45,7 @@
#include <vlc_sout.h>
#include <vlc_charset.h>
#include <vlc_interrupt.h>
+#include <vlc_keystore.h>
#ifndef IPPORT_FTP
# define IPPORT_FTP 21u
@@ -74,6 +75,10 @@ static void OutClose( vlc_object_t * );
#define ACCOUNT_LONGTEXT N_("Account that will be " \
"used for the connection.")
+#define LOGIN_DIALOG_TITLE _("FTP authentication")
+#define LOGIN_DIALOG_TEXT _("Please enter a valid login and password for " \
+ "the ftp connexion to %s")
+
vlc_module_begin ()
set_shortname( "FTP" )
set_description( N_("FTP input") )
@@ -115,7 +120,7 @@ static ssize_t Write( sout_access_out_t *, block_t * );
#endif
static int LoginUserPwd( vlc_object_t *, access_sys_t *,
- const char *, const char * );
+ const char *, const char *, bool * );
static void FeaturesCheck( void *, const char * );
typedef struct ftp_features_t
@@ -405,39 +410,35 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
}
}
- char *psz_user, *psz_pwd;
- if( p_sys->url.psz_username && *p_sys->url.psz_username )
- psz_user = strdup( p_sys->url.psz_username );
- else
- psz_user = var_InheritString( p_access, "ftp-user" );
- if( !psz_user )
- goto error;
-
- if( p_sys->url.psz_password && *p_sys->url.psz_password )
- psz_pwd = strdup( p_sys->url.psz_password );
- else
- psz_pwd = var_InheritString( p_access, "ftp-pwd" );
- if( !psz_pwd )
- {
- free( psz_user );
- goto error;
- }
-
- if( LoginUserPwd( p_access, p_sys, psz_user, psz_pwd ) == 0 )
+ vlc_url_t url;
+ vlc_credential credential;
+ vlc_UrlParse( &url, ((access_t *)p_access)->psz_url );
+ vlc_credential_init( &credential, &url );
+ bool b_logged = false;
+
+ while( vlc_credential_get( &credential, p_access, "ftp-user", "ftp-pwd",
+ LOGIN_DIALOG_TITLE, LOGIN_DIALOG_TEXT,
+ url.psz_host )
+ && LoginUserPwd( p_access, p_sys, credential.psz_username,
+ credential.psz_password, &b_logged ) == 0
+ && !b_logged );
+ if( b_logged )
{
- free( psz_user );
- free( psz_pwd );
+ vlc_credential_store( &credential );
+ vlc_credential_clean( &credential );
+ vlc_UrlClean( &url );
return 0;
}
- free( psz_user );
- free( psz_pwd );
+ vlc_credential_clean( &credential );
+ vlc_UrlClean( &url );
error:
clearCmdTLS( p_sys );
return -1;
}
static int LoginUserPwd( vlc_object_t *p_access, access_sys_t *p_sys,
- const char *psz_user, const char *psz_pwd)
+ const char *psz_user, const char *psz_pwd,
+ bool *p_logged )
{
int i_answer;
@@ -494,19 +495,18 @@ static int LoginUserPwd( vlc_object_t *p_access, access_sys_t *p_sys,
}
default:
- msg_Err( p_access, "password rejected" );
- dialog_Fatal( p_access, _("Network interaction failed"),
- "%s", _("Your password was rejected.") );
- return -1;
+ msg_Warn( p_access, "password rejected" );
+ *p_logged = false;
+ return 0;
}
break;
default:
- msg_Err( p_access, "user rejected" );
- dialog_Fatal( p_access, _("Network interaction failed"), "%s",
- _("Your connection attempt to the server was rejected.") );
- return -1;
+ msg_Warn( p_access, "user rejected" );
+ *p_logged = false;
+ return 0;
}
+ *p_logged = true;
return 0;
}
More information about the vlc-commits
mailing list