All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: wenchaoqemu@gmail.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 2.1 25/36] qapi event: convert VNC events
Date: Wed, 18 Jun 2014 08:43:49 +0200	[thread overview]
Message-ID: <1403073840-32603-26-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1403073840-32603-1-git-send-email-pbonzini@redhat.com>

From: Wenchao Xia <wenchaoqemu@gmail.com>

Since VNC_CONNECTED, VNC_DISCONNECTED, VNC_INITIALIZED share some
common functions, convert them in one patch.

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 docs/qmp/qmp-events.txt |  90 ---------------------------------------
 qapi-event.json         |  49 +++++++++++++++++++++
 ui/vnc.c                | 111 +++++++++++++++++++++++++-----------------------
 ui/vnc.h                |   4 +-
 4 files changed, 108 insertions(+), 146 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 101f207..37bc891 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -132,93 +132,3 @@ Example:
                       "connection-id": 1804289383, "host": "127.0.0.1",
                       "channel-id": 0, "tls": true}
 }}
-
-VNC_CONNECTED
--------------
-
-Emitted when a VNC client establishes a connection.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-
-Example:
-
-{ "event": "VNC_CONNECTED",
-    "data": {
-        "server": { "auth": "sasl", "family": "ipv4",
-                    "service": "5901", "host": "0.0.0.0" },
-        "client": { "family": "ipv4", "service": "58425",
-                    "host": "127.0.0.1" } },
-    "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
-
-
-Note: This event is emitted before any authentication takes place, thus
-the authentication ID is not provided.
-
-VNC_DISCONNECTED
-----------------
-
-Emitted when the connection is closed.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "x509_dname": TLS dname (json-string, optional)
-  - "sasl_username": SASL username (json-string, optional)
-
-Example:
-
-{ "event": "VNC_DISCONNECTED",
-    "data": {
-        "server": { "auth": "sasl", "family": "ipv4",
-                    "service": "5901", "host": "0.0.0.0" },
-        "client": { "family": "ipv4", "service": "58425",
-                    "host": "127.0.0.1", "sasl_username": "luiz" } },
-    "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
-
-VNC_INITIALIZED
----------------
-
-Emitted after authentication takes place (if any) and the VNC session is
-made active.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "x509_dname": TLS dname (json-string, optional)
-  - "sasl_username": SASL username (json-string, optional)
-
-Example:
-
-{ "event": "VNC_INITIALIZED",
-    "data": {
-        "server": { "auth": "sasl", "family": "ipv4",
-                    "service": "5901", "host": "0.0.0.0"},
-        "client": { "family": "ipv4", "service": "46089",
-                    "host": "127.0.0.1", "sasl_username": "luiz" } },
-        "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
diff --git a/qapi-event.json b/qapi-event.json
index b8dec47..a86f8c9 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -137,3 +137,52 @@
 ##
 { 'event': 'NIC_RX_FILTER_CHANGED',
   'data': { '*name': 'str', 'path': 'str' } }
+
+##
+# @VNC_CONNECTED
+#
+# Emitted when a VNC client establishes a connection
+#
+# @server: server information
+#
+# @client: client information
+#
+# Note: This event is emitted before any authentication takes place, thus
+# the authentication ID is not provided
+#
+# Since: 0.13.0
+##
+{ 'event': 'VNC_CONNECTED',
+  'data': { 'server': 'VncServerInfo',
+            'client': 'VncBasicInfo' } }
+
+##
+# @VNC_INITIALIZED
+#
+# Emitted after authentication takes place (if any) and the VNC session is
+# made active
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 0.13.0
+##
+{ 'event': 'VNC_INITIALIZED',
+  'data': { 'server': 'VncServerInfo',
+            'client': 'VncClientInfo' } }
+
+##
+# @VNC_DISCONNECTED
+#
+# Emitted when the connection is closed
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 0.13.0
+##
+{ 'event': 'VNC_DISCONNECTED',
+  'data': { 'server': 'VncServerInfo',
+            'client': 'VncClientInfo' } }
diff --git a/ui/vnc.c b/ui/vnc.c
index 95eee5a..9ccd5e3 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -35,6 +35,7 @@
 #include "qmp-commands.h"
 #include "qemu/osdep.h"
 #include "ui/input.h"
+#include "qapi-event.h"
 
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
@@ -124,9 +125,10 @@ char *vnc_socket_remote_addr(const char *format, int fd) {
     return addr_to_string(format, &sa, salen);
 }
 
-static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa,
-                          socklen_t salen)
+static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa,
+                                        socklen_t salen)
 {
+    VncBasicInfo *info;
     char host[NI_MAXHOST];
     char serv[NI_MAXSERV];
     int err;
@@ -137,40 +139,40 @@ static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa,
                            NI_NUMERICHOST | NI_NUMERICSERV)) != 0) {
         VNC_DEBUG("Cannot resolve address %d: %s\n",
                   err, gai_strerror(err));
-        return -1;
+        return NULL;
     }
 
