From nobody Tue Oct 28 17:55:02 2025 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1759756820; cv=none; d=zohomail.com; s=zohoarc; b=eNxbSQCl7HViODX7ZiHnSL0eeADyS40uzZ7vOP3/0xUg4OelKhVto81/AYoIl0MnhOjzpLOXQwriea9lOjcXEe5ZGj9iCOToWcWoWJr3qFRBt6xwkP8xpzh8dwO+9TSx7FsgAv9iqLFTcFzQYvmUIL6xZt1QLwcV7TdfitpTGdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759756820; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=3FGZm3NRPHBfcNn2mKN8htYAXBJ3bKRMl0jReoUu4gk=; b=OwaoPLbjtJDHI7Pr8xYjdLxoOPTIX5zLscO5oqdP9YrY3KB2bAVNyQYIJeSoPC1AlUlBxNxAwwEiv46QxS9Y9bGgrpBjhNm8eLdZvXo1V5GJATaGMExJ2/BwqaXlruvSK2rBakPG/mA/n6Z5a4/g8Mrlqj9HgOKj6B6Z4LFxJWc= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1759756820874835.534225764594; Mon, 6 Oct 2025 06:20:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B8789443ED; Mon, 6 Oct 2025 09:18:16 -0400 (EDT) Received: from [172.19.199.17] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 07BB84412B; Mon, 6 Oct 2025 09:16:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 9A13241C7E; Mon, 6 Oct 2025 09:15:04 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 51E4941C7F for ; Mon, 6 Oct 2025 09:15:02 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-sALM9Nl8MyCEgyxw07xZYg-1; Mon, 06 Oct 2025 09:15:00 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08B731800343 for ; Mon, 6 Oct 2025 13:14:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 532D830002CC for ; Mon, 6 Oct 2025 13:14:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759756502; 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=3FGZm3NRPHBfcNn2mKN8htYAXBJ3bKRMl0jReoUu4gk=; b=IPa/xAxCm/51nHeDVyFTFVT8GNOxjWJAKY5z95JM5Anm9QIjJM7jrMGW8XlNq/O8HJG9wT FTSS6HFhgFDmY8brgdj5Nw9W7S9DN/0PLNZFHrdTMZJB/qFodDKH3Bz+oJamsdxUxooaR6 +NKYgrINyDLC6CEwBJLtf1PGujmduTI= X-MC-Unique: sALM9Nl8MyCEgyxw07xZYg-1 X-Mimecast-MFC-AGG-ID: sALM9Nl8MyCEgyxw07xZYg_1759756499 To: devel@lists.libvirt.org Subject: [PATCH 02/20] virxml: Introduce virXPathTristateBool() Date: Mon, 6 Oct 2025 15:14:33 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Cdi8wfCHRX9VS_rKAg9hDZjjZuNeILS3iU3Sb321yCM_1759756499 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LEU5VRM5C5R2SRNBAQRU2O6MRTOR3RK7 X-Message-ID-Hash: LEU5VRM5C5R2SRNBAQRU2O6MRTOR3RK7 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1759756823887116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Similarly to other virXPath* functions, let's have a helper that evaluates an XPath and stores the value into virTristateBool. Signed-off-by: Michal Privoznik --- 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 db909e4b28..e2457a1569 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3826,6 +3826,7 @@ virXPathLongLong; virXPathNode; virXPathNodeSet; virXPathString; +virXPathTristateBool; virXPathTristateSwitch; virXPathUInt; virXPathUIntBase; diff --git a/src/util/virxml.c b/src/util/virxml.c index 60485c10fa..44f11accf3 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -318,6 +318,40 @@ virXPathTristateSwitch(const char *xpath, } =20 =20 +/** + * virXPathTristateBool: + * @xpath: the XPath string to evaluate + * @ctxt: an XPath context + * @value: the returned virTristateBool value + * + * Convenience function to evaluate an XPath tristate value. The @xpath + * expression must ensure that the evaluated value is returned as a + * string (use the 'string()' conversion in the expression). + * + * Returns 0 in case of success in which case @value is set, + * or -1 if the XPath evaluation failed or -2 if the + * value isn't of a virTristateBool value. + */ +int +virXPathTristateBool(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateBool *value) +{ + g_autoptr(xmlXPathObject) obj =3D NULL; + int rc; + + if (!(obj =3D virXPathEvalString(xpath, ctxt))) + return -1; + + rc =3D virTristateBoolTypeFromString((char *)obj->stringval); + if (rc < 0) + return -2; + + *value =3D rc; + return 0; +} + + /** * virXMLCheckIllegalChars: * @nodeName: Name of checked node diff --git a/src/util/virxml.h b/src/util/virxml.h index dfec386494..82218c0539 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -78,6 +78,11 @@ virXPathTristateSwitch(const char *xpath, xmlXPathContextPtr ctxt, virTristateSwitch *value); =20 +int +virXPathTristateBool(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateBool *value); + xmlNodePtr virXMLNodeGetSubelement(xmlNodePtr node, const char *name); --=20 2.49.1