File indexing completed on 2022-09-20 21:11:18

0001 /*
0002    SPDX-FileCopyrightText: 2019-2020 Fabian Vogt <fabian@ritter-vogt.de>
0003    SPDX-FileCopyrightText: 2019-2020 Alexander Saoutkin <a.saoutkin@gmail.com>
0004    SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <optional>
0010 
0011 #include <QObject>
0012 #include <QDBusMessage>
0013 #include <QDBusContext>
0014 #include <QTemporaryDir>
0015 #include <QStandardPaths>
0016 #include <QDBusAbstractAdaptor>
0017 
0018 #include "kiofusevfs.h"
0019 
0020 class KIOFuseServicePrivate : public QDBusAbstractAdaptor {
0021     Q_OBJECT
0022     Q_CLASSINFO("D-Bus Interface", "org.kde.KIOFuse.Private")
0023 
0024 public:
0025     KIOFuseServicePrivate(QObject *obj) : QDBusAbstractAdaptor(obj) {}
0026 
0027 public Q_SLOTS:
0028     /** Treat all nodes as expired, to not have to wait in automated testing. */
0029     void forceNodeTimeout();
0030 };
0031 
0032 class KIOFuseService : public QObject, protected QDBusContext
0033 {
0034     Q_OBJECT
0035     Q_CLASSINFO("D-Bus Interface", "org.kde.KIOFuse.VFS")
0036 
0037 public:
0038     virtual ~KIOFuseService();
0039     /** Attempts to register the service and start kiofusevfs. If both succeed,
0040       * returns true, false otherwise. */
0041     bool start(struct fuse_args &args, const QString &mountpoint, bool foreground);
0042     KIOFuseVFS kiofusevfs;
0043 
0044 public Q_SLOTS:
0045     /** Mounts a URL onto the filesystem, and returns the local path back. */
0046     QString mountUrl(const QString &remoteUrl, const QDBusMessage &message);
0047     /** Converts a local path into a remote URL if it is mounted within the VFS */
0048     QString remoteUrl(const QString &localPath);
0049 
0050 private Q_SLOTS:
0051     /** Stops the VFS when the DBus connection is lost. */
0052     void dbusDisconnected();
0053 
0054 private:
0055     /** Registers the kio-fuse process as the org.kde.KIOFuse service.
0056       * Returns false if this fails (otherwise you can't communicate with the process), true otherwise.*/
0057     bool registerService();
0058     /** Daemonizes the kio-fuse process, whilst also managing the registration of the org.kde.KIOFuse service.
0059       * Derived from fuse_daemonize() in libfuse. */
0060     bool registerServiceDaemonized();
0061     /** where kiofusevfs is mounted */
0062     QString m_mountpoint;
0063     /** tempdir created if user does not specify mountpoint */
0064     std::optional<QTemporaryDir> m_tempDir;
0065     /** A list of protocols that are blacklisted (for various reasons). */
0066     static const QStringList m_blacklist;
0067     /** DBus Adaptor exported as org.kde.KIOFuse.Private interface. */
0068     KIOFuseServicePrivate m_privateInterface{this};
0069 };