| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com> |
| 3 | SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org> |
| 4 | SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef DBUS_HELPER_PROXY_H |
| 10 | #define DBUS_HELPER_PROXY_H |
| 11 | |
| 12 | #include "HelperProxy.h" |
| 13 | #include "actionreply.h" |
| 14 | |
| 15 | #include <QDBusConnection> |
| 16 | #include <QDBusContext> |
| 17 | #include <QDBusUnixFileDescriptor> |
| 18 | #include <QVariant> |
| 19 | |
| 20 | namespace KAuth |
| 21 | { |
| 22 | class DBusHelperProxy : public HelperProxy, protected QDBusContext |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | Q_PLUGIN_METADATA(IID "org.kde.DBusHelperProxy" ) |
| 26 | Q_INTERFACES(KAuth::HelperProxy) |
| 27 | |
| 28 | QObject *responder; |
| 29 | QString m_name; |
| 30 | QString m_currentAction; |
| 31 | bool m_stopRequest; |
| 32 | QList<QString> m_actionsInProgress; |
| 33 | QDBusConnection m_busConnection; |
| 34 | |
| 35 | enum SignalType { |
| 36 | ActionStarted, // The blob argument is empty |
| 37 | ActionPerformed, // The blob argument contains the ActionReply |
| 38 | DebugMessage, // The blob argument contains the debug level and the message (in this order) |
| 39 | ProgressStepIndicator, // The blob argument contains the step indicator |
| 40 | ProgressStepData, // The blob argument contains the QVariantMap |
| 41 | }; |
| 42 | |
| 43 | public: |
| 44 | DBusHelperProxy(); |
| 45 | DBusHelperProxy(const QDBusConnection &busConnection); |
| 46 | |
| 47 | ~DBusHelperProxy() override; |
| 48 | |
| 49 | virtual void |
| 50 | executeAction(const QString &action, const QString &helperID, const DetailsMap &details, const QVariantMap &arguments, int timeout = -1) override; |
| 51 | void stopAction(const QString &action, const QString &helperID) override; |
| 52 | |
| 53 | bool initHelper(const QString &name) override; |
| 54 | void setHelperResponder(QObject *o) override; |
| 55 | bool hasToStopAction() override; |
| 56 | void sendDebugMessage(int level, const char *msg) override; |
| 57 | void sendProgressStep(int step) override; |
| 58 | void sendProgressStepData(const QVariantMap &data) override; |
| 59 | |
| 60 | int callerUid() const override; |
| 61 | |
| 62 | public Q_SLOTS: |
| 63 | void stopAction(const QString &action); |
| 64 | QByteArray performAction(const QString &action, |
| 65 | const QByteArray &callerID, |
| 66 | const QVariantMap &details, |
| 67 | QByteArray arguments, |
| 68 | const QMap<QString, QDBusUnixFileDescriptor> &fdArguments); |
| 69 | |
| 70 | Q_SIGNALS: |
| 71 | void remoteSignal(int type, const QString &action, const QByteArray &blob); // This signal is sent from the helper to the app |
| 72 | |
| 73 | private Q_SLOTS: |
| 74 | void remoteSignalReceived(int type, const QString &action, QByteArray blob); |
| 75 | |
| 76 | private: |
| 77 | bool isCallerAuthorized(const QString &action, const QByteArray &callerID, const QVariantMap &details); |
| 78 | }; |
| 79 | |
| 80 | } // namespace Auth |
| 81 | |
| 82 | #endif |
| 83 | |