-    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;
+    info = g_malloc0(sizeof(VncBasicInfo));
+    info->host = g_strdup(host);
+    info->service = g_strdup(serv);
+    info->family = inet_netfamily(sa->ss_family);
+    return info;
 }
 
-static int vnc_server_addr_put(QDict *qdict, int fd)
+static VncBasicInfo *vnc_basic_info_get_from_server_addr(int fd)
 {
     struct sockaddr_storage sa;
     socklen_t salen;
 
     salen = sizeof(sa);
     if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) {
-        return -1;
+        return NULL;
     }
 
-    return put_addr_qdict(qdict, &sa, salen);
+    return vnc_basic_info_get(&sa, salen);
 }
 
-static int vnc_qdict_remote_addr(QDict *qdict, int fd)
+static VncBasicInfo *vnc_basic_info_get_from_remote_addr(int fd)
 {
     struct sockaddr_storage sa;
     socklen_t salen;
 
     salen = sizeof(sa);
     if (getpeername(fd, (struct sockaddr*)&sa, &salen) < 0) {
-        return -1;
+        return NULL;
     }
 
-    return put_addr_qdict(qdict, &sa, salen);
+    return vnc_basic_info_get(&sa, salen);
 }
 
 static const char *vnc_auth_name(VncDisplay *vd) {
@@ -224,81 +226,82 @@ static const char *vnc_auth_name(VncDisplay *vd) {
     return "unknown";
 }
 
-static int vnc_server_info_put(QDict *qdict)
+static VncServerInfo *vnc_server_info_get(void)
 {
-    if (vnc_server_addr_put(qdict, vnc_display->lsock) < 0) {
-        return -1;
+    VncServerInfo *info;
+    VncBasicInfo *bi = vnc_basic_info_get_from_server_addr(vnc_display->lsock);
+    if (!bi) {
+        return NULL;
     }
 
-    qdict_put(qdict, "auth", qstring_from_str(vnc_auth_name(vnc_display)));
-    return 0;
+    info = g_malloc(sizeof(*info));
+    info->base = bi;
+    info->has_auth = true;
+    info->auth = g_strdup(vnc_auth_name(vnc_display));
+    return info;
 }
 
 static void vnc_client_cache_auth(VncState *client)
 {
-#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
-    QDict *qdict;
-#endif
-
     if (!client->info) {
         return;
     }
 
-#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
-    qdict = qobject_to_qdict(client->info);
-#endif
-
 #ifdef CONFIG_VNC_TLS
     if (client->tls.session &&
         client->tls.dname) {
-        qdict_put(qdict, "x509_dname", qstring_from_str(client->tls.dname));
+        client->info->has_x509_dname = true;
+        client->info->x509_dname = g_strdup(client->tls.dname);
     }
 #endif
 #ifdef CONFIG_VNC_SASL
     if (client->sasl.conn &&
         client->sasl.username) {
-        qdict_put(qdict, "sasl_username",
-                  qstring_from_str(client->sasl.username));
+        client->info->has_sasl_username = true;
+        client->info->sasl_username = g_strdup(client->sasl.username);
     }
 #endif
 }
 
 static void vnc_client_cache_addr(VncState *client)
 {
-    QDict *qdict;
+    VncBasicInfo *bi = vnc_basic_info_get_from_remote_addr(client->csock);
 
-    qdict = qdict_new();
-    if (vnc_qdict_remote_addr(qdict, client->csock) < 0) {
-        QDECREF(qdict);
-        /* XXX: how to report the error? */
-        return;
+    if (bi) {
+        client->info = g_malloc0(sizeof(*client->info));
+        client->info->base = bi;
     }
-
-    client->info = QOBJECT(qdict);
 }
 
-static void vnc_qmp_event(VncState *vs, MonitorEvent event)
+static void vnc_qmp_event(VncState *vs, QAPIEvent event)
 {
-    QDict *server;
-    QObject *data;
+    VncServerInfo *si;
 
     if (!vs->info) {
         return;
     }
+    g_assert(vs->info->base);
 
-    server = qdict_new();
-    if (vnc_server_info_put(server) < 0) {
-        QDECREF(server);
+    si = vnc_server_info_get();
+    if (!si) {
         return;
     }
 
-    data = qobject_from_jsonf("{ 'client': %p, 'server': %p }",
-                              vs->info, QOBJECT(server));
-
-    monitor_protocol_event(event, data);
+    switch (event) {
+    case QAPI_EVENT_VNC_CONNECTED:
+        qapi_event_send_vnc_connected(si, vs->info->base, &error_abort);
+        break;
+    case QAPI_EVENT_VNC_INITIALIZED:
+        qapi_event_send_vnc_initialized(si, vs->info, &error_abort);
+        break;
+    case QAPI_EVENT_VNC_DISCONNECTED:
+        qapi_event_send_vnc_disconnected(si, vs->info, &error_abort);
+        break;
+    default:
+        break;
+    }
 
-    qobject_incref(vs->info);
-    qobject_decref(data);
+    qapi_free_VncServerInfo(si);
 }
 
 static VncClientInfo *qmp_query_vnc_client(const VncState *client)
@@ -1037,7 +1040,7 @@ void vnc_disconnect_finish(VncState *vs)
     vnc_jobs_join(vs); /* Wait encoding jobs */
 
     vnc_lock_output(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_DISCONNECTED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_DISCONNECTED);
 
     buffer_free(&vs->input);
     buffer_free(&vs->output);
@@ -1046,7 +1049,7 @@ void vnc_disconnect_finish(VncState *vs)
     buffer_free(&vs->ws_output);
 #endif /* CONFIG_VNC_WS */
 
-    qobject_decref(vs->info);
+    qapi_free_VncClientInfo(vs->info);
 
     vnc_zlib_clear(vs);
     vnc_tight_clear(vs);
@@ -2321,7 +2324,7 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
     vnc_flush(vs);
 
     vnc_client_cache_auth(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_INITIALIZED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_INITIALIZED);
 
     vnc_read_when(vs, protocol_client_msg, 1);
 
@@ -2844,7 +2847,7 @@ static void vnc_connect(VncDisplay *vd, int csock,
     }
 
     vnc_client_cache_addr(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_CONNECTED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);
     vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);
 
     vs->vd = vd;
diff --git a/ui/vnc.h b/ui/vnc.h
index 8da81b8..07af9f7 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -31,7 +31,6 @@
 #include "qemu/queue.h"
 #include "qemu/thread.h"
 #include "ui/console.h"
-#include "monitor/monitor.h"
 #include "audio/audio.h"
 #include "qemu/bitmap.h"
 #include <zlib.h>
@@ -40,6 +39,7 @@
 #include "keymaps.h"
 #include "vnc-palette.h"
 #include "vnc-enc-zrle.h"
+#include "qapi-types.h"
 
 // #define _VNC_DEBUG 1
 
@@ -292,7 +292,7 @@ struct VncState
     bool websocket;
 #endif /* CONFIG_VNC_WS */
 
-    QObject *info;
+    VncClientInfo *info;
 
     Buffer output;
     Buffer input;
-- 
1.9.3

  parent reply	other threads:[~2014-06-18  6:45 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18  6:43 [Qemu-devel] [PATCH 2.1 00/36] Pending monitor patches for 2.1 Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 01/36] os-posix: include sys/time.h Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 02/36] qapi: Add includes from qapi/ as dependencies Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 03/36] qapi: add event helper functions Paolo Bonzini
2014-06-18 22:55   ` Wenchao Xia
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 04/36] qapi script: add event support Paolo Bonzini
2014-06-19 12:06   ` Eric Blake
2014-06-19 19:57   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 05/36] test: add test cases for qapi event Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 06/36] qapi: adjust existing defines Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 07/36] monitor: add an implemention of qapi event emit method Paolo Bonzini
2014-06-19  4:03   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 08/36] qapi: add new schema file qapi-event.json Paolo Bonzini
2014-06-19  4:04   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 09/36] qapi event: convert SHUTDOWN Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 10/36] qapi event: convert POWERDOWN Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 11/36] qapi event: convert RESET Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 12/36] qapi event: convert STOP Paolo Bonzini
2014-06-19 18:15   ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 13/36] qapi event: convert RESUME Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 14/36] qapi event: convert SUSPEND Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 15/36] qapi event: convert SUSPEND_DISK Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 16/36] qapi event: convert WAKEUP Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 17/36] qapi event: convert RTC_CHANGE Paolo Bonzini
2014-06-19  4:06   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 18/36] qapi event: convert WATCHDOG Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 19/36] qapi event: convert DEVICE_DELETED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 20/36] qapi event: convert DEVICE_TRAY_MOVED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 21/36] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Paolo Bonzini
2014-06-26 15:37   ` Markus Armbruster
2014-06-26 15:40     ` Paolo Bonzini
2014-06-26 15:44       ` Luiz Capitulino
2014-06-26 15:58       ` Markus Armbruster
2014-06-26 16:00         ` Luiz Capitulino
2014-06-27 12:21         ` Markus Armbruster
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 22/36] qapi event: convert BLOCK_IMAGE_CORRUPTED Paolo Bonzini
2014-06-19  4:09   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 23/36] qapi event: convert other BLOCK_JOB events Paolo Bonzini
2014-06-19  4:11   ` Eric Blake
2014-06-26 14:08   ` Markus Armbruster
2014-06-26 14:19     ` Paolo Bonzini
2014-06-26 14:24       ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 24/36] qapi event: convert NIC_RX_FILTER_CHANGED Paolo Bonzini
2014-06-18  6:43 ` Paolo Bonzini [this message]
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 26/36] qapi event: convert SPICE events Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 27/36] qapi event: convert BALLOON_CHANGE Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 28/36] qapi event: convert GUEST_PANICKED Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 29/36] qapi event: convert QUORUM events Paolo Bonzini
2014-06-19  4:14   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 30/36] qapi event: clean up Paolo Bonzini
2014-06-19  4:17   ` Eric Blake
2014-06-19  8:00     ` Paolo Bonzini
2014-06-19 14:51       ` Luiz Capitulino
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 32/36] qemu-char: do not call chr_write directly Paolo Bonzini
2014-06-19 14:47   ` Eric Blake
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 33/36] qemu-char: move pty_chr_update_read_handler around Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 34/36] qemu-char: make writes thread-safe Paolo Bonzini
2014-06-25  6:06   ` Stefan Weil
2014-06-25  7:03     ` Paolo Bonzini
2014-06-18  6:43 ` [Qemu-devel] [PATCH 2.1 35/36] monitor: protect outbuf and mux_out with mutex Paolo Bonzini
2014-06-18  6:44 ` [Qemu-devel] [PATCH 2.1 36/36] monitor: protect event emission Paolo Bonzini
     [not found] ` <1403073840-32603-32-git-send-email-pbonzini@redhat.com>
2014-06-19 12:03   ` [Qemu-devel] [PATCH 2.1 31/36] qemu-char: introduce qemu_chr_alloc Eric Blake
2014-06-19 12:52     ` Paolo Bonzini
2014-06-19 18:40 ` [Qemu-devel] [PATCH 2.1 00/36] Pending monitor patches for 2.1 Luiz Capitulino
2014-06-20 15:44 ` Eric Blake
2014-06-20 23:34   ` Wenchao Xia
2014-06-26 15:50 ` Markus Armbruster
2014-06-26 15:56   ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403073840-32603-26-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wenchaoqemu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.