From f8e901fb8766c562b66da96ba75b60a8886b9a04 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 14 Nov 2024 07:37:17 +0100 Subject: [PATCH] Stop relying on "using namespace" There were not many uses of this left after the move to std::exception and the move to the core library. Let's get rid of the last stragglers and reduce the risk of name collisions. --- common/network/UnixSocket.cxx | 1 - unix/vncpasswd/vncpasswd.cxx | 6 +- unix/x0vncserver/PollingManager.cxx | 8 +- unix/x0vncserver/XDesktop.cxx | 14 ++-- unix/x0vncserver/XPixelBuffer.cxx | 22 +++--- unix/x0vncserver/x0vncserver.cxx | 29 ++++--- unix/xserver/hw/vnc/XserverDesktop.cc | 33 ++++---- unix/xserver/hw/vnc/vncExtInit.cc | 18 ++--- vncviewer/CConn.cxx | 39 +++++----- vncviewer/DesktopWindow.cxx | 6 +- vncviewer/OptionsDialog.cxx | 107 +++++++++++++------------- vncviewer/ServerDialog.cxx | 22 +++--- vncviewer/UserDialog.cxx | 17 ++-- vncviewer/Viewport.cxx | 50 ++++++------ vncviewer/parameters.cxx | 19 +++-- vncviewer/vncviewer.cxx | 15 ++-- 16 files changed, 192 insertions(+), 214 deletions(-) diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index 9cea6184f..3aba8f045 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -36,7 +36,6 @@ #include using namespace network; -using namespace rdr; static core::LogWriter vlog("UnixSocket"); diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index 87fff5ac9..21f3b688c 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -42,8 +42,6 @@ #include #endif -using namespace rfb; - char* prog; static void usage() @@ -89,7 +87,7 @@ static int encrypt_pipe() { if (!result) break; - std::vector obfuscated = obfuscate(result); + std::vector obfuscated = rfb::obfuscate(result); if (fwrite(obfuscated.data(), obfuscated.size(), 1, stdout) != 1) { fprintf(stderr,"Writing to stdout failed\n"); return 1; @@ -178,7 +176,7 @@ static std::vector readpassword() { continue; } - return obfuscate(first.c_str()); + return rfb::obfuscate(first.c_str()); } } diff --git a/unix/x0vncserver/PollingManager.cxx b/unix/x0vncserver/PollingManager.cxx index e0bf4fbfa..04c3d065b 100644 --- a/unix/x0vncserver/PollingManager.cxx +++ b/unix/x0vncserver/PollingManager.cxx @@ -38,8 +38,6 @@ #include -using namespace rfb; - static core::LogWriter vlog("PollingMgr"); const int PollingManager::m_pollingOrder[32] = { @@ -126,7 +124,7 @@ void PollingManager::debugAfterPoll() // Search for changed rectangles on the screen. // -void PollingManager::poll(VNCServer *server) +void PollingManager::poll(rfb::VNCServer* server) { #ifdef DEBUG debugBeforePoll(); @@ -145,7 +143,7 @@ void PollingManager::poll(VNCServer *server) #define DBG_REPORT_CHANGES(title) #endif -bool PollingManager::pollScreen(VNCServer *server) +bool PollingManager::pollScreen(rfb::VNCServer* server) { if (!server) return false; @@ -262,7 +260,7 @@ int PollingManager::checkColumn(int x, int y, int h, bool *pChangeFlags) return nTilesChanged; } -int PollingManager::sendChanges(VNCServer *server) const +int PollingManager::sendChanges(rfb::VNCServer* server) const { const bool *pChangeFlags = m_changeFlags; int nTilesChanged = 0; diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index 3fd7e9a79..fd6edaeaa 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -58,8 +58,6 @@ void vncSetGlueContext(Display *dpy, void *res); #include #include -using namespace rfb; - extern const unsigned short code_map_qnum_to_xorgevdev[]; extern const unsigned int code_map_qnum_to_xorgevdev_len; @@ -244,7 +242,7 @@ void XDesktop::poll() { } } -void XDesktop::init(VNCServer* vs) +void XDesktop::init(rfb::VNCServer* vs) { server = vs; } @@ -612,9 +610,9 @@ void XDesktop::keyEvent(uint32_t keysym, uint32_t xtcode, bool down) { #endif } -ScreenSet XDesktop::computeScreenLayout() +rfb::ScreenSet XDesktop::computeScreenLayout() { - ScreenSet layout; + rfb::ScreenSet layout; char buffer[2048]; #ifdef HAVE_XRANDR @@ -629,7 +627,7 @@ ScreenSet XDesktop::computeScreenLayout() XRRFreeScreenResources(res); // Adjust the layout relative to the geometry - ScreenSet::iterator iter, iter_next; + rfb::ScreenSet::iterator iter, iter_next; core::Point offset(-geometry->offsetLeft(), -geometry->offsetTop()); for (iter = layout.begin();iter != layout.end();iter = iter_next) { iter_next = iter; ++iter_next; @@ -712,9 +710,9 @@ unsigned int XDesktop::setScreenLayout(int fb_width, int fb_height, } else { vlog.debug("Impossible layout - trying to adjust"); - ScreenSet::const_iterator firstscreen = layout.begin(); + rfb::ScreenSet::const_iterator firstscreen = layout.begin(); adjustedLayout.add_screen(*firstscreen); - ScreenSet::iterator iter = adjustedLayout.begin(); + rfb::ScreenSet::iterator iter = adjustedLayout.begin(); RROutput outputId = None; for (int i = 0;i < vncRandRGetOutputCount();i++) { diff --git a/unix/x0vncserver/XPixelBuffer.cxx b/unix/x0vncserver/XPixelBuffer.cxx index 8b8188ef5..5e89a342d 100644 --- a/unix/x0vncserver/XPixelBuffer.cxx +++ b/unix/x0vncserver/XPixelBuffer.cxx @@ -34,8 +34,6 @@ #include -using namespace rfb; - XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory, const core::Rect& rect) : FullFramePixelBuffer(), @@ -46,16 +44,16 @@ XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory, m_offsetTop(rect.tl.y) { // Fill in the PixelFormat structure of the parent class. - format = PixelFormat(m_image->xim->bits_per_pixel, - m_image->xim->depth, - (m_image->xim->byte_order == MSBFirst), - true, - m_image->xim->red_mask >> (ffs(m_image->xim->red_mask) - 1), - m_image->xim->green_mask >> (ffs(m_image->xim->green_mask) - 1), - m_image->xim->blue_mask >> (ffs(m_image->xim->blue_mask) - 1), - ffs(m_image->xim->red_mask) - 1, - ffs(m_image->xim->green_mask) - 1, - ffs(m_image->xim->blue_mask) - 1); + format = rfb::PixelFormat(m_image->xim->bits_per_pixel, + m_image->xim->depth, + (m_image->xim->byte_order == MSBFirst), + true, + m_image->xim->red_mask >> (ffs(m_image->xim->red_mask) - 1), + m_image->xim->green_mask >> (ffs(m_image->xim->green_mask) - 1), + m_image->xim->blue_mask >> (ffs(m_image->xim->blue_mask) - 1), + ffs(m_image->xim->red_mask) - 1, + ffs(m_image->xim->green_mask) - 1, + ffs(m_image->xim->blue_mask) - 1); // Set up the remaining data of the parent class. setBuffer(rect.width(), rect.height(), (uint8_t *)m_image->xim->data, diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index f07ab1c69..4cd673b8d 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -60,9 +60,6 @@ extern char buildtime[]; -using namespace rfb; -using namespace network; - static core::LogWriter vlog("Main"); static const char* defaultDesktopName(); @@ -144,7 +141,7 @@ static bool hasSystemdListeners() #endif } -static int createSystemdListeners(std::list *listeners) +static int createSystemdListeners(std::list *listeners) { #ifdef HAVE_LIBSYSTEMD int count = sd_listen_fds(0); @@ -155,7 +152,7 @@ static int createSystemdListeners(std::list *listeners) } for (int i = 0; i < count; ++i) - listeners->push_back(new TcpListener(SD_LISTEN_FDS_START + i)); + listeners->push_back(new network::TcpListener(SD_LISTEN_FDS_START + i)); return count; #else @@ -165,7 +162,7 @@ static int createSystemdListeners(std::list *listeners) } -class FileTcpFilter : public TcpFilter +class FileTcpFilter : public network::TcpFilter { public: @@ -183,7 +180,7 @@ class FileTcpFilter : public TcpFilter free(fileName); } - bool verifyConnection(Socket* s) override + bool verifyConnection(network::Socket* s) override { if (!reloadRules()) { vlog.error("Could not read IP filtering rules: rejecting all clients"); @@ -336,7 +333,7 @@ int main(int argc, char** argv) signal(SIGINT, CleanupSignalHandler); signal(SIGTERM, CleanupSignalHandler); - std::list listeners; + std::list listeners; try { TXWindow::init(dpy,"x0vncserver"); @@ -348,7 +345,7 @@ int main(int argc, char** argv) } XDesktop desktop(dpy, &geo); - VNCServerST server(desktopName, &desktop); + rfb::VNCServerST server(desktopName, &desktop); if (createSystemdListeners(&listeners) > 0) { // When systemd is in charge of listeners, do not listen to anything else @@ -380,7 +377,7 @@ int main(int argc, char** argv) FileTcpFilter fileTcpFilter(hostsFile); if (strlen(hostsFile) != 0) - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) listener->setFilter(&fileTcpFilter); } @@ -395,8 +392,8 @@ int main(int argc, char** argv) int wait_ms, nextTimeout; struct timeval tv; fd_set rfds, wfds; - std::list sockets; - std::list::iterator i; + std::list sockets; + std::list::iterator i; // Process any incoming X events TXWindow::handleXEvents(dpy); @@ -405,7 +402,7 @@ int main(int argc, char** argv) FD_ZERO(&wfds); FD_SET(ConnectionNumber(dpy), &rfds); - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) FD_SET(listener->getFd(), &rfds); server.getSockets(&sockets); @@ -458,9 +455,9 @@ int main(int argc, char** argv) } // Accept new VNC connections - for (SocketListener* listener : listeners) { + for (network::SocketListener* listener : listeners) { if (FD_ISSET(listener->getFd(), &rfds)) { - Socket* sock = listener->accept(); + network::Socket* sock = listener->accept(); if (sock) { server.addSocket(sock); } else { @@ -500,7 +497,7 @@ int main(int argc, char** argv) TXWindow::handleXEvents(dpy); // Run listener destructors; remove UNIX sockets etc - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) delete listener; vlog.info("Terminated"); diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index 54e88d701..6fb2c399d 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -60,9 +60,6 @@ void vncSetGlueContext(int screenIndex); void vncPresentMscEvent(uint64_t id, uint64_t msc); } -using namespace rfb; -using namespace network; - static core::LogWriter vlog("XserverDesktop"); core::BoolParameter @@ -87,10 +84,10 @@ XserverDesktop::XserverDesktop(int screenIndex_, { format = pf; - server = new VNCServerST(name, this); + server = new rfb::VNCServerST(name, this); setFramebuffer(width, height, fbptr, stride_); - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) vncSetNotifyFd(listener->getFd(), screenIndex, true, false); } @@ -118,7 +115,7 @@ void XserverDesktop::unblockUpdates() void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride_) { - ScreenSet layout; + rfb::ScreenSet layout; if (shadowFramebuffer) { delete [] shadowFramebuffer; @@ -322,10 +319,10 @@ void XserverDesktop::handleSocketEvent(int fd, bool read, bool write) } bool XserverDesktop::handleListenerEvent(int fd, - std::list* sockets, - VNCServer* sockserv) + std::list* sockets, + rfb::VNCServer* sockserv) { - std::list::iterator i; + std::list::iterator i; for (i = sockets->begin(); i != sockets->end(); i++) { if ((*i)->getFd() == fd) @@ -335,7 +332,7 @@ bool XserverDesktop::handleListenerEvent(int fd, if (i == sockets->end()) return false; - Socket* sock = (*i)->accept(); + network::Socket* sock = (*i)->accept(); vlog.debug("new client, sock %d", sock->getFd()); sockserv->addSocket(sock); vncSetNotifyFd(sock->getFd(), screenIndex, true, false); @@ -344,11 +341,11 @@ bool XserverDesktop::handleListenerEvent(int fd, } bool XserverDesktop::handleSocketEvent(int fd, - VNCServer* sockserv, + rfb::VNCServer* sockserv, bool read, bool write) { - std::list sockets; - std::list::iterator i; + std::list sockets; + std::list::iterator i; sockserv->getSockets(&sockets); for (i = sockets.begin(); i != sockets.end(); i++) { @@ -377,8 +374,8 @@ void XserverDesktop::blockHandler(int* timeout) vncInitInputDevice(); try { - std::list sockets; - std::list::iterator i; + std::list sockets; + std::list::iterator i; server->getSockets(&sockets); for (i = sockets.begin(); i != sockets.end(); i++) { int fd = (*i)->getFd(); @@ -414,10 +411,12 @@ void XserverDesktop::blockHandler(int* timeout) } } -void XserverDesktop::addClient(Socket* sock, bool reverse, bool viewOnly) +void XserverDesktop::addClient(network::Socket* sock, + bool reverse, bool viewOnly) { vlog.debug("new client, sock %d reverse %d",sock->getFd(),reverse); - server->addSocket(sock, reverse, viewOnly ? AccessView : AccessDefault); + server->addSocket(sock, reverse, + viewOnly ? rfb::AccessView : rfb::AccessDefault); vncSetNotifyFd(sock->getFd(), screenIndex, true, false); } diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 0b8427f7d..6f56e6d85 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -55,8 +55,6 @@ extern "C" { void vncSetGlueContext(int screenIndex); } -using namespace rfb; - static core::LogWriter vlog("vncext"); // We can't safely get this from Xorg @@ -140,7 +138,7 @@ static const char* defaultDesktopName() return name; } -static PixelFormat vncGetPixelFormat(int scrIdx) +static rfb::PixelFormat vncGetPixelFormat(int scrIdx) { int depth, bpp; int trueColour, bigEndian; @@ -164,9 +162,9 @@ static PixelFormat vncGetPixelFormat(int scrIdx) greenMax = greenMask >> greenShift; blueMax = blueMask >> blueShift; - return PixelFormat(bpp, depth, bigEndian, trueColour, - redMax, greenMax, blueMax, - redShift, greenShift, blueShift); + return rfb::PixelFormat(bpp, depth, bigEndian, trueColour, + redMax, greenMax, blueMax, + redShift, greenShift, blueShift); } static void parseOverrideList(const char *text, ParamSet &out) @@ -264,7 +262,7 @@ void vncExtensionInit(void) if (!inetd && listeners.empty()) throw std::runtime_error("No path or port configured for incoming connections"); - PixelFormat pf = vncGetPixelFormat(scr); + rfb::PixelFormat pf = vncGetPixelFormat(scr); vncSetGlueContext(scr); desktop[scr] = new XserverDesktop(scr, @@ -415,11 +413,11 @@ void vncSetLEDState(unsigned long leds) state = 0; if (leds & (1 << 0)) - state |= ledCapsLock; + state |= rfb::ledCapsLock; if (leds & (1 << 1)) - state |= ledNumLock; + state |= rfb::ledNumLock; if (leds & (1 << 2)) - state |= ledScrollLock; + state |= rfb::ledScrollLock; for (int scr = 0; scr < vncGetScreenCount(); scr++) desktop[scr]->setLEDState(state); diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 0887d84dd..23755b69d 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -61,19 +61,17 @@ #include "win32.h" #endif -using namespace rfb; - static core::LogWriter vlog("CConn"); // 8 colours (1 bit per component) -static const PixelFormat verylowColourPF(8, 3,false, true, - 1, 1, 1, 2, 1, 0); +static const rfb::PixelFormat verylowColourPF(8, 3,false, true, + 1, 1, 1, 2, 1, 0); // 64 colours (2 bits per component) -static const PixelFormat lowColourPF(8, 6, false, true, - 3, 3, 3, 4, 2, 0); +static const rfb::PixelFormat lowColourPF(8, 6, false, true, + 3, 3, 3, 4, 2, 0); // 256 colours (2-3 bits per component) -static const PixelFormat mediumColourPF(8, 8, false, true, - 7, 7, 3, 5, 2, 0); +static const rfb::PixelFormat mediumColourPF(8, 8, false, true, + 7, 7, 3, 5, 2, 0); // Time new bandwidth estimates are weighted against (in ms) static const unsigned bpsEstimateWindow = 1000; @@ -174,11 +172,11 @@ std::string CConn::connectionInfo() infoText += "\n"; infoText += core::format(_("Requested encoding: %s"), - encodingName(getPreferredEncoding())); + rfb::encodingName(getPreferredEncoding())); infoText += "\n"; infoText += core::format(_("Last used encoding: %s"), - encodingName(lastServerEncoding)); + rfb::encodingName(lastServerEncoding)); infoText += "\n"; infoText += core::format(_("Line speed estimate: %d kbit/s"), @@ -190,7 +188,7 @@ std::string CConn::connectionInfo() infoText += "\n"; infoText += core::format(_("Security method: %s"), - secTypeName(csecurity->getType())); + rfb::secTypeName(csecurity->getType())); infoText += "\n"; return infoText; @@ -285,7 +283,7 @@ void CConn::resetPassword() ////////////////////// CConnection callback methods ////////////////////// -bool CConn::showMsgBox(MsgBoxFlags flags, const char *title, +bool CConn::showMsgBox(rfb::MsgBoxFlags flags, const char *title, const char *text) { return dlg.showMsgBox(flags, title, text); @@ -315,7 +313,7 @@ void CConn::initDone() // Force a switch to the format and encoding we'd like updatePixelFormat(); - int encNum = encodingNum(::preferredEncoding); + int encNum = rfb::encodingNum(::preferredEncoding); if (encNum != -1) setPreferredEncoding(encNum); } @@ -334,7 +332,7 @@ void CConn::setExtendedDesktopSize(unsigned reason, unsigned result, { CConnection::setExtendedDesktopSize(reason, result, w, h, layout); - if ((reason == reasonClient) && (result != resultSuccess)) { + if ((reason == rfb::reasonClient) && (result != rfb::resultSuccess)) { vlog.error(_("SetDesktopSize failed: %d"), result); return; } @@ -420,7 +418,7 @@ bool CConn::dataRect(const core::Rect& r, int encoding) { bool ret; - if (encoding != encodingCopyRect) + if (encoding != rfb::encodingCopyRect) lastServerEncoding = encoding; ret = CConnection::dataRect(r, encoding); @@ -446,9 +444,10 @@ void CConn::fence(uint32_t flags, unsigned len, const uint8_t data[]) { CMsgHandler::fence(flags, len, data); - if (flags & fenceFlagRequest) { + if (flags & rfb::fenceFlagRequest) { // We handle everything synchronously so we trivially honor these modes - flags = flags & (fenceFlagBlockBefore | fenceFlagBlockAfter); + flags = flags & (rfb::fenceFlagBlockBefore | + rfb::fenceFlagBlockAfter); writer()->writeFence(flags, len, data); return; @@ -506,7 +505,7 @@ void CConn::autoSelectFormatAndEncoding() int newQualityLevel = ::qualityLevel; // Always use Tight - setPreferredEncoding(encodingTight); + setPreferredEncoding(rfb::encodingTight); // Select appropriate quality level if (!noJpeg) { @@ -552,7 +551,7 @@ void CConn::autoSelectFormatAndEncoding() // format and encoding appropriately. void CConn::updatePixelFormat() { - PixelFormat pf; + rfb::PixelFormat pf; if (fullColour) { pf = fullColourPF; @@ -580,7 +579,7 @@ void CConn::handleOptions(void *data) // list is cheap. Avoid overriding what the auto logic has selected // though. if (!autoSelect) { - int encNum = encodingNum(::preferredEncoding); + int encNum = rfb::encodingNum(::preferredEncoding); if (encNum != -1) self->setPreferredEncoding(encNum); diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index d378075c2..5dca5069d 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -73,8 +73,6 @@ static int edge_scroll_size_y = 96; // default: roughly 60 fps for smooth motion #define EDGE_SCROLL_SECONDS_PER_FRAME 0.016666 -using namespace rfb; - static core::LogWriter vlog("DesktopWindow"); // Global due to http://www.fltk.org/str.php?L2177 and the similar @@ -1297,8 +1295,8 @@ void DesktopWindow::reconfigureFullscreen(void* /*data*/) void DesktopWindow::remoteResize(int width, int height) { - ScreenSet layout; - ScreenSet::const_iterator iter; + rfb::ScreenSet layout; + rfb::ScreenSet::const_iterator iter; if (!fullscreen_active() || (width > w()) || (height > h())) { // In windowed mode (or the framebuffer is so large that we need diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx index a7e2de2f1..a958ceeba 100644 --- a/vncviewer/OptionsDialog.cxx +++ b/vncviewer/OptionsDialog.cxx @@ -53,9 +53,6 @@ #include #include -using namespace std; -using namespace rfb; - std::map OptionsDialog::callbacks; static std::set instances; @@ -162,24 +159,24 @@ void OptionsDialog::loadOptions(void) /* Compression */ autoselectCheckbox->value(autoSelect); - int encNum = encodingNum(preferredEncoding); + int encNum = rfb::encodingNum(preferredEncoding); switch (encNum) { - case encodingTight: + case rfb::encodingTight: tightButton->setonly(); break; - case encodingZRLE: + case rfb::encodingZRLE: zrleButton->setonly(); break; - case encodingHextile: + case rfb::encodingHextile: hextileButton->setonly(); break; #ifdef HAVE_H264 - case encodingH264: + case rfb::encodingH264: h264Button->setonly(); break; #endif - case encodingRaw: + case rfb::encodingRaw: rawButton->setonly(); break; } @@ -215,11 +212,11 @@ void OptionsDialog::loadOptions(void) #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) /* Security */ - Security security(SecurityClient::secTypes); + rfb::Security security(rfb::SecurityClient::secTypes); - list secTypes; + std::list secTypes; - list secTypesExt; + std::list secTypesExt; encNoneCheckbox->value(false); #ifdef HAVE_GNUTLS @@ -237,11 +234,11 @@ void OptionsDialog::loadOptions(void) secTypes = security.GetEnabledSecTypes(); for (uint8_t type : secTypes) { switch (type) { - case secTypeNone: + case rfb::secTypeNone: encNoneCheckbox->value(true); authNoneCheckbox->value(true); break; - case secTypeVncAuth: + case rfb::secTypeVncAuth: encNoneCheckbox->value(true); authVncCheckbox->value(true); break; @@ -251,49 +248,49 @@ void OptionsDialog::loadOptions(void) secTypesExt = security.GetEnabledExtSecTypes(); for (uint32_t type : secTypesExt) { switch (type) { - case secTypePlain: + case rfb::secTypePlain: encNoneCheckbox->value(true); authPlainCheckbox->value(true); break; #ifdef HAVE_GNUTLS - case secTypeTLSNone: + case rfb::secTypeTLSNone: encTLSCheckbox->value(true); authNoneCheckbox->value(true); break; - case secTypeTLSVnc: + case rfb::secTypeTLSVnc: encTLSCheckbox->value(true); authVncCheckbox->value(true); break; - case secTypeTLSPlain: + case rfb::secTypeTLSPlain: encTLSCheckbox->value(true); authPlainCheckbox->value(true); break; - case secTypeX509None: + case rfb::secTypeX509None: encX509Checkbox->value(true); authNoneCheckbox->value(true); break; - case secTypeX509Vnc: + case rfb::secTypeX509Vnc: encX509Checkbox->value(true); authVncCheckbox->value(true); break; - case secTypeX509Plain: + case rfb::secTypeX509Plain: encX509Checkbox->value(true); authPlainCheckbox->value(true); break; #endif #ifdef HAVE_NETTLE - case secTypeRA2: - case secTypeRA256: + case rfb::secTypeRA2: + case rfb::secTypeRA256: encRSAAESCheckbox->value(true); authVncCheckbox->value(true); authPlainCheckbox->value(true); break; - case secTypeRA2ne: - case secTypeRAne256: + case rfb::secTypeRA2ne: + case rfb::secTypeRAne256: authVncCheckbox->value(true); /* fall through */ - case secTypeDH: - case secTypeMSLogonII: + case rfb::secTypeDH: + case rfb::secTypeMSLogonII: encNoneCheckbox->value(true); authPlainCheckbox->value(true); break; @@ -303,8 +300,8 @@ void OptionsDialog::loadOptions(void) } #ifdef HAVE_GNUTLS - caInput->value(CSecurityTLS::X509CA); - crlInput->value(CSecurityTLS::X509CRL); + caInput->value(rfb::CSecurityTLS::X509CA); + crlInput->value(rfb::CSecurityTLS::X509CRL); handleX509(encX509Checkbox, this); #endif @@ -362,17 +359,17 @@ void OptionsDialog::storeOptions(void) autoSelect.setParam(autoselectCheckbox->value()); if (tightButton->value()) - preferredEncoding.setParam(encodingName(encodingTight)); + preferredEncoding.setParam(rfb::encodingName(rfb::encodingTight)); else if (zrleButton->value()) - preferredEncoding.setParam(encodingName(encodingZRLE)); + preferredEncoding.setParam(rfb::encodingName(rfb::encodingZRLE)); else if (hextileButton->value()) - preferredEncoding.setParam(encodingName(encodingHextile)); + preferredEncoding.setParam(rfb::encodingName(rfb::encodingHextile)); #ifdef HAVE_H264 else if (h264Button->value()) - preferredEncoding.setParam(encodingName(encodingH264)); + preferredEncoding.setParam(rfb::encodingName(rfb::encodingH264)); #endif else if (rawButton->value()) - preferredEncoding.setParam(encodingName(encodingRaw)); + preferredEncoding.setParam(rfb::encodingName(rfb::encodingRaw)); fullColour.setParam(fullcolorCheckbox->value()); if (verylowcolorCheckbox->value()) @@ -389,26 +386,26 @@ void OptionsDialog::storeOptions(void) #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) /* Security */ - Security security; + rfb::Security security; /* Process security types which don't use encryption */ if (encNoneCheckbox->value()) { if (authNoneCheckbox->value()) - security.EnableSecType(secTypeNone); + security.EnableSecType(rfb::secTypeNone); if (authVncCheckbox->value()) { - security.EnableSecType(secTypeVncAuth); + security.EnableSecType(rfb::secTypeVncAuth); #ifdef HAVE_NETTLE - security.EnableSecType(secTypeRA2ne); - security.EnableSecType(secTypeRAne256); + security.EnableSecType(rfb::secTypeRA2ne); + security.EnableSecType(rfb::secTypeRAne256); #endif } if (authPlainCheckbox->value()) { - security.EnableSecType(secTypePlain); + security.EnableSecType(rfb::secTypePlain); #ifdef HAVE_NETTLE - security.EnableSecType(secTypeRA2ne); - security.EnableSecType(secTypeRAne256); - security.EnableSecType(secTypeDH); - security.EnableSecType(secTypeMSLogonII); + security.EnableSecType(rfb::secTypeRA2ne); + security.EnableSecType(rfb::secTypeRAne256); + security.EnableSecType(rfb::secTypeDH); + security.EnableSecType(rfb::secTypeMSLogonII); #endif } } @@ -417,34 +414,34 @@ void OptionsDialog::storeOptions(void) /* Process security types which use TLS encryption */ if (encTLSCheckbox->value()) { if (authNoneCheckbox->value()) - security.EnableSecType(secTypeTLSNone); + security.EnableSecType(rfb::secTypeTLSNone); if (authVncCheckbox->value()) - security.EnableSecType(secTypeTLSVnc); + security.EnableSecType(rfb::secTypeTLSVnc); if (authPlainCheckbox->value()) - security.EnableSecType(secTypeTLSPlain); + security.EnableSecType(rfb::secTypeTLSPlain); } /* Process security types which use X509 encryption */ if (encX509Checkbox->value()) { if (authNoneCheckbox->value()) - security.EnableSecType(secTypeX509None); + security.EnableSecType(rfb::secTypeX509None); if (authVncCheckbox->value()) - security.EnableSecType(secTypeX509Vnc); + security.EnableSecType(rfb::secTypeX509Vnc); if (authPlainCheckbox->value()) - security.EnableSecType(secTypeX509Plain); + security.EnableSecType(rfb::secTypeX509Plain); } - CSecurityTLS::X509CA.setParam(caInput->value()); - CSecurityTLS::X509CRL.setParam(crlInput->value()); + rfb::CSecurityTLS::X509CA.setParam(caInput->value()); + rfb::CSecurityTLS::X509CRL.setParam(crlInput->value()); #endif #ifdef HAVE_NETTLE if (encRSAAESCheckbox->value()) { - security.EnableSecType(secTypeRA2); - security.EnableSecType(secTypeRA256); + security.EnableSecType(rfb::secTypeRA2); + security.EnableSecType(rfb::secTypeRA256); } #endif - SecurityClient::secTypes.setParam(security.ToString()); + rfb::SecurityClient::secTypes.setParam(security.ToString()); #endif /* Input */ diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index d131bf4e3..ad3fe88ca 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -57,9 +57,6 @@ #include "vncviewer.h" #include "parameters.h" - -using namespace std; - static core::LogWriter vlog("ServerDialog"); const char* SERVER_HISTORY="tigervnc.history"; @@ -144,7 +141,7 @@ void ServerDialog::run(const char* servername, char *newservername) dialog.loadServerHistory(); dialog.serverName->clear(); - for (const string& entry : dialog.serverHistory) + for (const std::string& entry : dialog.serverHistory) fltk_menu_add(dialog.serverName->menubutton(), entry.c_str(), 0, nullptr); } catch (std::exception& e) { @@ -314,13 +311,14 @@ void ServerDialog::handleConnect(Fl_Widget* /*widget*/, void *data) } -static bool same_server(const string& a, const string& b) +static bool same_server(const std::string& a, const std::string& b) { - string hostA, hostB; + std::string hostA, hostB; int portA, portB; #ifndef WIN32 - if ((a.find("/") != string::npos) || (b.find("/") != string::npos)) + if ((a.find("/") != std::string::npos) || + (b.find("/") != std::string::npos)) return a == b; #endif @@ -343,7 +341,7 @@ static bool same_server(const string& a, const string& b) void ServerDialog::loadServerHistory() { - list rawHistory; + std::list rawHistory; serverHistory.clear(); @@ -416,9 +414,11 @@ void ServerDialog::loadServerHistory() #endif // Filter out duplicates, even if they have different formats - for (const string& entry : rawHistory) { + for (const std::string& entry : rawHistory) { if (std::find_if(serverHistory.begin(), serverHistory.end(), - [&entry](const string& s) { return same_server(s, entry); }) != serverHistory.end()) + [&entry](const std::string& s) { + return same_server(s, entry); + }) != serverHistory.end()) continue; serverHistory.push_back(entry); } @@ -447,7 +447,7 @@ void ServerDialog::saveServerHistory() // Save the last X elements to the config file. size_t count = 0; - for (const string& entry : serverHistory) { + for (const std::string& entry : serverHistory) { if (++count > SERVER_HISTORY_SIZE) break; fprintf(f, "%s\n", entry.c_str()); diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index 206306613..b20a5d612 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -55,8 +55,6 @@ #include "../media/insecure.xpm" #pragma GCC diagnostic pop -using namespace rfb; - static Fl_Pixmap secure_icon(secure); static Fl_Pixmap insecure_icon(insecure); @@ -126,7 +124,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, obfPwd.resize(fread(obfPwd.data(), 1, obfPwd.size(), fp)); fclose(fp); - *password = deobfuscate(obfPwd.data(), obfPwd.size()); + *password = rfb::deobfuscate(obfPwd.data(), obfPwd.size()); return; } @@ -255,7 +253,8 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, throw rfb::auth_cancelled(); } -bool UserDialog::showMsgBox(MsgBoxFlags flags, const char* title, const char* text) +bool UserDialog::showMsgBox(rfb::MsgBoxFlags flags, + const char* title, const char* text) { char buffer[1024]; @@ -268,14 +267,14 @@ bool UserDialog::showMsgBox(MsgBoxFlags flags, const char* title, const char* te fl_message_title(title); switch (flags & 0xf) { - case M_OKCANCEL: + case rfb::M_OKCANCEL: return fl_choice("%s", nullptr, fl_ok, fl_cancel, buffer) == 1; - case M_YESNO: + case rfb::M_YESNO: return fl_choice("%s", nullptr, fl_yes, fl_no, buffer) == 1; - case M_OK: + case rfb::M_OK: default: - if (((flags & 0xf0) == M_ICONERROR) || - ((flags & 0xf0) == M_ICONWARNING)) + if (((flags & 0xf0) == rfb::M_ICONERROR) || + ((flags & 0xf0) == rfb::M_ICONWARNING)) fl_alert("%s", buffer); else fl_message("%s", buffer); diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 90ea855a5..66b2d8608 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -101,8 +101,6 @@ extern const unsigned int code_map_osx_to_qnum_len; #include "win32.h" #endif -using namespace rfb; - static core::LogWriter vlog("Viewport"); // Menu constants @@ -357,7 +355,8 @@ void Viewport::setLEDState(unsigned int ledState) memset(input, 0, sizeof(input)); count = 0; - if (!!(ledState & ledCapsLock) != !!(GetKeyState(VK_CAPITAL) & 0x1)) { + if (!!(ledState & rfb::ledCapsLock) != + !!(GetKeyState(VK_CAPITAL) & 0x1)) { input[count].type = input[count+1].type = INPUT_KEYBOARD; input[count].ki.wVk = input[count+1].ki.wVk = VK_CAPITAL; input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE; @@ -366,7 +365,8 @@ void Viewport::setLEDState(unsigned int ledState) count += 2; } - if (!!(ledState & ledNumLock) != !!(GetKeyState(VK_NUMLOCK) & 0x1)) { + if (!!(ledState & rfb::ledNumLock) != + !!(GetKeyState(VK_NUMLOCK) & 0x1)) { input[count].type = input[count+1].type = INPUT_KEYBOARD; input[count].ki.wVk = input[count+1].ki.wVk = VK_NUMLOCK; input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE; @@ -375,7 +375,8 @@ void Viewport::setLEDState(unsigned int ledState) count += 2; } - if (!!(ledState & ledScrollLock) != !!(GetKeyState(VK_SCROLL) & 0x1)) { + if (!!(ledState & rfb::ledScrollLock) != + !!(GetKeyState(VK_SCROLL) & 0x1)) { input[count].type = input[count+1].type = INPUT_KEYBOARD; input[count].ki.wVk = input[count+1].ki.wVk = VK_SCROLL; input[count].ki.wScan = input[count+1].ki.wScan = SCAN_FAKE; @@ -393,13 +394,13 @@ void Viewport::setLEDState(unsigned int ledState) #elif defined(__APPLE__) int ret; - ret = cocoa_set_caps_lock_state(ledState & ledCapsLock); + ret = cocoa_set_caps_lock_state(ledState & rfb::ledCapsLock); if (ret != 0) { vlog.error(_("Failed to update keyboard LED state: %d"), ret); return; } - ret = cocoa_set_num_lock_state(ledState & ledNumLock); + ret = cocoa_set_num_lock_state(ledState & rfb::ledNumLock); if (ret != 0) { vlog.error(_("Failed to update keyboard LED state: %d"), ret); return; @@ -416,17 +417,17 @@ void Viewport::setLEDState(unsigned int ledState) affect = values = 0; affect |= LockMask; - if (ledState & ledCapsLock) + if (ledState & rfb::ledCapsLock) values |= LockMask; mask = getModifierMask(XK_Num_Lock); affect |= mask; - if (ledState & ledNumLock) + if (ledState & rfb::ledNumLock) values |= mask; mask = getModifierMask(XK_Scroll_Lock); affect |= mask; - if (ledState & ledScrollLock) + if (ledState & rfb::ledScrollLock) values |= mask; ret = XkbLockModifiers(fl_display, XkbUseCoreKbd, affect, values); @@ -440,18 +441,18 @@ void Viewport::pushLEDState() unsigned int ledState; // Server support? - if (cc->server.ledState() == ledUnknown) + if (cc->server.ledState() == rfb::ledUnknown) return; ledState = 0; #if defined(WIN32) if (GetKeyState(VK_CAPITAL) & 0x1) - ledState |= ledCapsLock; + ledState |= rfb::ledCapsLock; if (GetKeyState(VK_NUMLOCK) & 0x1) - ledState |= ledNumLock; + ledState |= rfb::ledNumLock; if (GetKeyState(VK_SCROLL) & 0x1) - ledState |= ledScrollLock; + ledState |= rfb::ledScrollLock; #elif defined(__APPLE__) int ret; bool on; @@ -462,7 +463,7 @@ void Viewport::pushLEDState() return; } if (on) - ledState |= ledCapsLock; + ledState |= rfb::ledCapsLock; ret = cocoa_get_num_lock_state(&on); if (ret != 0) { @@ -470,10 +471,10 @@ void Viewport::pushLEDState() return; } if (on) - ledState |= ledNumLock; + ledState |= rfb::ledNumLock; // No support for Scroll Lock // - ledState |= (cc->server.ledState() & ledScrollLock); + ledState |= (cc->server.ledState() & rfb::ledScrollLock); #else unsigned int mask; @@ -488,28 +489,31 @@ void Viewport::pushLEDState() } if (xkbState.locked_mods & LockMask) - ledState |= ledCapsLock; + ledState |= rfb::ledCapsLock; mask = getModifierMask(XK_Num_Lock); if (xkbState.locked_mods & mask) - ledState |= ledNumLock; + ledState |= rfb::ledNumLock; mask = getModifierMask(XK_Scroll_Lock); if (xkbState.locked_mods & mask) - ledState |= ledScrollLock; + ledState |= rfb::ledScrollLock; #endif - if ((ledState & ledCapsLock) != (cc->server.ledState() & ledCapsLock)) { + if ((ledState & rfb::ledCapsLock) != + (cc->server.ledState() & rfb::ledCapsLock)) { vlog.debug("Inserting fake CapsLock to get in sync with server"); handleKeyPress(0x3a, XK_Caps_Lock); handleKeyRelease(0x3a); } - if ((ledState & ledNumLock) != (cc->server.ledState() & ledNumLock)) { + if ((ledState & rfb::ledNumLock) != + (cc->server.ledState() & rfb::ledNumLock)) { vlog.debug("Inserting fake NumLock to get in sync with server"); handleKeyPress(0x45, XK_Num_Lock); handleKeyRelease(0x45); } - if ((ledState & ledScrollLock) != (cc->server.ledState() & ledScrollLock)) { + if ((ledState & rfb::ledScrollLock) != + (cc->server.ledState() & rfb::ledScrollLock)) { vlog.debug("Inserting fake ScrollLock to get in sync with server"); handleKeyPress(0x46, XK_Scroll_Lock); handleKeyRelease(0x46); diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index f24b1610c..ff6595372 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -49,9 +49,6 @@ #include "i18n.h" -using namespace rfb; -using namespace std; - static core::LogWriter vlog("Parameters"); core::IntParameter @@ -229,10 +226,10 @@ static const char* IDENTIFIER_STRING = "TigerVNC Configuration file Version 1.0" static core::VoidParameter* parameterArray[] = { /* Security */ #ifdef HAVE_GNUTLS - &CSecurityTLS::X509CA, - &CSecurityTLS::X509CRL, + &rfb::CSecurityTLS::X509CA, + &rfb::CSecurityTLS::X509CRL, #endif // HAVE_GNUTLS - &SecurityClient::secTypes, + &rfb::SecurityClient::secTypes, /* Misc. */ &reconnectOnError, &shared, @@ -471,7 +468,8 @@ static void removeValue(const char* _name, HKEY* hKey) { } } -void saveHistoryToRegKey(const list& serverHistory) { +void saveHistoryToRegKey(const std::list& serverHistory) +{ HKEY hKey; LONG res = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\TigerVNC\\vncviewer\\history", 0, nullptr, @@ -486,7 +484,7 @@ void saveHistoryToRegKey(const list& serverHistory) { char indexString[3]; try { - for (const string& entry : serverHistory) { + for (const std::string& entry : serverHistory) { if (index > SERVER_HISTORY_SIZE) break; snprintf(indexString, 3, "%d", index); @@ -568,9 +566,10 @@ static void saveToReg(const char* servername) { throw core::win32_error(_("Failed to close registry key"), res); } -list loadHistoryFromRegKey() { +std::list loadHistoryFromRegKey() +{ HKEY hKey; - list serverHistory; + std::list serverHistory; LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\TigerVNC\\vncviewer\\history", 0, diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 1d1f61684..eda0bf271 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -83,9 +83,6 @@ static core::LogWriter vlog("main"); -using namespace network; -using namespace rfb; - char vncServerName[VNCSERVERNAMELEN] = { '\0' }; static const char *argv0 = nullptr; @@ -612,10 +609,10 @@ static void mktunnel() { const char *gatewayHost; std::string remoteHost; - int localPort = findFreeTcpPort(); + int localPort = network::findFreeTcpPort(); int remotePort; - getHostAndPort(vncServerName, &remoteHost, &remotePort); + network::getHostAndPort(vncServerName, &remoteHost, &remotePort); snprintf(vncServerName, VNCSERVERNAMELEN, "localhost::%d", localPort); vncServerName[VNCSERVERNAMELEN - 1] = '\0'; gatewayHost = (const char*)via; @@ -736,7 +733,7 @@ int main(int argc, char** argv) create_base_dirs(); - Socket *sock = nullptr; + network::Socket* sock = nullptr; #ifndef WIN32 /* Specifying -via and -listen together is nonsense */ @@ -750,7 +747,7 @@ int main(int argc, char** argv) #endif if (listenMode) { - std::list listeners; + std::list listeners; try { int port = 5500; if (isdigit(vncServerName[0])) @@ -766,7 +763,7 @@ int main(int argc, char** argv) while (sock == nullptr) { fd_set rfds; FD_ZERO(&rfds); - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) FD_SET(listener->getFd(), &rfds); int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr); @@ -779,7 +776,7 @@ int main(int argc, char** argv) } } - for (SocketListener* listener : listeners) + for (network::SocketListener* listener : listeners) if (FD_ISSET(listener->getFd(), &rfds)) { sock = listener->accept(); if (sock)