Patchwork [7/7] QMP: Introduce QMP connect event

login
register
mail settings
Submitter Luiz Capitulino
Date Jan. 8, 2010, 9:47 p.m.
Message ID <1262987236-2943-8-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/42541/
State New
Headers show

Comments

Luiz Capitulino - Jan. 8, 2010, 9:47 p.m.
It's emitted everytime a VNC client connects to QEMU,
client's information such as port and IP address is provided.

Note that if any kind of authentication is enabled, this
event is only emitted when the client successfully
authenticates.

For example:

{ "event": "VNC_CONNECT",
    "timestamp": { "seconds": 1262976601, "microseconds": 975795 },
    "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": "foo" } } }

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |    3 +++
 monitor.h |    1 +
 vnc.c     |    7 ++++++-
 3 files changed, 10 insertions(+), 1 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index 78fd33a..632a620 100644
--- a/monitor.c
+++ b/monitor.c
@@ -357,6 +357,9 @@  void monitor_protocol_event(MonitorEvent event, QObject *data)
         case QEVENT_STOP:
             event_name = "STOP";
             break;
+        case QEVENT_VNC_CONNECT:
+            event_name = "VNC_CONNECT";
+            break;
         case QEVENT_VNC_DISCONNECT:
             event_name = "VNC_DISCONNECT";
             break;
diff --git a/monitor.h b/monitor.h
index e836dd6..50067f6 100644
--- a/monitor.h
+++ b/monitor.h
@@ -20,6 +20,7 @@  typedef enum MonitorEvent {
     QEVENT_RESET,
     QEVENT_POWERDOWN,
     QEVENT_STOP,
+    QEVENT_VNC_CONNECT,
     QEVENT_VNC_DISCONNECT,
     QEVENT_MAX,
 } MonitorEvent;
diff --git a/vnc.c b/vnc.c
index f2f0ef3..aaba75d 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1088,7 +1088,11 @@  static void vnc_qmp_event(VncState *vs, MonitorEvent event)
 
     monitor_protocol_event(event, data);
 
-    qobject_decref(data); /* will also free 'vs->info' */
+    if (event == QEVENT_VNC_CONNECT) {
+        qobject_incref(vs->info);
+    }
+
+    qobject_decref(data); /* will also free 'vs->info' on disconnect */
 }
 
 static void vnc_disconnect_finish(VncState *vs)
@@ -2081,6 +2085,7 @@  static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
     int size;
 
     vnc_client_cache_info(vs);
+    vnc_qmp_event(vs, QEVENT_VNC_CONNECT);
 
     vnc_write_u16(vs, ds_get_width(vs->ds));
     vnc_write_u16(vs, ds_get_height(vs->ds));