ui: Move QMP commands from monitor to new ui/ui-qmp-cmds.c
[qemu.git] / ui / ui-qmp-cmds.c
blobc9f92caf1d71e6d6cf0e24258608172ecaf96375
1 /*
2 * QMP commands related to UI
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "qapi/qapi-commands-ui.h"
18 #include "qapi/qmp/qerror.h"
19 #include "qemu/cutils.h"
20 #include "ui/console.h"
21 #include "ui/qemu-spice.h"
23 void qmp_set_password(SetPasswordOptions *opts, Error **errp)
25 int rc;
27 if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
28 if (!qemu_using_spice(errp)) {
29 return;
31 rc = qemu_spice.set_passwd(opts->password,
32 opts->connected == SET_PASSWORD_ACTION_FAIL,
33 opts->connected == SET_PASSWORD_ACTION_DISCONNECT);
34 } else {
35 assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
36 if (opts->connected != SET_PASSWORD_ACTION_KEEP) {
37 /* vnc supports "connected=keep" only */
38 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
39 return;
42 * Note that setting an empty password will not disable login
43 * through this interface.
45 rc = vnc_display_password(opts->u.vnc.display, opts->password);
48 if (rc != 0) {
49 error_setg(errp, "Could not set password");
53 void qmp_expire_password(ExpirePasswordOptions *opts, Error **errp)
55 time_t when;
56 int rc;
57 const char *whenstr = opts->time;
58 const char *numstr = NULL;
59 uint64_t num;
61 if (strcmp(whenstr, "now") == 0) {
62 when = 0;
63 } else if (strcmp(whenstr, "never") == 0) {
64 when = TIME_MAX;
65 } else if (whenstr[0] == '+') {
66 when = time(NULL);
67 numstr = whenstr + 1;
68 } else {
69 when = 0;
70 numstr = whenstr;
73 if (numstr) {
74 if (qemu_strtou64(numstr, NULL, 10, &num) < 0) {
75 error_setg(errp, "Parameter 'time' doesn't take value '%s'",
76 whenstr);
77 return;
79 when += num;
82 if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
83 if (!qemu_using_spice(errp)) {
84 return;
86 rc = qemu_spice.set_pw_expire(when);
87 } else {
88 assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
89 rc = vnc_display_pw_expire(opts->u.vnc.display, when);
92 if (rc != 0) {
93 error_setg(errp, "Could not set password expire time");
97 #ifdef CONFIG_VNC
98 void qmp_change_vnc_password(const char *password, Error **errp)
100 if (vnc_display_password(NULL, password) < 0) {
101 error_setg(errp, "Could not set password");
104 #endif
106 void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
108 switch (arg->type) {
109 case DISPLAY_RELOAD_TYPE_VNC:
110 #ifdef CONFIG_VNC
111 if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) {
112 vnc_display_reload_certs(NULL, errp);
114 #else
115 error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
116 #endif
117 break;
118 default:
119 abort();
123 void qmp_display_update(DisplayUpdateOptions *arg, Error **errp)
125 switch (arg->type) {
126 case DISPLAY_UPDATE_TYPE_VNC:
127 #ifdef CONFIG_VNC
128 vnc_display_update(&arg->u.vnc, errp);
129 #else
130 error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
131 #endif
132 break;
133 default:
134 abort();