From 641f7e56e862e77955c0f8ab8bb1b5eaef4222cc Mon Sep 17 00:00:00 2001 From: Oleg Sheikin Date: Tue, 22 Nov 2005 18:04:10 +0000 Subject: [PATCH] The description of structure ListConnInfo has been added in library rfb. Also, codes which pass the information on connections for Control Panel have been added. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@410 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- rfb/ListConnInfo.h | 102 ++++++++++++++++++++++++++++++++++++++ rfb/VNCSConnectionST.cxx | 1 + rfb/VNCSConnectionST.h | 3 ++ rfb/VNCServerST.cxx | 13 +++++ rfb/VNCServerST.h | 4 ++ rfb/rfb.dsp | 4 ++ winvnc/ControlPanel.cxx | 22 ++++++-- winvnc/ControlPanel.h | 13 ++--- winvnc/STrayIcon.cxx | 7 ++- winvnc/VNCServerWin32.cxx | 6 +++ winvnc/VNCServerWin32.h | 5 +- 11 files changed, 166 insertions(+), 14 deletions(-) create mode 100644 rfb/ListConnInfo.h diff --git a/rfb/ListConnInfo.h b/rfb/ListConnInfo.h new file mode 100644 index 00000000..4eacadd5 --- /dev/null +++ b/rfb/ListConnInfo.h @@ -0,0 +1,102 @@ +/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + + +#ifndef __RFB_LISTCONNINFO_INCLUDED__ +#define __RFB_LISTCONNINFO_INCLUDED__ + +namespace rfb { + + struct ListConnInfo { + ListConnInfo() { + Clear(); + }; + + void Clear() { + conn.clear(); + IP_address.clear(); + time_conn.clear(); + status.clear(); + }; + + bool Empty() { + return conn.empty(); + } + + void iBegin() { + ci = conn.begin(); + Ii = IP_address.begin(); + ti = time_conn.begin(); + si = status.begin(); + } + + bool iEnd() { + return ci == conn.end(); + } + + void iNext() { + ci++; + Ii++; + ti++; + si++; + } + + void addInfo(DWORD Conn, char* IP, char* Time, int Status) { + conn.push_front(Conn); + IP_address.push_front(IP); + time_conn.push_front(Time); + status.push_front(Status); + } + + void iGetCharInfo(char* buf[3]) { + if (Empty()) + return; + buf[0] = (*Ii); + buf[1] = (*ti); + switch (*si) { + case 0: + buf[2] = strDup("Full control"); + break; + case 1: + buf[2] = strDup("View only"); + break; + case 2: + buf[2] = strDup("Stop updating"); + break; + default: + buf[2] = strDup("Unknown"); + }; + } + + DWORD iGetConn() { return *ci;}; + + int iGetStatus() { return *si;}; + + std::list conn; + std::list IP_address; + std::list time_conn; + std::list status; + std::list::iterator ci; + std::list::iterator Ii, ti; + std::list::iterator si; + + }; + +} +#endif + diff --git a/rfb/VNCSConnectionST.cxx b/rfb/VNCSConnectionST.cxx index ce48b3ec..514ea10d 100644 --- a/rfb/VNCSConnectionST.cxx +++ b/rfb/VNCSConnectionST.cxx @@ -56,6 +56,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, } server->clients.push_front(this); + startTime = time(0); } diff --git a/rfb/VNCSConnectionST.h b/rfb/VNCSConnectionST.h index ba480e59..faf54889 100644 --- a/rfb/VNCSConnectionST.h +++ b/rfb/VNCSConnectionST.h @@ -103,6 +103,8 @@ namespace rfb { void approveConnectionOrClose(bool accept, const char* reason); + char* getStartTime() { return ctime(&startTime); } + private: // SConnection callbacks @@ -163,6 +165,7 @@ namespace rfb { AccessRights accessRights; CharArray closeReason; + time_t startTime; }; } #endif diff --git a/rfb/VNCServerST.cxx b/rfb/VNCServerST.cxx index c4e02839..ae71a377 100644 --- a/rfb/VNCServerST.cxx +++ b/rfb/VNCServerST.cxx @@ -507,3 +507,16 @@ void VNCServerST::checkUpdate() comparer->clear(); } + +bool VNCServerST::getConnInfo(ListConnInfo * listConn) +{ + listConn->Clear(); + if (clients.empty()) + return false; + std::list::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ci++) { + listConn->addInfo((DWORD)(*ci), (*ci)->getSock()->getPeerAddress(), + (*ci)->getStartTime(), 4); + } + return true; +} \ No newline at end of file diff --git a/rfb/VNCServerST.h b/rfb/VNCServerST.h index a6939c83..b3e62a97 100644 --- a/rfb/VNCServerST.h +++ b/rfb/VNCServerST.h @@ -31,7 +31,9 @@ #include #include #include +#include #include +#include namespace rfb { @@ -187,6 +189,8 @@ namespace rfb { // are used, to save memory. void setEconomicTranslate(bool et) { useEconomicTranslate = et; } + bool getConnInfo(ListConnInfo * listConn); + protected: friend class VNCSConnectionST; diff --git a/rfb/rfb.dsp b/rfb/rfb.dsp index 281dd575..0662b427 100644 --- a/rfb/rfb.dsp +++ b/rfb/rfb.dsp @@ -488,6 +488,10 @@ SOURCE=.\keysymdef.h # End Source File # Begin Source File +SOURCE=.\ListConnInfo.h +# End Source File +# Begin Source File + SOURCE=.\Logger.h # End Source File # Begin Source File diff --git a/winvnc/ControlPanel.cxx b/winvnc/ControlPanel.cxx index 60624ce6..134cc211 100644 --- a/winvnc/ControlPanel.cxx +++ b/winvnc/ControlPanel.cxx @@ -44,7 +44,11 @@ bool ControlPanel::onCommand(int cmd) } case IDC_KILL_ALL: { - m_server->disconnectClients(); + COPYDATASTRUCT copyData; + copyData.dwData = 2; + copyData.lpData = 0; + copyData.cbData = 0; + SendMessage(m_hSTIcon, WM_COPYDATA, 0, (LPARAM)©Data); return false; } case IDC_DISABLE_CLIENTS: @@ -57,9 +61,19 @@ bool ControlPanel::onCommand(int cmd) } -void ControlPanel::UpdateListView() +void ControlPanel::UpdateListView(rfb::ListConnInfo* LCInfo) { - + DeleteAllLVItem(IDC_LIST_CONNECTIONS, handle); + if(LCInfo->Empty()) return; + + char* ItemString[3]; + int i = 0; + + for (LCInfo->iBegin(); !LCInfo->iEnd(); LCInfo->iNext()) { + LCInfo->iGetCharInfo(ItemString); + InsertLVItem(IDC_LIST_CONNECTIONS, handle, i, ItemString, 3); + i++; + } } BOOL ControlPanel::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -82,7 +96,7 @@ BOOL ControlPanel::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } -void ControlPanel::getSelectedConn(std::list* selsockets) +void ControlPanel::getSelConnInfo(std::list* conn, std::list* status) { } diff --git a/winvnc/ControlPanel.h b/winvnc/ControlPanel.h index 5f9bc240..51eb4213 100644 --- a/winvnc/ControlPanel.h +++ b/winvnc/ControlPanel.h @@ -10,33 +10,30 @@ #include - -#include #include #include #include #include +#include namespace winvnc { class ControlPanel : rfb::win32::Dialog, rfb::win32::ListViewControl { public: - ControlPanel(VNCServerWin32 * server, HWND hSTIcon) : Dialog(GetModuleHandle(0)), ListViewControl(){ - m_server = server; + ControlPanel(HWND hSTIcon) : Dialog(GetModuleHandle(0)), ListViewControl(){ m_hSTIcon = hSTIcon; }; virtual bool showDialog(); virtual void initDialog(); virtual bool onCommand(int cmd); - void UpdateListView(); + void UpdateListView(rfb::ListConnInfo* LCInfo); HWND GetHandle() {return handle;}; ~ControlPanel(); protected: virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - void getSelectedConn(std::list* selsockets); - VNCServerWin32 * m_server; - std::list sockets; + void getSelConnInfo(std::list* conn, std::list* status); HWND m_hSTIcon; + std::list Conn; }; }; diff --git a/winvnc/STrayIcon.cxx b/winvnc/STrayIcon.cxx index 448f08fb..a883caba 100644 --- a/winvnc/STrayIcon.cxx +++ b/winvnc/STrayIcon.cxx @@ -71,7 +71,7 @@ public: SetTimer(getHandle(), 1, 3000, 0); PostMessage(getHandle(), WM_TIMER, 1, 0); PostMessage(getHandle(), WM_SET_TOOLTIP, 0, 0); - CPanel = new ControlPanel(&thread.server, getHandle()); + CPanel = new ControlPanel(getHandle()); } virtual LRESULT processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { @@ -182,6 +182,10 @@ public: return 0; } setIcon(thread.server.isServerInUse() ? thread.activeIcon : thread.inactiveIcon); + + thread.server.getClientsInfo(&LCInfo); + CPanel->UpdateListView(&LCInfo); + return 0; case WM_SET_TOOLTIP: @@ -202,6 +206,7 @@ protected: LaunchProcess vncConnect; STrayIconThread& thread; ControlPanel * CPanel; + rfb::ListConnInfo LCInfo; }; diff --git a/winvnc/VNCServerWin32.cxx b/winvnc/VNCServerWin32.cxx index a24df120..7e562708 100644 --- a/winvnc/VNCServerWin32.cxx +++ b/winvnc/VNCServerWin32.cxx @@ -270,6 +270,9 @@ bool VNCServerWin32::addNewClient(const char* client) { return false; } +bool VNCServerWin32::getClientsInfo(rfb::ListConnInfo* LCInfo) { + return queueCommand(GetClientsInfo, LCInfo, 0); +} VNCServerST::queryResult VNCServerWin32::queryConnection(network::Socket* sock, const char* userName, @@ -330,6 +333,9 @@ void VNCServerWin32::doCommand() { "Connection rejected by user"); queryConnectDialog = 0; break; + case GetClientsInfo: + vncServer.getConnInfo((ListConnInfo*)commandData); + break; default: vlog.error("unknown command %d queued", command); diff --git a/winvnc/VNCServerWin32.h b/winvnc/VNCServerWin32.h index c824d542..f6c67235 100644 --- a/winvnc/VNCServerWin32.h +++ b/winvnc/VNCServerWin32.h @@ -28,6 +28,7 @@ #include #include #include +//#include namespace winvnc { @@ -66,13 +67,15 @@ namespace winvnc { const char* userName, char** reason); + bool getClientsInfo(rfb::ListConnInfo* LCInfo); + // Where to read the configuration settings from static const TCHAR* RegConfigPath; protected: // Perform a particular internal function in the server thread - typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete} Command; + typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, GetClientsInfo} Command; bool queueCommand(Command cmd, const void* data, int len); void doCommand(); Command command; -- 2.39.5