connect to the ovirt-vnc-proxy server to access a vm's vnc
[ovirt-viewer.git] / main.c
diff --git a/main.c b/main.c
index 356d379..2962f3f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -55,6 +55,8 @@
 
 gboolean debug = 0;
 
+gboolean verbose = 0;
+
 /* Usually /etc/pki/tls/certs/ca-bundle.crt unless overridden during
  * configure or on the command line.
  */
@@ -68,6 +70,10 @@ gboolean check_cert = FALSE; // do we want this enabled by default ?
 */
 static GSList *vmlist = NULL;
 
+/*  internal.h shared constructs */
+const char* hostname;
+struct vm* vm_in_focus;
+
 /* Private functions. */
 static void start_ui (void);
 static GtkWidget *menu_item_new (int which_menu);
@@ -198,6 +204,8 @@ static const GOptionEntry options[] = {
     "check the SSL certificate of the server", NULL },
   { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
     "turn on debugging messages", NULL },
+  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+    "turn on verbose messages", NULL },
   { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
     "display version and exit", NULL },
   { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
@@ -225,6 +233,10 @@ main (int argc, char *argv[])
    * processed in the main thread - see:
    * http://mail.gnome.org/archives/gtk-app-devel-list/2007-March/msg00232.html
    *
+   * A tunnel thread is also started to locally listen for vnc packets
+   * and make them proxyable, adding the vm name, before forwarding onto
+   * the server
+   *
    * Note that under Win32 you must confine all Gtk/Gdk interactions
    * to a single thread - see:
    * http://developer.gimp.org/api/2.0/gdk/gdk-Threads.html
@@ -267,6 +279,7 @@ main (int argc, char *argv[])
   gtk_main ();
 
   stop_wui_thread ();
+  stop_tunnel();
 
   exit (0);
 }
@@ -510,6 +523,7 @@ help_about (GtkWidget *menu)
   const char *authors[] = {
     "Richard W.M. Jones <rjones@redhat.com>",
     "Daniel P. Berrange <berrange@redhat.com>",
+    "Mohammed Morsi <mmorsi@redhat.com>",
     NULL
   };
 
@@ -557,7 +571,6 @@ connect_to_wui_on_enter (GtkWidget *widget, gpointer data)
 static void
 connect_to_wui (GtkWidget *widget, gpointer data)
 {
-  const char *hostname;
   char *uri;
   int len;
 
@@ -570,6 +583,7 @@ connect_to_wui (GtkWidget *widget, gpointer data)
   snprintf (uri, len, HTTPS "://%s/ovirt", hostname);
 
   wui_thread_send_connect (uri);
+  start_tunnel();
 }
 
 static void
@@ -606,7 +620,6 @@ connect_to_vm (GtkWidget *widget, gpointer _vm)
   int i, uuidlen, len, fd;
   GtkWidget *child;
   const char *label;
-  const char* hostname;
   char *label2;
   char new_title[97]; // 47 chars for title + 50 for vm name
 
@@ -637,9 +650,12 @@ connect_to_vm (GtkWidget *widget, gpointer _vm)
     return;
   }
 
+  // FIXME on notebook tab switch, change vm_in_focus
+  vm_in_focus = vm;
+
   /* This VM isn't in the notebook already, so create a new console. */
-  hostname = gtk_entry_get_text (GTK_ENTRY (ca_hostname));
-  fd = viewer_open_vnc_socket(hostname, vm->forward_vnc_port);
+  DEBUG ("connecting to local tunnel on port %i", tunnel_port);
+  fd = viewer_open_vnc_socket("127.0.0.1", tunnel_port);
   if (fd == -1) return;                /* We've already given an error. */
 
   child = vnc_display_new ();