From 50439d78fae2828356bfde789ec5c4fd0911ae09 Mon Sep 17 00:00:00 2001 From: Mathias Jonsson Date: Sun, 22 Apr 2018 19:10:30 +0200 Subject: [PATCH] Accept a cfg as an argument as an alt way to start the viewer The user can specify a tigervnc configuration file as an argument to the viewer. Previously the viewer assumed this to be a server, but now we will first check if there is any file matching the given argument. If so, try to load the content of that file, like we normally do. Fixes issue #38. --- java/com/tigervnc/vncviewer/VncViewer.java | 24 ++++++++++++++++ vncviewer/vncviewer.cxx | 33 ++++++++++++++++++++-- vncviewer/vncviewer.man | 16 +++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java index 566169be..93d3f3be 100644 --- a/java/com/tigervnc/vncviewer/VncViewer.java +++ b/java/com/tigervnc/vncviewer/VncViewer.java @@ -208,6 +208,8 @@ public class VncViewer extends javax.swing.JApplet vncServerName.put(argv[i].toCharArray()).flip(); } + // Check if the server name in reality is a configuration file + potentiallyLoadConfigurationFile(vncServerName); } public static void usage() { @@ -215,6 +217,7 @@ public class VncViewer extends javax.swing.JApplet "[host:displayNum]\n"+ " vncviewer [options/parameters] -listen [port] "+ "[options/parameters]\n"+ + " vncviewer [options/parameters] [.tigervnc file]\n"+ "\n"+ "Options:\n"+ " -log configure logging level\n"+ @@ -277,6 +280,27 @@ public class VncViewer extends javax.swing.JApplet System.exit(1); } + public static void potentiallyLoadConfigurationFile(CharBuffer vncServerName) { + String serverName = vncServerName.toString(); + boolean hasPathSeparator = (serverName.indexOf('/') != -1 || + (serverName.indexOf('\\')) != -1); + + if (hasPathSeparator) { + try { + serverName = loadViewerParameters(vncServerName.toString()); + if (serverName == "") { + vlog.info("Unable to load the server name from given file"); + System.exit(1); + } + vncServerName.clear(); + vncServerName.put(serverName).flip(); + } catch (com.tigervnc.rfb.Exception e) { + vlog.info(e.getMessage()); + System.exit(1); + } + } + } + public static void newViewer() { String cmd = "java -jar "; try { diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 413260d9..fabd665a 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -349,8 +349,9 @@ static void usage(const char *programName) fprintf(stderr, "\nusage: %s [parameters] [host:displayNum] [parameters]\n" - " %s [parameters] -listen [port] [parameters]\n", - programName, programName); + " %s [parameters] -listen [port] [parameters]\n" + " %s [parameters] [.tigervnc file]\n", + programName, programName, programName); fprintf(stderr,"\n" "Parameters can be turned on with - or off with -=0\n" "Parameters which take a value can be specified as " @@ -368,6 +369,31 @@ static void usage(const char *programName) exit(1); } +static void +potentiallyLoadConfigurationFile(char *vncServerName) +{ + const bool hasPathSeparator = (strchr(vncServerName, '/') != NULL || + (strchr(vncServerName, '\\')) != NULL); + + if (hasPathSeparator) { + try { + strncpy(vncServerName, loadViewerParameters(vncServerName), + VNCSERVERNAMELEN); + if (vncServerName[0] == '\0') { + vlog.error("Unable to load the server name from given file"); + if (alertOnFatalError) + fl_alert("Unable to load the server name from given file"); + exit(EXIT_FAILURE); + } + } catch (rfb::Exception& e) { + vlog.error("%s", e.str()); + if (alertOnFatalError) + fl_alert("%s", e.str()); + exit(EXIT_FAILURE); + } + } +} + #ifndef WIN32 static int interpretViaParam(char *remoteHost, int *remotePort, int localPort) @@ -516,6 +542,9 @@ int main(int argc, char** argv) i++; } + // Check if the server name in reality is a configuration file + potentiallyLoadConfigurationFile(vncServerName); + mkvnchomedir(); #if !defined(WIN32) && !defined(__APPLE__) diff --git a/vncviewer/vncviewer.man b/vncviewer/vncviewer.man index 22b46cd5..729c01d6 100644 --- a/vncviewer/vncviewer.man +++ b/vncviewer/vncviewer.man @@ -14,6 +14,10 @@ vncviewer \- VNC viewer for X .RI [ options ] .B \-listen .RI [ port ] +.br +.B vncviewer +.RI [ options ] +.RI [ .tigervnc file ] .SH DESCRIPTION .B vncviewer is a viewer (client) for Virtual Network Computing. This manual page documents @@ -31,6 +35,18 @@ VNC server on that machine. Either the machine name or display number can be omitted. So for example ":1" means display number 1 on the same machine, and "snoopy" means "snoopy:0" i.e. display 0 on machine "snoopy". +As another quick way to start a connection to a VNC server, specify a .tigervnc +configuration file as an argument to the viewer, e.g.: + +.RS +vncviewer ./some.tigervnc +.RE + +where './some.tigervnc' is an existing and valid TigerVNC configuration file. +The file name needs to include a path separator. Additional options may be +given too, but the given configuration file will overwrite any conflicting +parameters. + If the VNC server is successfully contacted, you will be prompted for a password to authenticate you. If the password is correct, a window will appear showing the desktop of the VNC server. -- 2.39.5