1 /* 2 * Copyright (C) by Kevin Ottens <kevin.ottens@nextcloud.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * for more details. 13 */ 14 #pragma once 15 16 #include <QObject> 17 18 #include "account.h" 19 20 class QLocalServer; 21 class QLocalSocket; 22 23 namespace OCC { 24 class GETFileJob; 25 class SyncJournalDb; 26 class VfsCfApi; 27 28 namespace EncryptionHelper { 29 class StreamingDecryptor; 30 }; 31 32 class HydrationJob : public QObject 33 { 34 Q_OBJECT 35 public: 36 enum Status { 37 Success = 0, 38 Error, 39 Cancelled, 40 }; 41 Q_ENUM(Status) 42 43 explicit HydrationJob(QObject *parent = nullptr); 44 45 AccountPtr account() const; 46 void setAccount(const AccountPtr &account); 47 48 QString remotePath() const; 49 void setRemotePath(const QString &remotePath); 50 51 QString localPath() const; 52 void setLocalPath(const QString &localPath); 53 54 SyncJournalDb *journal() const; 55 void setJournal(SyncJournalDb *journal); 56 57 QString requestId() const; 58 void setRequestId(const QString &requestId); 59 60 QString folderPath() const; 61 void setFolderPath(const QString &folderPath); 62 63 bool isEncryptedFile() const; 64 void setIsEncryptedFile(bool isEncrypted); 65 66 QString e2eMangledName() const; 67 void setE2eMangledName(const QString &e2eMangledName); 68 69 qint64 fileTotalSize() const; 70 void setFileTotalSize(qint64 totalSize); 71 72 Status status() const; 73 74 void start(); 75 void cancel(); 76 void finalize(OCC::VfsCfApi *vfs); 77 78 public slots: 79 void slotCheckFolderId(const QStringList &list); 80 void slotFolderIdError(); 81 void slotCheckFolderEncryptedMetadata(const QJsonDocument &json); 82 void slotFolderEncryptedMetadataError(const QByteArray &fileId, int httpReturnCode); 83 84 signals: 85 void finished(HydrationJob *job); 86 87 private: 88 void emitFinished(Status status); 89 90 void onNewConnection(); 91 void onCancellationServerNewConnection(); 92 void onGetFinished(); 93 94 void handleNewConnection(); 95 void handleNewConnectionForEncryptedFile(); 96 97 void startServerAndWaitForConnections(); 98 99 AccountPtr _account; 100 QString _remotePath; 101 QString _localPath; 102 SyncJournalDb *_journal = nullptr; 103 bool _isCancelled = false; 104 105 QString _requestId; 106 QString _folderPath; 107 108 bool _isEncryptedFile = false; 109 QString _e2eMangledName; 110 111 QLocalServer *_transferDataServer = nullptr; 112 QLocalServer *_signalServer = nullptr; 113 QLocalSocket *_transferDataSocket = nullptr; 114 QLocalSocket *_signalSocket = nullptr; 115 GETFileJob *_job = nullptr; 116 Status _status = Success; 117 }; 118 119 } // namespace OCC 120