qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, dgilbert@redhat.com, berrange@redhat.com,
	philmd@linaro.org
Subject: [PATCH v3 14/18] ui: Factor out hmp_change_vnc(), and move to ui/ui-hmp-cmds.c
Date: Tue, 20 Dec 2022 10:06:41 +0100	[thread overview]
Message-ID: <20221220090645.2844881-15-armbru@redhat.com> (raw)
In-Reply-To: <20221220090645.2844881-1-armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/monitor/hmp.h |  5 +++++
 monitor/hmp-cmds.c    | 30 ++----------------------------
 monitor/qmp-cmds.c    |  2 +-
 ui/ui-hmp-cmds.c      | 35 ++++++++++++++++++++++++++++++++++-
 4 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index b228a406f3..df89eac22a 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -73,6 +73,11 @@ void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
 void hmp_expire_password(Monitor *mon, const QDict *qdict);
 void hmp_change(Monitor *mon, const QDict *qdict);
+#ifdef CONFIG_VNC
+void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
+                    const char *arg, const char *read_only, bool force,
+                    Error **errp);
+#endif
 void hmp_migrate(Monitor *mon, const QDict *qdict);
 void hmp_device_add(Monitor *mon, const QDict *qdict);
 void hmp_device_del(Monitor *mon, const QDict *qdict);
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 4340e71c90..1dba973092 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -25,7 +25,7 @@
 #include "qemu/timer.h"
 #include "qemu/sockets.h"
 #include "qemu/help_option.h"
-#include "monitor/monitor-internal.h"
+#include "monitor/monitor.h"
 #include "qapi/error.h"
 #include "qapi/clone-visitor.h"
 #include "qapi/opts-visitor.h"
@@ -41,7 +41,6 @@
 #include "qapi/qapi-commands-run-state.h"
 #include "qapi/qapi-commands-stats.h"
 #include "qapi/qapi-commands-tpm.h"
-#include "qapi/qapi-commands-ui.h"
 #include "qapi/qapi-commands-virtio.h"
 #include "qapi/qapi-visit-virtio.h"
 #include "qapi/qapi-visit-net.h"
@@ -1075,15 +1074,6 @@ void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, err);
 }
 
