From patchwork Thu Jan 14 16:50:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 42912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 09F60B7CCD for ; Fri, 15 Jan 2010 04:05:35 +1100 (EST) Received: from localhost ([127.0.0.1]:54482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVT8V-0004tL-Qd for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2010 12:05:31 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NVSve-0007IE-F7 for qemu-devel@nongnu.org; Thu, 14 Jan 2010 11:52:14 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NVSvX-0007Db-K6 for qemu-devel@nongnu.org; Thu, 14 Jan 2010 11:52:12 -0500 Received: from [199.232.76.173] (port=44457 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVSvX-0007DD-6r for qemu-devel@nongnu.org; Thu, 14 Jan 2010 11:52:07 -0500 Received: from mx20.gnu.org ([199.232.41.8]:23756) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NVSvW-0002E2-RC for qemu-devel@nongnu.org; Thu, 14 Jan 2010 11:52:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NVSvV-000706-Tv for qemu-devel@nongnu.org; Thu, 14 Jan 2010 11:52:06 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0EGq4tU002910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Jan 2010 11:52:05 -0500 Received: from localhost (vpn-10-170.rdu.redhat.com [10.11.10.170]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0EGq3km007321; Thu, 14 Jan 2010 11:52:04 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 14 Jan 2010 14:50:56 -0200 Message-Id: <1263487859-6318-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1263487859-6318-1-git-send-email-lcapitulino@redhat.com> References: <1263487859-6318-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by mx20.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: armbru@redhat.com Subject: [Qemu-devel] [PATCH 5/8] VNC: Cache client info at connection time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When a disconnection happens the client's socket on QEMU side may become invalid, this way it won't be possible to query it to get client information, which is going to be needed by the future QMP VNC_DISCONNECTED event. To always have this information available we query the socket at connection time and cache the client info in struct VncState. Two function are introduced to perform this job. vnc_client_cache_addr() is called right when the connection is made, however the authentication information is not available at that moment so vnc_client_cache_auth() is called from protocol_client_init() to get auth info. Signed-off-by: Luiz Capitulino --- vnc.c | 40 ++++++++++++++++++++++++++++++---------- vnc.h | 2 ++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/vnc.c b/vnc.c index e023824..d37fa60 100644 --- a/vnc.c +++ b/vnc.c @@ -230,16 +230,16 @@ static int vnc_server_info_put(QDict *qdict) return 0; } -static QDict *do_info_vnc_client(Monitor *mon, VncState *client) +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) { @@ -253,8 +253,20 @@ static QDict *do_info_vnc_client(Monitor *mon, VncState *client) qstring_from_str(client->sasl.username)); } #endif +} - return qdict; +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; + } + + client->info = QOBJECT(qdict); } static void info_vnc_iter(QObject *obj, void *opaque) @@ -339,16 +351,17 @@ void do_info_vnc(Monitor *mon, QObject **ret_data) if (vnc_display == NULL || vnc_display->display == NULL) { *ret_data = qobject_from_jsonf("{ 'enabled': false }"); } else { - QDict *qdict; QList *clist; 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); + if (client->info) { + /* incref so that it's not freed by upper layers */ + qobject_incref(client->info); + qlist_append_obj(clist, client->info); + } client = client->next; } } @@ -1079,6 +1092,9 @@ static void vnc_disconnect_finish(VncState *vs) 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 */ @@ -2069,6 +2085,8 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) vnc_write(vs, buf, size); vnc_flush(vs); + vnc_client_cache_auth(vs); + vnc_read_when(vs, protocol_client_msg, 1); return 0; @@ -2377,6 +2395,8 @@ static void vnc_connect(VncDisplay *vd, int csock) socket_set_nonblock(vs->csock); qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); + vnc_client_cache_addr(vs); + vs->vd = vd; vs->ds = vd->ds; vs->last_x = -1; diff --git a/vnc.h b/vnc.h index fcc6824..1210824 100644 --- a/vnc.h +++ b/vnc.h @@ -144,6 +144,8 @@ struct VncState VncStateSASL sasl; #endif + QObject *info; + Buffer output; Buffer input; /* current output mode information */