1 /* 2 Copyright (C) 2009-2010 Collabora Ltd <info@collabora.co.uk> 3 @author George Goldberg <george.goldberg@collabora.co.uk> 4 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> 5 Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it> 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #ifndef RFBCLIENT_H 21 #define RFBCLIENT_H 22 23 #include "rfb.h" 24 #include <QObject> 25 26 class QSocketNotifier; 27 28 class RfbClient : public QObject 29 { 30 Q_OBJECT 31 Q_PROPERTY(bool controlEnabled READ controlEnabled WRITE setControlEnabled NOTIFY controlEnabledChanged) 32 Q_PROPERTY(bool onHold READ isOnHold WRITE setOnHold NOTIFY holdStatusChanged) 33 public: 34 explicit RfbClient(rfbClientPtr client, QObject *parent = nullptr); 35 ~RfbClient() override; 36 37 /** Returns a name for the client, to be shown to the user */ 38 virtual QString name() const; 39 40 static bool controlCanBeEnabled(); 41 bool controlEnabled() const; 42 bool isOnHold() const; 43 44 public Q_SLOTS: 45 void setControlEnabled(bool enabled); 46 void setOnHold(bool onHold); 47 void closeConnection(); 48 49 Q_SIGNALS: 50 void controlEnabledChanged(bool enabled); 51 void holdStatusChanged(bool onHold); 52 53 protected: 54 friend class RfbServer; //the following event handling methods are called by RfbServer 55 56 rfbClientPtr getRfbClientPtr(); 57 virtual void handleKeyboardEvent(bool down, rfbKeySym keySym); 58 virtual void handleMouseEvent(int buttonMask, int x, int y); 59 60 private Q_SLOTS: 61 void onSocketActivated(); 62 63 private: 64 ///called by RfbServerManager to send framebuffer updates 65 ///and check for possible disconnection 66 void update(); 67 friend class RfbServerManager; 68 69 struct Private; 70 Private *const d; 71 }; 72 73 74 class PendingRfbClient : public QObject 75 { 76 Q_OBJECT 77 public: 78 explicit PendingRfbClient(rfbClientPtr client, QObject *parent = nullptr); 79 ~PendingRfbClient() override; 80 81 Q_SIGNALS: 82 void finished(RfbClient *client); 83 84 protected Q_SLOTS: 85 virtual void processNewClient() = 0; 86 87 void accept(RfbClient *newClient); 88 void reject(); 89 90 protected: 91 92 friend class RfbServer; //Following two methods are handled by RfbServer 93 94 /** This method is supposed to check if the provided \a encryptedPassword 95 * matches the criteria for authenticating the client. 96 * The default implementation returns false if a password is required. 97 * Reimplement to do more useful stuff. 98 */ 99 virtual bool checkPassword(const QByteArray & encryptedPassword); 100 101 /** This method checks if the \a encryptedPassword that was sent from the remote 102 * user matches the \a password that you have specified locally to be the password 103 * for this connection. This assumes that the standard VNC authentication mechanism 104 * is used. Returns true if the password matches or false otherwise. 105 */ 106 bool vncAuthCheckPassword(const QByteArray & password, const QByteArray & encryptedPassword) const; 107 108 rfbClientPtr m_rfbClient; 109 110 private: 111 void onSocketActivated(); 112 113 QSocketNotifier *const m_notifier; 114 }; 115 116 #endif // RFBCLIENT_H 117