File indexing completed on 2024-06-23 05:24:07

0001 // SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl>
0002 //
0003 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0004 
0005 #pragma once
0006 
0007 #include <filesystem>
0008 #include <memory>
0009 
0010 #include <QTcpServer>
0011 
0012 #include <freerdp/settings.h>
0013 
0014 #include "krdp_export.h"
0015 
0016 namespace KRdp
0017 {
0018 
0019 class RdpConnection;
0020 
0021 /**
0022  * Core RDP server class.
0023  *
0024  * This class listens for TCP connections and creates a new @c Session for each
0025  * incoming connection. It takes care of basic system initialisation. It also
0026  * stores connection and security settings.
0027  */
0028 class KRDP_EXPORT Server : public QTcpServer
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit Server(QObject *parent = nullptr);
0034     ~Server() override;
0035 
0036     /**
0037      * Start listening for incoming connections.
0038      *
0039      * Note that `address` and `port` should be set before calling this,
0040      * changing them after the server has started listening has no effect.
0041      */
0042     bool start();
0043     /**
0044      * Stop listening for incoming connections.
0045      */
0046     void stop();
0047 
0048     /**
0049      * The host address to listen on.
0050      *
0051      * Set this to an appropriate address for the server to listen on. Common
0052      * options are `0.0.0.0` to listen on all interfaces and accept all incoming
0053      * connections or `127.0.0.1` to only listen on the loopback interface and
0054      * only allow local connections.
0055      *
0056      * By default the address is set to QHostAddress::LocalHost
0057      */
0058     QHostAddress address() const;
0059     void setAddress(const QHostAddress &newAddress);
0060 
0061     /**
0062      * The port to listen on.
0063      *
0064      * By default this is set to 3389, which is the standard port used for RDP.
0065      */
0066     quint16 port() const;
0067     void setPort(quint16 newPort);
0068 
0069     /**
0070      * The username needed to log in to the server.
0071      *
0072      * Note that if this is changed while the server is running, it will only
0073      * take effect for new sessions.
0074      */
0075     QString userName() const;
0076     void setUserName(const QString &userName);
0077 
0078     /**
0079      * The password needed to log in to the server.
0080      *
0081      * Note that if this is changed while the server is running, it will only
0082      * take effect for new sessions.
0083      */
0084     QString password() const;
0085     void setPassword(const QString &password);
0086 
0087     /**
0088      * The path of a certificate file to use for encrypting communications.
0089      *
0090      * This is required to be set to a valid file, as the RDP login process only
0091      * works over an encrypted connection.
0092      */
0093     std::filesystem::path tlsCertificate() const;
0094     void setTlsCertificate(const std::filesystem::path &newTlsCertificate);
0095 
0096     /**
0097      * The path of a certificate key to use for encrypting communications.
0098      *
0099      * This is required to be set to a valid file, as the RDP login process only
0100      * works over an encrypted connection.
0101      */
0102     std::filesystem::path tlsCertificateKey() const;
0103     void setTlsCertificateKey(const std::filesystem::path &newTlsCertificateKey);
0104 
0105     /**
0106      * Emitted whenever a new connection is started.
0107      *
0108      * \param connection The new connection that was just started.
0109      */
0110     Q_SIGNAL void newConnection(RdpConnection *connection);
0111 
0112 protected:
0113     /**
0114      * Overridden from QTcpServer
0115      */
0116     void incomingConnection(qintptr handle) override;
0117 
0118 private:
0119     friend class RdpConnection;
0120     rdp_settings *rdpSettings() const;
0121 
0122     class Private;
0123     const std::unique_ptr<Private> d;
0124 };
0125 
0126 }