From 2a7a8d60c8b5d5ded850e92a27d45e9e728b20f3 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 15 Feb 2013 08:33:39 +0000 Subject: [PATCH] Reimplement -listen in the new FLTK vncviewer. Work done by Justina Mickonyte for Cendio. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5041 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- vncviewer/CConn.cxx | 27 +++++++++++++++------------ vncviewer/CConn.h | 2 +- vncviewer/parameters.cxx | 3 +++ vncviewer/parameters.h | 2 ++ vncviewer/vncviewer.cxx | 38 ++++++++++++++++++++++++++++++-------- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 25e17efc..e4d55aa0 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -67,8 +67,8 @@ static const PixelFormat lowColourPF(8, 6, false, true, // 256 colours (palette) static const PixelFormat mediumColourPF(8, 8, false, false); -CConn::CConn(const char* vncServerName) - : serverHost(0), serverPort(0), sock(NULL), desktop(NULL), +CConn::CConn(const char* vncServerName, network::Socket* socket=NULL) + : serverHost(0), serverPort(0), desktop(NULL), pendingPFChange(false), currentEncoding(encodingTight), lastServerEncoding((unsigned int)-1), formatChange(false), encodingChange(false), @@ -76,6 +76,7 @@ CConn::CConn(const char* vncServerName) forceNonincremental(true), supportsSyncFence(false) { setShared(::shared); + sock = socket; int encNum = encodingNum(preferredEncoding); if (encNum != -1) @@ -93,16 +94,18 @@ CConn::CConn(const char* vncServerName) cp.noJpeg = noJpeg; cp.qualityLevel = qualityLevel; - try { - getHostAndPort(vncServerName, &serverHost, &serverPort); - - sock = new network::TcpSocket(serverHost, serverPort); - vlog.info(_("connected to host %s port %d"), serverHost, serverPort); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); - fl_alert("%s", e.str()); - exit_vncviewer(); - return; + if(sock == NULL) { + try { + getHostAndPort(vncServerName, &serverHost, &serverPort); + + sock = new network::TcpSocket(serverHost, serverPort); + vlog.info(_("connected to host %s port %d"), serverHost, serverPort); + } catch (rdr::Exception& e) { + vlog.error("%s", e.str()); + fl_alert("%s", e.str()); + exit_vncviewer(); + return; + } } Fl::add_fd(sock->getFd(), FL_READ | FL_EXCEPT, socketEvent, this); diff --git a/vncviewer/CConn.h b/vncviewer/CConn.h index ea4edb55..e48b3c71 100644 --- a/vncviewer/CConn.h +++ b/vncviewer/CConn.h @@ -29,7 +29,7 @@ class CConn : public rfb::CConnection, public rdr::FdInStreamBlockCallback { public: - CConn(const char* vncServerName); + CConn(const char* vncServerName, network::Socket* sock); ~CConn(); void refreshFramebuffer(); diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index d386bd45..6c2af38a 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -102,6 +102,9 @@ StringParameter desktopSize("DesktopSize", "connect (if possible)", ""); StringParameter geometry("geometry", "Specify size and position of viewer window", ""); + +BoolParameter listenMode("listen", "Listen for connections from VNC servers", false); + BoolParameter remoteResize("RemoteResize", "Dynamically resize the remote desktop size as " "the size of the local client window changes. " diff --git a/vncviewer/parameters.h b/vncviewer/parameters.h index 2b4c0390..9827b141 100644 --- a/vncviewer/parameters.h +++ b/vncviewer/parameters.h @@ -49,6 +49,8 @@ extern rfb::StringParameter desktopSize; extern rfb::StringParameter geometry; extern rfb::BoolParameter remoteResize; +extern rfb::BoolParameter listenMode; + extern rfb::BoolParameter viewOnly; extern rfb::BoolParameter shared; diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 569ee4a0..8e9622a5 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -441,18 +442,39 @@ int main(int argc, char** argv) CSecurityTLS::msg = &dlg; #endif - if (vncServerName[0] == '\0') { - ServerDialog::run(defaultServerName, vncServerName); - if (vncServerName[0] == '\0') - return 1; - } + Socket *sock = NULL; + + if(listenMode) { + try { + int port = 5500; + if (isdigit(vncServerName[0])) + port = atoi(vncServerName); + + TcpListener listener(NULL, port); + + vlog.info("Listening on port %d\n", port); + sock = listener.accept(); + } catch (rdr::Exception& e) { + vlog.error("%s", e.str()); + fl_alert("%s", e.str()); + exit_vncviewer(); + return 1; + } + + } else { + if (vncServerName[0] == '\0') { + ServerDialog::run(defaultServerName, vncServerName); + if (vncServerName[0] == '\0') + return 1; + } #ifndef WIN32 - if (strlen (via.getValueStr()) > 0 && mktunnel() != 0) - usage(argv[0]); + if (strlen (via.getValueStr()) > 0 && mktunnel() != 0) + usage(argv[0]); #endif + } - CConn *cc = new CConn(vncServerName); + CConn *cc = new CConn(vncServerName, sock); while (!exitMainloop) { int next_timer; -- 2.39.5