From nobody Sun Feb 8 19:24:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685705322; cv=none; d=zohomail.com; s=zohoarc; b=PM84zV/+BElz34Bi/tUWrkoeVk46pEYxZev58r3Zdl5C/9Go2HVFVaQRGD05dMFs+ngOeCbK8/R3bstTWpNeyzPe4GyAD7qF8UKy6j9HaxKHawvPvOKcow4xQda5INjCry2srQvNFkbOrmkJoSH0IX2pjCStpxelR2A9J1i+GI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685705322; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f6EiSBB1BBxGHmVfzhEL6kC2bIwQEIIiHN95z68D/pk=; b=OWn+FRVr2BYDS2yg046hWyaQPPGirCYDgPhJAmpk0ypSijKjlvaEKUAcpf3S02vN3945t6BIedfGjFB6C1Ntq4uT3bRL8Y1GUkJyKJZVf5b7C021e0PeTmpriLWpTlumGxXkoAiYhOg6o2ynDXjA1nEYwxpVbcsEzY1gpOe2ioI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1685705322856557.9151514399827; Fri, 2 Jun 2023 04:28:42 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-vpJzZt11Ns-iEMLXk6awoQ-1; Fri, 02 Jun 2023 07:28:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6117E3C11C9F; Fri, 2 Jun 2023 11:28:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E4B440D1B65; Fri, 2 Jun 2023 11:28:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D191519465B5; Fri, 2 Jun 2023 11:28:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D646219465B7 for ; Fri, 2 Jun 2023 11:28:31 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C91A29E71; Fri, 2 Jun 2023 11:28:31 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D8FE8162 for ; Fri, 2 Jun 2023 11:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685705321; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f6EiSBB1BBxGHmVfzhEL6kC2bIwQEIIiHN95z68D/pk=; b=JcQKWmpesuhfX272NwSg0u5eiDlkCAXF6IyvYv+fxkqYnFzHQOnrmM92laylgSPNAgEl3m Yvk/JqsSjC4otfkzIU618X7tMHyyN4K65E/dZcL3HGqctqRcJ503ULydniGgawG9IhGvxN dlxVh0/PfUQpLZKng+roMhOfQ98FyYg= X-MC-Unique: vpJzZt11Ns-iEMLXk6awoQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/15] util: xml: Introduce virXMLNodeGetSubelementList Date: Fri, 2 Jun 2023 13:28:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685705324108100005 Content-Type: text/plain; charset="utf-8" The new helper is similar to virXPathNodeSet list but for cases where we want to get subelements directly rather than using XPath. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virxml.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virxml.h | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 27b8e111aa..436d5a0770 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3709,6 +3709,7 @@ virXMLFormatMetadata; virXMLNewNode; virXMLNodeContentString; virXMLNodeGetSubelement; +virXMLNodeGetSubelementList; virXMLNodeNameEqual; virXMLNodeSanitizeNamespaces; virXMLNodeToString; diff --git a/src/util/virxml.c b/src/util/virxml.c index e04455fcaa..0dae15a039 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -899,6 +899,40 @@ virXMLNodeGetSubelement(xmlNodePtr node, } +/** + * virXMLNodeGetSubelementList: + * @node: node to get subelement of + * @name: name of subelement to fetch (NULL to fetch all sub-elements) + * @list: If non-NULL, filled with a list of pointers to the nodes. Caller= is + * responsible for freeeing the list but not the members. + * + * Find and return a sub-elements node of @node named @name in a list. + * Returns the number of subelements with @name + */ +size_t +virXMLNodeGetSubelementList(xmlNodePtr node, + const char *name, + xmlNodePtr **list) +{ + xmlNodePtr n; + size_t nelems =3D 0; + + for (n =3D node->children; n; n =3D n->next) { + if (n->type =3D=3D XML_ELEMENT_NODE) { + if (name && !virXMLNodeNameEqual(n, name)) + continue; + + if (list) + VIR_APPEND_ELEMENT_COPY(*list, nelems, n); + else + nelems++; + } + } + + return nelems; +} + + /** * virXPathNode: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index cca9f222ab..7af47437bd 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -77,6 +77,11 @@ xmlNodePtr virXMLNodeGetSubelement(xmlNodePtr node, const char *name); +size_t +virXMLNodeGetSubelementList(xmlNodePtr node, + const char *name, + xmlNodePtr **list); + xmlNodePtr virXPathNode(const char *xpath, xmlXPathContextPtr ctxt); --=20 2.40.1