diff --git a/src/gui/macOS/fileproviderdomainmanager_mac.mm b/src/gui/macOS/fileproviderdomainmanager_mac.mm index 6e670763b4..41f59b980e 100644 --- a/src/gui/macOS/fileproviderdomainmanager_mac.mm +++ b/src/gui/macOS/fileproviderdomainmanager_mac.mm @@ -41,7 +41,7 @@ class FileProviderDomainManager::Private { void addFileProviderDomain(const AccountState *accountState) { const QString accountDisplayName = accountState->account()->displayName(); - const QString accountId = accountState->account()->id(); + const QString accountId = accountState->account()->userIdAtHostWithPort(); qCDebug(lcMacFileProviderDomainManager) << "Adding new file provider domain for account with id: " << accountId; diff --git a/src/gui/macOS/fileprovidersocketcontroller.cpp b/src/gui/macOS/fileprovidersocketcontroller.cpp index af90a22f05..ec54da294c 100644 --- a/src/gui/macOS/fileprovidersocketcontroller.cpp +++ b/src/gui/macOS/fileprovidersocketcontroller.cpp @@ -16,6 +16,8 @@ #include +#include "accountmanager.h" + namespace OCC { namespace Mac { @@ -53,10 +55,53 @@ void FileProviderSocketController::slotReadyRead() Q_ASSERT(_socket); while(_socket->canReadLine()) { const QString line = QString::fromUtf8(_socket->readLine().trimmed()).normalized(QString::NormalizationForm_C); - Q_UNUSED(line); + qCDebug(lcFileProviderSocketController) << "Received message in file provider socket:" << line; + + parseReceivedLine(line); } } +void FileProviderSocketController::parseReceivedLine(const QString &receivedLine) +{ + if (receivedLine.isEmpty()) { + qCWarning(lcFileProviderSocketController) << "Received empty line, can't parse."; + return; + } + + const auto argPos = receivedLine.indexOf(QLatin1Char(':')); + if (argPos == -1) { + qCWarning(lcFileProviderSocketController) << "Received line:" + << receivedLine + << "is incorrectly structured. Can't parse."; + return; + } + + const auto command = receivedLine.mid(0, argPos); + const auto argument = receivedLine.mid(argPos + 1); + + if (command == QStringLiteral("FILE_PROVIDER_DOMAIN_IDENTIFIER_REQUEST_REPLY")) { + _accountState = accountStateFromFileProviderDomainIdentifier(argument); + return; + } + + qCWarning(lcFileProviderSocketController) << "Unknown command or reply:" << receivedLine; +} + +AccountStatePtr FileProviderSocketController::accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier) +{ + Q_ASSERT(!domainIdentifier.isEmpty()); + + // We use Account's userIdAtHostWithPort() as the file provider domain's identifier in FileProviderDomainManager. + // We can use this string to get a matching account here. + const auto accountForReceivedDomainIdentifier = AccountManager::instance()->accountFromUserId(domainIdentifier); + if (!accountForReceivedDomainIdentifier) { + qCWarning(lcFileProviderSocketController) << "Could not find account matching user id matching file provider domain identifier:" + << domainIdentifier; + } + + return accountForReceivedDomainIdentifier; +} + void FileProviderSocketController::sendMessage(const QString &message) const { if (!_socket) { @@ -75,6 +120,20 @@ void FileProviderSocketController::sendMessage(const QString &message) const } } + +void FileProviderSocketController::start() +{ + Q_ASSERT(_socket); + requestFileProviderDomainInfo(); +} + +void FileProviderSocketController::requestFileProviderDomainInfo() const +{ + Q_ASSERT(_socket); + const auto requestMessage = QStringLiteral("SEND_FILE_PROVIDER_DOMAIN_IDENTIFIER"); + sendMessage(requestMessage); +} + } } diff --git a/src/gui/macOS/fileprovidersocketcontroller.h b/src/gui/macOS/fileprovidersocketcontroller.h index 54ad59c7bd..6e33214942 100644 --- a/src/gui/macOS/fileprovidersocketcontroller.h +++ b/src/gui/macOS/fileprovidersocketcontroller.h @@ -18,6 +18,8 @@ #include #include +#include "accountstate.h" + namespace OCC { namespace Mac { @@ -34,14 +36,21 @@ signals: public slots: void sendMessage(const QString &message) const; + void start(); private slots: void slotOnDisconnected(); void slotSocketDestroyed(QObject *object); void slotReadyRead(); + void parseReceivedLine(const QString &receivedLine); + void requestFileProviderDomainInfo() const; + private: + static AccountStatePtr accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier); + QPointer _socket; + AccountStatePtr _accountState; }; } // namespace Mac diff --git a/src/gui/macOS/fileprovidersocketserver.cpp b/src/gui/macOS/fileprovidersocketserver.cpp index 7ebf55ea59..06c0349976 100644 --- a/src/gui/macOS/fileprovidersocketserver.cpp +++ b/src/gui/macOS/fileprovidersocketserver.cpp @@ -66,6 +66,8 @@ void FileProviderSocketServer::slotNewConnection() connect(socketController.data(), &FileProviderSocketController::socketDestroyed, this, &FileProviderSocketServer::slotSocketDestroyed); _socketControllers.insert(socket, socketController); + + socketController->start(); } void FileProviderSocketServer::slotSocketDestroyed(const QLocalSocket * const socket)