Revision: 5032
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=5032&view=rev
Author:   atkac
Date:     2013-01-23 13:55:46 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
Re-add the "-via" parameter support on UNIX platforms.

Modified Paths:
--------------
    trunk/vncviewer/ServerDialog.cxx
    trunk/vncviewer/ServerDialog.h
    trunk/vncviewer/parameters.cxx
    trunk/vncviewer/parameters.h
    trunk/vncviewer/vncviewer.cxx
    trunk/vncviewer/vncviewer.h

Modified: trunk/vncviewer/ServerDialog.cxx
===================================================================
--- trunk/vncviewer/ServerDialog.cxx    2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/ServerDialog.cxx    2013-01-23 13:55:46 UTC (rev 5032)
@@ -107,23 +107,22 @@
 }
 
 
-const char *ServerDialog::run(const char* servername)
+void ServerDialog::run(const char* servername, char *newservername)
 {
   ServerDialog dialog;
-  static char buffer[256];
 
   dialog.serverName->value(servername);
   
   dialog.show();
   while (dialog.shown()) Fl::wait();
 
-  if (dialog.serverName->value() == NULL)
-    return NULL;
+  if (dialog.serverName->value() == NULL) {
+    newservername[0] = '\0';
+    return;
+  }
 
-  strncpy(buffer, dialog.serverName->value(), sizeof(buffer));
-  buffer[sizeof(buffer)-1] = '\0';
-
-  return buffer;
+  strncpy(newservername, dialog.serverName->value(), VNCSERVERNAMELEN);
+  newservername[VNCSERVERNAMELEN - 1] = '\0';
 }
 
 void ServerDialog::handleOptions(Fl_Widget *widget, void *data)

Modified: trunk/vncviewer/ServerDialog.h
===================================================================
--- trunk/vncviewer/ServerDialog.h      2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/ServerDialog.h      2013-01-23 13:55:46 UTC (rev 5032)
@@ -29,7 +29,7 @@
   ~ServerDialog();
 
 public:
-  static const char *run(const char* servername);
+  static void run(const char* servername, char *newservername);
 
 protected:
   static void handleOptions(Fl_Widget *widget, void *data);

Modified: trunk/vncviewer/parameters.cxx
===================================================================
--- trunk/vncviewer/parameters.cxx      2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/parameters.cxx      2013-01-23 13:55:46 UTC (rev 5032)
@@ -133,6 +133,10 @@
                                    "to the server when in full screen mode.",
                                    true);
 
+#ifndef WIN32
+StringParameter via("via", "Gateway to tunnel via", "");
+#endif
+
 const char* IDENTIFIER_STRING = "TigerVNC Configuration file Version 1.0";
 
 VoidParameter* parameterArray[] = {

Modified: trunk/vncviewer/parameters.h
===================================================================
--- trunk/vncviewer/parameters.h        2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/parameters.h        2013-01-23 13:55:46 UTC (rev 5032)
@@ -60,6 +60,10 @@
 
 extern rfb::BoolParameter fullscreenSystemKeys;
 
+#ifndef WIN32
+extern rfb::StringParameter via;
+#endif
+
 void saveViewerParameters(const char *filename, const char *servername=NULL);
 char* loadViewerParameters(const char *filename);
 

Modified: trunk/vncviewer/vncviewer.cxx
===================================================================
--- trunk/vncviewer/vncviewer.cxx       2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/vncviewer.cxx       2013-01-23 13:55:46 UTC (rev 5032)
@@ -58,6 +58,7 @@
 #include "CConn.h"
 #include "ServerDialog.h"
 #include "UserDialog.h"
+#include "vncviewer.h"
 
 #ifdef WIN32
 #include "resource.h"
@@ -76,6 +77,8 @@
                                    "See http://www.tigervnc.org for 
information on TigerVNC.");
 extern const char* buildTime;
 
+char vncServerName[VNCSERVERNAMELEN] = { '\0' };
+
 static bool exitMainloop = false;
 static const char *exitError = NULL;
 
@@ -267,9 +270,84 @@
   exit(1);
 }
 
