Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 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 | |
| 19 | #ifndef __VNCSERVER_WIN32_H__ |
| 20 | #define __VNCSERVER_WIN32_H__ |
| 21 | |
| 22 | #include <winsock2.h> |
| 23 | #include <network/TcpSocket.h> |
| 24 | #include <rfb/VNCServerST.h> |
| 25 | #include <rfb_win32/RegConfig.h> |
| 26 | #include <rfb_win32/SDisplay.h> |
| 27 | #include <rfb_win32/SocketManager.h> |
| 28 | #include <rfb_win32/TCharArray.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 29 | #include <winvnc/QueryConnectDialog.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 30 | #include <winvnc/ManagedListener.h> |
| 31 | |
Pierre Ossman | 338e73a | 2016-07-07 15:35:13 +0200 | [diff] [blame] | 32 | namespace os { |
| 33 | class Mutex; |
| 34 | class Condition; |
| 35 | class Thread; |
| 36 | } |
| 37 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 38 | namespace winvnc { |
| 39 | |
Pierre Ossman | 025326d | 2018-10-08 16:03:01 +0200 | [diff] [blame] | 40 | class ListConnInfo; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 41 | class STrayIconThread; |
| 42 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 43 | class VNCServerWin32 : rfb::win32::QueryConnectionHandler, |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 44 | rfb::win32::SocketManager::AddressChangeNotifier, |
| 45 | rfb::win32::RegConfig::Callback, |
| 46 | rfb::win32::EventHandler { |
| 47 | public: |
| 48 | VNCServerWin32(); |
| 49 | virtual ~VNCServerWin32(); |
| 50 | |
| 51 | // Run the server in the current thread |
| 52 | int run(); |
| 53 | |
| 54 | // Cause the run() call to return |
| 55 | // THREAD-SAFE |
| 56 | void stop(); |
| 57 | |
| 58 | // Determine whether a viewer is active |
| 59 | // THREAD-SAFE |
| 60 | bool isServerInUse() const {return isDesktopStarted;} |
| 61 | |
| 62 | // Connect out to the specified VNC Viewer |
| 63 | // THREAD-SAFE |
| 64 | bool addNewClient(const char* client); |
| 65 | |
| 66 | // Disconnect all connected clients |
| 67 | // THREAD-SAFE |
| 68 | bool disconnectClients(const char* reason=0); |
| 69 | |
| 70 | // Call used to notify VNCServerST of user accept/reject query completion |
| 71 | // CALLED FROM AcceptConnectDialog THREAD |
| 72 | void queryConnectionComplete(); |
| 73 | |
| 74 | // Where to read the configuration settings from |
| 75 | static const TCHAR* RegConfigPath; |
| 76 | |
Pierre Ossman | 025326d | 2018-10-08 16:03:01 +0200 | [diff] [blame] | 77 | bool getClientsInfo(ListConnInfo* LCInfo); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 78 | |
Pierre Ossman | 025326d | 2018-10-08 16:03:01 +0200 | [diff] [blame] | 79 | bool setClientsStatus(ListConnInfo* LCInfo); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 80 | |
| 81 | protected: |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 82 | // QueryConnectionHandler interface |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 83 | // Callback used to prompt user to accept or reject a connection. |
| 84 | // CALLBACK IN VNCServerST "HOST" THREAD |
Pierre Ossman | e6aab24 | 2018-10-05 16:59:22 +0200 | [diff] [blame] | 85 | virtual void queryConnection(network::Socket* sock, |
| 86 | const char* userName); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 87 | |
| 88 | // SocketManager::AddressChangeNotifier interface |
| 89 | // Used to keep tray icon up to date |
Pierre Ossman | 79f82f9 | 2015-03-17 13:44:00 +0100 | [diff] [blame] | 90 | virtual void processAddressChange(); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 91 | |
| 92 | // RegConfig::Callback interface |
klemens | 0536d09 | 2017-01-28 20:56:56 +0100 | [diff] [blame] | 93 | // Called via the EventManager whenever RegConfig sees the registry change |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 94 | virtual void regConfigChanged(); |
| 95 | |
| 96 | // EventHandler interface |
| 97 | // Used to perform queued commands |
| 98 | virtual void processEvent(HANDLE event); |
| 99 | |
Pierre Ossman | 025326d | 2018-10-08 16:03:01 +0200 | [diff] [blame] | 100 | void getConnInfo(ListConnInfo * listConn); |
| 101 | void setConnStatus(ListConnInfo* listConn); |
| 102 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 103 | protected: |
| 104 | // Perform a particular internal function in the server thread |
| 105 | typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command; |
| 106 | bool queueCommand(Command cmd, const void* data, int len, bool wait=true); |
| 107 | Command command; |
| 108 | const void* commandData; |
| 109 | int commandDataLen; |
Pierre Ossman | 338e73a | 2016-07-07 15:35:13 +0200 | [diff] [blame] | 110 | os::Mutex* commandLock; |
| 111 | os::Condition* commandSig; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 112 | rfb::win32::Handle commandEvent; |
Samuel Mannehed | 60c4193 | 2014-02-07 14:53:24 +0000 | [diff] [blame] | 113 | rfb::win32::Handle sessionEvent; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 114 | |
| 115 | // VNCServerWin32 Server-internal state |
| 116 | rfb::win32::SDisplay desktop; |
| 117 | rfb::VNCServerST vncServer; |
Pierre Ossman | 338e73a | 2016-07-07 15:35:13 +0200 | [diff] [blame] | 118 | os::Mutex* runLock; |
| 119 | DWORD thread_id; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 120 | bool runServer; |
| 121 | bool isDesktopStarted; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 122 | rfb::win32::SocketManager sockMgr; |
| 123 | rfb::win32::RegConfig config; |
| 124 | |
| 125 | ManagedListener rfbSock; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 126 | STrayIconThread* trayIcon; |
| 127 | |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 128 | QueryConnectDialog* queryConnectDialog; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | }; |
| 132 | |
| 133 | #endif |