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.

VNCServerST.h 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. // -=- VNCServerST.h
  20. // Single-threaded VNCServer implementation
  21. #ifndef __RFB_VNCSERVERST_H__
  22. #define __RFB_VNCSERVERST_H__
  23. #include <sys/time.h>
  24. #include <rfb/SDesktop.h>
  25. #include <rfb/VNCServer.h>
  26. #include <rfb/LogWriter.h>
  27. #include <rfb/Blacklist.h>
  28. #include <rfb/Cursor.h>
  29. #include <rfb/Timer.h>
  30. #include <network/Socket.h>
  31. #include <rfb/ScreenSet.h>
  32. namespace rfb {
  33. class VNCSConnectionST;
  34. class ComparingUpdateTracker;
  35. class ListConnInfo;
  36. class PixelBuffer;
  37. class KeyRemapper;
  38. class VNCServerST : public VNCServer,
  39. public Timer::Callback,
  40. public network::SocketServer {
  41. public:
  42. // -=- Constructors
  43. // Create a server exporting the supplied desktop.
  44. VNCServerST(const char* name_, SDesktop* desktop_);
  45. virtual ~VNCServerST();
  46. // Methods overridden from SocketServer
  47. // addSocket
  48. // Causes the server to allocate an RFB-protocol management
  49. // structure for the socket & initialise it.
  50. virtual void addSocket(network::Socket* sock, bool outgoing=false);
  51. // removeSocket
  52. // Clean up any resources associated with the Socket
  53. virtual void removeSocket(network::Socket* sock);
  54. // getSockets() gets a list of sockets. This can be used to generate an
  55. // fd_set for calling select().
  56. virtual void getSockets(std::list<network::Socket*>* sockets);
  57. // processSocketReadEvent
  58. // Read more RFB data from the Socket. If an error occurs during
  59. // processing then shutdown() is called on the Socket, causing
  60. // removeSocket() to be called by the caller at a later time.
  61. virtual void processSocketReadEvent(network::Socket* sock);
  62. // processSocketWriteEvent
  63. // Flush pending data from the Socket on to the network.
  64. virtual void processSocketWriteEvent(network::Socket* sock);
  65. // checkTimeouts
  66. // Returns the number of milliseconds left until the next idle timeout
  67. // expires. If any have already expired, the corresponding connections
  68. // are closed. Zero is returned if there is no idle timeout.
  69. virtual int checkTimeouts();
  70. // Methods overridden from VNCServer
  71. virtual void blockUpdates();
  72. virtual void unblockUpdates();
  73. virtual void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout);
  74. virtual void setPixelBuffer(PixelBuffer* pb);
  75. virtual void setScreenLayout(const ScreenSet& layout);
  76. virtual PixelBuffer* getPixelBuffer() const { return pb; }
  77. virtual void serverCutText(const char* str, int len);
  78. virtual void add_changed(const Region &region);
  79. virtual void add_copied(const Region &dest, const Point &delta);
  80. virtual void setCursor(int width, int height, const Point& hotspot,
  81. const rdr::U8* data);
  82. virtual void setCursorPos(const Point& p);
  83. virtual void setLEDState(unsigned state);
  84. virtual void bell();
  85. // - Close all currently-connected clients, by calling
  86. // their close() method with the supplied reason.
  87. virtual void closeClients(const char* reason) {closeClients(reason, 0);}
  88. // VNCServerST-only methods
  89. // closeClients() closes all RFB sessions, except the specified one (if
  90. // any), and logs the specified reason for closure.
  91. void closeClients(const char* reason, network::Socket* sock);
  92. // getSConnection() gets the SConnection for a particular Socket. If
  93. // the Socket is not recognised then null is returned.
  94. SConnection* getSConnection(network::Socket* sock);
  95. // getName() returns the name of this VNC Server. NB: The value returned
  96. // is the server's internal buffer which may change after any other methods
  97. // are called - take a copy if necessary.
  98. const char* getName() const {return name.buf;}
  99. // setName() specifies the desktop name that the server should provide to
  100. // clients
  101. virtual void setName(const char* name_);
  102. // A QueryConnectionHandler, if supplied, is passed details of incoming
  103. // connections to approve, reject, or query the user about.
  104. //
  105. // queryConnection() is called when a connection has been
  106. // successfully authenticated. The sock and userName arguments identify
  107. // the socket and the name of the authenticated user, if any.
  108. // approveConnection() must be called some time later to accept or reject
  109. // the connection.
  110. struct QueryConnectionHandler {
  111. virtual ~QueryConnectionHandler() {}
  112. virtual void queryConnection(network::Socket* sock,
  113. const char* userName) = 0;
  114. };
  115. void setQueryConnectionHandler(QueryConnectionHandler* qch) {
  116. queryConnectionHandler = qch;
  117. }
  118. // queryConnection is called as described above, and either passes the
  119. // request on to the registered handler, or accepts the connection if
  120. // no handler has been specified.
  121. virtual void queryConnection(network::Socket* sock,
  122. const char* userName) {
  123. if (queryConnectionHandler) {
  124. queryConnectionHandler->queryConnection(sock, userName);
  125. return;
  126. }
  127. approveConnection(sock, true, NULL);
  128. }
  129. // approveConnection() is called by the active QueryConnectionHandler,
  130. // some time after queryConnection() has returned with PENDING, to accept
  131. // or reject the connection. The accept argument should be true for
  132. // acceptance, or false for rejection, in which case a string reason may
  133. // also be given.
  134. void approveConnection(network::Socket* sock, bool accept,
  135. const char* reason);
  136. // setBlacklist() is called to replace the VNCServerST's internal
  137. // Blacklist instance with another instance. This allows a single
  138. // Blacklist to be shared by multiple VNCServerST instances.
  139. void setBlacklist(Blacklist* bl) {blHosts = bl ? bl : &blacklist;}
  140. // setKeyRemapper() replaces the VNCServerST's default key remapper.
  141. // NB: A null pointer is valid here.
  142. void setKeyRemapper(KeyRemapper* kr) { keyRemapper = kr; }
  143. void getConnInfo(ListConnInfo * listConn);
  144. void setConnStatus(ListConnInfo* listConn);
  145. bool getDisable() { return disableclients;};
  146. void setDisable(bool disable) { disableclients = disable;};
  147. protected:
  148. friend class VNCSConnectionST;
  149. // Timer callbacks
  150. virtual bool handleTimeout(Timer* t);
  151. // - Internal methods
  152. void startDesktop();
  153. void stopDesktop();
  154. static LogWriter connectionsLog;
  155. Blacklist blacklist;
  156. Blacklist* blHosts;
  157. SDesktop* desktop;
  158. bool desktopStarted;
  159. int blockCounter;
  160. PixelBuffer* pb;
  161. ScreenSet screenLayout;
  162. unsigned int ledState;
  163. CharArray name;
  164. std::list<VNCSConnectionST*> clients;
  165. VNCSConnectionST* pointerClient;
  166. std::list<network::Socket*> closingSockets;
  167. ComparingUpdateTracker* comparer;
  168. Point cursorPos;
  169. Cursor* cursor;
  170. RenderedCursor renderedCursor;
  171. bool renderedCursorInvalid;
  172. // - Check how many of the clients are authenticated.
  173. int authClientCount();
  174. bool needRenderedCursor();
  175. void startFrameClock();
  176. void stopFrameClock();
  177. int msToNextUpdate();
  178. void writeUpdate();
  179. Region getPendingRegion();
  180. const RenderedCursor* getRenderedCursor();
  181. void notifyScreenLayoutChange(VNCSConnectionST *requester);
  182. bool getComparerState();
  183. QueryConnectionHandler* queryConnectionHandler;
  184. KeyRemapper* keyRemapper;
  185. time_t lastUserInputTime;
  186. time_t lastDisconnectTime;
  187. time_t lastConnectionTime;
  188. bool disableclients;
  189. Timer frameTimer;
  190. };
  191. };
  192. #endif