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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- VNCServerST.h
  19. // Single-threaded VNCServer implementation
  20. #ifndef __RFB_VNCSERVERST_H__
  21. #define __RFB_VNCSERVERST_H__
  22. #include <list>
  23. #include <rfb/SDesktop.h>
  24. #include <rfb/VNCServer.h>
  25. #include <rfb/Configuration.h>
  26. #include <rfb/LogWriter.h>
  27. #include <rfb/Blacklist.h>
  28. #include <rfb/Cursor.h>
  29. #include <network/Socket.h>
  30. #include <rfb/ListConnInfo.h>
  31. #include <rfb/ScreenSet.h>
  32. namespace rfb {
  33. class VNCSConnectionST;
  34. class ComparingUpdateTracker;
  35. class PixelBuffer;
  36. class KeyRemapper;
  37. class VNCServerST : public VNCServer, public network::SocketServer {
  38. public:
  39. // -=- Constructors
  40. // Create a server exporting the supplied desktop.
  41. VNCServerST(const char* name_, SDesktop* desktop_,
  42. SSecurityFactory* securityFactory_=0);
  43. virtual ~VNCServerST();
  44. // Methods overridden from SocketServer
  45. // addSocket
  46. // Causes the server to allocate an RFB-protocol management
  47. // structure for the socket & initialise it.
  48. virtual void addSocket(network::Socket* sock, bool outgoing=false);
  49. // removeSocket
  50. // Clean up any resources associated with the Socket
  51. virtual void removeSocket(network::Socket* sock);
  52. // processSocketEvent
  53. // Read more RFB data from the Socket. If an error occurs during
  54. // processing then shutdown() is called on the Socket, causing
  55. // removeSocket() to be called by the caller at a later time.
  56. virtual void processSocketEvent(network::Socket* sock);
  57. // checkTimeouts
  58. // Returns the number of milliseconds left until the next idle timeout
  59. // expires. If any have already expired, the corresponding connections
  60. // are closed. Zero is returned if there is no idle timeout.
  61. virtual int checkTimeouts();
  62. // Methods overridden from VNCServer
  63. virtual void setPixelBuffer(PixelBuffer* pb);
  64. virtual PixelBuffer* getPixelBuffer() const { return pb; }
  65. virtual void setColourMapEntries(int firstColour=0, int nColours=0);
  66. virtual void serverCutText(const char* str, int len);
  67. virtual void add_changed(const Region &region);
  68. virtual void add_copied(const Region &dest, const Point &delta);
  69. virtual bool clientsReadyForUpdate();
  70. virtual void tryUpdate();
  71. virtual void setCursor(int width, int height, const Point& hotspot,
  72. void* cursorData, void* mask);
  73. virtual void setCursorPos(const Point& p);
  74. virtual void setSSecurityFactory(SSecurityFactory* f) {securityFactory=f;}
  75. virtual void bell();
  76. // - Close all currently-connected clients, by calling
  77. // their close() method with the supplied reason.
  78. virtual void closeClients(const char* reason) {closeClients(reason, 0);}
  79. // VNCServerST-only methods
  80. // closeClients() closes all RFB sessions, except the specified one (if
  81. // any), and logs the specified reason for closure.
  82. void closeClients(const char* reason, network::Socket* sock);
  83. // getSockets() gets a list of sockets. This can be used to generate an
  84. // fd_set for calling select().
  85. void getSockets(std::list<network::Socket*>* sockets);
  86. // getSConnection() gets the SConnection for a particular Socket. If
  87. // the Socket is not recognised then null is returned.
  88. SConnection* getSConnection(network::Socket* sock);
  89. // getDesktopSize() returns the size of the SDesktop exported by this
  90. // server.
  91. Point getDesktopSize() const {return desktop->getFbSize();}
  92. // getName() returns the name of this VNC Server. NB: The value returned
  93. // is the server's internal buffer which may change after any other methods
  94. // are called - take a copy if necessary.
  95. const char* getName() const {return name.buf;}
  96. // setName() specifies the desktop name that the server should provide to
  97. // clients
  98. virtual void setName(const char* name_);
  99. // A QueryConnectionHandler, if supplied, is passed details of incoming
  100. // connections to approve, reject, or query the user about.
  101. //
  102. // queryConnection() is called when a connection has been
  103. // successfully authenticated. The sock and userName arguments identify
  104. // the socket and the name of the authenticated user, if any. It should
  105. // return ACCEPT if the connection should be accepted, REJECT if it should
  106. // be rejected, or PENDING if a decision cannot yet be reached. If REJECT
  107. // is returned, *reason can be set to a string describing the reason - this
  108. // will be delete[]ed when it is finished with. If PENDING is returned,
  109. // approveConnection() must be called some time later to accept or reject
  110. // the connection.
  111. enum queryResult { ACCEPT, REJECT, PENDING };
  112. struct QueryConnectionHandler {
  113. virtual ~QueryConnectionHandler() {}
  114. virtual queryResult queryConnection(network::Socket* sock,
  115. const char* userName,
  116. char** reason) = 0;
  117. };
  118. void setQueryConnectionHandler(QueryConnectionHandler* qch) {
  119. queryConnectionHandler = qch;
  120. }
  121. // queryConnection is called as described above, and either passes the
  122. // request on to the registered handler, or accepts the connection if
  123. // no handler has been specified.
  124. virtual queryResult queryConnection(network::Socket* sock,
  125. const char* userName,
  126. char** reason) {
  127. return queryConnectionHandler
  128. ? queryConnectionHandler->queryConnection(sock, userName, reason)
  129. : ACCEPT;
  130. }
  131. // approveConnection() is called by the active QueryConnectionHandler,
  132. // some time after queryConnection() has returned with PENDING, to accept
  133. // or reject the connection. The accept argument should be true for
  134. // acceptance, or false for rejection, in which case a string reason may
  135. // also be given.
  136. void approveConnection(network::Socket* sock, bool accept,
  137. const char* reason);
  138. // setBlacklist() is called to replace the VNCServerST's internal
  139. // Blacklist instance with another instance. This allows a single
  140. // Blacklist to be shared by multiple VNCServerST instances.
  141. void setBlacklist(Blacklist* bl) {blHosts = bl ? bl : &blacklist;}
  142. // setEconomicTranslate() determines (for new connections) whether pixels
  143. // should be translated for <=16bpp clients using a large lookup table
  144. // (fast) or separate, smaller R, G and B tables (slower). If set to true,
  145. // small tables are used, to save memory.
  146. void setEconomicTranslate(bool et) { useEconomicTranslate = et; }
  147. // setKeyRemapper() replaces the VNCServerST's default key remapper.
  148. // NB: A null pointer is valid here.
  149. void setKeyRemapper(KeyRemapper* kr) { keyRemapper = kr; }
  150. void getConnInfo(ListConnInfo * listConn);
  151. void setConnStatus(ListConnInfo* listConn);
  152. bool getDisable() { return disableclients;};
  153. void setDisable(bool disable) { disableclients = disable;};
  154. protected:
  155. friend class VNCSConnectionST;
  156. void startDesktop();
  157. static LogWriter connectionsLog;
  158. Blacklist blacklist;
  159. Blacklist* blHosts;
  160. SDesktop* desktop;
  161. bool desktopStarted;
  162. PixelBuffer* pb;
  163. ScreenSet screenLayout;
  164. CharArray name;
  165. std::list<VNCSConnectionST*> clients;
  166. VNCSConnectionST* pointerClient;
  167. std::list<network::Socket*> closingSockets;
  168. ComparingUpdateTracker* comparer;
  169. Point cursorPos;
  170. Cursor cursor;
  171. Point cursorTL() { return cursorPos.subtract(cursor.hotspot); }
  172. Point renderedCursorTL;
  173. ManagedPixelBuffer renderedCursor;
  174. bool renderedCursorInvalid;
  175. // - Check how many of the clients are authenticated.
  176. int authClientCount();
  177. bool needRenderedCursor();
  178. void checkUpdate();
  179. SSecurityFactory* securityFactory;
  180. QueryConnectionHandler* queryConnectionHandler;
  181. KeyRemapper* keyRemapper;
  182. bool useEconomicTranslate;
  183. time_t lastUserInputTime;
  184. time_t lastDisconnectTime;
  185. time_t lastConnectionTime;
  186. bool disableclients;
  187. };
  188. };
  189. #endif