| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/helper/helpermonitor.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "helpermonitor.h"cxx . . $ `<file>/src/helper/helpermonitor.h`/ |
| 5 | |
| 6 | #include "common/icryptolayer.h"cxx . . $ `<file>/src/common/icryptolayer.h`/ |
| 7 | #include "helperids.h"cxx . . $ `<file>/src/helper/helperids.h`/ |
| 8 | #include <QDBusConnection> |
| 9 | #include <QDBusInterface> |
| 10 | #include <QString> |
| 11 | #include <algorithm> |
| 12 | #include <format> |
| 13 | #include <spdlog/spdlog.h> |
| 14 | #include <stdexcept> |
| 15 | #include <utility> |
| 16 | |
| 17 | HelperMonitorcxx . . $ HelperMonitor#::HelperMonitorcxx . . $ HelperMonitor#HelperMonitor(fa3ab6c77c92806e).(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<ICryptoLayercxx . . $ ICryptoLayer#> cryptoLayer, |
| 18 | QObjectcxx . . $ QObject# *parent) noexcept |
| 19 | : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent) |
| 20 | , cryptoLayer_cxx . . $ HelperMonitor#cryptoLayer_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cryptoLayer)) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void HelperMonitorcxx . . $ HelperMonitor#::addObservercxx . . $ HelperMonitor#addObserver(c5c359039219b577).(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<IHelperMonitorcxx . . $ IHelperMonitor#::Observercxx . . $ IHelperMonitor#Observer#> observer) |
| 25 | { |
| 26 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(mutex_cxx . . $ HelperMonitor#mutex_.); |
| 27 | |
| 28 | auto const it = stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(observers_cxx . . $ HelperMonitor#observers_..begincxx . . $ std/vector#begin(55a6de06420d4903).(), observers_cxx . . $ HelperMonitor#observers_..endcxx . . $ std/vector#end(55a6de06420d4903).(), observer); |
| 29 | if (it ==cxx . . $ __gnu_cxx/`operator==`(d2eded1addd76ab7). observers_cxx . . $ HelperMonitor#observers_..endcxx . . $ std/vector#end(55a6de06420d4903).()) |
| 30 | observers_cxx . . $ HelperMonitor#observers_..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(observer)); |
| 31 | } |
| 32 | |
| 33 | void HelperMonitorcxx . . $ HelperMonitor#::removeObservercxx . . $ HelperMonitor#removeObserver(23661280549b0457).( |
| 34 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<IHelperMonitorcxx . . $ IHelperMonitor#::Observercxx . . $ IHelperMonitor#Observer#> const &observer) |
| 35 | { |
| 36 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(mutex_cxx . . $ HelperMonitor#mutex_.); |
| 37 | stdcxx . . $ std/::erasecxx . . $ std/erase(d1155fb03f0860d).(observers_cxx . . $ HelperMonitor#observers_., observer); |
| 38 | } |
| 39 | |
| 40 | void HelperMonitorcxx . . $ HelperMonitor#::initcxx . . $ HelperMonitor#init(49f6e7a06ebc5aa8).() |
| 41 | { |
| 42 | monitorInterface_cxx . . $ HelperMonitor#monitorInterface_. =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<QDBusInterfacecxx . . $ QDBusInterface#>( |
| 43 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!), QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!), |
| 44 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!), QDBusConnectioncxx . . $ QDBusConnection#::systemBuscxx . . $ QDBusConnection#systemBus(45d475f1888103b2).()); |
| 45 | |
| 46 | if (!monitorInterface_cxx . . $ HelperMonitor#monitorInterface_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).isValidcxx . . $ QDBusAbstractInterface#isValid(50ce9a9e25b4a850).()) |
| 47 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#( |
| 48 | stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("Cannot connect to D-Bus interface {} (path: {})"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., |
| 49 | DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!, DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!)); |
| 50 | |
| 51 | if (!QDBusConnectioncxx . . $ QDBusConnection#::systemBuscxx . . $ QDBusConnection#systemBus(45d475f1888103b2).().connectcxx . . $ QDBusConnection#connect(a950c2c6143dd21d).( |
| 52 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!), |
| 53 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!), |
| 54 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!), QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!("appExec"), |
| 55 | this, SLOTcxx . . $ `<external>/4766508314589701758/qobjectdefs.h:58:11`!(notifyAppExec(QByteArray const &, QByteArray const &)))) |
| 56 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#(stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).( |
| 57 | "Cannot connect to 'appExec' in D-Bus interface {} (path: {})"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., |
| 58 | DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!, DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!)); |
| 59 | |
| 60 | if (!QDBusConnectioncxx . . $ QDBusConnection#::systemBuscxx . . $ QDBusConnection#systemBus(45d475f1888103b2).().connectcxx . . $ QDBusConnection#connect(a950c2c6143dd21d).( |
| 61 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!), |
| 62 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!), |
| 63 | QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!), QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!("appExit"), |
| 64 | this, SLOTcxx . . $ `<external>/4766508314589701758/qobjectdefs.h:58:11`!(notifyAppExit(QByteArray const &, QByteArray const &)))) |
| 65 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#(stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).( |
| 66 | "Cannot connect to 'appExit' in D-Bus interface {} (path: {})"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., |
| 67 | DBUS_HELPER_PMON_INTERFACEcxx . . $ `src/helper/helperids.h:16:9`!, DBUS_HELPER_PMON_PATHcxx . . $ `src/helper/helperids.h:17:9`!)); |
| 68 | } |
| 69 | |
| 70 | void HelperMonitorcxx . . $ HelperMonitor#::watchAppcxx . . $ HelperMonitor#watchApp(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &app) |
| 71 | { |
| 72 | QByteArraycxx . . $ QByteArray# datacxx . . $ QByteArray#QByteArray(de40a1f2d6082f12).(app.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 73 | auto signature = cryptoLayer_cxx . . $ HelperMonitor#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).signaturecxx . . $ ICryptoLayer#signature(ba1ae99d10185369).(data); |
| 74 | monitorInterface_cxx . . $ HelperMonitor#monitorInterface_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).asyncCallcxx . . $ QDBusAbstractInterface#asyncCall(1ecb6b7bdc99c898).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!("watchApp"), data, signature); |
| 75 | } |
| 76 | |
| 77 | void HelperMonitorcxx . . $ HelperMonitor#::forgetAppcxx . . $ HelperMonitor#forgetApp(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &app) |
| 78 | { |
| 79 | QByteArraycxx . . $ QByteArray# datacxx . . $ QByteArray#QByteArray(de40a1f2d6082f12).(app.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 80 | auto signature = cryptoLayer_cxx . . $ HelperMonitor#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).signaturecxx . . $ ICryptoLayer#signature(ba1ae99d10185369).(data); |
| 81 | monitorInterface_cxx . . $ HelperMonitor#monitorInterface_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).asyncCallcxx . . $ QDBusAbstractInterface#asyncCall(1ecb6b7bdc99c898).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!("forgetApp"), data, signature); |
| 82 | } |
| 83 | |
| 84 | void HelperMonitorcxx . . $ HelperMonitor#::notifyAppExeccxx . . $ HelperMonitor#notifyAppExec(a34492a60dbd2bdc).(QByteArraycxx . . $ QByteArray# const &data, |
| 85 | QByteArraycxx . . $ QByteArray# const &signature) |
| 86 | { |
| 87 | if (!cryptoLayer_cxx . . $ HelperMonitor#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).verifycxx . . $ ICryptoLayer#verify(5ad6b2491b335728).(data, signature)) { |
| 88 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Failed to verify received data from D-Bus"); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(mutex_cxx . . $ HelperMonitor#mutex_.); |
| 93 | auto const app = data.toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).(); |
| 94 | for (auto &o : observers_cxx . . $ HelperMonitor#observers_.) |
| 95 | o->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).appExeccxx . . $ IHelperMonitor#Observer#appExec(8d4ab0a187bf9331).(appcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).); |
| 96 | } |
| 97 | |
| 98 | void HelperMonitorcxx . . $ HelperMonitor#::notifyAppExitcxx . . $ HelperMonitor#notifyAppExit(a34492a60dbd2bdc).(QByteArraycxx . . $ QByteArray# const &data, |
| 99 | QByteArraycxx . . $ QByteArray# const &signature) |
| 100 | { |
| 101 | if (!cryptoLayer_cxx . . $ HelperMonitor#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).verifycxx . . $ ICryptoLayer#verify(5ad6b2491b335728).(data, signature)) { |
| 102 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Failed to verify received data from D-Bus"); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(mutex_cxx . . $ HelperMonitor#mutex_.); |
| 107 | auto const app = data.toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).(); |
| 108 | for (auto &o : observers_cxx . . $ HelperMonitor#observers_.) |
| 109 | o->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).appExitcxx . . $ IHelperMonitor#Observer#appExit(8d4ab0a187bf9331).(appcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).); |
| 110 | } |