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"(<d:propfind xmlns:d="DAV:"> <d:prop xmlns:nc="http://nextcloud.org/ns"> <nc:is-encrypted/> </d:prop> </d:propfind>)";
- 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
- <?xml version="1.0"?>
- <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
- <d:response>
- <d:href>/remote.php/webdav/</d:href>
- <d:propstat>
- <d:prop>
- <nc:is-encrypted>0</nc:is-encrypted>
- </d:prop>
- <d:status>HTTP/1.1 200 OK</d:status>
- </d:propstat>
- </d:response>
- </d:multistatus>
- */
- QString base = account()->url().path();
- if (base.endsWith(QLatin1Char('/')))
- base.chop(1);
-
- QString currFile;
- int currEncryptedStatus = -1;
- QHash<QString, bool> 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)