2013-12-13 23:27:08 +04:00
|
|
|
/*
|
2013-10-18 14:24:29 +04:00
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
* 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; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 NETWORKJOBS_H
|
|
|
|
#define NETWORKJOBS_H
|
|
|
|
|
2015-06-17 18:29:11 +03:00
|
|
|
#include "abstractnetworkjob.h"
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2018-11-15 10:32:17 +03:00
|
|
|
#include "common/result.h"
|
2018-10-15 17:51:24 +03:00
|
|
|
|
2017-09-13 18:01:02 +03:00
|
|
|
#include <QBuffer>
|
2017-12-08 12:10:28 +03:00
|
|
|
#include <QUrlQuery>
|
2021-09-09 12:18:22 +03:00
|
|
|
#include <QJsonDocument>
|
2017-11-07 18:12:07 +03:00
|
|
|
#include <functional>
|
2017-09-13 18:01:02 +03:00
|
|
|
|
2013-10-18 14:24:29 +04:00
|
|
|
class QUrl;
|
2017-04-26 13:15:33 +03:00
|
|
|
class QJsonObject;
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2019-06-21 16:29:42 +03:00
|
|
|
/** Strips quotes and gzip annotations */
|
2019-06-28 18:26:54 +03:00
|
|
|
OWNCLOUDSYNC_EXPORT QByteArray parseEtag(const char *header);
|
2019-06-21 16:29:42 +03:00
|
|
|
|
2018-11-15 10:32:17 +03:00
|
|
|
struct HttpError
|
|
|
|
{
|
|
|
|
int code; // HTTP error code
|
|
|
|
QString message;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using HttpResult = Result<T, HttpError>;
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The EntityExistsJob class
|
|
|
|
* @ingroup libsync
|
2013-10-28 23:01:59 +04:00
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT EntityExistsJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-28 23:01:59 +04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit EntityExistsJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2013-11-14 22:20:09 +04:00
|
|
|
|
2013-10-28 23:01:59 +04:00
|
|
|
signals:
|
|
|
|
void exists(QNetworkReply *);
|
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2013-10-28 23:01:59 +04:00
|
|
|
};
|
|
|
|
|
2017-08-25 15:59:13 +03:00
|
|
|
/**
|
|
|
|
* @brief sends a DELETE http request to a url.
|
|
|
|
*
|
|
|
|
* See Nextcloud API usage for the possible DELETE requests.
|
|
|
|
*
|
|
|
|
* This does *not* delete files, it does a http request.
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT DeleteApiJob : public AbstractNetworkJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit DeleteApiJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2017-08-25 15:59:13 +03:00
|
|
|
void start() override;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void result(int httpCode);
|
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2017-08-25 15:59:13 +03:00
|
|
|
};
|
|
|
|
|
2017-08-25 14:56:13 +03:00
|
|
|
struct ExtraFolderInfo {
|
|
|
|
QByteArray fileId;
|
|
|
|
qint64 size = -1;
|
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The LsColJob class
|
|
|
|
* @ingroup libsync
|
2013-10-18 14:24:29 +04:00
|
|
|
*/
|
2015-04-14 14:41:51 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT LsColXMLParser : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit LsColXMLParser();
|
|
|
|
|
2017-08-25 14:56:13 +03:00
|
|
|
bool parse(const QByteArray &xml,
|
|
|
|
QHash<QString, ExtraFolderInfo> *sizes,
|
|
|
|
const QString &expectedPath);
|
2015-04-14 14:41:51 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void directoryListingSubfolders(const QStringList &items);
|
|
|
|
void directoryListingIterated(const QString &name, const QMap<QString, QString> &properties);
|
|
|
|
void finishedWithError(QNetworkReply *reply);
|
|
|
|
void finishedWithoutError();
|
|
|
|
};
|
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT LsColJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-18 14:24:29 +04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit LsColJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
|
|
|
explicit LsColJob(AccountPtr account, const QUrl &url, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2017-08-25 14:56:13 +03:00
|
|
|
QHash<QString, ExtraFolderInfo> _folderInfos;
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2015-03-02 13:00:37 +03:00
|
|
|
/**
|
|
|
|
* Used to specify which properties shall be retrieved.
|
|
|
|
*
|
|
|
|
* The properties can
|
|
|
|
* - contain no colon: they refer to a property in the DAV: namespace
|
|
|
|
* - contain a colon: and thus specify an explicit namespace,
|
|
|
|
* e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
|
|
|
|
*/
|
|
|
|
void setProperties(QList<QByteArray> properties);
|
|
|
|
QList<QByteArray> properties() const;
|
|
|
|
|
2013-10-18 14:24:29 +04:00
|
|
|
signals:
|
2014-12-02 14:25:51 +03:00
|
|
|
void directoryListingSubfolders(const QStringList &items);
|
2015-03-02 13:00:37 +03:00
|
|
|
void directoryListingIterated(const QString &name, const QMap<QString, QString> &properties);
|
2014-12-02 14:25:51 +03:00
|
|
|
void finishedWithError(QNetworkReply *reply);
|
|
|
|
void finishedWithoutError();
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2015-03-02 13:00:37 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
QList<QByteArray> _properties;
|
2016-08-02 18:14:44 +03:00
|
|
|
QUrl _url; // Used instead of path() if the url is specified in the constructor
|
2013-10-18 14:24:29 +04:00
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The PropfindJob class
|
2015-02-26 14:36:11 +03:00
|
|
|
*
|
|
|
|
* Setting the desired properties with setProperties() is mandatory.
|
2015-03-02 13:00:37 +03:00
|
|
|
*
|
|
|
|
* Note that this job is only for querying one item.
|
|
|
|
* There is also the LsColJob which can be used to list collections
|
2015-06-26 18:07:47 +03:00
|
|
|
*
|
2015-06-29 19:56:09 +03:00
|
|
|
* @ingroup libsync
|
2013-10-23 16:48:44 +04:00
|
|
|
*/
|
2015-03-04 15:50:55 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT PropfindJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-23 16:48:44 +04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit PropfindJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2015-02-26 14:36:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to specify which properties shall be retrieved.
|
|
|
|
*
|
|
|
|
* The properties can
|
|
|
|
* - contain no colon: they refer to a property in the DAV: namespace
|
|
|
|
* - contain a colon: and thus specify an explicit namespace,
|
|
|
|
* e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
|
|
|
|
*/
|
2013-11-14 22:20:09 +04:00
|
|
|
void setProperties(QList<QByteArray> properties);
|
|
|
|
QList<QByteArray> properties() const;
|
2013-10-23 16:48:44 +04:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void result(const QVariantMap &values);
|
2018-11-12 20:46:39 +03:00
|
|
|
void finishedWithError(QNetworkReply *reply = nullptr);
|
2013-10-23 16:48:44 +04:00
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2013-11-14 22:20:09 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
QList<QByteArray> _properties;
|
2013-10-23 16:48:44 +04:00
|
|
|
};
|
|
|
|
|
2017-11-23 12:11:39 +03:00
|
|
|
#ifndef TOKEN_AUTH_ONLY
|
2017-01-22 15:52:19 +03:00
|
|
|
/**
|
2017-11-21 12:18:15 +03:00
|
|
|
* @brief Retrieves the account users avatar from the server using a GET request.
|
2017-01-22 15:52:19 +03:00
|
|
|
*
|
|
|
|
* If the server does not have the avatar, the result Pixmap is empty.
|
|
|
|
*
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT AvatarJob : public AbstractNetworkJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-11-21 12:18:15 +03:00
|
|
|
/**
|
|
|
|
* @param userId The user for which to obtain the avatar
|
|
|
|
* @param size The size of the avatar (square so size*size)
|
|
|
|
*/
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit AvatarJob(AccountPtr account, const QString &userId, int size, QObject *parent = nullptr);
|
2017-11-21 12:18:15 +03:00
|
|
|
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2017-01-22 15:52:19 +03:00
|
|
|
|
2017-11-21 12:18:15 +03:00
|
|
|
/** The retrieved avatar images don't have the circle shape by default */
|
|
|
|
static QImage makeCircularAvatar(const QImage &baseAvatar);
|
|
|
|
|
2017-01-22 15:52:19 +03:00
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* @brief avatarPixmap - returns either a valid pixmap or not.
|
|
|
|
*/
|
|
|
|
|
2017-11-23 12:11:39 +03:00
|
|
|
void avatarPixmap(const QImage &);
|
2017-01-22 15:52:19 +03:00
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2017-01-22 15:52:19 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
QUrl _avatarUrl;
|
|
|
|
};
|
2017-11-23 12:11:39 +03:00
|
|
|
#endif
|
2017-01-22 15:52:19 +03:00
|
|
|
|
2015-11-12 13:20:45 +03:00
|
|
|
/**
|
|
|
|
* @brief Send a Proppatch request
|
|
|
|
*
|
|
|
|
* Setting the desired properties with setProperties() is mandatory.
|
|
|
|
*
|
|
|
|
* WARNING: Untested!
|
|
|
|
*
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT ProppatchJob : public AbstractNetworkJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit ProppatchJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2015-11-12 13:20:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to specify which properties shall be set.
|
|
|
|
*
|
|
|
|
* The property keys can
|
|
|
|
* - contain no colon: they refer to a property in the DAV: namespace
|
|
|
|
* - contain a colon: and thus specify an explicit namespace,
|
|
|
|
* e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
|
|
|
|
*/
|
|
|
|
void setProperties(QMap<QByteArray, QByteArray> properties);
|
|
|
|
QMap<QByteArray, QByteArray> properties() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void success();
|
|
|
|
void finishedWithError();
|
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2015-11-12 13:20:45 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
QMap<QByteArray, QByteArray> _properties;
|
|
|
|
};
|
|
|
|
|
2013-10-23 16:48:44 +04:00
|
|
|
/**
|
2015-06-29 19:56:09 +03:00
|
|
|
* @brief The MkColJob class
|
|
|
|
* @ingroup libsync
|
2013-10-23 16:48:44 +04:00
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT MkColJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-18 14:24:29 +04:00
|
|
|
Q_OBJECT
|
2016-08-02 14:48:56 +03:00
|
|
|
QUrl _url; // Only used if the constructor taking a url is taken.
|
2016-09-16 17:36:46 +03:00
|
|
|
QMap<QByteArray, QByteArray> _extraHeaders;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2013-10-18 14:24:29 +04:00
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit MkColJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2020-07-08 16:14:18 +03:00
|
|
|
explicit MkColJob(AccountPtr account, const QString &path, const QMap<QByteArray, QByteArray> &extraHeaders, QObject *parent = nullptr);
|
2016-09-16 17:36:46 +03:00
|
|
|
explicit MkColJob(AccountPtr account, const QUrl &url,
|
2018-11-12 20:46:39 +03:00
|
|
|
const QMap<QByteArray, QByteArray> &extraHeaders, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
signals:
|
2021-02-17 16:30:26 +03:00
|
|
|
void finishedWithError(QNetworkReply *reply);
|
|
|
|
void finishedWithoutError();
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2021-02-17 16:30:26 +03:00
|
|
|
private:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2013-10-18 14:24:29 +04:00
|
|
|
};
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The CheckServerJob class
|
|
|
|
* @ingroup libsync
|
2013-10-18 14:24:29 +04:00
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT CheckServerJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-18 14:24:29 +04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit CheckServerJob(AccountPtr account, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2013-10-23 16:48:44 +04:00
|
|
|
|
2017-04-26 13:15:33 +03:00
|
|
|
static QString version(const QJsonObject &info);
|
|
|
|
static QString versionString(const QJsonObject &info);
|
|
|
|
static bool installed(const QJsonObject &info);
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
signals:
|
2017-09-08 12:59:45 +03:00
|
|
|
/** Emitted when a status.php was successfully read.
|
|
|
|
*
|
|
|
|
* \a url see _serverStatusUrl (does not include "/status.php")
|
|
|
|
* \a info The status.php reply information
|
|
|
|
*/
|
2017-04-26 13:15:33 +03:00
|
|
|
void instanceFound(const QUrl &url, const QJsonObject &info);
|
2017-03-23 17:53:22 +03:00
|
|
|
|
|
|
|
/** Emitted on invalid status.php reply.
|
|
|
|
*
|
|
|
|
* \a reply is never null
|
|
|
|
*/
|
2014-04-14 17:08:43 +04:00
|
|
|
void instanceNotFound(QNetworkReply *reply);
|
2017-09-08 12:59:45 +03:00
|
|
|
|
|
|
|
/** A timeout occurred.
|
|
|
|
*
|
|
|
|
* \a url The specific url where the timeout happened.
|
|
|
|
*/
|
2013-11-14 20:02:41 +04:00
|
|
|
void timeout(const QUrl &url);
|
2013-10-18 14:24:29 +04:00
|
|
|
|
2017-03-23 17:53:22 +03:00
|
|
|
private:
|
2018-11-12 20:39:50 +03:00
|
|
|
bool finished() override;
|
|
|
|
void onTimedOut() override;
|
2013-10-18 14:24:29 +04:00
|
|
|
private slots:
|
2015-08-05 13:58:04 +03:00
|
|
|
virtual void metaDataChangedSlot();
|
2015-08-11 13:18:25 +03:00
|
|
|
virtual void encryptedSlot();
|
2017-09-08 12:59:45 +03:00
|
|
|
void slotRedirected(QNetworkReply *reply, const QUrl &targetUrl, int redirectCount);
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
private:
|
2014-04-14 17:08:43 +04:00
|
|
|
bool _subdirFallback;
|
2017-09-08 12:59:45 +03:00
|
|
|
|
|
|
|
/** The permanent-redirect adjusted account url.
|
|
|
|
*
|
|
|
|
* Note that temporary redirects or a permanent redirect behind a temporary
|
|
|
|
* one do not affect this url.
|
|
|
|
*/
|
|
|
|
QUrl _serverUrl;
|
|
|
|
|
|
|
|
/** Keep track of how many permanent redirect were applied. */
|
|
|
|
int _permanentRedirects;
|
2013-10-18 14:24:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The RequestEtagJob class
|
2013-10-18 14:24:29 +04:00
|
|
|
*/
|
2014-07-11 00:58:58 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT RequestEtagJob : public AbstractNetworkJob
|
|
|
|
{
|
2013-10-18 14:24:29 +04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit RequestEtagJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
signals:
|
2021-02-25 16:42:23 +03:00
|
|
|
void etagRetrieved(const QByteArray &etag, const QDateTime &time);
|
|
|
|
void finishedWithResult(const HttpResult<QByteArray> &etag);
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
private slots:
|
2018-11-12 20:43:58 +03:00
|
|
|
bool finished() override;
|
2013-10-18 14:24:29 +04:00
|
|
|
};
|
|
|
|
|
2015-01-26 17:33:00 +03:00
|
|
|
/**
|
|
|
|
* @brief Job to check an API that return JSON
|
|
|
|
*
|
|
|
|
* Note! you need to be in the connected state before calling this because of a server bug:
|
|
|
|
* https://github.com/owncloud/core/issues/12930
|
|
|
|
*
|
2015-06-26 18:07:47 +03:00
|
|
|
* To be used like this:
|
|
|
|
* \code
|
2015-01-26 17:33:00 +03:00
|
|
|
* _job = new JsonApiJob(account, QLatin1String("ocs/v1.php/foo/bar"), this);
|
2017-04-26 13:15:33 +03:00
|
|
|
* connect(job, SIGNAL(jsonReceived(QJsonDocument)), ...)
|
|
|
|
* The received QVariantMap is null in case of error
|
2015-06-26 18:07:47 +03:00
|
|
|
* \encode
|
2015-01-26 17:33:00 +03:00
|
|
|
*
|
2015-06-29 19:56:09 +03:00
|
|
|
* @ingroup libsync
|
2015-01-26 17:33:00 +03:00
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT JsonApiJob : public AbstractNetworkJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-09-09 12:18:22 +03:00
|
|
|
enum class Verb {
|
|
|
|
Get,
|
|
|
|
Post,
|
|
|
|
Put,
|
|
|
|
Delete,
|
|
|
|
};
|
|
|
|
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit JsonApiJob(const AccountPtr &account, const QString &path, QObject *parent = nullptr);
|
2015-11-02 19:37:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief addQueryParams - add more parameters to the ocs call
|
|
|
|
* @param params: list pairs of strings containing the parameter name and the value.
|
|
|
|
*
|
|
|
|
* All parameters from the passed list are appended to the query. Note
|
|
|
|
* that the format=json parameter is added automatically and does not
|
|
|
|
* need to be set this way.
|
|
|
|
*
|
|
|
|
* This function needs to be called before start() obviously.
|
|
|
|
*/
|
2017-12-08 12:10:28 +03:00
|
|
|
void addQueryParams(const QUrlQuery ¶ms);
|
2018-03-02 00:19:04 +03:00
|
|
|
void addRawHeader(const QByteArray &headerName, const QByteArray &value);
|
2015-11-19 17:59:10 +03:00
|
|
|
|
2021-09-09 12:18:22 +03:00
|
|
|
void setBody(const QJsonDocument &body);
|
|
|
|
|
|
|
|
void setVerb(Verb value);
|
2020-01-18 17:03:21 +03:00
|
|
|
|
2015-01-26 17:33:00 +03:00
|
|
|
public slots:
|
2018-11-12 20:39:50 +03:00
|
|
|
void start() override;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2015-01-26 17:33:00 +03:00
|
|
|
protected:
|
2018-11-12 20:39:50 +03:00
|
|
|
bool finished() override;
|
2015-01-26 17:33:00 +03:00
|
|
|
signals:
|
2015-11-19 17:59:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief jsonReceived - signal to report the json answer from ocs
|
2017-04-26 13:15:33 +03:00
|
|
|
* @param json - the parsed json document
|
2015-11-19 17:59:10 +03:00
|
|
|
* @param statusCode - the OCS status code: 100 (!) for success
|
|
|
|
*/
|
2017-04-26 13:15:33 +03:00
|
|
|
void jsonReceived(const QJsonDocument &json, int statusCode);
|
2015-11-19 17:59:10 +03:00
|
|
|
|
2018-03-02 00:19:04 +03:00
|
|
|
/**
|
|
|
|
* @brief etagResponseHeaderReceived - signal to report the ETag response header value
|
|
|
|
* from ocs api v2
|
|
|
|
* @param value - the ETag response header value
|
|
|
|
* @param statusCode - the OCS status code: 100 (!) for success
|
|
|
|
*/
|
|
|
|
void etagResponseHeaderReceived(const QByteArray &value, int statusCode);
|
2021-02-25 16:42:23 +03:00
|
|
|
|
2021-03-16 22:24:11 +03:00
|
|
|
/**
|
2021-03-21 22:55:21 +03:00
|
|
|
* @brief desktopNotificationStatusReceived - signal to report if notifications are allowed
|
2021-02-25 16:42:23 +03:00
|
|
|
* @param status - set desktop notifications allowed status
|
2021-03-16 22:24:11 +03:00
|
|
|
*/
|
2021-03-30 13:53:47 +03:00
|
|
|
void allowDesktopNotificationsChanged(bool isAllowed);
|
2018-03-02 00:19:04 +03:00
|
|
|
|
2015-11-02 19:37:23 +03:00
|
|
|
private:
|
2021-09-09 12:18:22 +03:00
|
|
|
QByteArray _body;
|
2017-12-08 12:10:28 +03:00
|
|
|
QUrlQuery _additionalParams;
|
2018-03-02 00:19:04 +03:00
|
|
|
QNetworkRequest _request;
|
2020-01-18 17:03:21 +03:00
|
|
|
|
2021-09-09 12:18:22 +03:00
|
|
|
Verb _verb = Verb::Get;
|
|
|
|
|
|
|
|
QByteArray verbToString() const;
|
2015-01-26 17:33:00 +03:00
|
|
|
};
|
|
|
|
|
2017-09-07 15:58:45 +03:00
|
|
|
/**
|
|
|
|
* @brief Checks with auth type to use for a server
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
2017-11-01 13:16:26 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT DetermineAuthTypeJob : public QObject
|
2017-09-07 15:58:45 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum AuthType {
|
2021-03-11 17:36:33 +03:00
|
|
|
NoAuthType, // used only before we got a chance to probe the server
|
2021-06-22 13:01:18 +03:00
|
|
|
#ifdef WITH_WEBENGINE
|
|
|
|
WebViewFlow,
|
|
|
|
#endif // WITH_WEBENGINE
|
2017-11-09 13:04:12 +03:00
|
|
|
Basic, // also the catch-all fallback for backwards compatibility reasons
|
2017-09-07 15:58:45 +03:00
|
|
|
OAuth,
|
2019-08-19 21:40:30 +03:00
|
|
|
LoginFlowV2
|
2017-09-07 15:58:45 +03:00
|
|
|
};
|
2019-12-12 16:33:07 +03:00
|
|
|
Q_ENUM(AuthType)
|
2017-09-07 15:58:45 +03:00
|
|
|
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit DetermineAuthTypeJob(AccountPtr account, QObject *parent = nullptr);
|
2017-11-01 13:16:26 +03:00
|
|
|
void start();
|
2017-09-07 15:58:45 +03:00
|
|
|
signals:
|
|
|
|
void authType(AuthType);
|
2017-11-01 13:16:26 +03:00
|
|
|
|
2017-09-07 15:58:45 +03:00
|
|
|
private:
|
2019-11-26 16:13:15 +03:00
|
|
|
void checkAllDone();
|
2017-11-01 13:16:26 +03:00
|
|
|
|
|
|
|
AccountPtr _account;
|
2021-03-11 17:36:33 +03:00
|
|
|
AuthType _resultGet = NoAuthType;
|
|
|
|
AuthType _resultPropfind = NoAuthType;
|
|
|
|
AuthType _resultOldFlow = NoAuthType;
|
2017-11-01 13:16:26 +03:00
|
|
|
bool _getDone = false;
|
|
|
|
bool _propfindDone = false;
|
2019-11-26 16:13:15 +03:00
|
|
|
bool _oldFlowDone = false;
|
2017-09-07 15:58:45 +03:00
|
|
|
};
|
|
|
|
|
2017-09-08 17:43:59 +03:00
|
|
|
/**
|
|
|
|
* @brief A basic job around a network request without extra funtionality
|
|
|
|
* @ingroup libsync
|
|
|
|
*
|
|
|
|
* Primarily adds timeout and redirection handling.
|
|
|
|
*/
|
|
|
|
class OWNCLOUDSYNC_EXPORT SimpleNetworkJob : public AbstractNetworkJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-12 20:46:39 +03:00
|
|
|
explicit SimpleNetworkJob(AccountPtr account, QObject *parent = nullptr);
|
2017-09-08 17:43:59 +03:00
|
|
|
|
|
|
|
QNetworkReply *startRequest(const QByteArray &verb, const QUrl &url,
|
|
|
|
QNetworkRequest req = QNetworkRequest(),
|
2018-11-12 20:46:39 +03:00
|
|
|
QIODevice *requestBody = nullptr);
|
2017-09-08 17:43:59 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void finishedSignal(QNetworkReply *reply);
|
|
|
|
private slots:
|
2018-11-12 20:39:50 +03:00
|
|
|
bool finished() override;
|
2017-09-08 17:43:59 +03:00
|
|
|
};
|
|
|
|
|
2021-12-20 12:13:48 +03:00
|
|
|
/**
|
|
|
|
* @brief A basic file manipulation job
|
|
|
|
* @ingroup libsync
|
|
|
|
*/
|
2021-12-20 15:59:08 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT SimpleFileJob : public AbstractNetworkJob
|
2021-12-20 12:13:48 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-12-20 15:59:08 +03:00
|
|
|
explicit SimpleFileJob(AccountPtr account, const QString &filePath, QObject *parent = nullptr);
|
2021-12-20 12:13:48 +03:00
|
|
|
|
|
|
|
QNetworkReply *startRequest(const QByteArray &verb, QNetworkRequest req = QNetworkRequest(), QIODevice *requestBody = nullptr);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void finishedSignal(QNetworkReply *reply);
|
|
|
|
private slots:
|
|
|
|
bool finished() override;
|
|
|
|
};
|
|
|
|
|
2017-11-07 18:12:07 +03:00
|
|
|
/**
|
|
|
|
* @brief Runs a PROPFIND to figure out the private link url
|
|
|
|
*
|
|
|
|
* The numericFileId is used only to build the deprecatedPrivateLinkUrl
|
|
|
|
* locally as a fallback. If it's empty and the PROPFIND fails, targetFun
|
|
|
|
* will be called with an empty string.
|
|
|
|
*
|
|
|
|
* The job and signal connections are parented to the target QObject.
|
|
|
|
*
|
|
|
|
* Note: targetFun is guaranteed to be called only through the event
|
|
|
|
* loop and never directly.
|
|
|
|
*/
|
|
|
|
void OWNCLOUDSYNC_EXPORT fetchPrivateLinkUrl(
|
|
|
|
AccountPtr account, const QString &remotePath,
|
|
|
|
const QByteArray &numericFileId, QObject *target,
|
|
|
|
std::function<void(const QString &url)> targetFun);
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2013-10-18 14:24:29 +04:00
|
|
|
|
|
|
|
#endif // NETWORKJOBS_H
|