+#ifndef WIN32
+static int
+interpretViaParam(char *remoteHost, int *remotePort, int localPort)
+{
+  const int SERVER_PORT_OFFSET = 5900;
+  char *pos = strchr(vncServerName, ':');
+  if (pos == NULL)
+    *remotePort = SERVER_PORT_OFFSET;
+  else {
+    int portOffset = SERVER_PORT_OFFSET;
+    size_t len;
+    *pos++ = '\0';
+    len = strlen(pos);
+    if (*pos == ':') {
+      /* Two colons is an absolute port number, not an offset. */
+      pos++;
+      len--;
+      portOffset = 0;
+    }
+    if (!len || strspn (pos, "-0123456789") != len )
+      return 1;
+    *remotePort = atoi(pos) + portOffset;
+  }
+
+  if (*vncServerName != '\0')
+    strncpy(remoteHost, vncServerName, VNCSERVERNAMELEN);
+  else
+    strncpy(remoteHost, "localhost", VNCSERVERNAMELEN);
+
+  remoteHost[VNCSERVERNAMELEN - 1] = '\0';
+
+  snprintf(vncServerName, VNCSERVERNAMELEN, "localhost::%d", localPort);
+  vncServerName[VNCSERVERNAMELEN - 1] = '\0';
+  vlog.error(vncServerName);
+
+  return 0;
+}
+
+static void
+createTunnel(const char *gatewayHost, const char *remoteHost,
+             int remotePort, int localPort)
+{
+  char *cmd = getenv("VNC_VIA_CMD");
+  char *percent;
+  char lport[10], rport[10];
+  sprintf(lport, "%d", localPort);
+  sprintf(rport, "%d", remotePort);
+  setenv("G", gatewayHost, 1);
+  setenv("H", remoteHost, 1);
+  setenv("R", rport, 1);
+  setenv("L", lport, 1);
+  vlog.error("%s, %s, %d, %d", gatewayHost, remoteHost, rport, lport);
+  if (!cmd)
+    cmd = "/usr/bin/ssh -f -L \"$L\":\"$H\":\"$R\" \"$G\" sleep 20";
+  /* Compatibility with TigerVNC's method. */
+  while ((percent = strchr(cmd, '%')) != NULL)
+    *percent = '$';
+  system(cmd);
+}
+
+static int mktunnel()
+{
+  const char *gatewayHost;
+  char remoteHost[VNCSERVERNAMELEN];
+  int localPort = findFreeTcpPort();
+  int remotePort;
+
+  gatewayHost = strDup(via.getValueStr());
+  if (interpretViaParam(remoteHost, &remotePort, localPort) != 0)
+    return 1;
+  createTunnel(gatewayHost, remoteHost, remotePort, localPort);
+
+  return 0;
+}
+#endif /* !WIN32 */
+
 int main(int argc, char** argv)
 {
-  const char* vncServerName = NULL;
   UserDialog dlg;
 
   setlocale(LC_ALL, "");
@@ -332,7 +410,8 @@
         usage(argv[0]);
       }
 
-      vncServerName = argv[i];
+      strncpy(vncServerName, argv[i], VNCSERVERNAMELEN);
+      vncServerName[VNCSERVERNAMELEN - 1] = '\0';
     }
 
   if (!::autoSelect.hasBeenSet()) {
@@ -363,12 +442,17 @@
   CSecurityTLS::msg = &dlg;
 #endif
 
-  if (vncServerName == NULL) {
-    vncServerName = ServerDialog::run(defaultServerName);
-    if ((vncServerName == NULL) || (vncServerName[0] == '\0'))
+  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]);
+#endif
+
   CConn *cc = new CConn(vncServerName);
 
   while (!exitMainloop) {

Modified: trunk/vncviewer/vncviewer.h
===================================================================
--- trunk/vncviewer/vncviewer.h 2013-01-22 08:11:05 UTC (rev 5031)
+++ trunk/vncviewer/vncviewer.h 2013-01-23 13:55:46 UTC (rev 5032)
@@ -19,6 +19,8 @@
 #ifndef __VNCVIEWER_H__
 #define __VNCVIEWER_H__
 
+#define VNCSERVERNAMELEN 64
+
 void exit_vncviewer(const char *error = NULL);
 void about_vncviewer();
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Tigervnc-commits mailing list
Tigervnc-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to