Blob Blame History Raw
From 25ef080ac79f31002259a050944079bb9672f5ea Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Fri, 31 Jan 2014 11:31:33 -0600
Subject: [PATCH] Move vnc-specific auth logic to VirtViewerSessionVnc

Conflicts:
	src/virt-viewer-auth.c
(cherry picked from commit dce19b379ad65a0d0edef6dfce19f1177eb082c6)
---
 src/virt-viewer-auth.c        | 97 -------------------------------------------
 src/virt-viewer-auth.h        |  6 ---
 src/virt-viewer-session-vnc.c | 92 +++++++++++++++++++++++++++++++++++++---
 3 files changed, 86 insertions(+), 109 deletions(-)

diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
index bb03516..a796619 100644
--- a/src/virt-viewer-auth.c
+++ b/src/virt-viewer-auth.c
@@ -105,103 +105,6 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
     return response == GTK_RESPONSE_OK ? 0 : -1;
 }
 
-#ifdef HAVE_GTK_VNC
-void
-virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
-                                 GtkWindow *window,
-                                 GtkWidget *vnc,
-                                 GValueArray *credList,
-                                 char *vncAddress)
-{
-    char *username = NULL, *password = NULL;
-    gboolean wantPassword = FALSE, wantUsername = FALSE;
-    int i;
-
-    g_debug("Got VNC credential request for %d credential(s)", credList->n_values);
-
-    for (i = 0 ; i < credList->n_values ; i++) {
-        GValue *cred = g_value_array_get_nth(credList, i);
-        switch (g_value_get_enum(cred)) {
-        case VNC_DISPLAY_CREDENTIAL_USERNAME:
-            wantUsername = TRUE;
-            break;
-        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
-            wantPassword = TRUE;
-            break;
-        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
-            break;
-        default:
-            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
-            vnc_display_close(VNC_DISPLAY(vnc));
-            goto cleanup;
-        }
-    }
-
-    VirtViewerFile *file = virt_viewer_session_get_file(session);
-    if (file != NULL) {
-        if (wantUsername && virt_viewer_file_is_set(file, "username")) {
-            username = virt_viewer_file_get_username(file);
-            wantUsername = FALSE;
-        }
-        if (wantPassword && virt_viewer_file_is_set(file, "password")) {
-            password = virt_viewer_file_get_password(file);
-            wantPassword = FALSE;
-        }
-    }
-
-    if (wantUsername || wantPassword) {
-        int ret = virt_viewer_auth_collect_credentials(window,
-                                                       "VNC", vncAddress,
-                                                       wantUsername ? &username : NULL,
-                                                       wantPassword ? &password : NULL);
-
-        if (ret < 0) {
-            vnc_display_close(VNC_DISPLAY(vnc));
-            goto cleanup;
-        }
-    }
-
-    for (i = 0 ; i < credList->n_values ; i++) {
-        GValue *cred = g_value_array_get_nth(credList, i);
-        switch (g_value_get_enum(cred)) {
-        case VNC_DISPLAY_CREDENTIAL_USERNAME:
-            if (!username ||
-                vnc_display_set_credential(VNC_DISPLAY(vnc),
-                                           g_value_get_enum(cred),
-                                           username)) {
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
-                vnc_display_close(VNC_DISPLAY(vnc));
-            }
-            break;
-        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
-            if (!password ||
-                vnc_display_set_credential(VNC_DISPLAY(vnc),
-                                           g_value_get_enum(cred),
-                                           password)) {
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
-                vnc_display_close(VNC_DISPLAY(vnc));
-            }
-            break;
-        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
-            if (vnc_display_set_credential(VNC_DISPLAY(vnc),
-                                           g_value_get_enum(cred),
-                                           "libvirt")) {
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
-                vnc_display_close(VNC_DISPLAY(vnc));
-            }
-            break;
-        default:
-            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
-            vnc_display_close(VNC_DISPLAY(vnc));
-        }
-    }
-
- cleanup:
-    g_free(username);
-    g_free(password);
-}
-#endif
-
 /*
  * Local variables:
  *  c-indent-level: 4
diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
index 1f102e0..ad932c5 100644
--- a/src/virt-viewer-auth.h
+++ b/src/virt-viewer-auth.h
@@ -32,12 +32,6 @@
 #include "virt-viewer-session.h"
 #include "virt-viewer-util.h"
 
-void virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
-                                      GtkWindow *window,
-                                      GtkWidget *vnc,
-                                      GValueArray *credList,
-                                      char *vncAddress);
-
 int virt_viewer_auth_collect_credentials(GtkWindow *window,
                                          const char *type,
                                          const char *address,
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index 1e82fbb..3f4c90d 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -254,17 +254,97 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
 
 
 static void
-virt_viewer_session_vnc_auth_credential(GtkWidget *src,
+virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
                                         GValueArray *credList,
                                         VirtViewerSession *session)
 {
     VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session);
+    char *username = NULL, *password = NULL;
+    gboolean wantPassword = FALSE, wantUsername = FALSE;
+    int i;
+
+    g_debug("Got VNC credential request for %d credential(s)", credList->n_values);
+
+    for (i = 0 ; i < credList->n_values ; i++) {
+        GValue *cred = g_value_array_get_nth(credList, i);
+        switch (g_value_get_enum(cred)) {
+        case VNC_DISPLAY_CREDENTIAL_USERNAME:
+            wantUsername = TRUE;
+            break;
+        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+            wantPassword = TRUE;
+            break;
+        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
+            break;
+        default:
+            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
+            vnc_display_close(self->priv->vnc);
+            goto cleanup;
+        }
+    }
+
+    VirtViewerFile *file = virt_viewer_session_get_file(VIRT_VIEWER_SESSION(self));
+    if (file != NULL) {
+        if (wantUsername && virt_viewer_file_is_set(file, "username")) {
+            username = virt_viewer_file_get_username(file);
+            wantUsername = FALSE;
+        }
+        if (wantPassword && virt_viewer_file_is_set(file, "password")) {
+            password = virt_viewer_file_get_password(file);
+            wantPassword = FALSE;
+        }
+    }
+
+    if (wantUsername || wantPassword) {
+        int ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                       "VNC", NULL,
+                                                       wantUsername ? &username : NULL,
+                                                       wantPassword ? &password : NULL);
+
+        if (ret < 0) {
+            vnc_display_close(self->priv->vnc);
+            goto cleanup;
+        }
+    }
+
+    for (i = 0 ; i < credList->n_values ; i++) {
+        GValue *cred = g_value_array_get_nth(credList, i);
+        switch (g_value_get_enum(cred)) {
+        case VNC_DISPLAY_CREDENTIAL_USERNAME:
+            if (!username ||
+                vnc_display_set_credential(self->priv->vnc,
+                                           g_value_get_enum(cred),
+                                           username)) {
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
+                vnc_display_close(self->priv->vnc);
+            }
+            break;
+        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+            if (!password ||
+                vnc_display_set_credential(self->priv->vnc,
+                                           g_value_get_enum(cred),
+                                           password)) {
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
+                vnc_display_close(self->priv->vnc);
+            }
+            break;
+        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
+            if (vnc_display_set_credential(self->priv->vnc,
+                                           g_value_get_enum(cred),
+                                           "libvirt")) {
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
+                vnc_display_close(self->priv->vnc);
+            }
+            break;
+        default:
+            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
+            vnc_display_close(self->priv->vnc);
+        }
+    }
 
-    virt_viewer_auth_vnc_credentials(session,
-                                     self->priv->main_window,
-                                     src,
-                                     credList,
-                                     NULL);
+ cleanup:
+    g_free(username);
+    g_free(password);
 }