qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: libvir-list@redhat.com, Anthony Liguori <aliguori@us.ibm.com>,
	Jan Kiszka <jan.kiszka@web.de>,
	Hollis Blanchard <hollisb@us.ibm.com>
Subject: [Qemu-devel] [PATCH 6/6] Implement vnc-event notifications (v2)
Date: Wed,  8 Apr 2009 13:35:02 -0500	[thread overview]
Message-ID: <1239215702-23818-6-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1239215702-23818-5-git-send-email-aliguori@us.ibm.com>

This patch adds notification whenever a client connects or disconnects via VNC.
I'd like to add a lot more events especially ones that are auth related but this
is at least a start.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/vnc.c b/vnc.c
index 6d93215..abe6bdf 100644
--- a/vnc.c
+++ b/vnc.c
@@ -29,6 +29,7 @@
 #include "qemu_socket.h"
 #include "qemu-timer.h"
 #include "acl.h"
+#include "wait.h"
 
 #define VNC_REFRESH_INTERVAL (1000 / 30)
 
@@ -872,6 +873,15 @@ static void audio_del(VncState *vs)
     }
 }
 
+static void vnc_send_connect_event(VncState *vs)
+{
+    qemu_notify_event("vnc-event", "connect", vs->peer_address);
+}
+
+static void vnc_send_disconnect_event(VncState *vs)
+{
+    qemu_notify_event("vnc-event", "disconnect", vs->peer_address);
+}
 
 int vnc_client_io_error(VncState *vs, int ret, int last_errno)
 {
@@ -889,6 +899,8 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno)
             }
         }
 
+        vnc_send_disconnect_event(vs);
+        qemu_free(vs->peer_address);
         VNC_DEBUG("Closing down client sock %d %d\n", ret, ret < 0 ? last_errno : 0);
         qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL);
         closesocket(vs->csock);
@@ -2008,6 +2020,9 @@ static void vnc_connect(VncDisplay *vd, int csock)
 
     vs->next = vd->clients;
     vd->clients = vs;
+
+    vs->peer_address = vnc_socket_remote_addr("client-address=%s:%s", vs->csock);
+    vnc_send_connect_event(vs);
 }
 
 static void vnc_listen_read(void *opaque)
@@ -2055,7 +2070,6 @@ void vnc_display_init(DisplayState *ds)
     register_displaychangelistener(ds, dcl);
 }
 
-
 void vnc_display_close(DisplayState *ds)
 {
     VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
diff --git a/vnc.h b/vnc.h
index 3ae95f3..745d655 100644
--- a/vnc.h
+++ b/vnc.h
@@ -161,6 +161,8 @@ struct VncState
     Buffer zlib_tmp;
     z_stream zlib_stream[4];
 
+    char *peer_address;
+
     VncState *next;
 };
 
diff --git a/wait-events.c b/wait-events.c
index ecd26d2..8a2af85 100644
--- a/wait-events.c
+++ b/wait-events.c
@@ -45,10 +45,24 @@ static const EventDesc vm_state_events[] = {
     { 0 },
 };
 
+static const EventDesc vnc_events[] = {
+    { "connect", "a client has connected",
+      "This event occurs whenever a client connects to the builtin VNC server.",
+      "address=host:service", },
+    { "disconnect", "a client has disconnected",
+      "This event occurs whenever a client disconnects to the builtin VNC server.",
+      "client-address=host:service", },
+    { 0 },
+};
+
 static const EventClassDesc vm_event_classes[] = {
     { "vm-state", "the VM start/stop state has changed",
       "These events occur whenever a VM's state changes.",
       vm_state_events, },
+    { "vnc-event", "events from the builtin VNC server",
+      "These events are generated by the builtin VNC server.  They include\n"
+      "connection information, authentication information, etc.",
+      vnc_events, },
     { 0 },
 };
 
diff --git a/wait.c b/wait.c
index a976a72..33fb702 100644
--- a/wait.c
+++ b/wait.c
@@ -114,7 +114,7 @@ static int event_in_mask(PendingWaiter *w, WaitEvent *e)
 {
     int ret;
 
-    if (e->class == NULL)
+    if (w->mask == NULL)
         ret = 1;
     else
         ret = find_string(w->mask, e->class);
@@ -128,20 +128,18 @@ static int event_in_mask(PendingWaiter *w, WaitEvent *e)
 static int try_to_process_events(void)
 {
     int processed_events = 0;
+    WaitEvent *e, *ne;
 
-    while (!TAILQ_EMPTY(&pending_events) && !TAILQ_EMPTY(&pending_waiters)) {
-        WaitEvent *e;
+    TAILQ_FOREACH_SAFE(e, &pending_events, node, ne) {
         PendingWaiter *w;
 
-        e = TAILQ_FIRST(&pending_events);
-        TAILQ_REMOVE(&pending_events, e, node);
-
         TAILQ_FOREACH(w, &pending_waiters, node) {
             if (event_in_mask(w, e))
                 break;
         }
 
         if (w) {
+            TAILQ_REMOVE(&pending_events, e, node);
             TAILQ_REMOVE(&pending_waiters, w, node);
 
             dispatch_event(w, e);

  reply	other threads:[~2009-04-08 18:35 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-08 18:34 [Qemu-devel] [PATCH 1/6] Allow multiple monitor devices (v2) Anthony Liguori
2009-04-08 18:34 ` [Qemu-devel] [PATCH 2/6] Introduce monitor 'wait' command (v2) Anthony Liguori
2009-04-08 18:34   ` [Qemu-devel] [PATCH 3/6] Introduce wait filtering (v2) Anthony Liguori
2009-04-08 18:35     ` [Qemu-devel] [PATCH 4/6] Document new events (v2) Anthony Liguori
2009-04-08 18:35       ` [Qemu-devel] [PATCH 5/6] Implement vm-state notifications (v2) Anthony Liguori
2009-04-08 18:35         ` Anthony Liguori [this message]
2009-04-08 18:43   ` [Qemu-devel] Re: [PATCH 2/6] Introduce monitor 'wait' command (v2) Anthony Liguori
2009-04-08 19:01   ` [Qemu-devel] " Blue Swirl
2009-04-08 19:02     ` Anthony Liguori
2009-04-09 11:01   ` Avi Kivity
2009-04-09 13:40     ` Anthony Liguori
2009-04-09 13:58       ` Avi Kivity
2009-04-09 14:19         ` Jan Kiszka
2009-04-09  8:19 ` [Qemu-devel] [PATCH 1/6] Allow multiple monitor devices (v2) Avi Kivity
2009-04-09 13:28   ` Anthony Liguori
2009-04-09 13:40     ` Avi Kivity
2009-04-09 13:47       ` Anthony Liguori
2009-04-09 14:03         ` Avi Kivity
2009-04-09 14:13           ` Anthony Liguori
2009-04-09 14:28             ` Avi Kivity
2009-04-09 14:30               ` Anthony Liguori
2009-04-09 14:37                 ` Avi Kivity
2009-04-09 14:57                   ` Anthony Liguori
2009-04-09 15:11                     ` Avi Kivity
2009-04-09 15:40                       ` Anthony Liguori
2009-04-09 15:57                         ` Avi Kivity
2009-04-09 16:09                           ` Anthony Liguori
2009-04-09 16:30                             ` Avi Kivity
2009-04-09 16:42                               ` Anthony Liguori
2009-04-09 17:00                                 ` Avi Kivity
2009-04-09 17:40                                   ` Anthony Liguori
2009-04-11 16:25                                     ` Avi Kivity
2009-04-11 20:18                                       ` Anthony Liguori
2009-04-11 21:14                                         ` Avi Kivity
2009-04-12 18:42                                           ` Jamie Lokier
2009-04-14  8:30                                             ` [libvirt] " Daniel P. Berrange
2009-04-14  9:15                                               ` Avi Kivity
2009-04-14  9:17                                                 ` Daniel P. Berrange
2009-04-14  9:29                                                   ` Jan Kiszka
2009-04-14  9:36                                                     ` Avi Kivity
2009-04-14  9:38                                                   ` Avi Kivity
2009-04-14 18:21                                                     ` Jamie Lokier
2009-04-14 18:19                                                 ` Jamie Lokier
2009-04-16  9:03                                                   ` Avi Kivity
2009-04-11 23:16                                       ` Zachary Amsden
2009-04-12  8:23                                         ` Zachary Amsden
2009-04-14  8:28                                           ` Gerd Hoffmann
2009-04-14 18:20                                             ` Jamie Lokier
2009-04-11 19:11                                 ` Avi Kivity
2009-04-11 21:47                                   ` Andreas Färber
2009-04-12 18:44                                     ` Jamie Lokier
2009-04-09 16:01                       ` Jamie Lokier
2009-04-09 14:15           ` [libvirt] " Gerd Hoffmann
2009-04-09 14:19             ` Avi Kivity
2009-04-09 14:56               ` Jan Kiszka
2009-04-09 15:15                 ` François Revol
2009-04-09 15:15                 ` Avi Kivity
2009-04-09 15:49                   ` Jan Kiszka
2009-04-09 16:01                     ` Avi Kivity
2009-04-09 16:07                   ` Jamie Lokier
2009-05-11 20:54 ` Hollis Blanchard
2009-05-11 21:51   ` Anthony Liguori
2009-05-12  8:48     ` Avi Kivity

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=1239215702-23818-6-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=hollisb@us.ibm.com \
    --cc=jan.kiszka@web.de \
    --cc=libvir-list@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).