From nobody Wed Oct 22 12:28:44 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=1759929293; cv=none; d=zohomail.com; s=zohoarc; b=Tk6iSMsgxWlzNTOecvj57KM3GQJkl5rIUv8wb7e7oXLBm5xGPyTJCXM2/g6DnCWL1336TK1qmpBkD2quKBo+Ad/Gf0/iHbRo6c1jBG3+f0rIVwIr3Pg81NjzvTdEIGLr3uS6n+0vMgiQnbc+xfidNDd2cBY9mEDcZjsZF9gu39M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759929293; 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=I/VU8Gy9jTXoxq1uqHTE6NY0jDzbX/9/fE7KwDOBG5A=; b=bFj4fz1T/Z9hSrPNj0EDX70UialG0P5PbGqVrdJ8U8fRAwpcb68cEBaLfHFkmJWMmx97PovvLB3bEB8zs9VzpFEVLfonMUR0RjVhQ+Uonv3wtdny2dxJa2s2Rc3NXaY0c79vgGE4VlQ2QlAal/0t9akyqS+TorYEfTjq8MShu1o= 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 175992929300789.47063018562403; Wed, 8 Oct 2025 06:14:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 5806444381; Wed, 8 Oct 2025 09:14:52 -0400 (EDT) Received: from [172.19.199.17] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id EA5F244264; Wed, 8 Oct 2025 09:10:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6CD7C44263; Wed, 8 Oct 2025 08:55:13 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 216F544329 for ; Wed, 8 Oct 2025 08:54:22 -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-689-Q0Ih7-wzPi-pM8yzAu-aBA-1; Wed, 08 Oct 2025 08:54:20 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [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 E20E21955F2B for ; Wed, 8 Oct 2025 12:54:19 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 38F4419560A2 for ; Wed, 8 Oct 2025 12:54:18 +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=1759928061; 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=I/VU8Gy9jTXoxq1uqHTE6NY0jDzbX/9/fE7KwDOBG5A=; b=fkvrFDXded0I+xkL6jk/DYYn7m+wBEwHpUUXLUqhy6bKUoRZas+R1/OQ2JVp5JgrKpBJWl w6nXiSXLqj3c5SEUQdZgOanOF7NyTGkLTh/ZjyI2WC5fCnHWMEpi/+I+AdE6T/r9xhyadW 9Q0Ji2RfO0h+blAbhavh5x/dc1Z+I/w= X-MC-Unique: Q0Ih7-wzPi-pM8yzAu-aBA-1 X-Mimecast-MFC-AGG-ID: Q0Ih7-wzPi-pM8yzAu-aBA_1759928060 To: devel@lists.libvirt.org Subject: [PATCH v2 12/29] virxml: Introduce virXPathTristateSwitch() Date: Wed, 8 Oct 2025 14:53:44 +0200 Message-ID: <8fb589c7bf62652e56b8a8afd8730bcfe1272cda.1759927755.git.mprivozn@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-MFC-PROC-ID: yS3YPB4TCmva5CTQ04YSp-zkrPa3am_GUggJeTRQ4Iw_1759928060 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: E3NK4FFSFVMHET6UL56FQXKVM3FVS5ZY X-Message-ID-Hash: E3NK4FFSFVMHET6UL56FQXKVM3FVS5ZY 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: 1759929294629154100 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 virTristateSwitch. 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 7986ad123c..0b692c038e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3827,6 +3827,7 @@ virXPathLongLong; virXPathNode; virXPathNodeSet; virXPathString; +virXPathTristateSwitch; virXPathUInt; virXPathUIntBase; virXPathULongLong; diff --git a/src/util/virxml.c b/src/util/virxml.c index bb80bb7444..60485c10fa 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -284,6 +284,40 @@ virXPathLongLong(const char *xpath, } =20 =20 +/** + * virXPathTristateSwitch: + * @xpath: the XPath string to evaluate + * @ctxt: an XPath context + * @value: the returned virTristateSwitch 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 virTristateSwitch value. + */ +int +virXPathTristateSwitch(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateSwitch *value) +{ + g_autoptr(xmlXPathObject) obj =3D NULL; + int rc; + + if (!(obj =3D virXPathEvalString(xpath, ctxt))) + return -1; + + rc =3D virTristateSwitchTypeFromString((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 7cc3f47913..dfec386494 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -73,6 +73,11 @@ virXPathLongLong(const char *xpath, xmlXPathContextPtr ctxt, long long *value); =20 +int +virXPathTristateSwitch(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateSwitch *value); + xmlNodePtr virXMLNodeGetSubelement(xmlNodePtr node, const char *name); --=20 2.49.1