2013-05-04 18:01:45 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONNECTIONVALIDATOR_H
|
|
|
|
#define CONNECTIONVALIDATOR_H
|
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
#include "owncloudlib.h"
|
2013-05-04 18:01:45 +04:00
|
|
|
#include <QObject>
|
|
|
|
#include <QStringList>
|
2013-10-23 16:48:44 +04:00
|
|
|
#include <QVariantMap>
|
|
|
|
#include <QNetworkReply>
|
2014-12-18 14:09:48 +03:00
|
|
|
#include "accountfwd.h"
|
2015-09-01 16:37:58 +03:00
|
|
|
#include "creds/abstractcredentials.h"
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
2015-02-05 17:18:38 +03:00
|
|
|
* This is a job-like class to check that the server is up and that we are connected.
|
|
|
|
* There is two entry point: checkServerAndAuth and checkAuthentication
|
|
|
|
* checkAutentication is the quick version that only do the propfind
|
|
|
|
* while checkServerAndAuth is doing the 3 calls.
|
|
|
|
*
|
|
|
|
* We cannot use the capabilites call to test the login and the password because of
|
|
|
|
* https://github.com/owncloud/core/issues/12930
|
|
|
|
*
|
|
|
|
* Here follows the state machine
|
|
|
|
|
2015-06-26 18:07:47 +03:00
|
|
|
\code{.unparsed}
|
2015-02-05 17:18:38 +03:00
|
|
|
*---> checkServerAndAuth (check status.php)
|
2015-03-24 23:30:42 +03:00
|
|
|
Will asynchronously check for system proxy (if using system proxy)
|
|
|
|
And then invoke slotCheckServerAndAuth
|
2015-02-05 17:18:38 +03:00
|
|
|
CheckServerJob
|
|
|
|
|
|
|
|
|
+-> slotNoStatusFound --> X
|
|
|
|
|
|
|
|
|
+-> slotJobTimeout --> X
|
|
|
|
|
|
|
|
|
+-> slotStatusFound
|
|
|
|
credential->fetch() --+
|
|
|
|
|
|
|
|
|
+-----------------------------------+
|
|
|
|
|
|
|
|
|
*-+-> checkAuthentication (PROPFIND on root)
|
|
|
|
PropfindJob
|
|
|
|
|
|
|
|
|
+-> slotAuthFailed --> X
|
|
|
|
|
|
|
|
|
+-> slotAuthSuccess --+--> X (depending if comming from checkServerAndAuth or not)
|
|
|
|
|
|
|
|
|
+---------------------------+
|
|
|
|
|
|
|
|
|
+-> checkServerCapabilities (cloud/capabilities)
|
|
|
|
JsonApiJob
|
|
|
|
|
|
|
|
|
+-> slotCapabilitiesRecieved --> X
|
2015-06-26 18:07:47 +03:00
|
|
|
\endcode
|
2015-02-05 17:18:38 +03:00
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT ConnectionValidator : public QObject
|
2013-05-04 18:01:45 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-09-01 16:37:58 +03:00
|
|
|
explicit ConnectionValidator(AccountPtr account, AbstractCredentials::FetchMode credentialsFetchMode, QObject *parent = 0);
|
2013-05-04 18:01:45 +04:00
|
|
|
|
|
|
|
enum Status {
|
|
|
|
Undefined,
|
|
|
|
Connected,
|
|
|
|
NotConfigured,
|
|
|
|
ServerVersionMismatch,
|
|
|
|
CredentialsWrong,
|
2014-12-11 17:43:48 +03:00
|
|
|
StatusNotFound,
|
2015-01-21 17:30:25 +03:00
|
|
|
UserCanceledCredentials,
|
2015-04-24 12:32:47 +03:00
|
|
|
ServiceUnavailable,
|
2014-12-11 17:43:48 +03:00
|
|
|
// actually also used for other errors on the authed request
|
|
|
|
Timeout
|
2013-05-04 18:01:45 +04:00
|
|
|
};
|
|
|
|
|
2014-12-11 15:55:59 +03:00
|
|
|
static QString statusString( Status );
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
public slots:
|
|
|
|
/// Checks the server and the authentication.
|
|
|
|
void checkServerAndAuth();
|
2015-03-24 23:30:42 +03:00
|
|
|
void systemProxyLookupDone(const QNetworkProxy &proxy);
|
2014-12-17 16:09:57 +03:00
|
|
|
|
|
|
|
/// Checks authentication only.
|
|
|
|
void checkAuthentication();
|
|
|
|
|
2013-05-04 18:01:45 +04:00
|
|
|
signals:
|
2014-12-11 15:55:59 +03:00
|
|
|
void connectionResult( ConnectionValidator::Status status, QStringList errors );
|
2013-05-04 18:01:45 +04:00
|
|
|
|
|
|
|
protected slots:
|
2015-03-24 23:30:42 +03:00
|
|
|
void slotCheckServerAndAuth();
|
|
|
|
|
2013-10-28 23:01:59 +04:00
|
|
|
void slotStatusFound(const QUrl&url, const QVariantMap &info);
|
|
|
|
void slotNoStatusFound(QNetworkReply *reply);
|
2014-12-11 15:55:59 +03:00
|
|
|
void slotJobTimeout(const QUrl& url);
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2013-10-28 23:01:59 +04:00
|
|
|
void slotAuthFailed(QNetworkReply *reply);
|
2013-10-23 16:48:44 +04:00
|
|
|
void slotAuthSuccess();
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2015-02-05 17:18:38 +03:00
|
|
|
void slotCapabilitiesRecieved(const QVariantMap&);
|
|
|
|
|
2013-05-04 18:01:45 +04:00
|
|
|
private:
|
2014-12-11 15:55:59 +03:00
|
|
|
void reportResult(Status status);
|
2015-02-05 17:18:38 +03:00
|
|
|
void checkServerCapabilities();
|
2014-12-11 15:55:59 +03:00
|
|
|
|
2013-05-04 18:01:45 +04:00
|
|
|
QStringList _errors;
|
2014-12-18 14:09:48 +03:00
|
|
|
AccountPtr _account;
|
2015-09-01 16:37:58 +03:00
|
|
|
AbstractCredentials::FetchMode _credentialsFetchMode;
|
2015-02-05 17:18:38 +03:00
|
|
|
bool _isCheckingServerAndAuth;
|
2013-05-04 18:01:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CONNECTIONVALIDATOR_H
|