qdict_put(qdict, "host", qstring_from_str(host));
qdict_put(qdict, "service", qstring_from_str(serv));
+ qdict_put(qdict, "family",qstring_from_str(inet_strfamily(sa->ss_family)));
return 0;
}
-static int vnc_qdict_local_addr(QDict *qdict, int fd)
+static int vnc_server_addr_put(QDict *qdict, int fd)
{
struct sockaddr_storage sa;
socklen_t salen;
return "unknown";
}
-static QDict *do_info_vnc_client(Monitor *mon, VncState *client)
+static int vnc_server_info_put(QDict *qdict)
+{
+ if (vnc_server_addr_put(qdict, vnc_display->lsock) < 0) {
+ return -1;
+ }
+
+ qdict_put(qdict, "auth", qstring_from_str(vnc_auth_name(vnc_display)));
+ return 0;
+}
+
+static void vnc_client_cache_auth(VncState *client)
{
QDict *qdict;
- qdict = qdict_new();
- if (vnc_qdict_remote_addr(qdict, client->csock) < 0) {
- QDECREF(qdict);
- return NULL;
+ if (!client->info) {
+ return;
}
+ qdict = qobject_to_qdict(client->info);
+
#ifdef CONFIG_VNC_TLS
if (client->tls.session &&
client->tls.dname) {
#ifdef CONFIG_VNC_SASL
if (client->sasl.conn &&
client->sasl.username) {
- qdict_put(qdict, "username", qstring_from_str(client->sasl.username));
+ qdict_put(qdict, "sasl_username",
+ qstring_from_str(client->sasl.username));
}
#endif
+}
+
+static void vnc_client_cache_addr(VncState *client)
+{
+ QDict *qdict;
+
+ qdict = qdict_new();
+ if (vnc_qdict_remote_addr(qdict, client->csock) < 0) {
+ QDECREF(qdict);
+ /* XXX: how to report the error? */
+ return;
+ }
- return qdict;
+ client->info = QOBJECT(qdict);
+}
+
+static void vnc_qmp_event(VncState *vs, MonitorEvent event)
+{
+ QDict *server;
+ QObject *data;
+
+ if (!vs->info) {
+ return;
+ }
+
+ server = qdict_new();
+ if (vnc_server_info_put(server) < 0) {
+ QDECREF(server);
+ return;
+ }
+
+ data = qobject_from_jsonf("{ 'client': %p, 'server': %p }",
+ vs->info, QOBJECT(server));
+
+ monitor_protocol_event(event, data);
+
+ qobject_incref(vs->info);
+ qobject_decref(data);
}
static void info_vnc_iter(QObject *obj, void *opaque)
#endif
#ifdef CONFIG_VNC_SASL
monitor_printf(mon, " username: %s\n",
- qdict_haskey(client, "username") ?
- qdict_get_str(client, "username") : "none");
+ qdict_haskey(client, "sasl_username") ?
+ qdict_get_str(client, "sasl_username") : "none");
#endif
}
QList *clients;
server = qobject_to_qdict(data);
- if (strcmp(qdict_get_str(server, "status"), "disabled") == 0) {
+ if (qdict_get_bool(server, "enabled") == 0) {
monitor_printf(mon, "Server: disabled\n");
return;
}
monitor_printf(mon, " address: %s:%s\n",
qdict_get_str(server, "host"),
qdict_get_str(server, "service"));
- monitor_printf(mon, " auth: %s\n",
- qdict_haskey(server, "auth") ? qdict_get_str(server, "auth") : "none");
+ monitor_printf(mon, " auth: %s\n", qdict_get_str(server, "auth"));
clients = qdict_get_qlist(server, "clients");
if (qlist_empty(clients)) {
*
* The main QDict contains the following:
*
- * - "status": "disabled" or "enabled"
+ * - "enabled": true or false
* - "host": server's IP address
+ * - "family": address family ("ipv4" or "ipv6")
* - "service": server's port number
- * - "auth": authentication method (optional)
+ * - "auth": authentication method
* - "clients": a QList of all connected clients
*
* Clients are described by a QDict, with the following information:
*
* - "host": client's IP address
+ * - "family": address family ("ipv4" or "ipv6")
* - "service": client's port number
* - "x509_dname": TLS dname (optional)
- * - "username": SASL username (optional)
+ * - "sasl_username": SASL username (optional)
*
* Example:
*
- * { "status": "enabled", "host": "0.0.0.0", "service": "50402", "auth": "vnc",
- * "clients": [ { "host": "127.0.0.1", "service": "50401" } ] }
+ * { "enabled": true, "host": "0.0.0.0", "service": "50402", "auth": "vnc",
+ * "family": "ipv4",
+ * "clients": [{ "host": "127.0.0.1", "service": "50401", "family": "ipv4" }]}
*/
void do_info_vnc(Monitor *mon, QObject **ret_data)
{
if (vnc_display == NULL || vnc_display->display == NULL) {
- *ret_data = qobject_from_jsonf("{ 'status': 'disabled' }");
+ *ret_data = qobject_from_jsonf("{ 'enabled': false }");
} else {
- QDict *qdict;
QList *clist;
+ VncState *client;
clist = qlist_new();
- if (vnc_display->clients) {
- VncState *client = vnc_display->clients;
- while (client) {
- qdict = do_info_vnc_client(mon, client);
- if (qdict)
- qlist_append(clist, qdict);
- client = client->next;
+ QTAILQ_FOREACH(client, &vnc_display->clients, next) {
+ if (client->info) {
+ /* incref so that it's not freed by upper layers */
+ qobject_incref(client->info);
+ qlist_append_obj(clist, client->info);
}
}
- *ret_data = qobject_from_jsonf("{ 'status': 'enabled', 'clients': %p }",
+ *ret_data = qobject_from_jsonf("{ 'enabled': true, 'clients': %p }",
QOBJECT(clist));
assert(*ret_data != NULL);
- qdict = qobject_to_qdict(*ret_data);
-
- if (vnc_display->auth != VNC_AUTH_NONE) {
- qdict_put(qdict, "auth",
- qstring_from_str(vnc_auth_name(vnc_display)));
- }
-
- if (vnc_qdict_local_addr(qdict, vnc_display->lsock) < 0) {
+ if (vnc_server_info_put(qobject_to_qdict(*ret_data)) < 0) {
qobject_decref(*ret_data);
*ret_data = NULL;
}
{
int size_changed;
VncDisplay *vd = ds->opaque;
- VncState *vs = vd->clients;
+ VncState *vs;
/* server surface */
if (!vd->server)
*(vd->guest.ds) = *(ds->surface);
memset(vd->guest.dirty, 0xFF, sizeof(vd->guest.dirty));
- while (vs != NULL) {
+ QTAILQ_FOREACH(vs, &vd->clients, next) {
vnc_colordepth(vs);
if (size_changed) {
if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) {
}
}
memset(vs->dirty, 0xFF, sizeof(vs->dirty));
- vs = vs->next;
}
}
int cmp_bytes;
vnc_refresh_server_surface(vd);
- for (vs = vd->clients; vs != NULL; vs = vn) {
- vn = vs->next;
+ QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vs->force_update = 1;
vnc_update_client(vs, 1);
if (memcmp(src_row, dst_row, cmp_bytes) == 0)
continue;
memmove(dst_row, src_row, cmp_bytes);
- vs = vd->clients;
- while (vs != NULL) {
- if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT))
+ QTAILQ_FOREACH(vs, &vd->clients, next) {
+ if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vnc_set_bit(vs->dirty[y], ((x + dst_x) / 16));
- vs = vs->next;
+ }
}
}
src_row += pitch - w * depth;
y += inc;
}
- for (vs = vd->clients; vs != NULL; vs = vs->next) {
- if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT))
+ QTAILQ_FOREACH(vs, &vd->clients, next) {
+ if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
vnc_copy(vs, src_x, src_y, dst_x, dst_y, w, h);
+ }
}
}
static void audio_add(VncState *vs)
{
- Monitor *mon = cur_mon;
struct audio_capture_ops ops;
if (vs->audio_cap) {
- monitor_printf(mon, "audio already running\n");
+ monitor_printf(default_mon, "audio already running\n");
return;
}
vs->audio_cap = AUD_add_capture(&vs->as, &ops, vs);
if (!vs->audio_cap) {
- monitor_printf(mon, "Failed to add audio capture\n");
+ monitor_printf(default_mon, "Failed to add audio capture\n");
}
}
static void vnc_disconnect_finish(VncState *vs)
{
+ vnc_qmp_event(vs, QEVENT_VNC_DISCONNECTED);
+
if (vs->input.buffer) {
qemu_free(vs->input.buffer);
vs->input.buffer = NULL;
qemu_free(vs->output.buffer);
vs->output.buffer = NULL;
}
+
+ qobject_decref(vs->info);
+
#ifdef CONFIG_VNC_TLS
vnc_tls_client_cleanup(vs);
#endif /* CONFIG_VNC_TLS */
#endif /* CONFIG_VNC_SASL */
audio_del(vs);
- VncState *p, *parent = NULL;
- for (p = vs->vd->clients; p != NULL; p = p->next) {
- if (p == vs) {
- if (parent)
- parent->next = p->next;
- else
- vs->vd->clients = p->next;
- break;
- }
- parent = p;
- }
- if (!vs->vd->clients)
+ QTAILQ_REMOVE(&vs->vd->clients, vs, next);
+
+ if (QTAILQ_EMPTY(&vs->vd->clients)) {
dcl->idle = 1;
+ }
vnc_remove_timer(vs->vd);
+ qemu_remove_led_event_handler(vs->led);
qemu_free(vs);
}
int i;
for(i = 0; i < 256; i++) {
if (vs->modifiers_state[i]) {
- if (i & 0x80)
- kbd_put_keycode(0xe0);
- kbd_put_keycode(i | 0x80);
+ if (i & SCANCODE_GREY)
+ kbd_put_keycode(SCANCODE_EMUL0);
+ kbd_put_keycode(i | SCANCODE_UP);
vs->modifiers_state[i] = 0;
}
}
static void press_key(VncState *vs, int keysym)
{
- kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) & 0x7f);
- kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) | 0x80);
+ int keycode = keysym2scancode(vs->vd->kbd_layout, keysym) & SCANCODE_KEYMASK;
+ if (keycode & SCANCODE_GREY)
+ kbd_put_keycode(SCANCODE_EMUL0);
+ kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+ if (keycode & SCANCODE_GREY)
+ kbd_put_keycode(SCANCODE_EMUL0);
+ kbd_put_keycode(keycode | SCANCODE_UP);
+}
+
+static void kbd_leds(void *opaque, int ledstate)
+{
+ VncState *vs = opaque;
+ int caps, num;
+
+ caps = ledstate & QEMU_CAPS_LOCK_LED ? 1 : 0;
+ num = ledstate & QEMU_NUM_LOCK_LED ? 1 : 0;
+
+ if (vs->modifiers_state[0x3a] != caps) {
+ vs->modifiers_state[0x3a] = caps;
+ }
+ if (vs->modifiers_state[0x45] != num) {
+ vs->modifiers_state[0x45] = num;
+ }
}
static void do_key_event(VncState *vs, int down, int keycode, int sym)
break;
case 0x3a: /* CapsLock */
case 0x45: /* NumLock */
- if (!down)
+ if (down)
vs->modifiers_state[keycode] ^= 1;
break;
}
}
if (is_graphic_console()) {
- if (keycode & 0x80)
- kbd_put_keycode(0xe0);
+ if (keycode & SCANCODE_GREY)
+ kbd_put_keycode(SCANCODE_EMUL0);
if (down)
- kbd_put_keycode(keycode & 0x7f);
+ kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
else
- kbd_put_keycode(keycode | 0x80);
+ kbd_put_keycode(keycode | SCANCODE_UP);
} else {
/* QEMU console emulation */
if (down) {
lsym = lsym - 'A' + 'a';
}
- keycode = keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF);
+ keycode = keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF) & SCANCODE_KEYMASK;
do_key_event(vs, down, keycode, sym);
}
vnc_write(vs, buf, size);
vnc_flush(vs);
+ vnc_client_cache_auth(vs);
+ vnc_qmp_event(vs, QEVENT_VNC_INITIALIZED);
+
vnc_read_when(vs, protocol_client_msg, 1);
return 0;
uint8_t *server_row;
int cmp_bytes;
uint32_t width_mask[VNC_DIRTY_WORDS];
- VncState *vs = NULL;
+ VncState *vs;
int has_dirty = 0;
/*
if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
continue;
memcpy(server_ptr, guest_ptr, cmp_bytes);
- vs = vd->clients;
- while (vs != NULL) {
+ QTAILQ_FOREACH(vs, &vd->clients, next) {
vnc_set_bit(vs->dirty[y], (x / 16));
- vs = vs->next;
}
has_dirty++;
}
static void vnc_refresh(void *opaque)
{
VncDisplay *vd = opaque;
- VncState *vs = NULL;
- int has_dirty = 0, rects = 0;
+ VncState *vs, *vn;
+ int has_dirty, rects = 0;
vga_hw_update();
has_dirty = vnc_refresh_server_surface(vd);
- vs = vd->clients;
- while (vs != NULL) {
+ QTAILQ_FOREACH_SAFE(vs, &vd->clients, next, vn) {
rects += vnc_update_client(vs, has_dirty);
- vs = vs->next;
+ /* vs might be free()ed here */
}
/* vd->timer could be NULL now if the last client disconnected,
* in this case don't update the timer */
static void vnc_init_timer(VncDisplay *vd)
{
vd->timer_interval = VNC_REFRESH_INTERVAL_BASE;
- if (vd->timer == NULL && vd->clients != NULL) {
+ if (vd->timer == NULL && !QTAILQ_EMPTY(&vd->clients)) {
vd->timer = qemu_new_timer(rt_clock, vnc_refresh, vd);
vnc_refresh(vd);
}
static void vnc_remove_timer(VncDisplay *vd)
{
- if (vd->timer != NULL && vd->clients == NULL) {
+ if (vd->timer != NULL && QTAILQ_EMPTY(&vd->clients)) {
qemu_del_timer(vd->timer);
qemu_free_timer(vd->timer);
vd->timer = NULL;
socket_set_nonblock(vs->csock);
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+ vnc_client_cache_addr(vs);
+ vnc_qmp_event(vs, QEVENT_VNC_CONNECTED);
+
vs->vd = vd;
vs->ds = vd->ds;
vs->last_x = -1;
vs->as.fmt = AUD_FMT_S16;
vs->as.endianness = 0;
- vs->next = vd->clients;
- vd->clients = vs;
+ QTAILQ_INSERT_HEAD(&vd->clients, vs, next);
vga_hw_update();
vnc_flush(vs);
vnc_read_when(vs, protocol_version, 12);
reset_keys(vs);
+ vs->led = qemu_add_led_event_handler(kbd_leds, vs);
vnc_init_timer(vd);
vs->lsock = -1;
vs->ds = ds;
+ QTAILQ_INIT(&vs->clients);
if (keyboard_layout)
vs->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
const char *options;
int password = 0;
int reverse = 0;
- int to_port = 0;
#ifdef CONFIG_VNC_TLS
int tls = 0, x509 = 0;
#endif
password = 1; /* Require password auth */
} else if (strncmp(options, "reverse", 7) == 0) {
reverse = 1;
- } else if (strncmp(options, "to=", 3) == 0) {
- to_port = atoi(options+3) + 5900;
#ifdef CONFIG_VNC_SASL
} else if (strncmp(options, "sasl", 4) == 0) {
sasl = 1; /* Require SASL auth */