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.4KB

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