diff --git a/src/libsync/clientsideencryptionjobs.cpp b/src/libsync/clientsideencryptionjobs.cpp index 505bd99f5..490f9f077 100644 --- a/src/libsync/clientsideencryptionjobs.cpp +++ b/src/libsync/clientsideencryptionjobs.cpp @@ -24,103 +24,6 @@ Q_LOGGING_CATEGORY(lcCseJob, "nextcloud.sync.networkjob.clientsideencrypt", QtIn namespace OCC { -GetFolderEncryptStatusJob::GetFolderEncryptStatusJob(const AccountPtr& account, const QString& folder, QObject *parent) - : OCC::AbstractNetworkJob(account, QStringLiteral("remote.php/webdav"), parent), _folder(folder) -{ -} - -QString GetFolderEncryptStatusJob::folder() const -{ - return _folder; -} - -void GetFolderEncryptStatusJob::start() -{ - QNetworkRequest req; - req.setPriority(QNetworkRequest::HighPriority); - req.setRawHeader("OCS-APIREQUEST", "true"); - req.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/xml")); - req.setRawHeader("Depth", "1"); - - QByteArray xml = R"( )"; - auto *buf = new QBuffer(this); - buf->setData(xml); - buf->open(QIODevice::ReadOnly); - QString tmpPath = path() + (!_folder.isEmpty() ? "/" + _folder : QString()); - sendRequest("PROPFIND", Utility::concatUrlPath(account()->url(), tmpPath), req, buf); - - AbstractNetworkJob::start(); -} - -bool GetFolderEncryptStatusJob::finished() -{ - qCInfo(lcCseJob()) << "GetFolderEncryptStatus of" << reply()->request().url() << "finished with status" - << reply()->error() - << (reply()->error() == QNetworkReply::NoError ? QLatin1String("") : errorString()); - - int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - if (http_result_code == 207) { - // Parse DAV response - QXmlStreamReader reader(reply()); - reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("d", "DAV:")); - - /* Example Xml - - - - /remote.php/webdav/ - - - 0 - - HTTP/1.1 200 OK - - - - */ - QString base = account()->url().path(); - if (base.endsWith(QLatin1Char('/'))) - base.chop(1); - - QString currFile; - int currEncryptedStatus = -1; - QHash folderStatus; - while (!reader.atEnd()) { - auto type = reader.readNext(); - if (type == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("href")) { - // If the current file is not a folder, ignore it. - currFile = QUrl::fromPercentEncoding(reader.readElementText(QXmlStreamReader::SkipChildElements).toUtf8()); - currFile.remove(base + QLatin1String("/remote.php/webdav/")); - if (!currFile.endsWith('/')) - currFile.clear(); - currEncryptedStatus = -1; - } - if (!currFile.isEmpty() && reader.name() == QLatin1String("is-encrypted")) { - currEncryptedStatus = (bool) reader.readElementText(QXmlStreamReader::SkipChildElements).toInt(); - } - } - - if (!currFile.isEmpty() && currEncryptedStatus != -1) { - folderStatus.insert(currFile, currEncryptedStatus); - currFile.clear(); - currEncryptedStatus = -1; - } - } - - emit encryptStatusReceived(folderStatus); - emit encryptStatusFolderReceived(_folder, folderStatus.value(_folder + QLatin1Char('/'))); - } else { - qCWarning(lcCseJob()) << "*not* successful, http result code is" << http_result_code - << (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String("")); - emit encryptStatusError(http_result_code); - // emit finishedWithError(reply()); - } - return true; -} - - GetMetadataApiJob::GetMetadataApiJob(const AccountPtr& account, const QByteArray& fileId, QObject* parent) diff --git a/src/libsync/clientsideencryptionjobs.h b/src/libsync/clientsideencryptionjobs.h index 4a78db8c7..a64a59b43 100644 --- a/src/libsync/clientsideencryptionjobs.h +++ b/src/libsync/clientsideencryptionjobs.h @@ -277,30 +277,5 @@ private: QByteArray _fileId; }; -/* I cant use the propfind network job because it defaults to the - * wrong dav url. - */ -class OWNCLOUDSYNC_EXPORT GetFolderEncryptStatusJob : public AbstractNetworkJob -{ - Q_OBJECT -public: - explicit GetFolderEncryptStatusJob (const AccountPtr &account, const QString& folder, QObject *parent = nullptr); - - QString folder() const; - -public slots: - void start() override; - -protected: - bool finished() override; - -signals: - void encryptStatusReceived(const QHash folderMetadata2EncryptionStatus); - void encryptStatusFolderReceived(const QString &folder, bool isEncrypted); - void encryptStatusError(int statusCode); -private: - QString _folder; -}; - } #endif