From 025326dd94070ba790e4c1f8596b93ce96fd5be4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 8 Oct 2018 16:03:01 +0200 Subject: [PATCH] Move ListConnInfo to WinVNC directory It is functionality specific to WinVNC, so move the code there to make things more clear. --- common/network/Socket.h | 2 - common/rfb/VNCSConnectionST.cxx | 44 +----------- common/rfb/VNCSConnectionST.h | 6 -- common/rfb/VNCServerST.cxx | 37 +--------- common/rfb/VNCServerST.h | 8 --- win/rfb_win32/SocketManager.cxx | 29 +++++++- win/rfb_win32/SocketManager.h | 4 ++ win/winvnc/ControlPanel.cxx | 9 ++- win/winvnc/ControlPanel.h | 12 ++-- {common/rfb => win/winvnc}/ListConnInfo.h | 27 +++---- win/winvnc/STrayIcon.cxx | 4 +- win/winvnc/VNCServerWin32.cxx | 88 +++++++++++++++++++++-- win/winvnc/VNCServerWin32.h | 8 ++- 13 files changed, 146 insertions(+), 132 deletions(-) rename {common/rfb => win/winvnc}/ListConnInfo.h (80%) diff --git a/common/network/Socket.h b/common/network/Socket.h index bfda8a57..c7d06c3e 100644 --- a/common/network/Socket.h +++ b/common/network/Socket.h @@ -151,8 +151,6 @@ namespace network { // there is no timeout and checkTimeouts() should be called the next time // an event occurs. virtual int checkTimeouts() = 0; - - virtual bool getDisable() {return false;}; }; } diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 50e6d88b..7b261e74 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -52,7 +52,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, losslessTimer(this), server(server_), updates(false), updateRenderedCursor(false), removeRenderedCursor(false), continuousUpdates(false), encodeManager(this), pointerEventTime(0), - clientHasCursor(false), startTime(time(0)) + clientHasCursor(false) { setStreams(&sock->inStream(), &sock->outStream()); peerEndpoint.buf = sock->getPeerEndpoint(); @@ -429,7 +429,6 @@ void VNCSConnectionST::authSuccess() // - Mark the entire display as "dirty" updates.add_changed(server->getPixelBuffer()->getRect()); - startTime = time(0); } void VNCSConnectionST::queryConnection(const char* userName) @@ -1113,44 +1112,3 @@ void VNCSConnectionST::setSocketTimeouts() sock->inStream().setTimeout(timeoutms); sock->outStream().setTimeout(timeoutms); } - -char* VNCSConnectionST::getStartTime() -{ - char* result = ctime(&startTime); - result[24] = '\0'; - return result; -} - -void VNCSConnectionST::setStatus(int status) -{ - AccessRights ar; - - ar = AccessDefault; - - switch (status) { - case 0: - ar |= AccessPtrEvents | AccessKeyEvents | AccessView; - break; - case 1: - ar |= rfb::SConnection::AccessView; - ar &= ~(AccessPtrEvents | AccessKeyEvents); - break; - case 2: - ar &= ~(AccessPtrEvents | AccessKeyEvents | AccessView); - break; - } - - setAccessRights(ar); - - framebufferUpdateRequest(server->getPixelBuffer()->getRect(), false); -} -int VNCSConnectionST::getStatus() -{ - if (accessCheck(AccessPtrEvents | AccessKeyEvents | AccessView)) - return 0; - else if (accessCheck(AccessView)) - return 1; - else - return 2; -} - diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index 121ebcc1..4fe92b00 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -112,11 +112,6 @@ namespace rfb { const char* getPeerEndpoint() const {return peerEndpoint.buf;} - char* getStartTime(); - - void setStatus(int status); - int getStatus(); - private: // SConnection callbacks @@ -198,7 +193,6 @@ namespace rfb { bool clientHasCursor; CharArray closeReason; - time_t startTime; }; } #endif diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index e09e085f..cf2a1144 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -53,7 +53,6 @@ #include #include -#include #include #include #include @@ -82,8 +81,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_) cursor(new Cursor(0, 0, Point(), NULL)), renderedCursorInvalid(false), keyRemapper(&KeyRemapper::defInstance), - lastConnectionTime(0), disableclients(false), - frameTimer(this) + lastConnectionTime(0), frameTimer(this) { lastUserInputTime = lastDisconnectTime = time(0); slog.debug("creating single-threaded server %s", name.buf); @@ -842,39 +840,6 @@ const RenderedCursor* VNCServerST::getRenderedCursor() return &renderedCursor; } -void VNCServerST::getConnInfo(ListConnInfo * listConn) -{ - listConn->Clear(); - listConn->setDisable(getDisable()); - if (clients.empty()) - return; - std::list::iterator i; - for (i = clients.begin(); i != clients.end(); i++) - listConn->addInfo((void*)(*i), (*i)->getSock()->getPeerAddress(), - (*i)->getStartTime(), (*i)->getStatus()); -} - -void VNCServerST::setConnStatus(ListConnInfo* listConn) -{ - setDisable(listConn->getDisable()); - if (listConn->Empty() || clients.empty()) return; - for (listConn->iBegin(); !listConn->iEnd(); listConn->iNext()) { - VNCSConnectionST* conn = (VNCSConnectionST*)listConn->iGetConn(); - std::list::iterator i; - for (i = clients.begin(); i != clients.end(); i++) { - if ((*i) == conn) { - int status = listConn->iGetStatus(); - if (status == 3) { - (*i)->close(0); - } else { - (*i)->setStatus(status); - } - break; - } - } - } -} - bool VNCServerST::getComparerState() { if (rfb::Server::compareFB == 0) diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h index ed8561a8..4dc384d4 100644 --- a/common/rfb/VNCServerST.h +++ b/common/rfb/VNCServerST.h @@ -144,12 +144,6 @@ namespace rfb { // NB: A null pointer is valid here. void setKeyRemapper(KeyRemapper* kr) { keyRemapper = kr; } - void getConnInfo(ListConnInfo * listConn); - void setConnStatus(ListConnInfo* listConn); - - bool getDisable() { return disableclients;}; - void setDisable(bool disable) { disableclients = disable;}; - // clientReady() is called by a VNCSConnectionST instance when the // client has completed the handshake and is ready for normal // communication. @@ -214,8 +208,6 @@ namespace rfb { time_t lastDisconnectTime; time_t lastConnectionTime; - bool disableclients; - Timer frameTimer; }; diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 5b211a0d..aa469e53 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -78,6 +78,7 @@ void SocketManager::addListener(network::SocketListener* sock_, li.sock = sock_; li.server = srvr; li.notifier = acn; + li.disable = false; listeners[event] = li; } @@ -128,6 +129,32 @@ void SocketManager::remSocket(network::Socket* sock_) { throw rdr::Exception("Socket not registered"); } +bool SocketManager::getDisable(network::SocketServer* srvr) +{ + std::map::iterator i; + for (i=listeners.begin(); i!=listeners.end(); i++) { + if (i->second.server == srvr) { + return i->second.disable; + } + } + throw rdr::Exception("Listener not registered"); +} + +void SocketManager::setDisable(network::SocketServer* srvr, bool disable) +{ + bool found = false; + std::map::iterator i; + for (i=listeners.begin(); i!=listeners.end(); i++) { + if (i->second.server == srvr) { + i->second.disable = disable; + // There might be multiple sockets for the same server, so + // continue iterating + found = true; + } + } + if (!found) + throw rdr::Exception("Listener not registered"); +} int SocketManager::checkTimeouts() { int timeout = EventManager::checkTimeouts(); @@ -164,7 +191,7 @@ void SocketManager::processEvent(HANDLE event) { WSAEnumNetworkEvents(li.sock->getFd(), event, &network_events); if (network_events.lNetworkEvents & FD_ACCEPT) { network::Socket* new_sock = li.sock->accept(); - if (new_sock && li.server->getDisable()) { + if (new_sock && li.disable) { delete new_sock; new_sock = 0; } diff --git a/win/rfb_win32/SocketManager.h b/win/rfb_win32/SocketManager.h index c3c8fafd..e5ca02e6 100644 --- a/win/rfb_win32/SocketManager.h +++ b/win/rfb_win32/SocketManager.h @@ -65,6 +65,9 @@ namespace rfb { // the SocketServer. void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true); + bool getDisable(network::SocketServer* srvr); + void setDisable(network::SocketServer* srvr, bool disable); + protected: virtual int checkTimeouts(); virtual void processEvent(HANDLE event); @@ -78,6 +81,7 @@ namespace rfb { network::SocketListener* sock; network::SocketServer* server; AddressChangeNotifier* notifier; + bool disable; }; std::map listeners; std::map connections; diff --git a/win/winvnc/ControlPanel.cxx b/win/winvnc/ControlPanel.cxx index ba6cab2c..e7262287 100644 --- a/win/winvnc/ControlPanel.cxx +++ b/win/winvnc/ControlPanel.cxx @@ -19,10 +19,9 @@ void ControlPanel::initDialog() { TCHAR *ColumnsStrings[] = { (TCHAR *) "IP address", - (TCHAR *) "Time connected", (TCHAR *) "Status" }; - InitLVColumns(IDC_LIST_CONNECTIONS, handle, 120, 3, ColumnsStrings, + InitLVColumns(IDC_LIST_CONNECTIONS, handle, 120, 2, ColumnsStrings, LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM, LVS_EX_FULLROWSELECT, LVCFMT_LEFT); SendCommand(4, -1); @@ -74,7 +73,7 @@ bool ControlPanel::onCommand(int cmd) } -void ControlPanel::UpdateListView(rfb::ListConnInfo* LCInfo) +void ControlPanel::UpdateListView(ListConnInfo* LCInfo) { getSelConnInfo(); DeleteAllLVItem(IDC_LIST_CONNECTIONS, handle); @@ -85,12 +84,12 @@ void ControlPanel::UpdateListView(rfb::ListConnInfo* LCInfo) ListConn.Copy(LCInfo); - char* ItemString[3]; + char* ItemString[2]; int i = 0; for (ListConn.iBegin(); !ListConn.iEnd(); ListConn.iNext()) { ListConn.iGetCharInfo(ItemString); - InsertLVItem(IDC_LIST_CONNECTIONS, handle, i, (TCHAR **) ItemString, 3); + InsertLVItem(IDC_LIST_CONNECTIONS, handle, i, (TCHAR **) ItemString, 2); for (ListSelConn.iBegin(); !ListSelConn.iEnd(); ListSelConn.iNext()) { if (ListSelConn.iGetConn() == ListConn.iGetConn()) SelectLVItem(IDC_LIST_CONNECTIONS, handle, i); diff --git a/win/winvnc/ControlPanel.h b/win/winvnc/ControlPanel.h index 73b859f8..f64a6081 100644 --- a/win/winvnc/ControlPanel.h +++ b/win/winvnc/ControlPanel.h @@ -11,10 +11,10 @@ #include #include +#include #include #include #include -#include namespace winvnc { @@ -27,19 +27,19 @@ namespace winvnc { virtual bool showDialog(); virtual void initDialog(); virtual bool onCommand(int cmd); - void UpdateListView(rfb::ListConnInfo* LCInfo); + void UpdateListView(ListConnInfo* LCInfo); HWND GetHandle() {return handle;}; void SendCommand(DWORD command, int data); ~ControlPanel(); - rfb::ListConnInfo ListConnStatus; + ListConnInfo ListConnStatus; protected: virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void getSelConnInfo(); HWND m_hSTIcon; - rfb::ListConnInfo ListConn; - rfb::ListConnInfo ListSelConn; + ListConnInfo ListConn; + ListConnInfo ListSelConn; bool stop_updating; }; }; -#endif \ No newline at end of file +#endif diff --git a/common/rfb/ListConnInfo.h b/win/winvnc/ListConnInfo.h similarity index 80% rename from common/rfb/ListConnInfo.h rename to win/winvnc/ListConnInfo.h index c49947da..6ca5b7c7 100644 --- a/common/rfb/ListConnInfo.h +++ b/win/winvnc/ListConnInfo.h @@ -24,7 +24,7 @@ #include -namespace rfb { +namespace winvnc { struct ListConnInfo { ListConnInfo() : disableClients(false) {} @@ -32,7 +32,6 @@ namespace rfb { void Clear() { conn.clear(); IP_address.clear(); - time_conn.clear(); status.clear(); } @@ -41,7 +40,6 @@ namespace rfb { void iBegin() { ci = conn.begin(); Ii = IP_address.begin(); - ti = time_conn.begin(); si = status.begin(); } @@ -50,32 +48,29 @@ namespace rfb { void iNext() { ci++; Ii++; - ti++; si++; } - void addInfo(void* Conn, char* IP, char* Time, int Status) { + void addInfo(void* Conn, char* IP, int Status) { conn.push_back(Conn); - IP_address.push_back(strDup(IP)); - time_conn.push_back(strDup(Time)); + IP_address.push_back(rfb::strDup(IP)); status.push_back(Status); } - void iGetCharInfo(char* buf[3]) { + void iGetCharInfo(char* buf[2]) { buf[0] = *Ii; - buf[1] = *ti; switch (*si) { case 0: - buf[2] = strDup("Full control"); + buf[1] = rfb::strDup("Full control"); break; case 1: - buf[2] = strDup("View only"); + buf[1] = rfb::strDup("View only"); break; case 2: - buf[2] = strDup("Stop updating"); + buf[1] = rfb::strDup("Stop updating"); break; default: - buf[2] = strDup("Unknown"); + buf[1] = rfb::strDup("Unknown"); } } @@ -95,9 +90,9 @@ namespace rfb { } void iAdd (ListConnInfo* InputList) { - char* buf[3]; + char* buf[2]; InputList->iGetCharInfo(buf); - addInfo(InputList->iGetConn(), buf[0], buf[1], InputList->iGetStatus()); + addInfo(InputList->iGetConn(), buf[0], InputList->iGetStatus()); } void setDisable(bool disable) {disableClients = disable;} @@ -113,11 +108,9 @@ namespace rfb { private: std::list conn; std::list IP_address; - std::list time_conn; std::list status; std::list::iterator ci; std::list::iterator Ii; - std::list::iterator ti; std::list::iterator si; bool disableClients; }; diff --git a/win/winvnc/STrayIcon.cxx b/win/winvnc/STrayIcon.cxx index 05a38d6e..fa483ee0 100644 --- a/win/winvnc/STrayIcon.cxx +++ b/win/winvnc/STrayIcon.cxx @@ -184,7 +184,7 @@ public: case 2: return thread.server.disconnectClients("IPC disconnect") ? 1 : 0; case 3: - thread.server.setClientsStatus((rfb::ListConnInfo *)command->lpData); + thread.server.setClientsStatus((ListConnInfo *)command->lpData); case 4: thread.server.getClientsInfo(&LCInfo); CPanel->UpdateListView(&LCInfo); @@ -230,7 +230,7 @@ protected: LaunchProcess vncConnect; STrayIconThread& thread; ControlPanel * CPanel; - rfb::ListConnInfo LCInfo; + ListConnInfo LCInfo; }; diff --git a/win/winvnc/VNCServerWin32.cxx b/win/winvnc/VNCServerWin32.cxx index 771ef78a..03b1bca7 100644 --- a/win/winvnc/VNCServerWin32.cxx +++ b/win/winvnc/VNCServerWin32.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -239,11 +240,11 @@ bool VNCServerWin32::addNewClient(const char* client) { return false; } -bool VNCServerWin32::getClientsInfo(rfb::ListConnInfo* LCInfo) { +bool VNCServerWin32::getClientsInfo(ListConnInfo* LCInfo) { return queueCommand(GetClientsInfo, LCInfo, 0); } -bool VNCServerWin32::setClientsStatus(rfb::ListConnInfo* LCInfo) { +bool VNCServerWin32::setClientsStatus(ListConnInfo* LCInfo) { return queueCommand(SetClientsStatus, LCInfo, 0); } @@ -307,10 +308,10 @@ void VNCServerWin32::processEvent(HANDLE event_) { sockMgr.addSocket((network::Socket*)commandData, &vncServer); break; case GetClientsInfo: - vncServer.getConnInfo((ListConnInfo*)commandData); + getConnInfo((ListConnInfo*)commandData); break; case SetClientsStatus: - vncServer.setConnStatus((ListConnInfo*)commandData); + setConnStatus((ListConnInfo*)commandData); break; case QueryConnectionComplete: @@ -339,3 +340,82 @@ void VNCServerWin32::processEvent(HANDLE event_) { } } +void VNCServerWin32::getConnInfo(ListConnInfo * listConn) +{ + std::list sockets; + std::list::iterator i; + + listConn->Clear(); + listConn->setDisable(sockMgr.getDisable(&vncServer)); + + vncServer.getSockets(&sockets); + + for (i = sockets.begin(); i != sockets.end(); i++) { + rfb::SConnection* conn; + int status; + + conn = vncServer.getConnection(*i); + if (!conn) + continue; + + if (conn->accessCheck(rfb::SConnection::AccessPtrEvents | + rfb::SConnection::AccessKeyEvents | + rfb::SConnection::AccessView)) + status = 0; + else if (conn->accessCheck(rfb::SConnection::AccessView)) + status = 1; + else + status = 2; + + listConn->addInfo((void*)(*i), (*i)->getPeerAddress(), status); + } +} + +void VNCServerWin32::setConnStatus(ListConnInfo* listConn) +{ + sockMgr.setDisable(&vncServer, listConn->getDisable()); + + if (listConn->Empty()) + return; + + for (listConn->iBegin(); !listConn->iEnd(); listConn->iNext()) { + network::Socket* sock; + rfb::SConnection* conn; + int status; + + sock = (network::Socket*)listConn->iGetConn(); + + conn = vncServer.getConnection(sock); + if (!conn) + continue; + + status = listConn->iGetStatus(); + if (status == 3) { + conn->close(0); + } else { + rfb::SConnection::AccessRights ar; + + ar = rfb::SConnection::AccessDefault; + + switch (status) { + case 0: + ar |= rfb::SConnection::AccessPtrEvents | + rfb::SConnection::AccessKeyEvents | + rfb::SConnection::AccessView; + break; + case 1: + ar |= rfb::SConnection::AccessView; + ar &= ~(rfb::SConnection::AccessPtrEvents | + rfb::SConnection::AccessKeyEvents); + break; + case 2: + ar &= ~(rfb::SConnection::AccessPtrEvents | + rfb::SConnection::AccessKeyEvents | + rfb::SConnection::AccessView); + break; + } + conn->setAccessRights(ar); + conn->framebufferUpdateRequest(vncServer.getPixelBuffer()->getRect(), false); + } + } +} diff --git a/win/winvnc/VNCServerWin32.h b/win/winvnc/VNCServerWin32.h index bd0cbbbf..1a737823 100644 --- a/win/winvnc/VNCServerWin32.h +++ b/win/winvnc/VNCServerWin32.h @@ -37,6 +37,7 @@ namespace os { namespace winvnc { + class ListConnInfo; class STrayIconThread; class VNCServerWin32 : rfb::win32::QueryConnectionHandler, @@ -73,9 +74,9 @@ namespace winvnc { // Where to read the configuration settings from static const TCHAR* RegConfigPath; - bool getClientsInfo(rfb::ListConnInfo* LCInfo); + bool getClientsInfo(ListConnInfo* LCInfo); - bool setClientsStatus(rfb::ListConnInfo* LCInfo); + bool setClientsStatus(ListConnInfo* LCInfo); protected: // QueryConnectionHandler interface @@ -96,6 +97,9 @@ namespace winvnc { // Used to perform queued commands virtual void processEvent(HANDLE event); + void getConnInfo(ListConnInfo * listConn); + void setConnStatus(ListConnInfo* listConn); + protected: // Perform a particular internal function in the server thread typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command; -- 2.39.5