From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAeVX-0005fO-Dk for qemu-devel@nongnu.org; Mon, 12 Jan 2015 07:54:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAeVP-0001TO-Ur for qemu-devel@nongnu.org; Mon, 12 Jan 2015 07:54:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAeVP-0001Ss-NQ for qemu-devel@nongnu.org; Mon, 12 Jan 2015 07:54:03 -0500 From: Gerd Hoffmann Date: Mon, 12 Jan 2015 13:53:55 +0100 Message-Id: <1421067237-6955-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1421067237-6955-1-git-send-email-kraxel@redhat.com> References: <1421067237-6955-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 08/10] vnc: factor out qmp_query_client_list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Anthony Liguori , Gerd Hoffmann so we can reuse it for the new vnc query command. Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 2ed16dc..d7c7865 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -385,6 +385,20 @@ static VncDisplay *vnc_display_find(const char *id) return NULL; } +static VncClientInfoList *qmp_query_client_list(VncDisplay *vd) +{ + VncClientInfoList *cinfo, *prev = NULL; + VncState *client; + + QTAILQ_FOREACH(client, &vd->clients, next) { + cinfo = g_new0(VncClientInfoList, 1); + cinfo->value = qmp_query_vnc_client(client); + cinfo->next = prev; + prev = cinfo; + } + return prev; +} + VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); @@ -393,30 +407,16 @@ VncInfo *qmp_query_vnc(Error **errp) if (vd == NULL || vd->display == NULL) { info->enabled = false; } else { - VncClientInfoList *cur_item = NULL; struct sockaddr_storage sa; socklen_t salen = sizeof(sa); char host[NI_MAXHOST]; char serv[NI_MAXSERV]; - VncState *client; info->enabled = true; /* for compatibility with the original command */ info->has_clients = true; - - QTAILQ_FOREACH(client, &vd->clients, next) { - VncClientInfoList *cinfo = g_malloc0(sizeof(*info)); - cinfo->value = qmp_query_vnc_client(client); - - /* XXX: waiting for the qapi to support GSList */ - if (!cur_item) { - info->clients = cur_item = cinfo; - } else { - cur_item->next = cinfo; - cur_item = cinfo; - } - } + info->clients = qmp_query_client_list(vd); if (vd->lsock == -1) { return info; -- 1.8.3.1