2022-12-22 16:37:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
|
|
|
|
*
|
|
|
|
* 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 "fileprovidersocketserver.h"
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
2023-03-15 18:04:12 +03:00
|
|
|
#include <QLoggingCategory>
|
2022-12-22 16:37:30 +03:00
|
|
|
|
|
|
|
#include "fileprovidersocketcontroller.h"
|
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
namespace Mac {
|
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(lcFileProviderSocketServer, "nextcloud.gui.macos.fileprovider.socketserver", QtInfoMsg)
|
|
|
|
|
|
|
|
FileProviderSocketServer::FileProviderSocketServer(QObject *parent)
|
|
|
|
: QObject{parent}
|
|
|
|
{
|
|
|
|
_socketPath = fileProviderSocketPath();
|
|
|
|
startListening();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileProviderSocketServer::startListening()
|
|
|
|
{
|
|
|
|
QLocalServer::removeServer(_socketPath);
|
|
|
|
|
|
|
|
const auto serverStarted = _socketServer.listen(_socketPath);
|
|
|
|
if (!serverStarted) {
|
|
|
|
qCWarning(lcFileProviderSocketServer) << "Could not start file provider socket server"
|
|
|
|
<< _socketPath;
|
|
|
|
} else {
|
|
|
|
qCInfo(lcFileProviderSocketServer) << "File provider socket server started, listening"
|
|
|
|
<< _socketPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(&_socketServer, &QLocalServer::newConnection,
|
|
|
|
this, &FileProviderSocketServer::slotNewConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileProviderSocketServer::slotNewConnection()
|
|
|
|
{
|
|
|
|
if (!_socketServer.hasPendingConnections()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCInfo(lcFileProviderSocketServer) << "New connection in file provider socket server";
|
|
|
|
const auto socket = _socketServer.nextPendingConnection();
|
|
|
|
if (!socket) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileProviderSocketControllerPtr socketController(new FileProviderSocketController(socket, this));
|
|
|
|
connect(socketController.data(), &FileProviderSocketController::socketDestroyed,
|
|
|
|
this, &FileProviderSocketServer::slotSocketDestroyed);
|
|
|
|
_socketControllers.insert(socket, socketController);
|
2022-12-29 00:28:30 +03:00
|
|
|
|
|
|
|
socketController->start();
|
2022-12-22 16:37:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileProviderSocketServer::slotSocketDestroyed(const QLocalSocket * const socket)
|
|
|
|
{
|
2023-03-15 19:56:56 +03:00
|
|
|
const auto socketController = _socketControllers.take(socket);
|
|
|
|
|
|
|
|
if (socketController) {
|
|
|
|
const auto rawSocketControllerPtr = socketController.data();
|
|
|
|
delete rawSocketControllerPtr;
|
|
|
|
}
|
2022-12-22 16:37:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Mac
|
|
|
|
|
|
|
|
} // namespace OCC
|