From nobody Sat Feb 7 09:04:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1616054500; cv=none; d=zohomail.com; s=zohoarc; b=W8k8ZRc+W3yXYRf3fBwewMkJhuqxJg7qr0+G5B2N9+CM7YV4QDPi7vbtZ5yjBkqmYIKYfAt2V4NoUnxVoSzsdWMw11WLJii9bb5qxWxsGI1SpASnqrcZzCrImGdmCSdPTIIWjQanufWyPqSt50JrdUVaJ6m+KpmyyCspLIJHGl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616054500; 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=2w5osUfTibKeF1ntemUfdjbj2l4Ep+a07SgBEFrxtCU=; b=Vk5N6IxOMKEcMWJ1Zo2DX2G2GF92hBa6CFTzqkqBydjkRmnoLpyXWwFpgWI7AfuHAr/Jn+YlQIeq/Zi+SOFWEdGkTxhdLw+xLotRqD1PMRtKAjasmxQp8WKBw8S17AI7G5iJ/GA8nQmkLYquCtv9P51s4RKOOHhl8kiHv/fCDuA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616054500397974.8306554293928; Thu, 18 Mar 2021 01:01:40 -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-510-3bgwZqCdOjyn7NYm4vj1BQ-1; Thu, 18 Mar 2021 04:01:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B0B8800FF0; Thu, 18 Mar 2021 08:01:30 +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 DAC5D60C13; Thu, 18 Mar 2021 08:01:29 +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 963904BB7C; Thu, 18 Mar 2021 08:01:29 +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 12I81QFf028139 for ; Thu, 18 Mar 2021 04:01:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6D38D66A05; Thu, 18 Mar 2021 08:01:26 +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 A4D1366FFF; Thu, 18 Mar 2021 08:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616054498; 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=2w5osUfTibKeF1ntemUfdjbj2l4Ep+a07SgBEFrxtCU=; b=Qo/fq/xu5vzcbFNhNQBbMtwjSlJwa//udG1N/r5j3q7v+EM1kXzL0rf2rsHQyugtT8Hldt 29jPqn0NQt6eY9vPXKtaXSgNB4uT3oTNx9lNopkEGDdTLmj4+4EhjG+HKzIDrS9rmZAJVD zifMp0wRAiYz5FELhh0CMml9v8ZFbKA= X-MC-Unique: 3bgwZqCdOjyn7NYm4vj1BQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 03/38] virxml: Add virXMLPropOnOff Date: Thu, 18 Mar 2021 09:00:42 +0100 Message-Id: <20210318080117.70255-4-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.12 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 an on / off attribute. Does not use virTristateSwitchTypeFromString to disallow "default". Signed-off-by: Tim Wiederhake --- src/util/virxml.c | 37 +++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 47e8414bd5..7c06530d25 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -593,6 +593,43 @@ virXMLPropYesNo(xmlNodePtr node, const char* name, vir= TristateBool *value) } =20 =20 +/** + * virXMLPropOnOff: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @value: The returned virTristateSwitch value + * + * Convenience function to return value of an on / off 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 +virXMLPropOnOff(xmlNodePtr node, const char* name, virTristateSwitch *valu= e) +{ + g_autofree char *tmp =3D virXMLPropString(node, name); + + if (!tmp) + return 0; + + if (STREQ("on", tmp)) { + *value =3D VIR_TRISTATE_SWITCH_ON; + return 1; + } + + if (STREQ("off", tmp)) { + *value =3D VIR_TRISTATE_SWITCH_OFF; + return 1; + } + + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in node '%s': '%s'.= Expected 'on' or 'off'"), + 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 072948b3e2..d0577723ef 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -81,6 +81,9 @@ char * virXMLNodeContentString(xmlNodePtr node); int virXMLPropYesNo(xmlNodePtr node, const char *name, virTristateBool *value); +int virXMLPropOnOff(xmlNodePtr node, + const char *name, + virTristateSwitch *value); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2