2017-11-07 22:55:28 +00:00
|
|
|
/*************************************************************************
|
2018-03-22 17:29:40 +00:00
|
|
|
* Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
2017-11-07 22:55:28 +00:00
|
|
|
* *
|
|
|
|
* 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 3 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. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef KPMCORE_EXTERNALCOMMANDHELPER_H
|
|
|
|
#define KPMCORE_EXTERNALCOMMANDHELPER_H
|
|
|
|
|
2018-08-03 19:37:24 +01:00
|
|
|
#include <memory>
|
2018-07-21 11:03:25 +01:00
|
|
|
#include <unordered_set>
|
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
#include <KAuth>
|
|
|
|
|
2018-03-19 10:33:20 +00:00
|
|
|
#include <QEventLoop>
|
2018-07-20 21:12:13 +01:00
|
|
|
#include <QRandomGenerator64>
|
2018-01-24 15:22:42 +00:00
|
|
|
#include <QString>
|
2017-11-07 22:55:28 +00:00
|
|
|
#include <QProcess>
|
|
|
|
|
2018-04-12 22:43:12 +01:00
|
|
|
#include <QtCrypto>
|
2018-03-23 22:45:51 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
using namespace KAuth;
|
|
|
|
|
|
|
|
class ExternalCommandHelper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-03-19 10:33:20 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand")
|
2017-11-07 22:55:28 +00:00
|
|
|
|
2018-01-24 15:22:42 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void progress(int);
|
2018-03-19 10:33:20 +00:00
|
|
|
void quit();
|
2018-01-24 15:22:42 +00:00
|
|
|
|
|
|
|
public:
|
2019-03-29 17:51:51 +00:00
|
|
|
bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size);
|
|
|
|
bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset);
|
2018-01-24 15:22:42 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
public Q_SLOTS:
|
2018-03-19 10:33:20 +00:00
|
|
|
ActionReply init(const QVariantMap& args);
|
2018-07-21 11:03:25 +01:00
|
|
|
Q_SCRIPTABLE quint64 getNonce();
|
|
|
|
Q_SCRIPTABLE QVariantMap start(const QByteArray& signature, const quint64 nonce, const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode);
|
2018-10-28 17:22:12 +00:00
|
|
|
Q_SCRIPTABLE QVariantMap copyblocks(const QByteArray& signature, const quint64 nonce, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize);
|
2018-11-29 22:32:07 +00:00
|
|
|
Q_SCRIPTABLE bool writeData(const QByteArray& signature, const quint64 nonce, const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte);
|
2018-07-21 11:03:25 +01:00
|
|
|
Q_SCRIPTABLE void exit(const QByteArray& signature, const quint64 nonce);
|
2018-03-23 21:19:33 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
private:
|
|
|
|
void onReadOutput();
|
|
|
|
|
2018-08-03 19:37:24 +01:00
|
|
|
std::unique_ptr<QEventLoop> m_loop;
|
2018-04-12 22:43:12 +01:00
|
|
|
QCA::Initializer initializer;
|
|
|
|
QCA::PublicKey m_publicKey;
|
2018-07-20 21:12:13 +01:00
|
|
|
QRandomGenerator64 m_Generator;
|
2018-07-21 11:03:25 +01:00
|
|
|
std::unordered_set<quint64> m_Nonces;
|
2018-03-19 10:33:20 +00:00
|
|
|
QString m_command;
|
|
|
|
QString m_sourceDevice;
|
|
|
|
QProcess m_cmd;
|
2018-03-23 21:19:33 +00:00
|
|
|
|
2017-11-07 22:55:28 +00:00
|
|
|
// QByteArray output;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|