From nobody Mon Feb 9 11:47:05 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=1618566146; cv=none; d=zohomail.com; s=zohoarc; b=It22mf37FHqItbUR0wRG6yVQlVTQtt6wa1u8aO5RdPDaoy2lP2L4wYfS/vfzlrP+UMAIVse8/qC8+iEe7OMEIjkFzdT94S1G3Vyc3upha2lMLJnwm6ou8CO3Gn4YVwlKu28oeFjV5HK5hh06ZTP4WDOxJ++anExHlIBzjdVS6xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566146; 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=6IT2rFS1HdV+vnhEZk/b2OjKdzh/fM3+DTG8MfGWILg=; b=YzElPXSI7IJjRcmK9mvQWpbBJ+9Y6XmZdmY+MGbAYfmktX/SR4cp/gLc/ATVhUfdSuPJ7JAVkCny3XXSBXHke7rTjM1Avr7tGaO9cHrWHMHMI250ZnbpNbNtaUihDUbPy2V8+6MUB7IWnVb2oq8/bU1naqdKrf/5lgMh9bJs8xA= 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 1618566146197686.2753274154055; Fri, 16 Apr 2021 02:42:26 -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-456-Rvw6KiRPN1qvJ7ZI9PX-hQ-1; Fri, 16 Apr 2021 05:42:22 -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 A3C50C744B; Fri, 16 Apr 2021 09:42:17 +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 6A11D5DAA5; Fri, 16 Apr 2021 09:42:17 +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 31A9544A64; Fri, 16 Apr 2021 09:42:17 +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 13G9fxB0006179 for ; Fri, 16 Apr 2021 05:41:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id E89E56A04C; Fri, 16 Apr 2021 09:41:59 +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 06D0D6A046; Fri, 16 Apr 2021 09:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566145; 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=6IT2rFS1HdV+vnhEZk/b2OjKdzh/fM3+DTG8MfGWILg=; b=eBnU8vRNfPWdMECXw4upZ4YZhUFD1kt9z6M+HHJO7NXHsteY8TbCkp6h/hwgRamFCfYxZv E5/V9Z3wDOGginps2RXywlEa3i80vbs4YkSX4qItjulRO7RQG8x7X/MQINffA5eoTKAM6y 821Z1wCfWHzgq/sBOeCDEai+HsnoRtg= X-MC-Unique: Rvw6KiRPN1qvJ7ZI9PX-hQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 2/8] virxml: Add virXMLPropTristateSwitch Date: Fri, 16 Apr 2021 11:41:46 +0200 Message-Id: <20210416094152.202334-3-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.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 an on / off 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 | 6 ++++++ 3 files changed, 51 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 331cbb57d5..ba70e8b4ca 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3551,6 +3551,7 @@ virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; +virXMLPropTristateSwitch; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 6b197e0fff..1b1c3878e6 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -602,6 +602,50 @@ virXMLPropTristateBool(xmlNodePtr node, } =20 =20 +/** + * virXMLPropTristateSwitch: + * @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 an on / off 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 +virXMLPropTristateSwitch(xmlNodePtr node, + const char* name, + virXMLPropFlags flags, + virTristateSwitch *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 virTristateSwitchTypeFromString(tmp)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected 'on' or 'off'"), + 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 bd246153f5..4c9497ba17 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -90,6 +90,12 @@ int virXMLPropTristateBool(xmlNodePtr node, virTristateBool *result) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 +int virXMLPropTristateSwitch(xmlNodePtr node, + const char *name, + virXMLPropFlags flags, + virTristateSwitch *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