]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Initialise file provider socket controller by requesting file provder domain data...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 28 Dec 2022 21:28:30 +0000 (22:28 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 12 May 2023 05:21:08 +0000 (13:21 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderdomainmanager_mac.mm
src/gui/macOS/fileprovidersocketcontroller.cpp
src/gui/macOS/fileprovidersocketcontroller.h
src/gui/macOS/fileprovidersocketserver.cpp

index 6e670763b4e5c5c332471694f98cd7bacc511da0..41f59b980e88290cf23025f93f4739d80a312a65 100644 (file)
@@ -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;
 
index af90a22f05e200d035a440eb848e971b491f381d..ec54da294c03896a3845edd854218f642f022fca 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <QLoggingCategory>
 
+#include "accountmanager.h"
+
 namespace OCC {
 
 namespace Mac {
@@ -53,8 +55,51 @@ 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
@@ -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);
+}
+
 }
 
 }
index 54ad59c7bd280b9e81c820b4d8c5880e8fa3cbff..6e3321494271b6fb8799b93e46276460393c1d78 100644 (file)
@@ -18,6 +18,8 @@
 #include <QPointer>
 #include <QLocalSocket>
 
+#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<QLocalSocket> _socket;
+    AccountStatePtr _accountState;
 };
 
 } // namespace Mac
index 7ebf55ea59aba1b313274537158bec8ec16b5daa..06c0349976d5035936be74e5e1a79558bdb28799 100644 (file)
@@ -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)