Browse Source

Move ListConnInfo to WinVNC directory

It is functionality specific to WinVNC, so move the code there
to make things more clear.
tags/v1.9.90
Pierre Ossman 5 years ago
parent
commit
025326dd94

+ 0
- 2
common/network/Socket.h View File

// there is no timeout and checkTimeouts() should be called the next time // there is no timeout and checkTimeouts() should be called the next time
// an event occurs. // an event occurs.
virtual int checkTimeouts() = 0; virtual int checkTimeouts() = 0;

virtual bool getDisable() {return false;};
}; };


} }

+ 1
- 43
common/rfb/VNCSConnectionST.cxx View File

losslessTimer(this), server(server_), updates(false), losslessTimer(this), server(server_), updates(false),
updateRenderedCursor(false), removeRenderedCursor(false), updateRenderedCursor(false), removeRenderedCursor(false),
continuousUpdates(false), encodeManager(this), pointerEventTime(0), continuousUpdates(false), encodeManager(this), pointerEventTime(0),
clientHasCursor(false), startTime(time(0))
clientHasCursor(false)
{ {
setStreams(&sock->inStream(), &sock->outStream()); setStreams(&sock->inStream(), &sock->outStream());
peerEndpoint.buf = sock->getPeerEndpoint(); peerEndpoint.buf = sock->getPeerEndpoint();


// - Mark the entire display as "dirty" // - Mark the entire display as "dirty"
updates.add_changed(server->getPixelBuffer()->getRect()); updates.add_changed(server->getPixelBuffer()->getRect());
startTime = time(0);
} }


void VNCSConnectionST::queryConnection(const char* userName) void VNCSConnectionST::queryConnection(const char* userName)
sock->inStream().setTimeout(timeoutms); sock->inStream().setTimeout(timeoutms);
sock->outStream().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;
}


+ 0
- 6
common/rfb/VNCSConnectionST.h View File



const char* getPeerEndpoint() const {return peerEndpoint.buf;} const char* getPeerEndpoint() const {return peerEndpoint.buf;}


char* getStartTime();

void setStatus(int status);
int getStatus();

private: private:
// SConnection callbacks // SConnection callbacks


bool clientHasCursor; bool clientHasCursor;


CharArray closeReason; CharArray closeReason;
time_t startTime;
}; };
} }
#endif #endif

+ 1
- 36
common/rfb/VNCServerST.cxx View File



#include <rfb/ComparingUpdateTracker.h> #include <rfb/ComparingUpdateTracker.h>
#include <rfb/KeyRemapper.h> #include <rfb/KeyRemapper.h>
#include <rfb/ListConnInfo.h>
#include <rfb/LogWriter.h> #include <rfb/LogWriter.h>
#include <rfb/Security.h> #include <rfb/Security.h>
#include <rfb/ServerCore.h> #include <rfb/ServerCore.h>
cursor(new Cursor(0, 0, Point(), NULL)), cursor(new Cursor(0, 0, Point(), NULL)),
renderedCursorInvalid(false), renderedCursorInvalid(false),
keyRemapper(&KeyRemapper::defInstance), keyRemapper(&KeyRemapper::defInstance),
lastConnectionTime(0), disableclients(false),
frameTimer(this)
lastConnectionTime(0), frameTimer(this)
{ {
lastUserInputTime = lastDisconnectTime = time(0); lastUserInputTime = lastDisconnectTime = time(0);
slog.debug("creating single-threaded server %s", name.buf); slog.debug("creating single-threaded server %s", name.buf);
return &renderedCursor; return &renderedCursor;
} }


void VNCServerST::getConnInfo(ListConnInfo * listConn)
{
listConn->Clear();
listConn->setDisable(getDisable());
if (clients.empty())
return;
std::list<VNCSConnectionST*>::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<VNCSConnectionST*>::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() bool VNCServerST::getComparerState()
{ {
if (rfb::Server::compareFB == 0) if (rfb::Server::compareFB == 0)

+ 0
- 8
common/rfb/VNCServerST.h View File

// NB: A null pointer is valid here. // NB: A null pointer is valid here.
void setKeyRemapper(KeyRemapper* kr) { keyRemapper = kr; } 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 // clientReady() is called by a VNCSConnectionST instance when the
// client has completed the handshake and is ready for normal // client has completed the handshake and is ready for normal
// communication. // communication.
time_t lastDisconnectTime; time_t lastDisconnectTime;
time_t lastConnectionTime; time_t lastConnectionTime;


bool disableclients;

Timer frameTimer; Timer frameTimer;
}; };



+ 28
- 1
win/rfb_win32/SocketManager.cxx View File

li.sock = sock_; li.sock = sock_;
li.server = srvr; li.server = srvr;
li.notifier = acn; li.notifier = acn;
li.disable = false;
listeners[event] = li; listeners[event] = li;
} }


throw rdr::Exception("Socket not registered"); throw rdr::Exception("Socket not registered");
} }


bool SocketManager::getDisable(network::SocketServer* srvr)
{
std::map<HANDLE,ListenInfo>::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<HANDLE,ListenInfo>::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 SocketManager::checkTimeouts() {
int timeout = EventManager::checkTimeouts(); int timeout = EventManager::checkTimeouts();
WSAEnumNetworkEvents(li.sock->getFd(), event, &network_events); WSAEnumNetworkEvents(li.sock->getFd(), event, &network_events);
if (network_events.lNetworkEvents & FD_ACCEPT) { if (network_events.lNetworkEvents & FD_ACCEPT) {
network::Socket* new_sock = li.sock->accept(); network::Socket* new_sock = li.sock->accept();
if (new_sock && li.server->getDisable()) {
if (new_sock && li.disable) {
delete new_sock; delete new_sock;
new_sock = 0; new_sock = 0;
} }

+ 4
- 0
win/rfb_win32/SocketManager.h View File

// the SocketServer. // the SocketServer.
void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true); void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true);


bool getDisable(network::SocketServer* srvr);
void setDisable(network::SocketServer* srvr, bool disable);

protected: protected:
virtual int checkTimeouts(); virtual int checkTimeouts();
virtual void processEvent(HANDLE event); virtual void processEvent(HANDLE event);
network::SocketListener* sock; network::SocketListener* sock;
network::SocketServer* server; network::SocketServer* server;
AddressChangeNotifier* notifier; AddressChangeNotifier* notifier;
bool disable;
}; };
std::map<HANDLE, ListenInfo> listeners; std::map<HANDLE, ListenInfo> listeners;
std::map<HANDLE, ConnInfo> connections; std::map<HANDLE, ConnInfo> connections;

+ 4
- 5
win/winvnc/ControlPanel.cxx View File

{ {
TCHAR *ColumnsStrings[] = { TCHAR *ColumnsStrings[] = {
(TCHAR *) "IP address", (TCHAR *) "IP address",
(TCHAR *) "Time connected",
(TCHAR *) "Status" (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, LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
LVS_EX_FULLROWSELECT, LVCFMT_LEFT); LVS_EX_FULLROWSELECT, LVCFMT_LEFT);
SendCommand(4, -1); SendCommand(4, -1);
} }


void ControlPanel::UpdateListView(rfb::ListConnInfo* LCInfo)
void ControlPanel::UpdateListView(ListConnInfo* LCInfo)
{ {
getSelConnInfo(); getSelConnInfo();
DeleteAllLVItem(IDC_LIST_CONNECTIONS, handle); DeleteAllLVItem(IDC_LIST_CONNECTIONS, handle);


ListConn.Copy(LCInfo); ListConn.Copy(LCInfo);


char* ItemString[3];
char* ItemString[2];
int i = 0; int i = 0;


for (ListConn.iBegin(); !ListConn.iEnd(); ListConn.iNext()) { for (ListConn.iBegin(); !ListConn.iEnd(); ListConn.iNext()) {
ListConn.iGetCharInfo(ItemString); 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()) { for (ListSelConn.iBegin(); !ListSelConn.iEnd(); ListSelConn.iNext()) {
if (ListSelConn.iGetConn() == ListConn.iGetConn()) if (ListSelConn.iGetConn() == ListConn.iGetConn())
SelectLVItem(IDC_LIST_CONNECTIONS, handle, i); SelectLVItem(IDC_LIST_CONNECTIONS, handle, i);

+ 6
- 6
win/winvnc/ControlPanel.h View File



#include <list> #include <list>
#include <winvnc/resource.h> #include <winvnc/resource.h>
#include <winvnc/ListConnInfo.h>
#include <rfb_win32/Dialog.h> #include <rfb_win32/Dialog.h>
#include <rfb_win32/ListViewControl.h> #include <rfb_win32/ListViewControl.h>
#include <rfb_win32/Win32Util.h> #include <rfb_win32/Win32Util.h>
#include <rfb/ListConnInfo.h>


namespace winvnc { namespace winvnc {
virtual bool showDialog(); virtual bool showDialog();
virtual void initDialog(); virtual void initDialog();
virtual bool onCommand(int cmd); virtual bool onCommand(int cmd);
void UpdateListView(rfb::ListConnInfo* LCInfo);
void UpdateListView(ListConnInfo* LCInfo);
HWND GetHandle() {return handle;}; HWND GetHandle() {return handle;};
void SendCommand(DWORD command, int data); void SendCommand(DWORD command, int data);
~ControlPanel(); ~ControlPanel();
rfb::ListConnInfo ListConnStatus;
ListConnInfo ListConnStatus;
protected: protected:
virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void getSelConnInfo(); void getSelConnInfo();
HWND m_hSTIcon; HWND m_hSTIcon;
rfb::ListConnInfo ListConn;
rfb::ListConnInfo ListSelConn;
ListConnInfo ListConn;
ListConnInfo ListSelConn;
bool stop_updating; bool stop_updating;
}; };
}; };


#endif
#endif

common/rfb/ListConnInfo.h → win/winvnc/ListConnInfo.h View File



#include <rfb/util.h> #include <rfb/util.h>


namespace rfb {
namespace winvnc {


struct ListConnInfo { struct ListConnInfo {
ListConnInfo() : disableClients(false) {} ListConnInfo() : disableClients(false) {}
void Clear() { void Clear() {
conn.clear(); conn.clear();
IP_address.clear(); IP_address.clear();
time_conn.clear();
status.clear(); status.clear();
} }


void iBegin() { void iBegin() {
ci = conn.begin(); ci = conn.begin();
Ii = IP_address.begin(); Ii = IP_address.begin();
ti = time_conn.begin();
si = status.begin(); si = status.begin();
} }


void iNext() { void iNext() {
ci++; ci++;
Ii++; Ii++;
ti++;
si++; si++;
} }


void addInfo(void* Conn, char* IP, char* Time, int Status) {
void addInfo(void* Conn, char* IP, int Status) {
conn.push_back(Conn); 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); status.push_back(Status);
} }


void iGetCharInfo(char* buf[3]) {
void iGetCharInfo(char* buf[2]) {
buf[0] = *Ii; buf[0] = *Ii;
buf[1] = *ti;
switch (*si) { switch (*si) {
case 0: case 0:
buf[2] = strDup("Full control");
buf[1] = rfb::strDup("Full control");
break; break;
case 1: case 1:
buf[2] = strDup("View only");
buf[1] = rfb::strDup("View only");
break; break;
case 2: case 2:
buf[2] = strDup("Stop updating");
buf[1] = rfb::strDup("Stop updating");
break; break;
default: default:
buf[2] = strDup("Unknown");
buf[1] = rfb::strDup("Unknown");
} }
} }


} }


void iAdd (ListConnInfo* InputList) { void iAdd (ListConnInfo* InputList) {
char* buf[3];
char* buf[2];
InputList->iGetCharInfo(buf); 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;} void setDisable(bool disable) {disableClients = disable;}
private: private:
std::list<void*> conn; std::list<void*> conn;
std::list<char*> IP_address; std::list<char*> IP_address;
std::list<char*> time_conn;
std::list<int> status; std::list<int> status;
std::list<void*>::iterator ci; std::list<void*>::iterator ci;
std::list<char*>::iterator Ii; std::list<char*>::iterator Ii;
std::list<char*>::iterator ti;
std::list<int>::iterator si; std::list<int>::iterator si;
bool disableClients; bool disableClients;
}; };

+ 2
- 2
win/winvnc/STrayIcon.cxx View File

case 2: case 2:
return thread.server.disconnectClients("IPC disconnect") ? 1 : 0; return thread.server.disconnectClients("IPC disconnect") ? 1 : 0;
case 3: case 3:
thread.server.setClientsStatus((rfb::ListConnInfo *)command->lpData);
thread.server.setClientsStatus((ListConnInfo *)command->lpData);
case 4: case 4:
thread.server.getClientsInfo(&LCInfo); thread.server.getClientsInfo(&LCInfo);
CPanel->UpdateListView(&LCInfo); CPanel->UpdateListView(&LCInfo);
LaunchProcess vncConnect; LaunchProcess vncConnect;
STrayIconThread& thread; STrayIconThread& thread;
ControlPanel * CPanel; ControlPanel * CPanel;
rfb::ListConnInfo LCInfo;
ListConnInfo LCInfo;
}; };





+ 84
- 4
win/winvnc/VNCServerWin32.cxx View File



#include <winvnc/VNCServerWin32.h> #include <winvnc/VNCServerWin32.h>
#include <winvnc/resource.h> #include <winvnc/resource.h>
#include <winvnc/ListConnInfo.h>
#include <winvnc/STrayIcon.h> #include <winvnc/STrayIcon.h>


#include <os/Mutex.h> #include <os/Mutex.h>
return false; return false;
} }


