📄 vncserver.cpp
字号:
}
BOOL
vncServer::SetDisableTrayIcon(BOOL disableTrayIcon)
{
if (disableTrayIcon != m_disableTrayIcon)
{
m_disableTrayIcon = disableTrayIcon;
}
return TRUE;
}
BOOL
vncServer::GetDisableTrayIcon()
{
return m_disableTrayIcon;
}
// CORBA connection handling
BOOL
vncServer::CORBAConnect(BOOL On)
{
// Are we being asked to switch CORBA connects on or off?
if (On)
{
// Is there a CORBA object?
if (m_corbaConn == NULL)
{
m_corbaConn = new vncCorbaConnect();
}
if (m_corbaConn == NULL)
return FALSE;
if (!m_corbaConn->Init(this))
{
delete m_corbaConn;
m_corbaConn = NULL;
return FALSE;
}
}
else
{
// Is there a listening socket?
if (m_corbaConn != NULL)
{
// Close the socket
delete m_corbaConn;
m_corbaConn = NULL;
}
}
return TRUE;
}
BOOL
vncServer::CORBAConnected()
{
return m_corbaConn != NULL;
}
void
vncServer::GetScreenInfo(int &width, int &height, int &depth)
{
rfbServerInitMsg scrinfo;
omni_mutex_lock l(m_desktopLock);
vnclog.Print(LL_INTINFO, VNCLOG("GetScreenInfo called\n"));
// Is a desktop object currently active?
if (m_desktop == NULL)
{
vncDesktop desktop;
// No, so create a dummy desktop and interrogate it
if (!desktop.Init(this))
{
scrinfo.framebufferWidth = 0;
scrinfo.framebufferHeight = 0;
scrinfo.format.bitsPerPixel = 0;
}
else
{
desktop.FillDisplayInfo(&scrinfo);
}
}
else
{
m_desktop->FillDisplayInfo(&scrinfo);
}
// Get the info from the scrinfo structure
width = m_shared_rect.right - m_shared_rect.left;
height = m_shared_rect.bottom - m_shared_rect.top;
depth = scrinfo.format.bitsPerPixel;
}
void
vncServer::SetAuthHosts(const char*hostlist) {
omni_mutex_lock l(m_clientsLock);
if (m_auth_hosts != 0)
free(m_auth_hosts);
if (hostlist == 0) {
vnclog.Print(LL_INTINFO, VNCLOG("authhosts cleared\n"));
m_auth_hosts = 0;
return;
}
vnclog.Print(LL_INTINFO, VNCLOG("authhosts set to \"%s\"\n"), hostlist);
m_auth_hosts = strdup(hostlist);
}
char*
vncServer::AuthHosts() {
omni_mutex_lock l(m_clientsLock);
if (m_auth_hosts == 0)
return strdup("");
else
return strdup(m_auth_hosts);
}
inline BOOL
MatchStringToTemplate(const char *addr, size_t addrlen,
const char *filtstr, size_t filtlen) {
if (filtlen == 0)
return 1;
if (addrlen < filtlen)
return 0;
for (size_t x = 0; x < filtlen; x++) {
if (addr[x] != filtstr[x])
return 0;
}
if ((addrlen > filtlen) && (addr[filtlen] != '.'))
return 0;
return 1;
}
vncServer::AcceptQueryReject
vncServer::VerifyHost(const char *hostname) {
if (ClientsDisabled())
return vncServer::aqrReject;
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
vncServer::BlacklistEntry *previous = 0;
SYSTEMTIME systime;
FILETIME ftime;
LARGE_INTEGER now;
// Get the current time as a 64-bit value
GetSystemTime(&systime);
SystemTimeToFileTime(&systime, &ftime);
now.LowPart=ftime.dwLowDateTime;now.HighPart=ftime.dwHighDateTime;
now.QuadPart /= 10000000; // Convert it into seconds
while (current) {
// Has the blacklist entry timed out?
if ((now.QuadPart - current->_lastRefTime.QuadPart) > 0) {
// Yes. Is it a "blocked" entry?
if (current->_blocked) {
// Yes, so unblock it & re-set the reference time
current->_blocked = FALSE;
current->_lastRefTime.QuadPart = now.QuadPart + 10;
} else {
// No, so remove it
if (previous)
previous->_next = current->_next;
else
m_blacklist = current->_next;
vncServer::BlacklistEntry *next = current->_next;
free(current->_machineName);
delete current;
current = next;
continue;
}
}
// Is this the entry we're interested in?
if ((strcmp(current->_machineName, hostname) == 0) &&
(current->_blocked)) {
// Machine is blocked, so just reject it
return vncServer::aqrReject;
}
previous = current;
current = current->_next;
}
// Has a hostname been specified?
if (hostname == 0) {
vnclog.Print(LL_INTWARN, VNCLOG("verify failed - null hostname\n"));
return vncServer::aqrReject;
}
// Set the state machine into the correct mode & process the filter
enum vh_Mode {vh_ExpectDelimiter, vh_ExpectIncludeExclude, vh_ExpectPattern};
vh_Mode machineMode = vh_ExpectIncludeExclude;
vncServer::AcceptQueryReject verifiedHost = vncServer::aqrAccept;
vncServer::AcceptQueryReject patternType = vncServer::aqrReject;
UINT authHostsPos = 0;
UINT patternStart = 0;
UINT hostNameLen = strlen(hostname);
// Run through the auth hosts string until we hit the end
if (m_auth_hosts) {
while (1) {
// Which mode are we in?
switch (machineMode) {
// ExpectIncludeExclude - we should see a + or -.
case vh_ExpectIncludeExclude:
if (m_auth_hosts[authHostsPos] == '+') {
patternType = vncServer::aqrAccept;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] == '-') {
patternType = vncServer::aqrReject;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] == '?') {
patternType = vncServer::aqrQuery;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] != '\0') {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - malformed AuthHosts string\n"));
machineMode = vh_ExpectDelimiter;
}
break;
// ExpectPattern - we expect to see a valid pattern
case vh_ExpectPattern:
// ExpectDelimiter - we're scanning for the next ':', skipping a pattern
case vh_ExpectDelimiter:
if ((m_auth_hosts[authHostsPos] == ':') ||
(m_auth_hosts[authHostsPos] == '\0')) {
if (machineMode == vh_ExpectPattern) {
if (patternStart == 0) {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - pattern processing failed!\n"));
} else {
// Process the match
if (MatchStringToTemplate(hostname, hostNameLen,
&(m_auth_hosts[patternStart]), authHostsPos-patternStart)) {
// The hostname matched - apply the include/exclude rule
verifiedHost = patternType;
}
}
}
// We now expect another + or -
machineMode = vh_ExpectIncludeExclude;
}
break;
}
// Have we hit the end of the pattern string?
if (m_auth_hosts[authHostsPos] == '\0')
break;
authHostsPos++;
}
}
return AdjustVerification(verifiedHost);
}
vncServer::AcceptQueryReject
vncServer::AdjustVerification(vncServer::AcceptQueryReject host)
{
vncServer::AcceptQueryReject verifiedHost = host;
// Based on the server's QuerySetting, adjust the verification result
switch (host) {
case vncServer::aqrAccept:
if (QuerySetting() >= 3)
verifiedHost = vncServer::aqrQuery;
break;
case vncServer::aqrQuery:
if (QuerySetting() <= 1)
verifiedHost = vncServer::aqrAccept;
else if (QuerySetting() == 4)
verifiedHost = vncServer::aqrReject;
break;
case vncServer::aqrReject:
if (QuerySetting() == 0)
verifiedHost = vncServer::aqrQuery;
break;
};
return verifiedHost;
}
void
vncServer::AddAuthHostsBlacklist(const char *machine) {
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
// Get the current time as a 64-bit value
SYSTEMTIME systime;
FILETIME ftime;
LARGE_INTEGER now;
GetSystemTime(&systime);
SystemTimeToFileTime(&systime, &ftime);
now.LowPart=ftime.dwLowDateTime;now.HighPart=ftime.dwHighDateTime;
now.QuadPart /= 10000000; // Convert it into seconds
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
// If the host is already blocked then ignore
if (current->_blocked)
return;
// Set the RefTime & failureCount
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_failureCount++;
if (current->_failureCount > 5)
current->_blocked = TRUE;
return;
}
current = current->_next;
}
// Didn't find the entry
current = new vncServer::BlacklistEntry;
current->_blocked = FALSE;
current->_failureCount = 0;
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_machineName = strdup(machine);
current->_next = m_blacklist;
m_blacklist = current;
}
void
vncServer::RemAuthHostsBlacklist(const char *machine) {
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
vncServer::BlacklistEntry *previous = 0;
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
if (previous)
previous->_next = current->_next;
else
m_blacklist = current->_next;
vncServer::BlacklistEntry *next = current->_next;
free (current->_machineName);
delete current;
current = next;
continue;
}
previous = current;
current = current->_next;
}
}
void
vncServer::SetWindowShared(HWND hWnd)
{
m_hwndShared=hWnd;
}
void vncServer::SetMatchSizeFields(int left,int top,int right,int bottom)
{
RECT trect = GetScreenRect();
/* if ( right - left < 32 )
right = left + 32;
if ( bottom - top < 32)
bottom = top + 32 ;*/
if( right > trect.right )
right = trect.right;
if( bottom > trect.bottom )
bottom = trect.bottom;
if( left < trect.left)
left = trect.left;
if( top < trect.top)
top = trect.top;
m_screenarea_rect.left=left;
m_screenarea_rect.top=top;
m_screenarea_rect.bottom=bottom;
m_screenarea_rect.right=right;
}
void
vncServer::SetKeyboardCounter(int count)
{
omni_mutex_lock l(m_clientsLock);
if (LocalInputPriority() && vncService::IsWin95())
{
m_remote_keyboard += count;
if (count == 0)
m_remote_keyboard = 0;
}
}
void
vncServer::SetMouseCounter(int count, POINT &cursor_pos, BOOL mousemove)
{
if( (mousemove) && ( abs (m_cursor_pos.x - cursor_pos.x)==0
&& abs (m_cursor_pos.y - cursor_pos.y)==0 ) )
return;
omni_mutex_lock l(m_clientsLock);
if (LocalInputPriority() && vncService::IsWin95())
{
m_remote_mouse += count;
if (count == 0)
m_remote_mouse = 0;
m_cursor_pos.x = cursor_pos.x;
m_cursor_pos.y = cursor_pos.y;
}
}
void
vncServer::SetNewFBSize(BOOL sendnewfb)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post new framebuffer size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->SetNewFBSize( sendnewfb);
}
}
BOOL
vncServer::FullRgnRequested()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Iterate over the authorised clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i)->FullRgnRequested())
return TRUE;
}
return FALSE;
}
BOOL
vncServer::IncrRgnRequested()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Iterate over the authorised clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i)->IncrRgnRequested())
return TRUE;
}
return FALSE;
}
void
vncServer::UpdateLocalFormat()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Iterate over the authorised clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
GetClient(*i)->UpdateLocalFormat();
}
return;
}
void
vncServer::SetPollingCycle(UINT msec)
{
if (m_polling_cycle != msec && msec > 10) {
m_polling_cycle = msec;
PollingCycleChanged(true);
}
}
BOOL
vncServer::checkPointer(vncClient *pClient)
{
vncClientList::iterator i;
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i) == pClient) return TRUE;
}
return FALSE;
}
BOOL
vncServer::DriverActive() {
return (m_desktop != NULL) ? m_desktop->DriverActive() : FALSE;
}
typedef HMONITOR (WINAPI* pMonitorFromPoint)(POINT,DWORD);
typedef BOOL (WINAPI* pGetMonitorInfo)(HMONITOR,LPMONITORINFO);
BOOL vncServer::SetShareMonitorFromPoint(POINT pt)
{
HINSTANCE hInstUser32 = LoadLibrary("User32.DLL");
if (!hInstUser32) return FALSE;
pMonitorFromPoint pMFP = (pMonitorFromPoint)GetProcAddress(hInstUser32, "MonitorFromPoint");
pGetMonitorInfo pGMI = (pGetMonitorInfo)GetProcAddress(hInstUser32, "GetMonitorInfoA");
if (!pMFP || !pGMI)
{
vnclog.Print(
LL_INTERR,
VNCLOG("Can not import '%s' and '%s' from '%s'.\n"),
"MonitorFromPoint",
"GetMonitorInfoA",
"User32.DLL");
FreeLibrary(hInstUser32);
return FALSE;
}
HMONITOR hm = pMFP(pt, MONITOR_DEFAULTTONEAREST);
if (!hm)
{
FreeLibrary(hInstUser32);
return FALSE;
}
MONITORINFO moninfo;
moninfo.cbSize = sizeof(moninfo);
if (!pGMI(hm, &moninfo))
{
FreeLibrary(hInstUser32);
return FALSE;
}
FullScreen(FALSE);
WindowShared(FALSE);
ScreenAreaShared(TRUE);
PrimaryDisplayOnlyShared(FALSE);
SetMatchSizeFields(
moninfo.rcMonitor.left,
moninfo.rcMonitor.top,
moninfo.rcMonitor.right,
moninfo.rcMonitor.bottom);
FreeLibrary(hInstUser32);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -