From nobody Sat Feb 7 09:04:03 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=1616054511; cv=none; d=zohomail.com; s=zohoarc; b=HGROGv8a+u/IYa/dkEL24onxBpeuAVZhr54ruNRvrwhuhVZDrjWJ/u4fbn0y2l4MAEkjqFR9HnykkwCxejmLPFQeHfijU4VIRtmPN8mjRQXxEd98t/QegDbWFNa++GEBGyINyuBA3pzGA4t77mbsC0ikReTboOQtoDrigWqFz3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616054511; 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=SRs5SIveEfJa4GutIbum6Opqsgnvauwh5Cg+ywWYOVo=; b=U0BtMXZSQIP66/CHfdSuOiGVkhIvLgMGXLueRQkcO6k+v4oz6V68AnldrkU42upBY7I606bAbPinpH5TNVrtWTNA/fQgN7mFk4nqEAVutY8kdKw89v13+98hnCVD7mt09QBU0fSOIhixqY36QUCaLPgYMPFmBBgVOZbON/bBypg= 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 1616054511771236.5239234454035; Thu, 18 Mar 2021 01:01:51 -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-361-8xjVvj-xNQCR6PXs75e8Cw-1; Thu, 18 Mar 2021 04:01:48 -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 D06B110866BF; Thu, 18 Mar 2021 08:01:40 +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 A46245D9D3; Thu, 18 Mar 2021 08:01:40 +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 5C6494A703; Thu, 18 Mar 2021 08:01:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12I81Pq4028133 for ; Thu, 18 Mar 2021 04:01:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4747B66A05; Thu, 18 Mar 2021 08:01:25 +0000 (UTC) Received: from work.redhat.com (ovpn-112-180.ams2.redhat.com [10.36.112.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CBA3669F2; Thu, 18 Mar 2021 08:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616054510; 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=SRs5SIveEfJa4GutIbum6Opqsgnvauwh5Cg+ywWYOVo=; b=CxdUVK1N1fJHMenXHUKTm+wPWfzZrBR6a70uBSqIRt+HFLHyFuhentCbLdpgOLTYJbMLf3 hqv28V+xFhHGr3lIo7Ar31NqA/rAMLY1wnOZP1b/dKw5g64iR08Nr6721eI8doLBQH1wdF UC/hWF0MheBQHNel98Y6agGOhdK2yzw= X-MC-Unique: 8xjVvj-xNQCR6PXs75e8Cw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 02/38] virxml: Add virXMLPropYesNo Date: Thu, 18 Mar 2021 09:00:41 +0100 Message-Id: <20210318080117.70255-3-twiederh@redhat.com> In-Reply-To: <20210318080117.70255-1-twiederh@redhat.com> References: <20210318080117.70255-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 value of a yes / no attribute. Does not use virTristateBoolTypeFromString to disallow "default". Signed-off-by: Tim Wiederhake --- src/util/virxml.c | 37 +++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 4 ++++ 2 files changed, 41 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 060b7530fc..47e8414bd5 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -556,6 +556,43 @@ virXMLNodeContentString(xmlNodePtr node) } =20 =20 +/** + * virXMLPropYesNo: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @value: The returned virTristateBool value + * + * Convenience function to return value of a yes / no attribute. + * + * Returns 1 in case of success in which case @value is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropYesNo(xmlNodePtr node, const char* name, virTristateBool *value) +{ + g_autofree char *tmp =3D virXMLPropString(node, name); + + if (!tmp) + return 0; + + if (STREQ("yes", tmp)) { + *value =3D VIR_TRISTATE_BOOL_YES; + return 1; + } + + if (STREQ("no", tmp)) { + *value =3D VIR_TRISTATE_BOOL_NO; + return 1; + } + + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in node '%s': '%s'.= Expected 'yes' or 'no'"), + name, node->name, tmp); + return -1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index d32f77b867..072948b3e2 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -28,6 +28,7 @@ #include =20 #include "virbuffer.h" +#include "virenum.h" =20 xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) G_GNUC_WARN_UNUSED_RESULT; @@ -77,6 +78,9 @@ char * virXMLPropStringLimit(xmlNodePtr node, const char *name, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); +int virXMLPropYesNo(xmlNodePtr node, + const char *name, + virTristateBool *value); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2