зеркало из https://github.com/nextcloud/desktop.git
store the custom config for each reply object.
This commit is contained in:
Родитель
f0bae07a2c
Коммит
d5d0c472ed
|
@ -32,6 +32,7 @@ QNetworkAccessManager* ownCloudInfo::_manager = 0;
|
||||||
SslErrorDialog *ownCloudInfo::_sslErrorDialog = 0;
|
SslErrorDialog *ownCloudInfo::_sslErrorDialog = 0;
|
||||||
bool ownCloudInfo::_certsUntrusted = false;
|
bool ownCloudInfo::_certsUntrusted = false;
|
||||||
int ownCloudInfo::_authAttempts = 0;
|
int ownCloudInfo::_authAttempts = 0;
|
||||||
|
QHash<QNetworkReply*, QString> ownCloudInfo::_configHandleMap;
|
||||||
|
|
||||||
ownCloudInfo::ownCloudInfo( const QString& connectionName, QObject *parent ) :
|
ownCloudInfo::ownCloudInfo( const QString& connectionName, QObject *parent ) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
|
@ -62,6 +63,7 @@ ownCloudInfo::~ownCloudInfo()
|
||||||
void ownCloudInfo::setCustomConfigHandle( const QString& handle )
|
void ownCloudInfo::setCustomConfigHandle( const QString& handle )
|
||||||
{
|
{
|
||||||
_configHandle = handle;
|
_configHandle = handle;
|
||||||
|
_authAttempts = 0; // allow a couple of tries again.
|
||||||
resetSSLUntrust();
|
resetSSLUntrust();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +97,11 @@ void ownCloudInfo::getRequest( const QString& path, bool webdav )
|
||||||
connect( reply, SIGNAL(finished()), SLOT(slotReplyFinished()));
|
connect( reply, SIGNAL(finished()), SLOT(slotReplyFinished()));
|
||||||
_directories[reply] = path;
|
_directories[reply] = path;
|
||||||
|
|
||||||
|
if( !_configHandle.isEmpty() ) {
|
||||||
|
qDebug() << "Setting config handle " << _configHandle;
|
||||||
|
_configHandleMap[reply] = _configHandle;
|
||||||
|
}
|
||||||
|
|
||||||
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
||||||
this, SLOT(slotError( QNetworkReply::NetworkError )));
|
this, SLOT(slotError( QNetworkReply::NetworkError )));
|
||||||
}
|
}
|
||||||
|
@ -166,15 +173,21 @@ void ownCloudInfo::qhttpRequestFinished(int id, bool success )
|
||||||
void ownCloudInfo::mkdirRequest( const QString& dir )
|
void ownCloudInfo::mkdirRequest( const QString& dir )
|
||||||
{
|
{
|
||||||
qDebug() << "OCInfo Making dir " << dir;
|
qDebug() << "OCInfo Making dir " << dir;
|
||||||
|
_authAttempts = 0;
|
||||||
MirallConfigFile cfgFile( _configHandle );
|
MirallConfigFile cfgFile( _configHandle );
|
||||||
QNetworkRequest req;
|
QNetworkRequest req;
|
||||||
req.setUrl( QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ) );
|
req.setUrl( QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ) );
|
||||||
QNetworkReply *reply = davRequest("MKCOL", req, 0);
|
QNetworkReply *reply = davRequest("MKCOL", req, 0);
|
||||||
|
|
||||||
|
// remember the confighandle used for this request
|
||||||
|
if( ! _configHandle.isEmpty() )
|
||||||
|
qDebug() << "Setting config handle " << _configHandle;
|
||||||
|
_configHandleMap[reply] = _configHandle;
|
||||||
|
|
||||||
if( reply->error() != QNetworkReply::NoError ) {
|
if( reply->error() != QNetworkReply::NoError ) {
|
||||||
qDebug() << "mkdir request network error: " << reply->errorString();
|
qDebug() << "mkdir request network error: " << reply->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect( reply, SIGNAL(finished()), SLOT(slotMkdirFinished()) );
|
connect( reply, SIGNAL(finished()), SLOT(slotMkdirFinished()) );
|
||||||
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
||||||
this, SLOT(slotError(QNetworkReply::NetworkError )));
|
this, SLOT(slotError(QNetworkReply::NetworkError )));
|
||||||
|
@ -191,35 +204,53 @@ void ownCloudInfo::slotMkdirFinished()
|
||||||
|
|
||||||
emit webdavColCreated( reply->error() );
|
emit webdavColCreated( reply->error() );
|
||||||
qDebug() << "mkdir slot hit with status: " << reply->error();
|
qDebug() << "mkdir slot hit with status: " << reply->error();
|
||||||
|
if( _configHandleMap.contains( reply ) ) {
|
||||||
|
_configHandleMap.remove( reply );
|
||||||
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth )
|
void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth )
|
||||||
{
|
{
|
||||||
if( auth && reply ) {
|
if( !(auth && reply) ) return;
|
||||||
qDebug() << "Auth request to me and I am " << this;
|
QString configHandle;
|
||||||
_authAttempts++;
|
|
||||||
MirallConfigFile cfgFile( _configHandle );
|
// an empty config handle is ok for the default config.
|
||||||
qDebug() << "Authenticating request for " << reply->url();
|
if( _configHandleMap.contains(reply) ) {
|
||||||
qDebug() << "Our Url: " << cfgFile.ownCloudUrl(_connection, true);
|
configHandle = _configHandleMap[reply];
|
||||||
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) {
|
qDebug() << "Auth: Have a custom config handle: " << configHandle;
|
||||||
auth->setUser( cfgFile.ownCloudUser( _connection ) );
|
|
||||||
auth->setPassword( cfgFile.ownCloudPasswd( _connection ));
|
|
||||||
} else {
|
|
||||||
qDebug() << "WRN: attempt to authenticate to different url!";
|
|
||||||
}
|
|
||||||
if( _authAttempts > 10 ) {
|
|
||||||
qDebug() << "Too many attempts to authenticate. Stop request.";
|
|
||||||
reply->close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "Auth request to me and I am " << this;
|
||||||
|
_authAttempts++;
|
||||||
|
MirallConfigFile cfgFile( configHandle );
|
||||||
|
qDebug() << "Authenticating request for " << reply->url();
|
||||||
|
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) {
|
||||||
|
auth->setUser( cfgFile.ownCloudUser( _connection ) );
|
||||||
|
auth->setPassword( cfgFile.ownCloudPasswd( _connection ));
|
||||||
|
} else {
|
||||||
|
qDebug() << "WRN: attempt to authenticate to different url - attempt " <<_authAttempts;
|
||||||
|
}
|
||||||
|
if( _authAttempts > 10 ) {
|
||||||
|
qDebug() << "Too many attempts to authenticate. Stop request.";
|
||||||
|
reply->close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ownCloudInfo::slotSSLFailed( QNetworkReply *reply, QList<QSslError> errors )
|
void ownCloudInfo::slotSSLFailed( QNetworkReply *reply, QList<QSslError> errors )
|
||||||
{
|
{
|
||||||
qDebug() << "SSL-Warnings happened for url " << reply->url().toString();
|
qDebug() << "SSL-Warnings happened for url " << reply->url().toString();
|
||||||
|
|
||||||
|
QString configHandle;
|
||||||
|
// an empty config handle is ok for the default config.
|
||||||
|
if( _configHandleMap.contains(reply) ) {
|
||||||
|
configHandle = _configHandleMap[reply];
|
||||||
|
qDebug() << "SSL: Have a custom config handle: " << configHandle;
|
||||||
|
}
|
||||||
|
|
||||||
if( _certsUntrusted ) {
|
if( _certsUntrusted ) {
|
||||||
// User decided once to untrust. Honor this decision.
|
// User decided once to untrust. Honor this decision.
|
||||||
return;
|
return;
|
||||||
|
@ -229,6 +260,9 @@ void ownCloudInfo::slotSSLFailed( QNetworkReply *reply, QList<QSslError> errors
|
||||||
_sslErrorDialog = new SslErrorDialog();
|
_sslErrorDialog = new SslErrorDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make the ssl dialog aware of the custom config. It loads known certs.
|
||||||
|
_sslErrorDialog->setCustomConfigHandle( configHandle );
|
||||||
|
|
||||||
if( _sslErrorDialog->setErrorList( errors ) ) {
|
if( _sslErrorDialog->setErrorList( errors ) ) {
|
||||||
// all ssl certs are known and accepted. We can ignore the problems right away.
|
// all ssl certs are known and accepted. We can ignore the problems right away.
|
||||||
qDebug() << "Certs are already known and trusted, Warnings are not valid.";
|
qDebug() << "Certs are already known and trusted, Warnings are not valid.";
|
||||||
|
@ -322,6 +356,9 @@ void ownCloudInfo::slotReplyFinished()
|
||||||
|
|
||||||
emit ownCloudDirExists( dir, reply );
|
emit ownCloudDirExists( dir, reply );
|
||||||
}
|
}
|
||||||
|
if( _configHandleMap.contains(reply)) {
|
||||||
|
_configHandleMap.remove(reply);
|
||||||
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ private:
|
||||||
QString _connection;
|
QString _connection;
|
||||||
QString _configHandle;
|
QString _configHandle;
|
||||||
QHash<QNetworkReply*, QString> _directories;
|
QHash<QNetworkReply*, QString> _directories;
|
||||||
|
static QHash<QNetworkReply*, QString> _configHandleMap;
|
||||||
static SslErrorDialog *_sslErrorDialog;
|
static SslErrorDialog *_sslErrorDialog;
|
||||||
static bool _certsUntrusted;
|
static bool _certsUntrusted;
|
||||||
static int _authAttempts;
|
static int _authAttempts;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче