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 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2016 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 : public SConnection,
  35. public Timer::Callback {
  36. public:
  37. VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
  38. virtual ~VNCSConnectionST();
  39. // Methods called from VNCServerST. None of these methods ever knowingly
  40. // throw an exception.
  41. // Unless otherwise stated, the SConnectionST may not be valid after any of
  42. // these methods are called, since they catch exceptions and may have
  43. // called close() which deletes the object.
  44. // init() must be called to initialise the protocol. If it fails it
  45. // returns false, and close() will have been called.
  46. bool init();
  47. // close() shuts down the socket to the client and deletes the
  48. // SConnectionST object.
  49. void close(const char* reason);
  50. // processMessages() processes incoming messages from the client, invoking
  51. // various callbacks as a result. It continues to process messages until
  52. // reading might block. shutdown() will be called on the connection's
  53. // Socket if an error occurs, via the close() call.
  54. void processMessages();
  55. // flushSocket() pushes any unwritten data on to the network.
  56. void flushSocket();
  57. // Called when the underlying pixelbuffer is resized or replaced.
  58. void pixelBufferChange();
  59. // Wrappers to make these methods "safe" for VNCServerST.
  60. void writeFramebufferUpdateOrClose();
  61. void screenLayoutChangeOrClose(rdr::U16 reason);
  62. void setCursorOrClose();
  63. void bellOrClose();
  64. void serverCutTextOrClose(const char *str, int len);
  65. void setDesktopNameOrClose(const char *name);
  66. void setLEDStateOrClose(unsigned int state);
  67. void approveConnectionOrClose(bool accept, const char* reason);
  68. // checkIdleTimeout() returns the number of milliseconds left until the
  69. // idle timeout expires. If it has expired, the connection is closed and
  70. // zero is returned. Zero is also returned if there is no idle timeout.
  71. int checkIdleTimeout();
  72. // The following methods never throw exceptions nor do they ever delete the
  73. // SConnectionST object.
  74. // getComparerState() returns if this client would like the framebuffer
  75. // comparer to be enabled.
  76. bool getComparerState();
  77. // renderedCursorChange() is called whenever the server-side rendered
  78. // cursor changes shape or position. It ensures that the next update will
  79. // clean up the old rendered cursor and if necessary draw the new rendered
  80. // cursor.
  81. void renderedCursorChange();
  82. // needRenderedCursor() returns true if this client needs the server-side
  83. // rendered cursor. This may be because it does not support local cursor
  84. // or because the current cursor position has not been set by this client.
  85. bool needRenderedCursor();
  86. network::Socket* getSock() { return sock; }
  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. char* getStartTime();
  93. void setStatus(int status);
  94. int getStatus();
  95. private:
  96. // SConnection callbacks
  97. // These methods are invoked as callbacks from processMsg(). Note that
  98. // none of these methods should call any of the above methods which may
  99. // delete the SConnectionST object.
  100. virtual void authSuccess();
  101. virtual void queryConnection(const char* userName);
  102. virtual void clientInit(bool shared);
  103. virtual void setPixelFormat(const PixelFormat& pf);
  104. virtual void pointerEvent(const Point& pos, int buttonMask);
  105. virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
  106. virtual void clientCutText(const char* str, int len);
  107. virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
  108. virtual void setDesktopSize(int fb_width, int fb_height,
  109. const ScreenSet& layout);
  110. virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
  111. virtual void enableContinuousUpdates(bool enable,
  112. int x, int y, int w, int h);
  113. virtual void supportsLocalCursor();
  114. virtual void supportsFence();
  115. virtual void supportsContinuousUpdates();
  116. virtual void supportsLEDState();
  117. // setAccessRights() allows a security package to limit the access rights
  118. // of a VNCSConnectioST to the server. These access rights are applied
  119. // such that the actual rights granted are the minimum of the server's
  120. // default access settings and the connection's access settings.
  121. virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
  122. // Timer callbacks
  123. virtual bool handleTimeout(Timer* t);
  124. // Internal methods
  125. bool isShiftPressed();
  126. // Congestion control
  127. void writeRTTPing();
  128. bool isCongested();
  129. // writeFramebufferUpdate() attempts to write a framebuffer update to the
  130. // client.
  131. void writeFramebufferUpdate();
  132. void writeNoDataUpdate();
  133. void writeDataUpdate();
  134. void screenLayoutChange(rdr::U16 reason);
  135. void setCursor();
  136. void setDesktopName(const char *name);
  137. void setLEDState(unsigned int state);
  138. void setSocketTimeouts();
  139. network::Socket* sock;
  140. CharArray peerEndpoint;
  141. bool reverseConnection;
  142. bool inProcessMessages;
  143. bool pendingSyncFence, syncFence;
  144. rdr::U32 fenceFlags;
  145. unsigned fenceDataLen;
  146. char *fenceData;
  147. Congestion congestion;
  148. Timer congestionTimer;
  149. Timer losslessTimer;
  150. VNCServerST* server;
  151. SimpleUpdateTracker updates;
  152. Region requested;
  153. bool updateRenderedCursor, removeRenderedCursor;
  154. Region damagedCursorRegion;
  155. bool continuousUpdates;
  156. Region cuRegion;
  157. EncodeManager encodeManager;
  158. std::map<rdr::U32, rdr::U32> pressedKeys;
  159. time_t lastEventTime;
  160. time_t pointerEventTime;
  161. Point pointerEventPos;
  162. bool clientHasCursor;
  163. AccessRights accessRights;
  164. CharArray closeReason;
  165. time_t startTime;
  166. };
  167. }
  168. #endif