You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VNCSConnectionST.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2019 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. //
  20. // VNCSConnectionST is our derived class of SConnection for VNCServerST - there
  21. // is one for each connected client. We think of VNCSConnectionST as part of
  22. // the VNCServerST implementation, so its methods are allowed full access to
  23. // members of VNCServerST.
  24. //
  25. #ifndef __RFB_VNCSCONNECTIONST_H__
  26. #define __RFB_VNCSCONNECTIONST_H__
  27. #include <map>
  28. #include <rfb/Congestion.h>
  29. #include <rfb/EncodeManager.h>
  30. #include <rfb/SConnection.h>
  31. #include <rfb/Timer.h>
  32. namespace rfb {
  33. class VNCServerST;
  34. class VNCSConnectionST : private SConnection,
  35. public Timer::Callback {
  36. public:
  37. VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
  38. virtual ~VNCSConnectionST();
  39. // SConnection methods
  40. virtual bool accessCheck(AccessRights ar) const;
  41. virtual void close(const char* reason);
  42. using SConnection::authenticated;
  43. // Methods called from VNCServerST. None of these methods ever knowingly
  44. // throw an exception.
  45. // init() must be called to initialise the protocol. If it fails it
  46. // returns false, and close() will have been called.
  47. bool init();
  48. // processMessages() processes incoming messages from the client, invoking
  49. // various callbacks as a result. It continues to process messages until
  50. // reading might block. shutdown() will be called on the connection's
  51. // Socket if an error occurs, via the close() call.
  52. void processMessages();
  53. // flushSocket() pushes any unwritten data on to the network.
  54. void flushSocket();
  55. // Called when the underlying pixelbuffer is resized or replaced.
  56. void pixelBufferChange();
  57. // Wrappers to make these methods "safe" for VNCServerST.
  58. void writeFramebufferUpdateOrClose();
  59. void screenLayoutChangeOrClose(rdr::U16 reason);
  60. void setCursorOrClose();
  61. void bellOrClose();
  62. void setDesktopNameOrClose(const char *name);
  63. void setLEDStateOrClose(unsigned int state);
  64. void approveConnectionOrClose(bool accept, const char* reason);
  65. void requestClipboardOrClose();
  66. void announceClipboardOrClose(bool available);
  67. void sendClipboardDataOrClose(const char* data);
  68. // The following methods never throw exceptions
  69. // getComparerState() returns if this client would like the framebuffer
  70. // comparer to be enabled.
  71. bool getComparerState();
  72. // renderedCursorChange() is called whenever the server-side rendered
  73. // cursor changes shape or position. It ensures that the next update will
  74. // clean up the old rendered cursor and if necessary draw the new rendered
  75. // cursor.
  76. void renderedCursorChange();
  77. // cursorPositionChange() is called whenever the cursor has changed position by
  78. // the server. If the client supports being informed about these changes then
  79. // it will arrange for the new cursor position to be sent to the client.
  80. void cursorPositionChange();
  81. // needRenderedCursor() returns true if this client needs the server-side
  82. // rendered cursor. This may be because it does not support local cursor
  83. // or because the current cursor position has not been set by this client.
  84. bool needRenderedCursor();
  85. network::Socket* getSock() { return sock; }
  86. // Change tracking
  87. void add_changed(const Region& region) { updates.add_changed(region); }
  88. void add_copied(const Region& dest, const Point& delta) {
  89. updates.add_copied(dest, delta);
  90. }
  91. const char* getPeerEndpoint() const {return peerEndpoint.buf;}
  92. private:
  93. // SConnection callbacks
  94. // These methods are invoked as callbacks from processMsg()
  95. virtual void authSuccess();
  96. virtual void queryConnection(const char* userName);
  97. virtual void clientInit(bool shared);
  98. virtual void setPixelFormat(const PixelFormat& pf);
  99. virtual void pointerEvent(const Point& pos, int buttonMask);
  100. virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
  101. virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
  102. virtual void setDesktopSize(int fb_width, int fb_height,
  103. const ScreenSet& layout);
  104. virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
  105. virtual void enableContinuousUpdates(bool enable,
  106. int x, int y, int w, int h);
  107. virtual void handleClipboardRequest();
  108. virtual void handleClipboardAnnounce(bool available);
  109. virtual void handleClipboardData(const char* data);
  110. virtual void supportsLocalCursor();
  111. virtual void supportsFence();
  112. virtual void supportsContinuousUpdates();
  113. virtual void supportsLEDState();
  114. // Timer callbacks
  115. virtual bool handleTimeout(Timer* t);
  116. // Internal methods
  117. bool isShiftPressed();
  118. // Congestion control
  119. void writeRTTPing();
  120. bool isCongested();
  121. // writeFramebufferUpdate() attempts to write a framebuffer update to the
  122. // client.
  123. void writeFramebufferUpdate();
  124. void writeNoDataUpdate();
  125. void writeDataUpdate();
  126. void writeLosslessRefresh();
  127. void screenLayoutChange(rdr::U16 reason);
  128. void setCursor();
  129. void setCursorPos();
  130. void setDesktopName(const char *name);
  131. void setLEDState(unsigned int state);
  132. private:
  133. network::Socket* sock;
  134. CharArray peerEndpoint;
  135. bool reverseConnection;
  136. bool inProcessMessages;
  137. bool pendingSyncFence, syncFence;
  138. rdr::U32 fenceFlags;
  139. unsigned fenceDataLen;
  140. char *fenceData;
  141. Congestion congestion;
  142. Timer congestionTimer;
  143. Timer losslessTimer;
  144. VNCServerST* server;
  145. SimpleUpdateTracker updates;
  146. Region requested;
  147. bool updateRenderedCursor, removeRenderedCursor;
  148. Region damagedCursorRegion;
  149. bool continuousUpdates;
  150. Region cuRegion;
  151. EncodeManager encodeManager;
  152. std::map<rdr::U32, rdr::U32> pressedKeys;
  153. Timer idleTimer;
  154. time_t pointerEventTime;
  155. Point pointerEventPos;
  156. bool clientHasCursor;
  157. CharArray closeReason;
  158. };
  159. }
  160. #endif