mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Get rid of now unused GetFolderEncryptStatusJob
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
parent
36b8e7c2a4
commit
1acb2679dd
2 changed files with 0 additions and 122 deletions
|
@ -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"(<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)
|
||||
|
|
|
@ -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<QString, bool> folderMetadata2EncryptionStatus);
|
||||
void encryptStatusFolderReceived(const QString &folder, bool isEncrypted);
|
||||
void encryptStatusError(int statusCode);
|
||||
private:
|
||||
QString _folder;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue