From nobody Mon Feb 9 17:35:15 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=1617872353; cv=none; d=zohomail.com; s=zohoarc; b=Dq6lKJhRzuwY9BFJjucbVOIAOrdWxeuQ6AO1MqlywbvgbKys1qd2w/sB+umAVeVrMeHgNMMd5Rtb91Wm1oi9xD/d99syBFat574gZQqKa6+/9SQfLeB0+jMkr4vfbmSswLPjzQtrfGyjU93H5Yd+WKgiRuSXafP0l9dcQbrEK58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872353; 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=1/JFJ906uM7X9KzyXzA1Vi3SJOU6inSMwh/AbkBgDKA=; b=Ok/tPSeYtPXwosDej0fpNmCqWIMzFrcj/zuX5ppkT4aZ/erEmDAjJl9IpQEZKxe4SdtYsMYzoixuh5i/Ha+kC1GVstR2XkGg5bI4UWqmzZvnZpW2PLc7VfOAhDDMW+G3MCyBSZd+2Rmyx4I/jPpfa0KEdZOtYKKSWTnMJTkQAcc= 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) header.from= 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 1617872353191903.2829609321382; Thu, 8 Apr 2021 01:59: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-350-7o5iFTC3OoSlvZ1NJDH08A-1; Thu, 08 Apr 2021 04:59:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FBA9800D53; Thu, 8 Apr 2021 08:59:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7643A5D9DC; Thu, 8 Apr 2021 08:59:05 +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 353C31806D06; Thu, 8 Apr 2021 08:59:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1388vH4O013660 for ; Thu, 8 Apr 2021 04:57:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 916385D9DC; Thu, 8 Apr 2021 08:57:17 +0000 (UTC) Received: from work.redhat.com (ovpn-112-196.ams2.redhat.com [10.36.112.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id D15C75D9CC; Thu, 8 Apr 2021 08:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872352; 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=1/JFJ906uM7X9KzyXzA1Vi3SJOU6inSMwh/AbkBgDKA=; b=K6i5L7M5f9yOa2/E9ZgI9lqBYqhWhNtZHyOADiKzE5Aso/LxgEj6FApziUV2JNk4GPIo6t 3gFFsy1mtTLtIT84vIT8QlKwyyCTqKY4/nGY7+7UD9ME3Ur8zshQAvzdkW1l3vaHrlP6jj Ef/rEE1x865N04R0cyuWgjU3Qx4IHco= X-MC-Unique: 7o5iFTC3OoSlvZ1NJDH08A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 1/8] virxml: Add virXMLPropTristateBool Date: Thu, 8 Apr 2021 10:57:03 +0200 Message-Id: <20210408085710.19379-2-twiederh@redhat.com> In-Reply-To: <20210408085710.19379-1-twiederh@redhat.com> References: <20210408085710.19379-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: 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.14 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 --- src/libvirt_private.syms | 1 + src/util/virxml.c | 49 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 10 ++++++++ 3 files changed, 60 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cb9fe7c80a..1aac0de1ae 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3546,6 +3546,7 @@ virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; +virXMLPropTristateBool; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 4a6fe09468..0b822d7c4d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -558,6 +558,55 @@ 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 (!node || !name || !result) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid argument to %s"), + __FUNCTION__); + return -1; + } + + if (!(tmp =3D virXMLPropString(node, name))) { + if ((flags & VIR_XML_PROP_REQUIRED) !=3D 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 d32f77b867..53de416a7f 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 abse= nt */ +} virXMLPropFlags; + int virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt); char * virXPathString(const char *xpath, @@ -77,6 +83,10 @@ char * virXMLPropStringLimit(xmlNodePtr node, const char *name, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); +int virXMLPropTristateBool(xmlNodePtr node, + const char *name, + virXMLPropFlags flags, + virTristateBool *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2