-#ifdef CONFIG_VNC
-static void hmp_change_read_arg(void *opaque, const char *password,
-                                void *readline_opaque)
-{
-    qmp_change_vnc_password(password, NULL);
-    monitor_read_command(opaque, 1);
-}
-#endif
-
 void hmp_change(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_str(qdict, "device");
@@ -1096,23 +1086,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
 
 #ifdef CONFIG_VNC
     if (strcmp(device, "vnc") == 0) {
-        if (read_only) {
-            error_setg(&err, "Parameter 'read-only-mode' is invalid for VNC");
-            goto end;
-        }
-        if (strcmp(target, "passwd") == 0 ||
-            strcmp(target, "password") == 0) {
-            if (!arg) {
-                MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
-                monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
-                return;
-            } else {
-                qmp_change_vnc_password(arg, &err);
-            }
-        } else {
-            error_setg(&err, "Expected 'password' after 'vnc'");
-            goto end;
-        }
+        hmp_change_vnc(mon, device, target, arg, read_only, force, &err);
     } else
 #endif
     {
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index b5b736761a..14f0f78e51 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -168,7 +168,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
                     bool has_skipauth, bool skipauth, bool has_tls, bool tls,
                     Error **errp)
 {
-    static struct {
+    static const struct {
         const char *name;
         bool (*add_client)(int fd, bool has_skipauth, bool skipauth,
                            bool has_tls, bool tls, Error **errp);
diff --git a/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c
index 95abd4693f..41d934acb9 100644
--- a/ui/ui-hmp-cmds.c
+++ b/ui/ui-hmp-cmds.c
@@ -18,7 +18,8 @@
 #include <spice/enums.h>
 #endif
 #include "monitor/hmp.h"
-#include "monitor/monitor.h"
+#include "monitor/monitor-internal.h"
+#include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/cutils.h"
@@ -311,6 +312,38 @@ out:
     hmp_handle_error(mon, err);
 }
 
+#ifdef CONFIG_VNC
+static void hmp_change_read_arg(void *opaque, const char *password,
+                                void *readline_opaque)
+{
+    qmp_change_vnc_password(password, NULL);
+    monitor_read_command(opaque, 1);
+}
+
+void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
+                    const char *arg, const char *read_only, bool force,
+                    Error **errp)
+{
+    if (read_only) {
+        error_setg(errp, "Parameter 'read-only-mode' is invalid for VNC");
+        return;
+    }
+    if (strcmp(target, "passwd") == 0 ||
+        strcmp(target, "password") == 0) {
+        if (!arg) {
+            MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
+            monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
+            return;
+        } else {
+            qmp_change_vnc_password(arg, errp);
+        }
+    } else {
+        error_setg(errp, "Expected 'password' after 'vnc'");
+        return;
+    }
+}
+#endif
+
 void hmp_sendkey(Monitor *mon, const QDict *qdict)
 {
     const char *keys = qdict_get_str(qdict, "keys");
-- 
2.38.1



  parent reply	other threads:[~2022-12-20  9:08 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20  9:06 [PATCH v3 00/18] ui: Move and clean up monitor command code Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 01/18] ui: Check numeric part of expire_password argument @time properly Markus Armbruster
2022-12-20  9:10   ` Daniel P. Berrangé
2022-12-20  9:06 ` [PATCH v3 02/18] ui: Fix silent truncation of numeric keys in HMP sendkey Markus Armbruster
2023-01-04 16:19   ` Dr. David Alan Gilbert
2023-01-09 11:50     ` Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 03/18] ui/spice: Require spice-protocol >= 0.14.0 Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 04/18] Revert "hmp: info spice: take out webdav" Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 05/18] ui/spice: Require spice-server >= 0.14.0 Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 06/18] ui/spice: QXLInterface method set_mm_time() is now dead, drop Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 07/18] ui/spice: Give hmp_info_spice()'s channel_names[] static linkage Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 08/18] ui: Clean up a few things checkpatch.pl would flag later on Markus Armbruster
2022-12-20 11:13   ` Philippe Mathieu-Daudé
2022-12-20  9:06 ` [PATCH v3 09/18] ui: Move QMP commands from monitor to new ui/ui-qmp-cmds.c Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 10/18] ui: Factor out qmp_add_client() parts and move to ui/ui-qmp-cmds.c Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 11/18] ui: Move HMP commands from monitor to new ui/ui-hmp-cmds.c Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 12/18] ui: Move more HMP commands from monitor to ui/ Markus Armbruster
2022-12-20  9:11   ` Daniel P. Berrangé
2022-12-20 11:22   ` Philippe Mathieu-Daudé
2022-12-20 11:49     ` Markus Armbruster
2022-12-20 12:29       ` Philippe Mathieu-Daudé
2022-12-20 15:30         ` Markus Armbruster
2022-12-20 16:35           ` Philippe Mathieu-Daudé
2022-12-20  9:06 ` [PATCH v3 13/18] ui: Improve "change vnc" error reporting Markus Armbruster
2022-12-20 11:23   ` Philippe Mathieu-Daudé
2022-12-20  9:06 ` Markus Armbruster [this message]
2022-12-20  9:06 ` [PATCH v3 15/18] ui: Reduce nesting in hmp_change_vnc() slightly Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 16/18] ui: Split hmp_mouse_set() and move the HMP part to ui/ Markus Armbruster
2022-12-20  9:15   ` Daniel P. Berrangé
2022-12-20 11:20     ` Markus Armbruster
2022-12-20 11:17   ` Philippe Mathieu-Daudé
2023-01-09 14:35     ` Markus Armbruster
2022-12-20  9:06 ` [PATCH v3 17/18] ui: Don't check for mode change after mouse_set error Markus Armbruster
2022-12-20  9:16   ` Daniel P. Berrangé
2022-12-20  9:06 ` [PATCH v3 18/18] ui: Simplify control flow in qemu_mouse_set() Markus Armbruster
2022-12-20  9:17   ` Daniel P. Berrangé
2022-12-20 10:52 ` [PATCH v3 00/18] ui: Move and clean up monitor command code Philippe Mathieu-Daudé
2022-12-20 11:17   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221220090645.2844881-15-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).