From nobody Mon Feb 9 03:29:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1669990691; cv=none; d=zohomail.com; s=zohoarc; b=R8qbo23H/BmYyMi7r+zZ4cqLOty3mZV+43gaIPypAGVZhhryitZbAaJnt7Q1W4SgqwqWMqC+/WmS+zW8wJynJqHcgx9Fq2XE0UEuEtHrbBAdWP13+Aa+eCJd0rtJOEmoug8TNQQr1l8jFMPtOhn+Gs8B52SjrkwR2MbjE5mrELg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669990691; 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=FhZhkZwpRpnXwY6abi6ZuZnPI+vdZVx+sNRHZWdpTVc=; b=jK+KiJ4h0VhB4r8wl/rDjkotH7oGVYcg99aOcJdZAat9CBHJ532qr08otH2kkbFdWuLbWTsTuHbSSlPE3F714G8irGfngjjBeInEJowVyR8WVeA2t8FM3V/cPXY9b7uHpuEFIi+/O9fKpYWrgDQ4j0d1c2rGENoqVHFGIu2hMOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1669990691542429.1747347343179; Fri, 2 Dec 2022 06:18:11 -0800 (PST) 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-92-kuqWdUv3MG6YVo7RgGMzDQ-1; Fri, 02 Dec 2022 09:17:29 -0500 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 1D7D72A59568; Fri, 2 Dec 2022 14:17:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A77640E9785; Fri, 2 Dec 2022 14:17:27 +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 EE5E4194658F; Fri, 2 Dec 2022 14:17:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4BDC519465A0 for ; Fri, 2 Dec 2022 14:17:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3257F40E9785; Fri, 2 Dec 2022 14:17:20 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BAFF40E9787 for ; Fri, 2 Dec 2022 14:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669990690; 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=FhZhkZwpRpnXwY6abi6ZuZnPI+vdZVx+sNRHZWdpTVc=; b=hMg3OFeG0Hp9yNruxgdPC0I39joMMcajRCBzPDiKAo2+0WiLwC7YslPDxxhTuJyEmYA/Ty u5HRNAK0HarmE6kYA21Zt+eTXFYdAJ0Ric1P5MJwO467AgxGIwdgMa/dYoEYPFBRNI33rk IVQ1o39HFXfLhAJSlF1QeK/o4V0EiCI= X-MC-Unique: kuqWdUv3MG6YVo7RgGMzDQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/13] util: xml: Introduce virXMLNodeGetSubelement Date: Fri, 2 Dec 2022 15:16:56 +0100 Message-Id: <0ca37d33f0cbdba7496bdd0d2b92bac5f59dd836.1669990545.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1669990692853100001 Content-Type: text/plain; charset="utf-8" Introduce a simple helper fetching a sub-element node by name. This is meant as a simple replacement for either open-coded versions of this or use of XPath for this trivial lookup. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 23 +++++++++++++++++++++++ src/util/virxml.h | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ebd7bc61a8..209ec14544 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3671,6 +3671,7 @@ virXMLFormatElementInternal; virXMLFormatMetadata; virXMLNewNode; virXMLNodeContentString; +virXMLNodeGetSubelement; virXMLNodeNameEqual; virXMLNodeSanitizeNamespaces; virXMLNodeToString; diff --git a/src/util/virxml.c b/src/util/virxml.c index 870ba194b0..7d9d4bb234 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -849,6 +849,29 @@ virXPathBoolean(const char *xpath, } +/** + * virXMLNodeGetSubelement: + * @node: node to get subelement of + * @name: name of subelement to fetch + * + * Find and return a sub-element node of @node named @name. + */ +xmlNodePtr +virXMLNodeGetSubelement(xmlNodePtr node, + const char *name) +{ + xmlNodePtr n; + + for (n =3D node->children; n; n =3D n->next) { + if (n->type =3D=3D XML_ELEMENT_NODE && + virXMLNodeNameEqual(n, name)) + return n; + } + + return NULL; +} + + /** * virXPathNode: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index f19cbe59ae..d5b998263c 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -72,6 +72,11 @@ int virXPathLongLong(const char *xpath, xmlXPathContextPtr ctxt, long long *value); + +xmlNodePtr +virXMLNodeGetSubelement(xmlNodePtr node, + const char *name); + xmlNodePtr virXPathNode(const char *xpath, xmlXPathContextPtr ctxt); --=20 2.38.1