From nobody Mon Feb 9 09:16:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14866459607001006.4455728100329; Thu, 9 Feb 2017 05:12:40 -0800 (PST) Received: from localhost ([::1]:37826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cboWb-0001KR-E6 for importer@patchew.org; Thu, 09 Feb 2017 08:12:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cboLu-0008Sl-VI for qemu-devel@nongnu.org; Thu, 09 Feb 2017 08:01:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cboLu-00023E-19 for qemu-devel@nongnu.org; Thu, 09 Feb 2017 08:01:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36700) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cboLt-00022q-SD for qemu-devel@nongnu.org; Thu, 09 Feb 2017 08:01:33 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EECD38553E for ; Thu, 9 Feb 2017 13:01:33 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-117-196.ams2.redhat.com [10.36.117.196]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v19D1Um4027356; Thu, 9 Feb 2017 08:01:32 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 1056280FD5; Thu, 9 Feb 2017 14:01:20 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 9 Feb 2017 14:01:16 +0100 Message-Id: <1486645277-4724-10-git-send-email-kraxel@redhat.com> In-Reply-To: <1486645277-4724-1-git-send-email-kraxel@redhat.com> References: <1486645277-4724-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 09 Feb 2017 13:01:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/10] util: add iterators for QemuOpts values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" To iterate over all QemuOpts currently requires using a callback function which is inconvenient for control flow. Add support for using iterator functions more directly QemuOptsIter iter; QemuOpt *opt; qemu_opts_iter_init(&iter, opts, "repeated-key"); while ((opt =3D qemu_opts_iter_next(&iter)) !=3D NULL) { ....do something... } Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170203120649.15637-8-berrange@redhat.com Signed-off-by: Gerd Hoffmann --- include/qemu/option.h | 9 +++++++++ util/qemu-option.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 1f9e3f9..e786df0 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -100,6 +100,15 @@ typedef int (*qemu_opt_loopfunc)(void *opaque, int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, Error **errp); =20 +typedef struct { + QemuOpts *opts; + QemuOpt *opt; + const char *name; +} QemuOptsIter; + +void qemu_opt_iter_init(QemuOptsIter *iter, QemuOpts *opts, const char *na= me); +const char *qemu_opt_iter_next(QemuOptsIter *iter); + QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists, Error **errp); diff --git a/util/qemu-option.c b/util/qemu-option.c index 3467dc2..d611946 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -332,6 +332,25 @@ const char *qemu_opt_get(QemuOpts *opts, const char *n= ame) return opt ? opt->str : NULL; } =20 +void qemu_opt_iter_init(QemuOptsIter *iter, QemuOpts *opts, const char *na= me) +{ + iter->opts =3D opts; + iter->opt =3D QTAILQ_FIRST(&opts->head); + iter->name =3D name; +} + +const char *qemu_opt_iter_next(QemuOptsIter *iter) +{ + QemuOpt *ret =3D iter->opt; + if (iter->name) { + while (ret && !g_str_equal(iter->name, ret->name)) { + ret =3D QTAILQ_NEXT(ret, next); + } + } + iter->opt =3D ret ? QTAILQ_NEXT(ret, next) : NULL; + return ret ? ret->str : NULL; +} + /* Get a known option (or its default) and remove it from the list * all in one action. Return a malloced string of the option value. * Result must be freed by caller with g_free(). --=20 1.8.3.1