aboutsummaryrefslogtreecommitdiffstats
path: root/unix/x0vncserver
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2024-06-24 14:35:43 +0200
committerPierre Ossman <ossman@cendio.se>2024-06-24 14:35:43 +0200
commit1b6d5594e34bf3c96e225eab794943dc1ce6b1de (patch)
tree3088799b3e595f2e062e258c515d97970b00402b /unix/x0vncserver
parent0e9a00e87cf12087b253e0be214c7a7a045c94de (diff)
parent02c6a1bf7ec18701a0f1a44bec20fc383b8f3565 (diff)
downloadtigervnc-1b6d5594e34bf3c96e225eab794943dc1ce6b1de.tar.gz
tigervnc-1b6d5594e34bf3c96e225eab794943dc1ce6b1de.zip
Merge branch 'c++11' of github.com:CendioOssman/tigervnc
Diffstat (limited to 'unix/x0vncserver')
-rw-r--r--unix/x0vncserver/Geometry.cxx2
-rw-r--r--unix/x0vncserver/Image.cxx49
-rw-r--r--unix/x0vncserver/Image.h12
-rw-r--r--unix/x0vncserver/XDesktop.cxx58
-rw-r--r--unix/x0vncserver/XDesktop.h36
-rw-r--r--unix/x0vncserver/XPixelBuffer.cxx2
-rw-r--r--unix/x0vncserver/XPixelBuffer.h2
-rw-r--r--unix/x0vncserver/x0vncserver.cxx55
8 files changed, 104 insertions, 112 deletions
diff --git a/unix/x0vncserver/Geometry.cxx b/unix/x0vncserver/Geometry.cxx
index 3f7f2863..28e71be4 100644
--- a/unix/x0vncserver/Geometry.cxx
+++ b/unix/x0vncserver/Geometry.cxx
@@ -71,7 +71,7 @@ Rect Geometry::parseString(const char *arg) const
{
Rect result; // empty by default
- if (arg != NULL && strlen(arg) > 0) {
+ if (arg != nullptr && strlen(arg) > 0) {
int w, h;
int x = 0, y = 0;
char sign_x[2] = "+";
diff --git a/unix/x0vncserver/Image.cxx b/unix/x0vncserver/Image.cxx
index 755da787..c2026134 100644
--- a/unix/x0vncserver/Image.cxx
+++ b/unix/x0vncserver/Image.cxx
@@ -63,13 +63,13 @@ ImageCleanup imageCleanup;
static rfb::LogWriter vlog("Image");
Image::Image(Display *d)
- : xim(NULL), dpy(d)
+ : xim(nullptr), dpy(d)
{
imageCleanup.images.push_back(this);
}
Image::Image(Display *d, int width, int height)
- : xim(NULL), dpy(d)
+ : xim(nullptr), dpy(d)
{
imageCleanup.images.push_back(this);
Init(width, height);
@@ -85,10 +85,11 @@ void Image::Init(int width, int height)
}
xim = XCreateImage(dpy, vis, DefaultDepth(dpy, DefaultScreen(dpy)),
- ZPixmap, 0, 0, width, height, BitmapPad(dpy), 0);
+ ZPixmap, 0, nullptr, width, height,
+ BitmapPad(dpy), 0);
xim->data = (char *)malloc(xim->bytes_per_line * xim->height);
- if (xim->data == NULL) {
+ if (xim->data == nullptr) {
vlog.error("malloc() failed");
exit(1);
}
@@ -99,7 +100,7 @@ Image::~Image()
imageCleanup.images.remove(this);
// XDestroyImage will free xim->data if necessary
- if (xim != NULL)
+ if (xim != nullptr)
XDestroyImage(xim);
}
@@ -217,12 +218,12 @@ static int ShmCreationXErrorHandler(Display* /*dpy*/,
}
ShmImage::ShmImage(Display *d)
- : Image(d), shminfo(NULL)
+ : Image(d), shminfo(nullptr)
{
}
ShmImage::ShmImage(Display *d, int width, int height)
- : Image(d), shminfo(NULL)
+ : Image(d), shminfo(nullptr)
{
Init(width, height);
}
@@ -241,7 +242,7 @@ void ShmImage::Init(int width, int height, const XVisualInfo *vinfo)
Visual *visual;
int depth;
- if (vinfo == NULL) {
+ if (vinfo == nullptr) {
visual = DefaultVisual(dpy, DefaultScreen(dpy));
depth = DefaultDepth(dpy, DefaultScreen(dpy));
} else {
@@ -256,12 +257,12 @@ void ShmImage::Init(int width, int height, const XVisualInfo *vinfo)
shminfo = new XShmSegmentInfo;
- xim = XShmCreateImage(dpy, visual, depth, ZPixmap, 0, shminfo,
+ xim = XShmCreateImage(dpy, visual, depth, ZPixmap, nullptr, shminfo,
width, height);
- if (xim == NULL) {
+ if (xim == nullptr) {
vlog.error("XShmCreateImage() failed");
delete shminfo;
- shminfo = NULL;
+ shminfo = nullptr;
return;
}
@@ -273,22 +274,22 @@ void ShmImage::Init(int width, int height, const XVisualInfo *vinfo)
vlog.error("shmget() failed (%d bytes requested)",
int(xim->bytes_per_line * xim->height));
XDestroyImage(xim);
- xim = NULL;
+ xim = nullptr;
delete shminfo;
- shminfo = NULL;
+ shminfo = nullptr;
return;
}
- shminfo->shmaddr = xim->data = (char *)shmat(shminfo->shmid, 0, 0);
+ shminfo->shmaddr = xim->data = (char *)shmat(shminfo->shmid, nullptr, 0);
if (shminfo->shmaddr == (char *)-1) {
perror("shmat");
vlog.error("shmat() failed (%d bytes requested)",
int(xim->bytes_per_line * xim->height));
- shmctl(shminfo->shmid, IPC_RMID, 0);
+ shmctl(shminfo->shmid, IPC_RMID, nullptr);
XDestroyImage(xim);
- xim = NULL;
+ xim = nullptr;
delete shminfo;
- shminfo = NULL;
+ shminfo = nullptr;
return;
}
@@ -301,21 +302,21 @@ void ShmImage::Init(int width, int height, const XVisualInfo *vinfo)
if (caughtShmError) {
vlog.error("XShmAttach() failed");
shmdt(shminfo->shmaddr);
- shmctl(shminfo->shmid, IPC_RMID, 0);
+ shmctl(shminfo->shmid, IPC_RMID, nullptr);
XDestroyImage(xim);
- xim = NULL;
+ xim = nullptr;
delete shminfo;
- shminfo = NULL;
+ shminfo = nullptr;
return;
}
}
ShmImage::~ShmImage()
{
- if (shminfo != NULL) {
+ if (shminfo != nullptr) {
XShmDetach(dpy, shminfo);
shmdt(shminfo->shmaddr);
- shmctl(shminfo->shmid, IPC_RMID, 0);
+ shmctl(shminfo->shmid, IPC_RMID, nullptr);
delete shminfo;
}
}
@@ -354,13 +355,13 @@ ImageFactory::~ImageFactory()
Image *ImageFactory::newImage(Display *d, int width, int height)
{
- Image *image = NULL;
+ Image *image = nullptr;
// Now, try to use shared memory image.
if (mayUseShm) {
image = new ShmImage(d, width, height);
- if (image->xim != NULL) {
+ if (image->xim != nullptr) {
return image;
}
diff --git a/unix/x0vncserver/Image.h b/unix/x0vncserver/Image.h
index bf62e7d0..a89a26ad 100644
--- a/unix/x0vncserver/Image.h
+++ b/unix/x0vncserver/Image.h
@@ -98,20 +98,20 @@ public:
ShmImage(Display *d, int width, int height);
virtual ~ShmImage();
- virtual const char *className() const {
+ const char *className() const override {
return "ShmImage";
}
- virtual const char *classDesc() const {
+ const char *classDesc() const override {
return "shared memory image";
}
- virtual void get(Window wnd, int x = 0, int y = 0);
- virtual void get(Window wnd, int x, int y, int w, int h,
- int dst_x = 0, int dst_y = 0);
+ void get(Window wnd, int x = 0, int y = 0) override;
+ void get(Window wnd, int x, int y, int w, int h,
+ int dst_x = 0, int dst_y = 0) override;
protected:
- void Init(int width, int height, const XVisualInfo *vinfo = NULL);
+ void Init(int width, int height, const XVisualInfo *vinfo = nullptr);
XShmSegmentInfo *shminfo;
diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx
index 55ea9667..4286c541 100644
--- a/unix/x0vncserver/XDesktop.cxx
+++ b/unix/x0vncserver/XDesktop.cxx
@@ -26,6 +26,8 @@
#include <signal.h>
#include <unistd.h>
+#include <algorithm>
+
#include <network/Socket.h>
#include <rfb/LogWriter.h>
@@ -80,11 +82,11 @@ static const char * ledNames[XDESKTOP_N_LEDS] = {
};
XDesktop::XDesktop(Display* dpy_, Geometry *geometry_)
- : dpy(dpy_), geometry(geometry_), pb(0), server(0),
- queryConnectDialog(0), queryConnectSock(0),
+ : dpy(dpy_), geometry(geometry_), pb(nullptr), server(nullptr),
+ queryConnectDialog(nullptr), queryConnectSock(nullptr),
oldButtonMask(0), haveXtest(false), haveDamage(false),
maxButtons(0), running(false), ledMasks(), ledState(0),
- codeMap(0), codeMapLen(0)
+ codeMap(nullptr), codeMapLen(0)
{
int major, minor;
@@ -108,7 +110,7 @@ XDesktop::XDesktop(Display* dpy_, Geometry *geometry_)
Bool on;
a = XInternAtom(dpy, ledNames[i], True);
- if (!a || !XkbGetNamedIndicator(dpy, a, &shift, &on, NULL, NULL))
+ if (!a || !XkbGetNamedIndicator(dpy, a, &shift, &on, nullptr, nullptr))
continue;
ledMasks[i] = 1u << shift;
@@ -283,7 +285,7 @@ void XDesktop::stop() {
#ifdef HAVE_XTEST
// Delete added keycodes
- deleteAddedKeysyms(dpy);
+ deleteAddedKeysyms();
#endif
#ifdef HAVE_XDAMAGE
@@ -292,12 +294,12 @@ void XDesktop::stop() {
#endif
delete queryConnectDialog;
- queryConnectDialog = 0;
+ queryConnectDialog = nullptr;
- server->setPixelBuffer(0);
+ server->setPixelBuffer(nullptr);
delete pb;
- pb = 0;
+ pb = nullptr;
}
void XDesktop::terminate() {
@@ -316,15 +318,13 @@ void XDesktop::queryConnection(network::Socket* sock,
// Someone already querying?
if (queryConnectSock) {
std::list<network::Socket*> sockets;
- std::list<network::Socket*>::iterator i;
// Check if this socket is still valid
server->getSockets(&sockets);
- for (i = sockets.begin(); i != sockets.end(); i++) {
- if (*i == queryConnectSock) {
- server->approveConnection(sock, false, "Another connection is currently being queried.");
- return;
- }
+ if (std::find(sockets.begin(), sockets.end(),
+ queryConnectSock) != sockets.end()) {
+ server->approveConnection(sock, false, "Another connection is currently being queried.");
+ return;
}
}
@@ -368,7 +368,7 @@ void XDesktop::pointerEvent(const Point& pos, int buttonMask) {
}
#ifdef HAVE_XTEST
-KeyCode XDesktop::XkbKeysymToKeycode(Display* dpy, KeySym keysym) {
+KeyCode XDesktop::XkbKeysymToKeycode(KeySym keysym) {
XkbDescPtr xkb;
XkbStateRec state;
unsigned int mods;
@@ -401,12 +401,12 @@ KeyCode XDesktop::XkbKeysymToKeycode(Display* dpy, KeySym keysym) {
// Shift+Tab is usually ISO_Left_Tab, but RFB hides this fact. Do
// another attempt if we failed the initial lookup
if ((keycode == 0) && (keysym == XK_Tab) && (mods & ShiftMask))
- return XkbKeysymToKeycode(dpy, XK_ISO_Left_Tab);
+ return XkbKeysymToKeycode(XK_ISO_Left_Tab);
return keycode;
}
-KeyCode XDesktop::addKeysym(Display* dpy, KeySym keysym)
+KeyCode XDesktop::addKeysym(KeySym keysym)
{
int types[1];
unsigned int key;
@@ -460,7 +460,7 @@ KeyCode XDesktop::addKeysym(Display* dpy, KeySym keysym)
return 0;
}
-void XDesktop::deleteAddedKeysyms(Display* dpy) {
+void XDesktop::deleteAddedKeysyms() {
XkbDescPtr xkb;
xkb = XkbGetMap(dpy, XkbAllComponentsMask, XkbUseCoreKbd);
@@ -476,10 +476,10 @@ void XDesktop::deleteAddedKeysyms(Display* dpy) {
for (it = addedKeysyms.begin(); it != addedKeysyms.end(); it++) {
if (XkbKeyNumGroups(xkb, it->second) != 0) {
// Check if we are removing keysym we added ourself
- if (XkbKeysymToKeycode(dpy, it->first) != it->second)
+ if (XkbKeysymToKeycode(it->first) != it->second)
continue;
- XkbChangeTypesOfKey(xkb, it->second, 0, XkbGroup1Mask, NULL, &changes);
+ XkbChangeTypesOfKey(xkb, it->second, 0, XkbGroup1Mask, nullptr, &changes);
if (it->second < lowestKeyCode)
lowestKeyCode = it->second;
@@ -501,19 +501,19 @@ void XDesktop::deleteAddedKeysyms(Display* dpy) {
addedKeysyms.clear();
}
-KeyCode XDesktop::keysymToKeycode(Display* dpy, KeySym keysym) {
+KeyCode XDesktop::keysymToKeycode(KeySym keysym) {
int keycode = 0;
// XKeysymToKeycode() doesn't respect state, so we have to use
// something slightly more complex
- keycode = XkbKeysymToKeycode(dpy, keysym);
+ keycode = XkbKeysymToKeycode(keysym);
if (keycode != 0)
return keycode;
// TODO: try to further guess keycode with all possible mods as Xvnc does
- keycode = addKeysym(dpy, keysym);
+ keycode = addKeysym(keysym);
if (keycode == 0)
vlog.error("Failure adding new keysym 0x%lx", keysym);
@@ -538,7 +538,7 @@ void XDesktop::keyEvent(uint32_t keysym, uint32_t xtcode, bool down) {
if (pressedKeys.find(keysym) != pressedKeys.end())
keycode = pressedKeys[keysym];
else {
- keycode = keysymToKeycode(dpy, keysym);
+ keycode = keysymToKeycode(keysym);
}
}
@@ -931,7 +931,7 @@ bool XDesktop::handleGlobalEvent(XEvent* ev) {
if (cev->window == cev->root)
return false;
- server->setCursor(0, 0, Point(), NULL);
+ server->setCursor(0, 0, Point(), nullptr);
return true;
#endif
}
@@ -942,8 +942,8 @@ bool XDesktop::handleGlobalEvent(XEvent* ev) {
void XDesktop::queryApproved()
{
assert(isRunning());
- server->approveConnection(queryConnectSock, true, 0);
- queryConnectSock = 0;
+ server->approveConnection(queryConnectSock, true, nullptr);
+ queryConnectSock = nullptr;
}
void XDesktop::queryRejected()
@@ -951,7 +951,7 @@ void XDesktop::queryRejected()
assert(isRunning());
server->approveConnection(queryConnectSock, false,
"Connection rejected by local user");
- queryConnectSock = 0;
+ queryConnectSock = nullptr;
}
#ifdef HAVE_XFIXES
@@ -960,7 +960,7 @@ bool XDesktop::setCursor()
XFixesCursorImage *cim;
cim = XFixesGetCursorImage(dpy);
- if (cim == NULL)
+ if (cim == nullptr)
return false;
// Copied from XserverDesktop::setCursor() in
diff --git a/unix/x0vncserver/XDesktop.h b/unix/x0vncserver/XDesktop.h
index fc230e5b..125ddeb0 100644
--- a/unix/x0vncserver/XDesktop.h
+++ b/unix/x0vncserver/XDesktop.h
@@ -47,25 +47,25 @@ public:
virtual ~XDesktop();
void poll();
// -=- SDesktop interface
- virtual void init(rfb::VNCServer* vs);
- virtual void start();
- virtual void stop();
- virtual void terminate();
+ void init(rfb::VNCServer* vs) override;
+ void start() override;
+ void stop() override;
+ void terminate() override;
bool isRunning();
- virtual void queryConnection(network::Socket* sock,
- const char* userName);
- virtual void pointerEvent(const rfb::Point& pos, int buttonMask);
- virtual void keyEvent(uint32_t keysym, uint32_t xtcode, bool down);
- virtual void clientCutText(const char* str);
- virtual unsigned int setScreenLayout(int fb_width, int fb_height,
- const rfb::ScreenSet& layout);
+ void queryConnection(network::Socket* sock,
+ const char* userName) override;
+ void pointerEvent(const rfb::Point& pos, int buttonMask) override;
+ void keyEvent(uint32_t keysym, uint32_t xtcode, bool down) override;
+ void clientCutText(const char* str) override;
+ unsigned int setScreenLayout(int fb_width, int fb_height,
+ const rfb::ScreenSet& layout) override;
// -=- TXGlobalEventHandler interface
- virtual bool handleGlobalEvent(XEvent* ev);
+ bool handleGlobalEvent(XEvent* ev) override;
// -=- QueryResultCallback interface
- virtual void queryApproved();
- virtual void queryRejected();
+ void queryApproved() override;
+ void queryRejected() override;
protected:
Display* dpy;
@@ -101,10 +101,10 @@ protected:
protected:
#ifdef HAVE_XTEST
- KeyCode XkbKeysymToKeycode(Display* dpy, KeySym keysym);
- KeyCode addKeysym(Display* dpy, KeySym keysym);
- void deleteAddedKeysyms(Display* dpy);
- KeyCode keysymToKeycode(Display* dpy, KeySym keysym);
+ KeyCode XkbKeysymToKeycode(KeySym keysym);
+ KeyCode addKeysym(KeySym keysym);
+ void deleteAddedKeysyms();
+ KeyCode keysymToKeycode(KeySym keysym);
#endif
#ifdef HAVE_XFIXES
bool setCursor();
diff --git a/unix/x0vncserver/XPixelBuffer.cxx b/unix/x0vncserver/XPixelBuffer.cxx
index b7506513..0e24cc51 100644
--- a/unix/x0vncserver/XPixelBuffer.cxx
+++ b/unix/x0vncserver/XPixelBuffer.cxx
@@ -35,7 +35,7 @@ using namespace rfb;
XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
const Rect &rect)
: FullFramePixelBuffer(),
- m_poller(0),
+ m_poller(nullptr),
m_dpy(dpy),
m_image(factory.newImage(dpy, rect.width(), rect.height())),
m_offsetLeft(rect.tl.x),
diff --git a/unix/x0vncserver/XPixelBuffer.h b/unix/x0vncserver/XPixelBuffer.h
index 18c85fe2..7556e6ef 100644
--- a/unix/x0vncserver/XPixelBuffer.h
+++ b/unix/x0vncserver/XPixelBuffer.h
@@ -45,7 +45,7 @@ public:
inline void poll(rfb::VNCServer *server) { m_poller->poll(server); }
// Override PixelBuffer::grabRegion().
- virtual void grabRegion(const rfb::Region& region);
+ void grabRegion(const rfb::Region& region) override;
protected:
PollingManager *m_poller;
diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx
index ffaf5788..49c95137 100644
--- a/unix/x0vncserver/x0vncserver.cxx
+++ b/unix/x0vncserver/x0vncserver.cxx
@@ -90,10 +90,10 @@ static const char* defaultDesktopName()
return "";
struct passwd* pwent = getpwuid(getuid());
- if (pwent == NULL)
+ if (pwent == nullptr)
return "";
- int len = snprintf(NULL, 0, "%s@%s", pwent->pw_name, hostname.data());
+ int len = snprintf(nullptr, 0, "%s@%s", pwent->pw_name, hostname.data());
if (len < 0)
return "";
@@ -154,19 +154,19 @@ class FileTcpFilter : public TcpFilter
public:
FileTcpFilter(const char *fname)
- : TcpFilter("-"), fileName(NULL), lastModTime(0)
+ : TcpFilter("-"), fileName(nullptr), lastModTime(0)
{
- if (fname != NULL)
+ if (fname != nullptr)
fileName = strdup((char *)fname);
}
virtual ~FileTcpFilter()
{
- if (fileName != NULL)
+ if (fileName != nullptr)
free(fileName);
}
- virtual bool verifyConnection(Socket* s)
+ bool verifyConnection(Socket* s) override
{
if (!reloadRules()) {
vlog.error("Could not read IP filtering rules: rejecting all clients");
@@ -182,7 +182,7 @@ protected:
bool reloadRules()
{
- if (fileName == NULL)
+ if (fileName == nullptr)
return true;
struct stat st;
@@ -192,7 +192,7 @@ protected:
if (st.st_mtime != lastModTime) {
// Actually reload only if the file was modified
FILE *fp = fopen(fileName, "r");
- if (fp == NULL)
+ if (fp == nullptr)
return false;
// Remove all the rules from the parent class
@@ -225,14 +225,14 @@ private:
bool readLine(char *buf, int bufSize, FILE *fp)
{
- if (fp == NULL || buf == NULL || bufSize == 0)
+ if (fp == nullptr || buf == nullptr || bufSize == 0)
return false;
- if (fgets(buf, bufSize, fp) == NULL)
+ if (fgets(buf, bufSize, fp) == nullptr)
return false;
char *ptr = strchr(buf, '\n');
- if (ptr != NULL) {
+ if (ptr != nullptr) {
*ptr = '\0'; // remove newline at the end
} else {
if (!feof(fp)) {
@@ -353,7 +353,7 @@ int main(int argc, char** argv)
const char *addr = interface;
if (strcasecmp(addr, "all") == 0)
- addr = 0;
+ addr = nullptr;
if (localhostOnly)
createLocalTcpListeners(&tcp_listeners, (int)rfbport);
else
@@ -368,10 +368,8 @@ int main(int argc, char** argv)
FileTcpFilter fileTcpFilter(hostsFile);
if (strlen(hostsFile) != 0)
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++)
- (*i)->setFilter(&fileTcpFilter);
+ for (SocketListener* listener : listeners)
+ listener->setFilter(&fileTcpFilter);
}
if (listeners.empty()) {
@@ -395,10 +393,8 @@ int main(int argc, char** argv)
FD_ZERO(&wfds);
FD_SET(ConnectionNumber(dpy), &rfds);
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++)
- FD_SET((*i)->getFd(), &rfds);
+ for (SocketListener* listener : listeners)
+ FD_SET(listener->getFd(), &rfds);
server.getSockets(&sockets);
int clients_connected = 0;
@@ -436,8 +432,8 @@ int main(int argc, char** argv)
// Do the wait...
sched.sleepStarted();
- int n = select(FD_SETSIZE, &rfds, &wfds, 0,
- wait_ms ? &tv : NULL);
+ int n = select(FD_SETSIZE, &rfds, &wfds, nullptr,
+ wait_ms ? &tv : nullptr);
sched.sleepFinished();
if (n < 0) {
@@ -450,11 +446,9 @@ int main(int argc, char** argv)
}
// Accept new VNC connections
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++) {
- if (FD_ISSET((*i)->getFd(), &rfds)) {
- Socket* sock = (*i)->accept();
+ for (SocketListener* listener : listeners) {
+ if (FD_ISSET(listener->getFd(), &rfds)) {
+ Socket* sock = listener->accept();
if (sock) {
server.addSocket(sock);
} else {
@@ -494,11 +488,8 @@ int main(int argc, char** argv)
TXWindow::handleXEvents(dpy);
// Run listener destructors; remove UNIX sockets etc
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++) {
- delete *i;
- }
+ for (SocketListener* listener : listeners)
+ delete listener;
vlog.info("Terminated");
return 0;