From nobody Mon Feb 9 12:24:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618566133; cv=none; d=zohomail.com; s=zohoarc; b=jSft3/zuVq5IXY19kpmT+FH49e7PBiP1ve4dHFIkUeejDr7Da+Nb7lncOOoUsFct4OQksFNTruvt8hK6LjMRA/PSDuZfnj9A367zo4FGFcTtCT7pV/PuW6mJz1XlhIu0HmtJvv3ogdX1NNfvMhBKV8OT+joYpzy2Zaw/01BPRcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566133; h=Content-Type:Content-Transfer-Encoding:Cc: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=0M5PW0+oLNWAuJJrf3AIECyu43k4fK9tv1n4IncjLD4=; b=IBx7dJ1mZ+GIDkH7X0ESy0xeEcHZFGKX1Y+dCSE25qFgRxAhVYJam2AJofSH+1zFy76Bcv2Y2GfNArl9CvwvAb83THeGI97n5I77xRXK+n7mlXzgBAnsh8Z5Azo9rr3k7ePrrPvlDLyw+Cqkhva3pe9983m9FWM0XiqfbY6Z3yM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618566133879652.6507776473803; Fri, 16 Apr 2021 02:42:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-woAODv-vMbO4_jTJwjNE3Q-1; Fri, 16 Apr 2021 05:42:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB175107ACE4; Fri, 16 Apr 2021 09:42:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76B265C8AA; Fri, 16 Apr 2021 09:42:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AC8B24E58D; Fri, 16 Apr 2021 09:42:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13G9fwCm006166 for ; Fri, 16 Apr 2021 05:41:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id A43DF6A04C; Fri, 16 Apr 2021 09:41:58 +0000 (UTC) Received: from work.redhat.com (ovpn-113-12.ams2.redhat.com [10.36.113.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4E8A6A046; Fri, 16 Apr 2021 09:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566132; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=0M5PW0+oLNWAuJJrf3AIECyu43k4fK9tv1n4IncjLD4=; b=LAH5v4j6I564tYiMZZdQq4r8NpBt/jLl7Qw26uGgXzVVa518VtF6fW/fLkKSRyiwVuwx+l 0x8CmyxdGqa8f6SJfjz5FCaq+O0gykm48YIlky+qLMgSaG9mK8vKNBF44n1hArgFddEXxH Ht4CqeWZ+5STgaV8Yv+FRDLifxLaM/0= X-MC-Unique: woAODv-vMbO4_jTJwjNE3Q-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 1/8] virxml: Add virXMLPropTristateBool Date: Fri, 16 Apr 2021 11:41:45 +0200 Message-Id: <20210416094152.202334-2-twiederh@redhat.com> In-Reply-To: <20210416094152.202334-1-twiederh@redhat.com> References: <20210416094152.202334-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Peter Krempa , Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Convenience function to return the value of a yes / no XML attribute. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 12 +++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a727537c76..331cbb57d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3550,6 +3550,7 @@ virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; +virXMLPropTristateBool; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 117f50f2bf..6b197e0fff 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -558,6 +558,50 @@ virXMLNodeContentString(xmlNodePtr node) } =20 =20 +/** + * virXMLPropTristateBool: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * + * Convenience function to return value of a yes / no attribute. + * + * Returns 1 in case of success in which case @result is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropTristateBool(xmlNodePtr node, + const char* name, + virXMLPropFlags flags, + virTristateBool *result) +{ + g_autofree char *tmp =3D NULL; + int val; + + if (!(tmp =3D virXMLPropString(node, name))) { + if (!(flags & VIR_XML_PROP_REQUIRED)) + return 0; + + virReportError(VIR_ERR_XML_ERROR, + _("Missing required attribute '%s' in element '%s'"= ), + name, node->name); + return -1; + } + + if ((val =3D virTristateBoolTypeFromString(tmp)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected 'yes' or 'no'"), + name, node->name, tmp); + return -1; + } + + *result =3D val; + return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index de171dce12..bd246153f5 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -28,10 +28,16 @@ #include =20 #include "virbuffer.h" +#include "virenum.h" =20 xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) G_GNUC_WARN_UNUSED_RESULT; =20 +typedef enum { + VIR_XML_PROP_OPTIONAL =3D 0, /* Attribute may be absent */ + VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be absent */ +} virXMLPropFlags; + int virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt); char * virXPathString(const char *xpath, @@ -78,6 +84,12 @@ char * virXMLPropStringLimit(xmlNodePtr node, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); =20 +int virXMLPropTristateBool(xmlNodePtr node, + const char *name, + virXMLPropFlags flags, + virTristateBool *result) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, const char *filename, --=20 2.26.2