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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-05-04 18:01:45 +04:00
|
|
|
*
|
|
|
|
* 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"
|
2017-09-12 12:21:53 +03:00
|
|
|
#include "clientsideencryption.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.
|
2015-10-05 06:20:09 +03:00
|
|
|
* There are two entry points: checkServerAndAuth and checkAuthentication
|
|
|
|
* checkAuthentication is the quick version that only does the propfind
|
2016-09-16 16:49:43 +03:00
|
|
|
* while checkServerAndAuth is doing the 4 calls.
|
2015-02-05 17:18:38 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
2015-09-05 16:37:20 +03:00
|
|
|
+-> slotStatusFound --+--> X (if credentials are still missing)
|
|
|
|
|
|
|
|
|
+---------------------------+
|
2015-02-05 17:18:38 +03:00
|
|
|
|
|
|
|
|
*-+-> checkAuthentication (PROPFIND on root)
|
|
|
|
PropfindJob
|
|
|
|
|
|
|
|
|
+-> slotAuthFailed --> X
|
|
|
|
|
|
2015-10-05 06:20:09 +03:00
|
|
|
+-> slotAuthSuccess --+--> X (depending if coming from checkServerAndAuth or not)
|
2015-02-05 17:18:38 +03:00
|
|
|
|
|
|
|
|
+---------------------------+
|
|
|
|
|
|
2017-11-10 11:57:42 +03:00
|
|
|
+-> checkServerCapabilities --------------v (in parallel)
|
2021-07-15 10:53:31 +03:00
|
|
|
JsonApiJob (cloud/capabilities)
|
2016-09-16 16:49:43 +03:00
|
|
|
+-> slotCapabilitiesRecieved -+
|
|
|
|
|
|
2017-09-11 17:52:57 +03:00
|
|
|
+---------------------------------+
|
|
|
|
|
|
|
|
|
fetchUser
|
2020-02-14 04:10:01 +03:00
|
|
|
Utilizes the UserInfo class to fetch the user and avatar image
|
2017-09-12 12:21:53 +03:00
|
|
|
+-----------------------------------+
|
|
|
|
|
|
|
|
|
+-> Client Side Encryption Checks --+ --reportResult()
|
2015-06-26 18:07:47 +03:00
|
|
|
\endcode
|
2015-02-05 17:18:38 +03:00
|
|
|
*/
|
2017-09-12 12:21:53 +03:00
|
|
|
|
2020-02-14 04:10:01 +03:00
|
|
|
class UserInfo;
|
|
|
|
|
2018-02-21 17:03:55 +03:00
|
|
|
class ConnectionValidator : public QObject
|
2013-05-04 18:01:45 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-02-14 04:10:01 +03:00
|
|
|
explicit ConnectionValidator(AccountStatePtr accountState, QObject *parent = nullptr);
|
2013-05-04 18:01:45 +04:00
|
|
|
|
|
|
|
enum Status {
|
|
|
|
Undefined,
|
|
|
|
Connected,
|
|
|
|
NotConfigured,
|
2017-05-08 13:39:08 +03:00
|
|
|
ServerVersionMismatch, // The server version is too old
|
2017-04-27 14:58:26 +03:00
|
|
|
CredentialsNotReady, // Credentials aren't ready
|
|
|
|
CredentialsWrong, // AuthenticationRequiredError
|
|
|
|
SslError, // SSL handshake error, certificate rejected by user?
|
2017-05-08 13:39:08 +03:00
|
|
|
StatusNotFound, // Error retrieving status.php
|
|
|
|
ServiceUnavailable, // 503 on authed request
|
|
|
|
MaintenanceMode, // maintenance enabled in status.php
|
|
|
|
Timeout // actually also used for other errors on the authed request
|
2013-05-04 18:01:45 +04:00
|
|
|
};
|
2018-02-21 17:12:21 +03:00
|
|
|
Q_ENUM(Status);
|
2013-05-04 18:01:45 +04:00
|
|
|
|
2015-11-23 23:47:30 +03:00
|
|
|
// How often should the Application ask this object to check for the connection?
|
2019-09-06 15:33:37 +03:00
|
|
|
enum { DefaultCallingIntervalMsec = 62 * 1000 };
|
2015-11-23 23:47:30 +03: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:
|
2022-10-24 17:00:50 +03:00
|
|
|
void connectionResult(OCC::ConnectionValidator::Status status, const QStringList &errors);
|
2013-05-04 18:01:45 +04:00
|
|
|
|
|
|
|
protected slots:
|
2015-03-24 23:30:42 +03:00
|
|
|
void slotCheckServerAndAuth();
|
|
|
|
|
2017-04-26 13:15:33 +03:00
|
|
|
void slotStatusFound(const QUrl &url, const QJsonObject &info);
|
2013-10-28 23:01:59 +04:00
|
|
|
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
|
|
|
|
2017-04-26 13:15:33 +03:00
|
|
|
void slotCapabilitiesRecieved(const QJsonDocument &);
|
2022-10-24 17:00:50 +03:00
|
|
|
void slotUserFetched(OCC::UserInfo *userInfo);
|
2015-02-05 17:18:38 +03:00
|
|
|
|
2013-05-04 18:01:45 +04:00
|
|
|
private:
|
2020-02-14 04:10:01 +03:00
|
|
|
#ifndef TOKEN_AUTH_ONLY
|
2017-09-11 17:52:57 +03:00
|
|
|
void reportConnected();
|
2020-02-14 04:10:01 +03:00
|
|
|
#endif
|
2014-12-11 15:55:59 +03:00
|
|
|
void reportResult(Status status);
|
2015-02-05 17:18:38 +03:00
|
|
|
void checkServerCapabilities();
|
2016-09-16 16:49:43 +03:00
|
|
|
void fetchUser();
|
2014-12-11 15:55:59 +03:00
|
|
|
|
2017-04-19 12:02:03 +03:00
|
|
|
/** Sets the account's server version
|
|
|
|
*
|
|
|
|
* Returns false and reports ServerVersionMismatch for very old servers.
|
|
|
|
*/
|
|
|
|
bool setAndCheckServerVersion(const QString &version);
|
|
|
|
|
2013-05-04 18:01:45 +04:00
|
|
|
QStringList _errors;
|
2020-02-14 04:10:01 +03:00
|
|
|
AccountStatePtr _accountState;
|
2014-12-18 14:09:48 +03:00
|
|
|
AccountPtr _account;
|
2015-02-05 17:18:38 +03:00
|
|
|
bool _isCheckingServerAndAuth;
|
2013-05-04 18:01:45 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CONNECTIONVALIDATOR_H
|