bool VNCServerWin32::getClientsInfo(rfb::ListConnInfo* LCInfo) {
bool VNCServerWin32::getClientsInfo(ListConnInfo* LCInfo) {
return queueCommand(GetClientsInfo, LCInfo, 0); return queueCommand(GetClientsInfo, LCInfo, 0);
} }


bool VNCServerWin32::setClientsStatus(rfb::ListConnInfo* LCInfo) {
bool VNCServerWin32::setClientsStatus(ListConnInfo* LCInfo) {
return queueCommand(SetClientsStatus, LCInfo, 0); return queueCommand(SetClientsStatus, LCInfo, 0);
} }


sockMgr.addSocket((network::Socket*)commandData, &vncServer); sockMgr.addSocket((network::Socket*)commandData, &vncServer);
break; break;
case GetClientsInfo: case GetClientsInfo:
vncServer.getConnInfo((ListConnInfo*)commandData);
getConnInfo((ListConnInfo*)commandData);
break; break;
case SetClientsStatus: case SetClientsStatus:
vncServer.setConnStatus((ListConnInfo*)commandData);
setConnStatus((ListConnInfo*)commandData);
break; break;


case QueryConnectionComplete: case QueryConnectionComplete:
} }
} }


void VNCServerWin32::getConnInfo(ListConnInfo * listConn)
{
std::list<network::Socket*> sockets;
std::list<network::Socket*>::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);
}
}
}

+ 6
- 2
win/winvnc/VNCServerWin32.h View File



namespace winvnc { namespace winvnc {


class ListConnInfo;
class STrayIconThread; class STrayIconThread;


class VNCServerWin32 : rfb::win32::QueryConnectionHandler, class VNCServerWin32 : rfb::win32::QueryConnectionHandler,
// Where to read the configuration settings from // Where to read the configuration settings from
static const TCHAR* RegConfigPath; static const TCHAR* RegConfigPath;


bool getClientsInfo(rfb::ListConnInfo* LCInfo);
bool getClientsInfo(ListConnInfo* LCInfo);


bool setClientsStatus(rfb::ListConnInfo* LCInfo);
bool setClientsStatus(ListConnInfo* LCInfo);


protected: protected:
// QueryConnectionHandler interface // QueryConnectionHandler interface
// Used to perform queued commands // Used to perform queued commands
virtual void processEvent(HANDLE event); virtual void processEvent(HANDLE event);


void getConnInfo(ListConnInfo * listConn);
void setConnStatus(ListConnInfo* listConn);

protected: protected:
// Perform a particular internal function in the server thread // Perform a particular internal function in the server thread
typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command; typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;

Loading…
Cancel
Save