2013-10-21 23:42:52 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@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 SERVERCONNECTION_H
|
|
|
|
#define SERVERCONNECTION_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QNetworkCookie>
|
2013-10-23 16:48:44 +04:00
|
|
|
#include <QNetworkRequest>
|
2014-11-18 18:44:14 +03:00
|
|
|
#include <QSslSocket>
|
2013-10-23 16:48:44 +04:00
|
|
|
#include <QSslCertificate>
|
2014-01-21 04:45:02 +04:00
|
|
|
#include <QSslConfiguration>
|
2015-08-11 13:18:25 +03:00
|
|
|
#include <QSslCipher>
|
2013-10-24 02:29:08 +04:00
|
|
|
#include <QSslError>
|
2014-12-18 14:09:48 +03:00
|
|
|
#include <QSharedPointer>
|
2014-04-25 01:45:20 +04:00
|
|
|
#include "utility.h"
|
2015-06-15 16:04:39 +03:00
|
|
|
#include <memory>
|
2015-07-16 22:49:12 +03:00
|
|
|
#include "capabilities.h"
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
class QSettings;
|
|
|
|
class QNetworkReply;
|
|
|
|
class QUrl;
|
2013-10-23 16:48:44 +04:00
|
|
|
class QNetworkAccessManager;
|
2013-10-21 23:42:52 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
class AbstractCredentials;
|
|
|
|
class Account;
|
2014-12-18 14:09:48 +03:00
|
|
|
typedef QSharedPointer<Account> AccountPtr;
|
2014-02-20 20:00:45 +04:00
|
|
|
class QuotaInfo;
|
2014-11-10 00:30:29 +03:00
|
|
|
class AccessManager;
|
2013-10-21 23:42:52 +04:00
|
|
|
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief Reimplement this to handle SSL errors from libsync
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2013-10-24 02:29:08 +04:00
|
|
|
class AbstractSslErrorHandler {
|
|
|
|
public:
|
2013-10-24 14:55:26 +04:00
|
|
|
virtual ~AbstractSslErrorHandler() {}
|
2015-04-06 22:46:03 +03:00
|
|
|
virtual bool handleErrors(QList<QSslError>, const QSslConfiguration &conf, QList<QSslCertificate>*, AccountPtr) = 0;
|
2013-10-24 02:29:08 +04:00
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The Account class represents an account on an ownCloud Server
|
|
|
|
* @ingroup libsync
|
2013-10-21 23:42:52 +04:00
|
|
|
*/
|
2014-04-25 01:45:20 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT Account : public QObject {
|
2013-10-24 02:29:08 +04:00
|
|
|
Q_OBJECT
|
2013-10-21 23:42:52 +04:00
|
|
|
public:
|
2014-03-21 20:14:04 +04:00
|
|
|
QString davPath() const { return _davPath; }
|
|
|
|
void setDavPath(const QString&s) { _davPath = s; }
|
2013-10-28 23:01:59 +04:00
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
static AccountPtr create();
|
2013-11-04 19:36:23 +04:00
|
|
|
~Account();
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
void setSharedThis(AccountPtr sharedThis);
|
|
|
|
AccountPtr sharedFromThis();
|
|
|
|
|
2015-04-23 15:51:06 +03:00
|
|
|
/// The name of the account as shown in the toolbar
|
|
|
|
QString displayName() const;
|
|
|
|
|
2015-04-23 15:57:36 +03:00
|
|
|
/// The internal id of the account.
|
|
|
|
QString id() const;
|
|
|
|
|
2013-10-30 19:31:47 +04:00
|
|
|
/**
|
2015-06-29 19:56:09 +03:00
|
|
|
* @brief Checks the Account instance is different from @param other
|
2013-10-30 19:31:47 +04:00
|
|
|
*
|
|
|
|
* @returns true, if credentials or url have changed, false otherwise
|
|
|
|
*/
|
2014-12-18 14:09:48 +03:00
|
|
|
bool changed(AccountPtr other, bool ignoreUrlProtocol) const;
|
2013-10-30 19:31:47 +04:00
|
|
|
|
2013-10-21 23:42:52 +04:00
|
|
|
/** Holds the accounts credentials */
|
|
|
|
AbstractCredentials* credentials() const;
|
|
|
|
void setCredentials(AbstractCredentials *cred);
|
|
|
|
|
|
|
|
/** Server url of the account */
|
|
|
|
void setUrl(const QUrl &url);
|
2013-10-23 16:48:44 +04:00
|
|
|
QUrl url() const { return _url; }
|
|
|
|
|
2013-10-21 23:42:52 +04:00
|
|
|
/** Returns webdav entry URL, based on url() */
|
|
|
|
QUrl davUrl() const;
|
|
|
|
|
2014-06-12 18:51:47 +04:00
|
|
|
/** set and retrieve the migration flag: if an account of a branded
|
|
|
|
* client was migrated from a former ownCloud Account, this is true
|
|
|
|
*/
|
|
|
|
void setMigrated(bool mig);
|
|
|
|
bool wasMigrated();
|
|
|
|
|
2013-10-21 23:42:52 +04:00
|
|
|
QList<QNetworkCookie> lastAuthCookies() const;
|
|
|
|
|
2013-10-28 23:01:59 +04:00
|
|
|
QNetworkReply* headRequest(const QString &relPath);
|
|
|
|
QNetworkReply* headRequest(const QUrl &url);
|
2013-10-21 23:42:52 +04:00
|
|
|
QNetworkReply* getRequest(const QString &relPath);
|
2013-10-28 23:01:59 +04:00
|
|
|
QNetworkReply* getRequest(const QUrl &url);
|
2013-10-23 16:48:44 +04:00
|
|
|
QNetworkReply* davRequest(const QByteArray &verb, const QString &relPath, QNetworkRequest req, QIODevice *data = 0);
|
2013-10-28 23:01:59 +04:00
|
|
|
QNetworkReply* davRequest(const QByteArray &verb, const QUrl &url, QNetworkRequest req, QIODevice *data = 0);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
2014-01-21 04:45:02 +04:00
|
|
|
/** The ssl configuration during the first connection */
|
2015-05-08 15:21:27 +03:00
|
|
|
QSslConfiguration getOrCreateSslConfig();
|
2014-01-21 04:45:02 +04:00
|
|
|
QSslConfiguration sslConfiguration() const { return _sslConfiguration; }
|
|
|
|
void setSslConfiguration(const QSslConfiguration &config);
|
2015-08-11 13:18:25 +03:00
|
|
|
// Because of bugs in Qt, we use this to store info needed for the SSL Button
|
|
|
|
QSslCipher _sessionCipher;
|
|
|
|
QByteArray _sessionTicket;
|
|
|
|
QList<QSslCertificate> _peerCertificateChain;
|
|
|
|
|
|
|
|
|
2013-10-23 16:48:44 +04:00
|
|
|
/** The certificates of the account */
|
2013-10-24 02:29:08 +04:00
|
|
|
QList<QSslCertificate> approvedCerts() const { return _approvedCerts; }
|
|
|
|
void setApprovedCerts(const QList<QSslCertificate> certs);
|
2013-11-07 15:04:45 +04:00
|
|
|
void addApprovedCerts(const QList<QSslCertificate> certs);
|
2013-10-21 23:42:52 +04:00
|
|
|
|
2015-05-08 11:17:21 +03:00
|
|
|
// Usually when a user explicitly rejects a certificate we don't
|
|
|
|
// ask again. After this call, a dialog will again be shown when
|
|
|
|
// the next unknown certificate is encountered.
|
|
|
|
void resetSslCertErrorState();
|
|
|
|
|
2013-11-04 19:36:23 +04:00
|
|
|
// pluggable handler
|
2013-10-24 02:29:08 +04:00
|
|
|
void setSslErrorHandler(AbstractSslErrorHandler *handler);
|
2013-10-23 16:48:44 +04:00
|
|
|
|
2013-11-04 19:36:23 +04:00
|
|
|
// static helper function
|
2015-02-13 16:52:40 +03:00
|
|
|
static QUrl concatUrlPath(const QUrl &url, const QString &concatPath,
|
2015-02-17 16:04:16 +03:00
|
|
|
const QList< QPair<QString, QString> > &queryItems = (QList<QPair<QString, QString>>()));
|
2014-03-26 20:08:34 +04:00
|
|
|
|
|
|
|
/** Returns a new settings pre-set in a specific group. The Settings will be created
|
|
|
|
with the given parent. If no parents is specified, the caller must destroy the settings */
|
2015-07-02 14:31:42 +03:00
|
|
|
static std::unique_ptr<QSettings> settingsWithGroup(const QString& group, QObject* parent = 0);
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2013-11-04 19:36:23 +04:00
|
|
|
// to be called by credentials only
|
|
|
|
QVariant credentialSetting(const QString& key) const;
|
|
|
|
void setCredentialSetting(const QString& key, const QVariant &value);
|
|
|
|
|
2015-01-23 22:08:14 +03:00
|
|
|
void setCertificate(const QByteArray certficate = QByteArray(), const QString privateKey = QString());
|
2015-02-12 14:59:00 +03:00
|
|
|
|
2015-02-05 17:18:38 +03:00
|
|
|
void setCapabilities(const QVariantMap &caps);
|
2015-07-29 13:05:00 +03:00
|
|
|
const Capabilities &capabilities() const;
|
2015-02-12 14:59:00 +03:00
|
|
|
void setServerVersion(const QString &version);
|
|
|
|
QString serverVersion();
|
2015-02-05 17:18:38 +03:00
|
|
|
|
2014-03-03 19:36:30 +04:00
|
|
|
void clearCookieJar();
|
2015-06-18 21:41:00 +03:00
|
|
|
void lendCookieJarTo(QNetworkAccessManager *guest);
|
2014-03-03 19:36:30 +04:00
|
|
|
|
2015-03-19 13:40:47 +03:00
|
|
|
void resetNetworkAccessManager();
|
2014-05-14 13:11:45 +04:00
|
|
|
QNetworkAccessManager* networkAccessManager();
|
|
|
|
|
2014-12-17 16:09:57 +03:00
|
|
|
/// Called by network jobs on credential errors.
|
2014-12-11 17:43:48 +03:00
|
|
|
void handleInvalidCredentials();
|
|
|
|
|
2013-11-07 15:22:17 +04:00
|
|
|
signals:
|
2014-09-18 16:00:51 +04:00
|
|
|
void propagatorNetworkActivity();
|
2014-12-17 16:09:57 +03:00
|
|
|
void invalidCredentials();
|
|
|
|
void credentialsFetched(AbstractCredentials* credentials);
|
2013-11-07 15:22:17 +04:00
|
|
|
|
2015-07-16 15:21:51 +03:00
|
|
|
/// Forwards from QNetworkAccessManager::proxyAuthenticationRequired().
|
|
|
|
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
|
|
|
|
|
2015-08-14 12:31:01 +03:00
|
|
|
// e.g. when the approved SSL certificates changed
|
|
|
|
void wantsAccountSaved(AccountPtr acc);
|
|
|
|
|
2013-11-05 21:15:47 +04:00
|
|
|
protected Q_SLOTS:
|
2015-07-16 15:21:51 +03:00
|
|
|
void slotHandleSslErrors(QNetworkReply*,QList<QSslError>);
|
2014-12-11 17:43:48 +03:00
|
|
|
void slotCredentialsFetched();
|
2013-10-24 02:29:08 +04:00
|
|
|
|
2013-10-21 23:42:52 +04:00
|
|
|
private:
|
2014-12-18 14:09:48 +03:00
|
|
|
Account(QObject *parent = 0);
|
|
|
|
|
|
|
|
QWeakPointer<Account> _sharedThis;
|
2015-04-23 15:57:36 +03:00
|
|
|
QString _id;
|
2013-11-04 19:36:23 +04:00
|
|
|
QMap<QString, QVariant> _settingsMap;
|
2013-10-21 23:42:52 +04:00
|
|
|
QUrl _url;
|
2013-10-24 02:29:08 +04:00
|
|
|
QList<QSslCertificate> _approvedCerts;
|
2014-01-21 04:45:02 +04:00
|
|
|
QSslConfiguration _sslConfiguration;
|
2015-07-16 22:49:12 +03:00
|
|
|
Capabilities _capabilities;
|
2015-02-12 14:59:00 +03:00
|
|
|
QString _serverVersion;
|
2013-10-24 14:55:26 +04:00
|
|
|
QScopedPointer<AbstractSslErrorHandler> _sslErrorHandler;
|
2014-11-18 18:44:14 +03:00
|
|
|
QuotaInfo *_quotaInfo;
|
2013-11-07 15:22:17 +04:00
|
|
|
QNetworkAccessManager *_am;
|
|
|
|
AbstractCredentials* _credentials;
|
|
|
|
bool _treatSslErrorsAsFailure;
|
2013-11-14 18:48:46 +04:00
|
|
|
static QString _configFileName;
|
2014-11-18 18:44:14 +03:00
|
|
|
QByteArray _pemCertificate;
|
|
|
|
QString _pemPrivateKey;
|
2015-02-18 19:49:07 +03:00
|
|
|
QString _davPath; // defaults to value from theme, might be overwritten in brandings
|
2014-06-12 18:51:47 +04:00
|
|
|
bool _wasMigrated;
|
2015-04-09 17:19:17 +03:00
|
|
|
friend class AccountManager;
|
2013-10-21 23:42:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
Q_DECLARE_METATYPE(OCC::AccountPtr)
|
2014-02-06 15:56:34 +04:00
|
|
|
|
2013-10-21 23:42:52 +04:00
|
|
|
#endif //SERVERCONNECTION_H
|