aboutsummaryrefslogtreecommitdiffstats
path: root/monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/monitor.c b/monitor.c
index ab63f22..4ddfd1b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -31,6 +31,56 @@ static void show_error(struct qemu_window *win, char *cmd, char *reply)
gtk_widget_show_all(dialog);
}
+static void monitor_parse_vnc(struct qemu_window *win, char *reply)
+{
+ char *ptr, host[64];
+ int vnc = 0;
+ int tty = 0;
+ int passwd = 0;
+ int port;
+
+ if (strcmp(reply, "VNC server disabled") == 0 || /* qemu 0.9.x */
+ strcmp(reply, "Server: disabled") == 0) { /* qemu 0.10.x */
+ if (win->sercon)
+ tty = 1;
+ } else if (1 == sscanf(reply, "VNC server active on: %127[^\r\n]",
+ win->vnc_display)) {
+ /* qemu 0.9.x */
+ if (strstr(reply, "No client connected")) {
+ vnc = 1;
+ if (strstr(win->vnc_display, ",password"))
+ passwd = 1;
+ }
+ } else if (strncmp(reply, "Server:",7) == 0) {
+ /* qemu 0.10.x */
+ ptr = strstr(reply, "address: ");
+ if (2 == sscanf(ptr, "address: %63[^:]:%d", host, &port)) {
+ snprintf(win->vnc_display, sizeof(win->vnc_display),
+ "%s:%d", host, port - 5900);
+ vnc = 1;
+ if (strstr(reply, "auth: vnc"))
+ passwd = 1;
+ }
+ }
+
+ if (vnc) {
+ if (passwd) {
+ win->vnc_password = malloc(32);
+#if 1
+ /* FIXME: do something less predictable */
+ srand(time(NULL)+getpid());
+ snprintf(win->vnc_password, 32, "%x", rand() & 0xfffffff);
+#endif
+ win->vnc_send_password = 1;
+ monitor_append(win, "change vnc password");
+ } else {
+ vnc_connect(win);
+ }
+ } else if (tty) {
+ conn_open_term(win, "serial0", win->sercon, 0);
+ }
+}
+
static int monitor_parse(struct qemu_window *win, char *buf, int len)
{
char *reply, *prompt, *cmd;
@@ -94,26 +144,7 @@ static int monitor_parse(struct qemu_window *win, char *buf, int len)
conn_open_term(win, "serial0", win->sercon, 0);
} else if (0 == strcmp(cmd, "info vnc")) {
- if (1 == sscanf(reply, "VNC server active on: %127[^\r\n]",
- win->vnc_display) &&
- strstr(reply, "No client connected")) {
- if (strstr(win->vnc_display, ",password")) {
- win->vnc_password = malloc(32);
-#if 1
- /* FIXME: do something less predictable */
- srand(time(NULL)+getpid());
- snprintf(win->vnc_password, 32, "%x", rand() & 0xfffffff);
-#endif
- win->vnc_send_password = 1;
- monitor_append(win, "change vnc password");
- } else {
- vnc_connect(win);
- }
- } else if (strcmp(reply, "VNC server disabled") == 0) {
- /* no vnc -> try opening serial console instead */
- if (win->sercon)
- conn_open_term(win, "serial0", win->sercon, 0);
- }
+ monitor_parse_vnc(win, reply);
} else if (0 == strcmp(cmd, "change vnc password")) {
vnc_connect(win);