Skip to content

Commit

Permalink
Stop relying on "using namespace"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CendioOssman committed Nov 14, 2024
1 parent 674223f commit 494c375
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 214 deletions.
1 change: 0 additions & 1 deletion common/network/UnixSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <network/UnixSocket.h>

using namespace network;
using namespace rdr;

static core::LogWriter vlog("UnixSocket");

Expand Down
6 changes: 2 additions & 4 deletions unix/vncpasswd/vncpasswd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
#include <pwquality.h>
#endif

using namespace rfb;

char* prog;

static void usage()
Expand Down Expand Up @@ -90,7 +88,7 @@ static int encrypt_pipe() {
if (!result)
break;

std::vector<uint8_t> obfuscated = obfuscate(result);
std::vector<uint8_t> obfuscated = rfb::obfuscate(result);
if (fwrite(obfuscated.data(), obfuscated.size(), 1, stdout) != 1) {
fprintf(stderr,"Writing to stdout failed\n");
return 1;
Expand Down Expand Up @@ -179,7 +177,7 @@ static std::vector<uint8_t> readpassword() {
continue;
}

return obfuscate(first.c_str());
return rfb::obfuscate(first.c_str());
}
}

Expand Down
8 changes: 3 additions & 5 deletions unix/x0vncserver/PollingManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

#include <x0vncserver/PollingManager.h>

using namespace rfb;

static core::LogWriter vlog("PollingMgr");

const int PollingManager::m_pollingOrder[32] = {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions unix/x0vncserver/XDesktop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ void vncSetGlueContext(Display *dpy, void *res);
#include <x0vncserver/Geometry.h>
#include <x0vncserver/XPixelBuffer.h>

using namespace rfb;

extern const unsigned short code_map_qnum_to_xorgevdev[];
extern const unsigned int code_map_qnum_to_xorgevdev_len;

Expand Down Expand Up @@ -241,7 +239,7 @@ void XDesktop::poll() {
}
}

void XDesktop::init(VNCServer* vs)
void XDesktop::init(rfb::VNCServer* vs)
{
server = vs;
}
Expand Down Expand Up @@ -609,9 +607,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
Expand All @@ -626,7 +624,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;
Expand Down Expand Up @@ -709,9 +707,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++) {
Expand Down
22 changes: 10 additions & 12 deletions unix/x0vncserver/XPixelBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

#include <x0vncserver/XPixelBuffer.h>

using namespace rfb;

XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
const core::Rect& rect)
: FullFramePixelBuffer(),
Expand All @@ -45,16 +43,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,
Expand Down
29 changes: 13 additions & 16 deletions unix/x0vncserver/x0vncserver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@

extern char buildtime[];

using namespace rfb;
using namespace network;

static core::LogWriter vlog("Main");

static const char* defaultDesktopName();
Expand Down Expand Up @@ -143,7 +140,7 @@ static bool hasSystemdListeners()
#endif
}

static int createSystemdListeners(std::list<SocketListener*> *listeners)
static int createSystemdListeners(std::list<network::SocketListener*> *listeners)
{
#ifdef HAVE_LIBSYSTEMD
int count = sd_listen_fds(0);
Expand All @@ -154,7 +151,7 @@ static int createSystemdListeners(std::list<SocketListener*> *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
Expand All @@ -164,7 +161,7 @@ static int createSystemdListeners(std::list<SocketListener*> *listeners)
}


class FileTcpFilter : public TcpFilter
class FileTcpFilter : public network::TcpFilter
{

public:
Expand All @@ -182,7 +179,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");
Expand Down Expand Up @@ -335,7 +332,7 @@ int main(int argc, char** argv)
signal(SIGINT, CleanupSignalHandler);
signal(SIGTERM, CleanupSignalHandler);

std::list<SocketListener*> listeners;
std::list<network::SocketListener*> listeners;

try {
TXWindow::init(dpy,"x0vncserver");
Expand All @@ -347,7 +344,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
Expand Down Expand Up @@ -379,7 +376,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);
}

Expand All @@ -394,8 +391,8 @@ int main(int argc, char** argv)
int wait_ms, nextTimeout;
struct timeval tv;
fd_set rfds, wfds;
std::list<Socket*> sockets;
std::list<Socket*>::iterator i;
std::list<network::Socket*> sockets;
std::list<network::Socket*>::iterator i;

// Process any incoming X events
TXWindow::handleXEvents(dpy);
Expand All @@ -404,7 +401,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);
Expand Down Expand Up @@ -457,9 +454,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 {
Expand Down Expand Up @@ -499,7 +496,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");
Expand Down
33 changes: 16 additions & 17 deletions unix/xserver/hw/vnc/XserverDesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,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 rawKeyboard("RawKeyboard",
Expand All @@ -85,10 +82,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);
}

Expand Down Expand Up @@ -116,7 +113,7 @@ void XserverDesktop::unblockUpdates()

void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride_)
{
ScreenSet layout;
rfb::ScreenSet layout;

if (shadowFramebuffer) {
delete [] shadowFramebuffer;
Expand Down Expand Up @@ -320,10 +317,10 @@ void XserverDesktop::handleSocketEvent(int fd, bool read, bool write)
}

bool XserverDesktop::handleListenerEvent(int fd,
std::list<SocketListener*>* sockets,
VNCServer* sockserv)
std::list<network::SocketListener*>* sockets,
rfb::VNCServer* sockserv)
{
std::list<SocketListener*>::iterator i;
std::list<network::SocketListener*>::iterator i;

for (i = sockets->begin(); i != sockets->end(); i++) {
if ((*i)->getFd() == fd)
Expand All @@ -333,7 +330,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);
Expand All @@ -342,11 +339,11 @@ bool XserverDesktop::handleListenerEvent(int fd,
}

bool XserverDesktop::handleSocketEvent(int fd,
VNCServer* sockserv,
rfb::VNCServer* sockserv,
bool read, bool write)
{
std::list<Socket*> sockets;
std::list<Socket*>::iterator i;
std::list<network::Socket*> sockets;
std::list<network::Socket*>::iterator i;

sockserv->getSockets(&sockets);
for (i = sockets.begin(); i != sockets.end(); i++) {
Expand Down Expand Up @@ -375,8 +372,8 @@ void XserverDesktop::blockHandler(int* timeout)
vncInitInputDevice();

try {
std::list<Socket*> sockets;
std::list<Socket*>::iterator i;
std::list<network::Socket*> sockets;
std::list<network::Socket*>::iterator i;
server->getSockets(&sockets);
for (i = sockets.begin(); i != sockets.end(); i++) {
int fd = (*i)->getFd();
Expand Down Expand Up @@ -412,10 +409,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);
}

Expand Down
Loading

0 comments on commit 494c375

Please sign in to comment.