Signed-off-by: Markus Armbruster <arm...@redhat.com> --- include/monitor/hmp.h | 5 +++++ monitor/hmp-cmds.c | 28 +--------------------------- ui/ui-hmp-cmds.c | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index dfbc0c9a2f..992d91f181 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 8542eee3d4..78bcdede85 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -42,7 +42,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" @@ -1187,15 +1186,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"); @@ -1208,23 +1198,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/ui/ui-hmp-cmds.c b/ui/ui-hmp-cmds.c index 90a4f86f25..b1b18d5a5d 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" @@ -270,12 +271,20 @@ 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(mon, "Parameter 'read-only-mode' is invalid for VNC"); + error_setg(errp, "Parameter 'read-only-mode' is invalid for VNC"); return; } if (strcmp(target, "passwd") == 0 || @@ -285,12 +294,14 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target, monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); return; } else { - qmp_change_vnc_password(arg, &err); + qmp_change_vnc_password(arg, errp); } } else { - monitor_printf(mon, "Expected 'password' after 'vnc'\n"); + error_setg(errp, "Expected 'password' after 'vnc'"); + return; } } +#endif void hmp_sendkey(Monitor *mon, const QDict *qdict) { -- 2.37.3