nextcloud-desktop/src/gui/connectionvalidator.h

153 lines
4.7 KiB
C
Raw Normal View History

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; 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
#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>
#include "accountfwd.h"
#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
/**
* This is a job-like class to check that the server is up and that we are connected.
* There are two entry points: checkServerAndAuth and checkAuthentication
* checkAuthentication is the quick version that only does the propfind
* while checkServerAndAuth is doing the 4 calls.
*
* We cannot use the capabilities call to test the login and the password because of
* https://github.com/owncloud/core/issues/12930
*
* Here follows the state machine
\code{.unparsed}
*---> checkServerAndAuth (check status.php)
Will asynchronously check for system proxy (if using system proxy)
And then invoke slotCheckServerAndAuth
CheckServerJob
|
+-> slotNoStatusFound --> X
|
+-> slotJobTimeout --> X
|
+-> slotStatusFound --+--> X (if credentials are still missing)
|
+---------------------------+
|
*-+-> checkAuthentication (PROPFIND on root)
PropfindJob
|
+-> slotAuthFailed --> X
|
+-> slotAuthSuccess --+--> X (depending if coming from checkServerAndAuth or not)
|
+---------------------------+
|
+-> checkServerCapabilities --------------v (in parallel)
JsonApiJob (cloud/capabilities)
+-> slotCapabilitiesRecieved -+
|
+---------------------------------+
|
fetchUser
Utilizes the UserInfo class to fetch the user and avatar image
+-----------------------------------+
|
+-> Client Side Encryption Checks --+ --reportResult()
\endcode
*/
class UserInfo;
class ConnectionValidator : public QObject
2013-05-04 18:01:45 +04:00
{
Q_OBJECT
public:
explicit ConnectionValidator(AccountStatePtr accountState, QObject *parent = nullptr);
2013-05-04 18:01:45 +04:00
enum Status {
Undefined,
Connected,
NotConfigured,
ServerVersionMismatch, // The server version is too old
CredentialsNotReady, // Credentials aren't ready
CredentialsWrong, // AuthenticationRequiredError
SslError, // SSL handshake error, certificate rejected by user?
StatusNotFound, // Error retrieving status.php
StatusRedirect, // 204 URL received one of redirect HTTP codes (301-307), possibly a captive portal
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
};
Q_ENUM(Status);
2013-05-04 18:01:45 +04:00
// How often should the Application ask this object to check for the connection?
enum { DefaultCallingIntervalMsec = 62 * 1000 };
public slots:
/// Checks the server and the authentication.
void checkServerAndAuth();
void systemProxyLookupDone(const QNetworkProxy &proxy);
/// Checks authentication only.
void checkAuthentication();
2013-05-04 18:01:45 +04:00
signals:
void connectionResult(OCC::ConnectionValidator::Status status, const QStringList &errors);
2013-05-04 18:01:45 +04:00
protected slots:
void slotCheckRedirectCostFreeUrl();
void slotCheckServerAndAuth();
void slotCheckRedirectCostFreeUrlFinished(int statusCode);
2017-05-17 11:55:42 +03:00
void slotStatusFound(const QUrl &url, const QJsonObject &info);
void slotNoStatusFound(QNetworkReply *reply);
2017-05-17 11:55:42 +03:00
void slotJobTimeout(const QUrl &url);
2013-05-04 18:01:45 +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-05-17 11:55:42 +03:00
void slotCapabilitiesRecieved(const QJsonDocument &);
void slotUserFetched(OCC::UserInfo *userInfo);
2013-05-04 18:01:45 +04:00
private:
#ifndef TOKEN_AUTH_ONLY
void reportConnected();
#endif
void reportResult(Status status);
void checkServerCapabilities();
void fetchUser();
/** Sets the account's server version
*
* Returns false and reports ServerVersionMismatch for very old servers.
*/
2017-05-17 11:55:42 +03:00
bool setAndCheckServerVersion(const QString &version);
2013-05-04 18:01:45 +04:00
QStringList _errors;
AccountStatePtr _accountState;
2017-05-17 11:55:42 +03:00
AccountPtr _account;
bool _isCheckingServerAndAuth = false;
2013-05-04 18:01:45 +04:00
};
}
#endif // CONNECTIONVALIDATOR_H