Use accessor methods for VNCServerST
Avoid having VNCSConnectionST poking around in VNCServerST's internals
and instead access things via safer methods.
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index f4c6d07..7b79139 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -192,8 +192,9 @@
{
try {
if (!authenticated()) return;
- if (cp.width && cp.height && (server->pb->width() != cp.width ||
- server->pb->height() != cp.height))
+ if (cp.width && cp.height &&
+ (server->getPixelBuffer()->width() != cp.width ||
+ server->getPixelBuffer()->height() != cp.height))
{
// We need to clip the next update to the new size, but also add any
// extra bits if it's bigger. If we wanted to do this exactly, something
@@ -210,11 +211,11 @@
// updates.add_changed(Rect(0, cp.height, cp.width,
// server->pb->height()));
- damagedCursorRegion.assign_intersect(server->pb->getRect());
+ damagedCursorRegion.assign_intersect(server->getPixelBuffer()->getRect());
- cp.width = server->pb->width();
- cp.height = server->pb->height();
- cp.screenLayout = server->screenLayout;
+ cp.width = server->getPixelBuffer()->width();
+ cp.height = server->getPixelBuffer()->height();
+ cp.screenLayout = server->getScreenLayout();
if (state() == RFBSTATE_NORMAL) {
// We should only send EDS to client asking for both
if (!writer()->writeExtendedDesktopSize()) {
@@ -226,12 +227,12 @@
}
// Drop any lossy tracking that is now outside the framebuffer
- encodeManager.pruneLosslessRefresh(Region(server->pb->getRect()));
+ encodeManager.pruneLosslessRefresh(Region(server->getPixelBuffer()->getRect()));
}
// Just update the whole screen at the moment because we're too lazy to
// work out what's actually changed.
updates.clear();
- updates.add_changed(server->pb->getRect());
+ updates.add_changed(server->getPixelBuffer()->getRect());
writeFramebufferUpdate();
} catch(rdr::Exception &e) {
close(e.str());
@@ -388,7 +389,7 @@
if (!cp.supportsLocalCursorWithAlpha &&
!cp.supportsLocalCursor && !cp.supportsLocalXCursor)
return true;
- if (!server->cursorPos.equals(pointerEventPos) &&
+ if (!server->getCursorPos().equals(pointerEventPos) &&
(time(0) - pointerEventTime) > 0)
return true;
@@ -415,20 +416,20 @@
lastEventTime = time(0);
// - Set the connection parameters appropriately
- cp.width = server->pb->width();
- cp.height = server->pb->height();
- cp.screenLayout = server->screenLayout;
+ cp.width = server->getPixelBuffer()->width();
+ cp.height = server->getPixelBuffer()->height();
+ cp.screenLayout = server->getScreenLayout();
cp.setName(server->getName());
- cp.setLEDState(server->ledState);
+ cp.setLEDState(server->getLEDState());
// - Set the default pixel format
- cp.setPF(server->pb->getPF());
+ cp.setPF(server->getPixelBuffer()->getPF());
char buffer[256];
cp.pf().print(buffer, 256);
vlog.info("Server default pixel format %s", buffer);
// - Mark the entire display as "dirty"
- updates.add_changed(server->pb->getRect());
+ updates.add_changed(server->getPixelBuffer()->getRect());
startTime = time(0);
}
@@ -555,7 +556,7 @@
}
// Avoid lock keys if we don't know the server state
- if ((server->ledState == ledUnknown) &&
+ if ((server->getLEDState() == ledUnknown) &&
((keysym == XK_Caps_Lock) ||
(keysym == XK_Num_Lock) ||
(keysym == XK_Scroll_Lock))) {
@@ -573,7 +574,7 @@
return;
}
- if (down && (server->ledState != ledUnknown)) {
+ if (down && (server->getLEDState() != ledUnknown)) {
// CapsLock synchronisation heuristic
// (this assumes standard interaction between CapsLock the Shift
// keys and normal characters)
@@ -583,7 +584,7 @@
uppercase = (keysym >= XK_A) && (keysym <= XK_Z);
shift = isShiftPressed();
- lock = server->ledState & ledCapsLock;
+ lock = server->getLEDState() & ledCapsLock;
if (lock == (uppercase == shift)) {
vlog.debug("Inserting fake CapsLock to get in sync with client");
@@ -603,7 +604,7 @@
number = ((keysym >= XK_KP_0) && (keysym <= XK_KP_9)) ||
(keysym == XK_KP_Separator) || (keysym == XK_KP_Decimal);
shift = isShiftPressed();
- lock = server->ledState & ledNumLock;
+ lock = server->getLEDState() & ledNumLock;
if (shift) {
// We don't know the appropriate NumLock state for when Shift
@@ -993,7 +994,7 @@
bogusCopiedCursor = damagedCursorRegion;
bogusCopiedCursor.translate(ui.copy_delta);
- bogusCopiedCursor.assign_intersect(server->pb->getRect());
+ bogusCopiedCursor.assign_intersect(server->getPixelBuffer()->getRect());
if (!ui.copied.intersect(bogusCopiedCursor).is_empty()) {
updates.add_changed(bogusCopiedCursor);
needNewUpdateInfo = true;
@@ -1116,7 +1117,7 @@
if (!authenticated())
return;
- cp.screenLayout = server->screenLayout;
+ cp.screenLayout = server->getScreenLayout();
if (state() != RFBSTATE_NORMAL)
return;
@@ -1140,7 +1141,7 @@
cp.setCursor(emptyCursor);
clientHasCursor = false;
} else {
- cp.setCursor(*server->cursor);
+ cp.setCursor(*server->getCursor());
clientHasCursor = true;
}
@@ -1207,7 +1208,7 @@
accessRights = accessRights & ~(AccessPtrEvents | AccessKeyEvents | AccessView);
break;
}
- framebufferUpdateRequest(server->pb->getRect(), false);
+ framebufferUpdateRequest(server->getPixelBuffer()->getRect(), false);
}
int VNCSConnectionST::getStatus()
{
diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h
index 4f6f021..2987ec0 100644
--- a/common/rfb/VNCServer.h
+++ b/common/rfb/VNCServer.h
@@ -52,7 +52,7 @@
virtual void setScreenLayout(const ScreenSet& layout) = 0;
// getPixelBuffer() returns a pointer to the PixelBuffer object.
- virtual PixelBuffer* getPixelBuffer() const = 0;
+ virtual const PixelBuffer* getPixelBuffer() const = 0;
// serverCutText() tells the server that the cut text has changed. This
// will normally be sent to all clients.
diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h
index 6ab1b20..ef83619 100644
--- a/common/rfb/VNCServerST.h
+++ b/common/rfb/VNCServerST.h
@@ -93,7 +93,7 @@
virtual void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout);
virtual void setPixelBuffer(PixelBuffer* pb);
virtual void setScreenLayout(const ScreenSet& layout);
- virtual PixelBuffer* getPixelBuffer() const { return pb; }
+ virtual const PixelBuffer* getPixelBuffer() const { return pb; }
virtual void serverCutText(const char* str, int len);
virtual void approveConnection(network::Socket* sock, bool accept,
@@ -105,12 +105,21 @@
virtual void setCursor(int width, int height, const Point& hotspot,
const rdr::U8* data);
virtual void setCursorPos(const Point& p);
+ virtual void setName(const char* name_);
virtual void setLEDState(unsigned state);
virtual void bell();
// VNCServerST-only methods
+ // Methods to get the currently set server state
+
+ const ScreenSet& getScreenLayout() const { return screenLayout; }
+ const Cursor* getCursor() const { return cursor; }
+ const Point& getCursorPos() const { return cursorPos; }
+ const char* getName() const { return name.buf; }
+ unsigned getLEDState() const { return ledState; }
+
// closeClients() closes all RFB sessions, except the specified one (if
// any), and logs the specified reason for closure.
void closeClients(const char* reason, network::Socket* sock);
@@ -120,15 +129,6 @@
SConnection* getSConnection(network::Socket* sock);
- // getName() returns the name of this VNC Server. NB: The value returned
- // is the server's internal buffer which may change after any other methods
- // are called - take a copy if necessary.
- const char* getName() const {return name.buf;}
-
- // setName() specifies the desktop name that the server should provide to
- // clients
- virtual void setName(const char* name_);
-
// queryConnection() is called when a connection has been
// successfully authenticated. The sock and userName arguments identify
// the socket and the name of the authenticated user, if any.