From: Claudio Cambra Date: Wed, 21 Dec 2022 18:53:20 +0000 (+0100) Subject: Implement basic local socket server to communicate with file provider extension X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~96^2^2~55^2~322 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=de68b1bbb4e4675b81fdf4b9edf60c9c3cfc7d3a;p=nextcloud-desktop.git Implement basic local socket server to communicate with file provider extension Signed-off-by: Claudio Cambra --- diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 726308289..cd63cda99 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -284,7 +284,10 @@ IF( APPLE ) macOS/fileprovider.h macOS/fileprovider_mac.mm macOS/fileproviderdomainmanager.h - macOS/fileproviderdomainmanager_mac.mm) + macOS/fileproviderdomainmanager_mac.mm + macOS/fileprovidersocketcontroller.h + macOS/fileprovidersocketcontroller.cpp + macOS/fileprovidersocketcontroller_mac.mm) if(SPARKLE_FOUND AND BUILD_UPDATER) # Define this, we need to check in updater.cpp diff --git a/src/gui/macOS/fileprovidersocketcontroller.cpp b/src/gui/macOS/fileprovidersocketcontroller.cpp new file mode 100644 index 000000000..6ed6e0f04 --- /dev/null +++ b/src/gui/macOS/fileprovidersocketcontroller.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 by Claudio Cambra + * + * 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 2 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. + */ + +#include "fileprovidersocketcontroller.h" + +namespace OCC +{ + +namespace Mac +{ + +Q_LOGGING_CATEGORY(lcFileProviderSocketController, "nextcloud.gui.macos.fileprovider.socketcontroller", QtInfoMsg) + +FileProviderSocketController::FileProviderSocketController(QObject *parent) + : QObject{parent} +{ +#ifdef Q_OS_MACOS + _socketPath = fileProviderSocketPath(); +#endif + startListening(); +} + +void FileProviderSocketController::startListening() +{ + QLocalServer::removeServer(_socketPath); + + const auto serverStarted = _socketServer.listen(_socketPath); + if (!serverStarted) { + qCWarning(lcFileProviderSocketController) << "Could not start file provider socket server" + << _socketPath; + } else { + qCInfo(lcFileProviderSocketController) << "File provider socket server started, listening" + << _socketPath; + } + + connect(&_socketServer, &QLocalServer::newConnection, + this, &FileProviderSocketController::slotNewConnection); +} + +void FileProviderSocketController::slotNewConnection() +{ + if (!_socketServer.hasPendingConnections()) { + return; + } + + const auto socket = _socketServer.nextPendingConnection(); + if (!socket) { + return; + } +} + +} // namespace Mac + +} // namespace OCC diff --git a/src/gui/macOS/fileprovidersocketcontroller.h b/src/gui/macOS/fileprovidersocketcontroller.h new file mode 100644 index 000000000..feb6447f3 --- /dev/null +++ b/src/gui/macOS/fileprovidersocketcontroller.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 by Claudio Cambra + * + * 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 2 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. + */ + +#pragma once + +#include +#include +#include + +namespace OCC +{ + +namespace Mac { + +#ifdef Q_OS_MACOS +QString fileProviderSocketPath(); +#endif + +class FileProviderSocketController : public QObject +{ + Q_OBJECT + +public: + explicit FileProviderSocketController(QObject *parent = nullptr); + +private slots: + void startListening(); + void slotNewConnection(); + +private: + QString _socketPath; + QLocalServer _socketServer; + +}; + +} // namespace Mac + +} // namespace OCC diff --git a/src/gui/macOS/fileprovidersocketcontroller_mac.mm b/src/gui/macOS/fileprovidersocketcontroller_mac.mm new file mode 100644 index 000000000..8377adb96 --- /dev/null +++ b/src/gui/macOS/fileprovidersocketcontroller_mac.mm @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 by Claudio Cambra + * + * 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 2 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. + */ + +#import +#import + +#include "config.h" + +namespace OCC +{ + +namespace Mac +{ + +QString fileProviderSocketPath() +{ + // This must match the code signing Team setting of the extension + // Example for developer builds (with ad-hoc signing identity): "" "com.owncloud.desktopclient" ".fileprovidersocket" + // Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".fileprovidersocket" + NSString *appGroupId = @SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN; + + NSURL *container = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId]; + NSURL *socketPath = [container URLByAppendingPathComponent:@".fileprovidersocket" isDirectory:false]; + return QString::fromNSString(socketPath.path); +} + +} // namespace Mac + +} // namespace OCC