target/hppa: Extract system helpers to sys_helper.c
[qemu/armbru.git] / ui / ui-qmp-cmds.c
blobdbc4afcd731b825796e8e690ffd819a9edc8be86
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 "monitor/qmp-helpers.h"
18 #include "qapi/qapi-commands-ui.h"
19 #include "qapi/qmp/qerror.h"
20 #include "qemu/cutils.h"
21 #include "ui/console.h"
22 #include "ui/dbus-display.h"
23 #include "ui/qemu-spice.h"
25 void qmp_set_password(SetPasswordOptions *opts, Error **errp)
27 int rc;
29 if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
30 if (!qemu_using_spice(errp)) {
31 return;
33 rc = qemu_spice.set_passwd(opts->password,
34 opts->connected == SET_PASSWORD_ACTION_FAIL,
35 opts->connected == SET_PASSWORD_ACTION_DISCONNECT);
36 } else {
37 assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
38 if (opts->connected != SET_PASSWORD_ACTION_KEEP) {
39 /* vnc supports "connected=keep" only */
40 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
41 return;
44 * Note that setting an empty password will not disable login
45 * through this interface.
47 rc = vnc_display_password(opts->u.vnc.display, opts->password);
50 if (rc != 0) {
51 error_setg(errp, "Could not set password");
55 void qmp_expire_password(ExpirePasswordOptions *opts, Error **errp)
57 time_t when;
58 int rc;
59 const char *whenstr = opts->time;
60 const char *numstr = NULL;
61 uint64_t num;
63 if (strcmp(whenstr, "now") == 0) {
64 when = 0;
65 } else if (strcmp(whenstr, "never") == 0) {
66 when = TIME_MAX;
67 } else if (whenstr[0] == '+') {
68 when = time(NULL);
69 numstr = whenstr + 1;
70 } else {
71 when = 0;
72 numstr = whenstr;
75 if (numstr) {
76 if (qemu_strtou64(numstr, NULL, 10, &num) < 0) {
77 error_setg(errp, "Parameter 'time' doesn't take value '%s'",
78 whenstr);
79 return;
81 when += num;
84 if (opts->protocol == DISPLAY_PROTOCOL_SPICE) {
85 if (!qemu_using_spice(errp)) {
86 return;
88 rc = qemu_spice.set_pw_expire(when);
89 } else {
90 assert(opts->protocol == DISPLAY_PROTOCOL_VNC);
91 rc = vnc_display_pw_expire(opts->u.vnc.display, when);
94 if (rc != 0) {
95 error_setg(errp, "Could not set password expire time");
99 #ifdef CONFIG_VNC
100 void qmp_change_vnc_password(const char *password, Error **errp)
102 if (vnc_display_password(NULL, password) < 0) {
103 error_setg(errp, "Could not set password");
106 #endif
108 bool qmp_add_client_spice(int fd, bool has_skipauth, bool skipauth,
109 bool has_tls, bool tls, Error **errp)
111 if (!qemu_using_spice(errp)) {
112 return false;
114 skipauth = has_skipauth ? skipauth : false;
115 tls = has_tls ? tls : false;
116 if (qemu_spice.display_add_client(fd, skipauth, tls) < 0) {
117 error_setg(errp, "spice failed to add client");
118 return false;
120 return true;
123 #ifdef CONFIG_VNC
124 bool qmp_add_client_vnc(int fd, bool has_skipauth, bool skipauth,
125 bool has_tls, bool tls, Error **errp)
127 skipauth = has_skipauth ? skipauth : false;
128 vnc_display_add_client(NULL, fd, skipauth);
129 return true;
131 #endif
133 #ifdef CONFIG_DBUS_DISPLAY
134 bool qmp_add_client_dbus_display(int fd, bool has_skipauth, bool skipauth,
135 bool has_tls, bool tls, Error **errp)
137 if (!qemu_using_dbus_display(errp)) {
138 return false;
140 if (!qemu_dbus_display.add_client(fd, errp)) {
141 return false;
143 return true;
145 #endif
147 void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
149 switch (arg->type) {
150 case DISPLAY_RELOAD_TYPE_VNC:
151 #ifdef CONFIG_VNC
152 if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) {
153 vnc_display_reload_certs(NULL, errp);
155 #else
156 error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
157 #endif
158 break;
159 default:
160 abort();
164 void qmp_display_update(DisplayUpdateOptions *arg, Error **errp)
166 switch (arg->type) {
167 case DISPLAY_UPDATE_TYPE_VNC:
168 #ifdef CONFIG_VNC
169 vnc_display_update(&arg->u.vnc, errp);
170 #else
171 error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
172 #endif
173 break;
174 default:
175 abort();