From nobody Sat Feb 7 04:36:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1727703079555519.0253124887761; Mon, 30 Sep 2024 06:31:19 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 539CE1539; Mon, 30 Sep 2024 09:31:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 34F701449; Mon, 30 Sep 2024 09:29:56 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 06E711351; Mon, 30 Sep 2024 09:29:50 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id AEA73138B for ; Mon, 30 Sep 2024 09:29:44 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-OOemoBndOyq8n4HPLL209Q-1; Mon, 30 Sep 2024 09:29:43 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8164C1902FF0 for ; Mon, 30 Sep 2024 13:29:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C2B8319541A0 for ; Mon, 30 Sep 2024 13:29:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727702984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PRj1P3xCv0sR2zh5GrTV/j88L751Eut/CE7PCb5pypY=; b=MWixYU9twXQlVOUlJFbIquooSArIuv2wxd2rT62cLsy7/Qvjs7fqyzE7imYVjZxcl5iAPD S4ZAGhghfRA8jAruisP9vPfGi5F08RUZ1knn4eX1NbM+x+ZHi0u+0tUprA7ADQlv5wk8ct lxrWpprsDCj26Y+P2Xk1MYinZfAaAQk= X-MC-Unique: OOemoBndOyq8n4HPLL209Q-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 04/13] virTypedParamsFilter: Introduce option to filter also by type Date: Mon, 30 Sep 2024 15:29:26 +0200 Message-ID: <21f59b57965bac313d55e7e498f247fd5920dbac.1727702835.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IJXCOSDKZ2HGPK66UZ76DW6T4LGNIJ7T X-Message-ID-Hash: IJXCOSDKZ2HGPK66UZ76DW6T4LGNIJ7T X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1727703080939116600 Content-Type: text/plain; charset="utf-8" The only caller of this function is doing some additional filtering so it's useful if the filtering function was able to do so internally. Introduce a 'type' parameter which will optionally filter the results by type and extend the testsuite to cover this scenario. Signed-off-by: Peter Krempa --- src/util/virtypedparam.c | 19 +++++++++++++------ src/util/virtypedparam.h | 1 + tests/virtypedparamtest.c | 14 +++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 86fbaf5e9d..a080d7ba0f 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -391,10 +391,12 @@ virTypedParamsCopy(virTypedParameterPtr *dst, * @params: array of typed parameters * @nparams: number of parameters in the @params array * @name: name of the parameter to find + * @type: type of fields to filter (ignored if 0 is passed) * @ret: pointer to the returned array * * Filters @params retaining only the parameters named @name in the - * resulting array @ret. + * resulting array @ret. If @type is non-zero it also filters out paramete= rs + * whose type doesn't match @type. * * Important Caller should free the @ret array but not the items since the= y are * pointing to the @params elements. I.e. callers must not use @@ -406,6 +408,7 @@ size_t virTypedParamsFilter(virTypedParameterPtr params, int nparams, const char *name, + int type, virTypedParameterPtr **ret) { size_t i; @@ -414,10 +417,14 @@ virTypedParamsFilter(virTypedParameterPtr params, *ret =3D g_new0(virTypedParameterPtr, nparams); for (i =3D 0; i < nparams; i++) { - if (STREQ(params[i].field, name)) { - (*ret)[n] =3D ¶ms[i]; - n++; - } + if (STRNEQ(params[i].field, name)) + continue; + + if (type !=3D 0 && + params[i].type !=3D type) + continue; + + (*ret)[n++] =3D ¶ms[i]; } return n; @@ -453,7 +460,7 @@ virTypedParamsGetStringList(virTypedParameterPtr params, *values =3D NULL; - nfiltered =3D virTypedParamsFilter(params, nparams, name, &filtered); + nfiltered =3D virTypedParamsFilter(params, nparams, name, 0, &filtered= ); if (nfiltered =3D=3D 0) return 0; diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index afd923aacb..774744244a 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -85,6 +85,7 @@ size_t virTypedParamsFilter(virTypedParameterPtr params, int nparams, const char *name, + int type, virTypedParameterPtr **ret) G_GNUC_WARN_UNUSED_RESULT; diff --git a/tests/virtypedparamtest.c b/tests/virtypedparamtest.c index 5ced453be5..1a8b49383f 100644 --- a/tests/virtypedparamtest.c +++ b/tests/virtypedparamtest.c @@ -91,13 +91,14 @@ testTypedParamsFilter(const void *opaque G_GNUC_UNUSED) { .field =3D "bar", .type =3D VIR_TYPED_PARAM_UINT }, { .field =3D "foo", .type =3D VIR_TYPED_PARAM_INT }, { .field =3D "foobar", .type =3D VIR_TYPED_PARAM_STRING }, - { .field =3D "foo", .type =3D VIR_TYPED_PARAM_INT } + { .field =3D "foo", .type =3D VIR_TYPED_PARAM_INT }, + { .field =3D "foobar", .type =3D VIR_TYPED_PARAM_INT }, }; virTypedParameterPtr *filtered =3D NULL; nfiltered =3D virTypedParamsFilter(params, G_N_ELEMENTS(params), - "foo", &filtered); + "foo", 0, &filtered); if (nfiltered !=3D 3) goto cleanup; @@ -108,7 +109,7 @@ testTypedParamsFilter(const void *opaque G_GNUC_UNUSED) VIR_FREE(filtered); nfiltered =3D virTypedParamsFilter(params, G_N_ELEMENTS(params), - "bar", &filtered); + "bar", VIR_TYPED_PARAM_UINT, &filtere= d); if (nfiltered !=3D 2) goto cleanup; @@ -117,6 +118,13 @@ testTypedParamsFilter(const void *opaque G_GNUC_UNUSED) if (filtered[i] !=3D ¶ms[i * 2]) goto cleanup; } + VIR_FREE(filtered); + + nfiltered =3D virTypedParamsFilter(params, G_N_ELEMENTS(params), + "foobar", VIR_TYPED_PARAM_STRING, &fi= ltered); + + if (nfiltered !=3D 1) + goto cleanup; rv =3D 0; cleanup: --=20 2.46.0