qa: Replace deprecated qVariantFromValue() by QVariant::fromValue()
[quassel.git] / src / core / identserver.h
index 5aa8273..f8fa094 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2018 by the Quassel Project                        *
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #pragma once
 
+#include <list>
+
+#include <QHash>
+#include <QObject>
+#include <QPointer>
+#include <QString>
 #include <QTcpServer>
 #include <QTcpSocket>
 
 #include "coreidentity.h"
 
-class IdentServer : public QObject {
-Q_OBJECT
+struct Request
+{
+    QPointer<QTcpSocket> socket;
+    uint16_t localPort;
+    QString query;
+    qint64 transactionId;
+    qint64 requestId;
+
+    friend bool operator==(const Request& a, const Request& b);
+
+    void respondSuccess(const QString& user);
+    void respondError(const QString& error);
+};
+
+class IdentServer : public QObject
+{
+    Q_OBJECT
+
 public:
-    IdentServer(bool strict, QObject *parent);
-    ~IdentServer();
+    IdentServer(QObject* parent = nullptr);
 
     bool startListening();
-    void stopListening(const QString &msg);
+    void stopListening(const QString& msg);
+    qint64 addWaitingSocket();
+
 public slots:
-    bool addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort);
-    bool removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort);
+    void addSocket(const CoreIdentity* identity,
+                   const QHostAddress& localAddress,
+                   quint16 localPort,
+                   const QHostAddress& peerAddress,
+                   quint16 peerPort,
+                   qint64 socketId);
+    void removeSocket(const CoreIdentity* identity,
+                      const QHostAddress& localAddress,
+                      quint16 localPort,
+                      const QHostAddress& peerAddress,
+                      quint16 peerPort,
+                      qint64 socketId);
 
 private slots:
     void incomingConnection();
-
     void respond();
 
 private:
-    QTcpServer _server, _v6server;
+    bool responseAvailable(Request request) const;
+
+    qint64 lowestSocketId() const;
 
-    bool _strict;
+    void processWaiting(qint64 socketId);
+
+    void removeWaitingSocket(qint64 socketId);
+
+    QTcpServer _server, _v6server;
 
     QHash<uint16_t, QString> _connections;
+    std::list<Request> _requestQueue;
+    std::list<qint64> _waiting;
+    qint64 _socketId{0};
+    qint64 _requestId{0};
 };