File indexing completed on 2024-04-21 04:58:41

0001 /*
0002     Copyright (C) 2009-2010 Collabora Ltd <info@collabora.co.uk>
0003       @author George Goldberg <george.goldberg@collabora.co.uk>
0004       @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
0005     Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
0006 
0007     This program is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This program is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015     GNU General Public License for more details.
0016 
0017     You should have received a copy of the GNU Lesser General Public License
0018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 #ifndef RFBCLIENT_H
0021 #define RFBCLIENT_H
0022 
0023 #include "rfb.h"
0024 #include <QObject>
0025 
0026 class QSocketNotifier;
0027 
0028 class RfbClient : public QObject
0029 {
0030     Q_OBJECT
0031     Q_PROPERTY(bool controlEnabled READ controlEnabled WRITE setControlEnabled NOTIFY controlEnabledChanged)
0032     Q_PROPERTY(bool onHold READ isOnHold WRITE setOnHold NOTIFY holdStatusChanged)
0033 public:
0034     explicit RfbClient(rfbClientPtr client, QObject *parent = nullptr);
0035     ~RfbClient() override;
0036 
0037     /** Returns a name for the client, to be shown to the user */
0038     virtual QString name() const;
0039 
0040     static bool controlCanBeEnabled();
0041     bool controlEnabled() const;
0042     bool isOnHold() const;
0043 
0044 public Q_SLOTS:
0045     void setControlEnabled(bool enabled);
0046     void setOnHold(bool onHold);
0047     void closeConnection();
0048 
0049 Q_SIGNALS:
0050     void controlEnabledChanged(bool enabled);
0051     void holdStatusChanged(bool onHold);
0052 
0053 protected:
0054     friend class RfbServer; //the following event handling methods are called by RfbServer
0055 
0056     rfbClientPtr getRfbClientPtr();
0057     virtual void handleKeyboardEvent(bool down, rfbKeySym keySym);
0058     virtual void handleMouseEvent(int buttonMask, int x, int y);
0059 
0060 private Q_SLOTS:
0061     void onSocketActivated();
0062 
0063 private:
0064     ///called by RfbServerManager to send framebuffer updates
0065     ///and check for possible disconnection
0066     void update();
0067     friend class RfbServerManager;
0068 
0069     struct Private;
0070     Private *const d;
0071 };
0072 
0073 
0074 class PendingRfbClient : public QObject
0075 {
0076     Q_OBJECT
0077 public:
0078     explicit PendingRfbClient(rfbClientPtr client, QObject *parent = nullptr);
0079     ~PendingRfbClient() override;
0080 
0081 Q_SIGNALS:
0082     void finished(RfbClient *client);
0083 
0084 protected Q_SLOTS:
0085     virtual void processNewClient() = 0;
0086 
0087     void accept(RfbClient *newClient);
0088     void reject();
0089 
0090 protected:
0091 
0092     friend class RfbServer; //Following two methods are handled by RfbServer
0093 
0094     /** This method is supposed to check if the provided \a encryptedPassword
0095      * matches the criteria for authenticating the client.
0096      * The default implementation returns false if a password is required.
0097      * Reimplement to do more useful stuff.
0098      */
0099     virtual bool checkPassword(const QByteArray & encryptedPassword);
0100 
0101     /** This method checks if the \a encryptedPassword that was sent from the remote
0102      * user matches the \a password that you have specified locally to be the password
0103      * for this connection. This assumes that the standard VNC authentication mechanism
0104      * is used. Returns true if the password matches or false otherwise.
0105      */
0106     bool vncAuthCheckPassword(const QByteArray & password, const QByteArray & encryptedPassword) const;
0107 
0108     rfbClientPtr m_rfbClient;
0109 
0110 private:
0111     void onSocketActivated();
0112 
0113     QSocketNotifier *const m_notifier;
0114 };
0115 
0116 #endif // RFBCLIENT_H