From nobody Fri Apr 26 12:41:02 2024 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 From nobody Fri Apr 26 12:41:02 2024 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=1617872378; cv=none; d=zohomail.com; s=zohoarc; b=dAtKsTedlYmXgLNlahfnyw8LaD+27oZ7uKmTYW6dDpzqFDiC4uMOFF6W09BINl7gTGQjCWTgG3qNX/S5dlBZWU9VaXhmSmhRfBcXkvfoY7EQqmACuPwA7lS3zl7EEmeFJl7d3KIZgun9Esu1IR61lMEz/LsUkK7WMtbJWiaVPLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872378; 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=X9PLoiciGQyryDYCSZsGxjK6YUbZN0sm/gr6yG4cho0=; b=Dbh8/O4K1oIfuJ5WLBCZCM2dkAYnTE5M62eqxqQHSE7v7rwGYWrMUoGi2IixxnjALXm4eG4kmMF9Aq3LmLB0bqSrR3HlUYo/00x1p2kzk+uwzhPKQKX5ViaWh6ak3jrTRwddzO77xTjUpLXm27sR/DTnY4JNFTDW4EeN+rSaerg= 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 1617872378231526.685566282199; Thu, 8 Apr 2021 01:59:38 -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-321-k11ecDMlOXS2PX_32rhImg-1; Thu, 08 Apr 2021 04:59:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18F201926DA4; Thu, 8 Apr 2021 08:59:27 +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 ED3C65D764; Thu, 8 Apr 2021 08:59:26 +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 AFE8B1806D14; Thu, 8 Apr 2021 08:59:26 +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 1388vIMY013671 for ; Thu, 8 Apr 2021 04:57:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id A71235D9D0; Thu, 8 Apr 2021 08:57:18 +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 E4FD95D9CC; Thu, 8 Apr 2021 08:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872375; 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=X9PLoiciGQyryDYCSZsGxjK6YUbZN0sm/gr6yG4cho0=; b=ddT+ZABFgSsa9tDG7YMGlOSfb3fi5WOpbCA8guoCEx1yvWLKJr+Ed1dHLHrUN7t64nivYZ z3nBgiiI++GprjKhNpcKAnWNmnHYxKqP1vV289S5jObkN2UnGzHqlcsAC04lmgNT/r5LLX gGBr3ZrKw/UOOD2roQwajduZ1S2Toyw= X-MC-Unique: k11ecDMlOXS2PX_32rhImg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 2/8] virxml: Add virXMLPropTristateSwitch Date: Thu, 8 Apr 2021 10:57:04 +0200 Message-Id: <20210408085710.19379-3-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.15 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 | 49 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 4 ++++ 3 files changed, 54 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1aac0de1ae..776387e6b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3547,6 +3547,7 @@ virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; +virXMLPropTristateSwitch; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 0b822d7c4d..f62c5c39c4 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -607,6 +607,55 @@ virXMLPropTristateBool(xmlNodePtr node, const char* na= me, } =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 (!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 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 53de416a7f..a5ecfbb01a 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -87,6 +87,10 @@ int virXMLPropTristateBool(xmlNodePtr node, const char *name, virXMLPropFlags flags, virTristateBool *result); +int virXMLPropTristateSwitch(xmlNodePtr node, + const char *name, + virXMLPropFlags flags, + virTristateSwitch *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872250; cv=none; d=zohomail.com; s=zohoarc; b=JQXlLCZJvAw36pih0ejFUUpW4kGU0cQugUBS6evQ0+l1pcE1rCj+1ToAukWtPRUm0X8g91mk4Cw2UosopEiMAYAN0fnk9Wp7ZGN/5f/iRHi7AX9N0a0IaWTba3eUFWd5YvoMj3MrmxYW0DhSySvnzqlMYKqJOZxbFYnJH0/KONE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872250; 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=n7bDuN4Se9+NAHCpTaC34Ev42Ir8ch1gG7+2/9FS0ek=; b=nAlwxEU5G5ZB8bHI7aEe/gZwKyS1rxBJSsVN7Q4OB794/ZvgttA12CsAn/H5G9+yu//THmVgdsy0vvouwZLTqzbEVANdsF5vFKAbM3AlLxERn4CKyZepkalVVQO0y5hrl76ZGpv8kfvU4HegA5+Jb7r7pmKREwTnYN4a45ohkdU= 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 1617872250978774.2163885211103; Thu, 8 Apr 2021 01:57:30 -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-36-l2aKKSLJMh6gbtRLAOBvzw-1; Thu, 08 Apr 2021 04:57:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A79AB1006C80; Thu, 8 Apr 2021 08:57:22 +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 6BFD15D755; Thu, 8 Apr 2021 08:57:22 +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 28E5A1806D06; Thu, 8 Apr 2021 08:57:22 +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 1388vKfi013687 for ; Thu, 8 Apr 2021 04:57:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id F02A75D9E3; Thu, 8 Apr 2021 08:57:20 +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 0A68E5D9CC; Thu, 8 Apr 2021 08:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872249; 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=n7bDuN4Se9+NAHCpTaC34Ev42Ir8ch1gG7+2/9FS0ek=; b=W4y3OrzEszyvG1ksHdVdVnzHm/TdS/8PnjOy5ryXokyRiCOd/y0O5FuILNkJaa2Ovj+VVB Iopp0lxy1b9f8vTjJxHlxkWva1hpDKA1eP58Db9yt3FcymSOF09ZwItNM+prPwThnQ+X25 m1VlTgjaTj8LHQY+InBIApoRErKFdoE= X-MC-Unique: l2aKKSLJMh6gbtRLAOBvzw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 3/8] virxml: Add virXMLPropInt Date: Thu, 8 Apr 2021 10:57:05 +0200 Message-Id: <20210408085710.19379-4-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.15 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 integer XML attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 +++++ 3 files changed, 58 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 776387e6b3..bdb63349ee 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3544,6 +3544,7 @@ virXMLNodeSanitizeNamespaces; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropInt; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; diff --git a/src/util/virxml.c b/src/util/virxml.c index f62c5c39c4..807cb7dae9 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -656,6 +656,57 @@ virXMLPropTristateSwitch(xmlNodePtr node, const char* = name, } =20 =20 +/** + * virXMLPropInt: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @base: Number base, see strtol + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * + * Convenience function to return value of an integer 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 +virXMLPropInt(xmlNodePtr node, const char *name, int base, + virXMLPropFlags flags, int *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + + 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; + } + + ret =3D virStrToLong_i(tmp, NULL, base, result); + + if ((ret < 0) || ((flags & VIR_XML_PROP_NONZERO) && (*result =3D=3D 0)= )) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + name, node->name, tmp); + return -1; + } + + return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index a5ecfbb01a..aba863ae11 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -36,6 +36,7 @@ xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) 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 */ + VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero= */ } virXMLPropFlags; =20 int virXPathBoolean(const char *xpath, @@ -91,6 +92,11 @@ int virXMLPropTristateSwitch(xmlNodePtr node, const char *name, virXMLPropFlags flags, virTristateSwitch *result); +int virXMLPropInt(xmlNodePtr node, + const char *name, + int base, + virXMLPropFlags flags, + int *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872280; cv=none; d=zohomail.com; s=zohoarc; b=W0v6Ols/LbOBhWNjXf3lkCEhy74nZ0rkaplQv0tVFdy/2G8dTjCBfAQPmqiRX9ngqMQPrmmzHraAryV+4AsfFm3rdLf25qMLQ3oqVz9aDvm5CE3SGy4cq1kLOmydJW4f06PndfxuuTJuJ5TADWxm46hWhVo1NUZn2Tp6yiyDvr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872280; 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=TDYKRZ9H3cniyNZEDwQo0FLIBbuJv48U7FPuQlKsVzM=; b=HlHRRc8d5nL7dbEKNiPrUtUhYhKRg0e6j8v0XeMVZTv7d2nUPuVEDtWYo+WDvcxsllQXYXvRb6z/IBqjrR8LsdKU/zfCaZAESgJHHX8cXzcDoB2rC7AobMr0KgZvqAnHLa2Jeb2wT3aaym0f/xkHgHrlskbQmc/bpRuabQmUx20= 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 1617872280618466.2668282539406; Thu, 8 Apr 2021 01:58:00 -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-229-SU6VJ09HPtuywPJtdZckrQ-1; Thu, 08 Apr 2021 04:57:57 -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 B0ED883DD20; Thu, 8 Apr 2021 08:57:51 +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 8A42D5D9CC; Thu, 8 Apr 2021 08:57:51 +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 4DD881806D11; Thu, 8 Apr 2021 08:57:51 +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 1388vNru013705 for ; Thu, 8 Apr 2021 04:57:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 379385D9D0; Thu, 8 Apr 2021 08:57:23 +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 6AFCD5D9DC; Thu, 8 Apr 2021 08:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872279; 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=TDYKRZ9H3cniyNZEDwQo0FLIBbuJv48U7FPuQlKsVzM=; b=cJEQi8JVONRJf5eBbOMHMDokH8FWZSnacCtHfHoJNCzo1cYjmLMq0zQ982HD4AQW/9PovH uIwPb075qLWq3Y/+8i5eBsmRkmf45ommbc5s9AP1xZ9udcc7dupqtgRowT7L8uKZmFTElM ZFqg+uOmbi3LSljZ7DS5xBgv6SOCoWc= X-MC-Unique: SU6VJ09HPtuywPJtdZckrQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 4/8] virxml: Add virXMLPropUInt Date: Thu, 8 Apr 2021 10:57:06 +0200 Message-Id: <20210408085710.19379-5-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 an unsigned integer XML attribu= te. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 +++++ 3 files changed, 62 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bdb63349ee..dc6c9191c8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3549,6 +3549,7 @@ virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; virXMLPropTristateSwitch; +virXMLPropUInt; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 807cb7dae9..4d8cda3985 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -707,6 +707,61 @@ virXMLPropInt(xmlNodePtr node, const char *name, int b= ase, } =20 =20 +/** + * virXMLPropUInt: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @base: Number base, see strtol + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * + * Convenience function to return value of an unsigned integer 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 +virXMLPropUInt(xmlNodePtr node, const char* name, int base, + virXMLPropFlags flags, unsigned int *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + + 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 (flags & VIR_XML_PROP_WRAPNEGATIVE) { + ret =3D virStrToLong_ui(tmp, NULL, base, result); + } else { + ret =3D virStrToLong_uip(tmp, NULL, base, result); + } + + if ((ret < 0) || ((flags & VIR_XML_PROP_NONZERO) && (*result =3D=3D 0)= )) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + name, node->name, tmp); + return -1; + } + + return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index aba863ae11..82d5d16375 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -37,6 +37,7 @@ 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 */ VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero= */ + VIR_XML_PROP_WRAPNEGATIVE =3D 1 << 2, /* Wrap around negative valu= es */ } virXMLPropFlags; =20 int virXPathBoolean(const char *xpath, @@ -97,6 +98,11 @@ int virXMLPropInt(xmlNodePtr node, int base, virXMLPropFlags flags, int *result); +int virXMLPropUInt(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + unsigned int *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872277; cv=none; d=zohomail.com; s=zohoarc; b=KWZ6r6GJ0N8zADDmxuQrXTmSx+ZgZRUlZFh2jf5hzfFCapAJ8y8nI/4rNyvElYPVe1zBGzNTES7z2S5t8eBGo/MFjMaNaumwdOfct/t5f7XTPs4WodaromGJPbncahmGammVKLMJbjm1BhexIE/5t8wj3M5fjtp3WetW12elJH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872277; 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=utCtkUgmtrn2hAy8o1ZYLdUC1yrviFLEM4MphHy6wvk=; b=d0WAv45fbShxr+sGmbjkDAd65t7+057V/nnHW16QSDv7BvmF4+ZbnbhDLmNSuYUgWwJFb9yOOZoU2OnTFZZhYqJaoxi9UwJLX7z9Qz5DnNIyyT4SnUsZ+xOHe3BSDjTo6gHYJRJfT3//SiTOtGxQxgYv5AZaez9lLXzN+0T8sys= 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 161787227784758.93778991803822; Thu, 8 Apr 2021 01:57:57 -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-472-AOdENK0_OLuPqNw9bGx3Aw-1; Thu, 08 Apr 2021 04:57:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B17D1107ACC7; Thu, 8 Apr 2021 08:57:49 +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 754B05D755; Thu, 8 Apr 2021 08:57:49 +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 EC1154349A; Thu, 8 Apr 2021 08:57:48 +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 1388vO3V013711 for ; Thu, 8 Apr 2021 04:57:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4329C5DAA5; Thu, 8 Apr 2021 08:57:24 +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 8A0FE5D9D0; Thu, 8 Apr 2021 08:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872276; 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=utCtkUgmtrn2hAy8o1ZYLdUC1yrviFLEM4MphHy6wvk=; b=TJXl/oAwiGeIJWXWJm05sz6DATGruYzvSJ4lvLRcrKm0HcfkGMdulhhLVdPv9bAQuO15I8 c1vZqou9h5bvsr3CfOsuJln3Eg517Pcj+Aw1ERVd+Jmn27hNGR+FTj/SlFm1SezuV3Sy9w Az4kfgAHQBZ9M1lP2+J4LaBu8DARDvI= X-MC-Unique: AOdENK0_OLuPqNw9bGx3Aw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 5/8] virxml: Add virXMLPropEnum Date: Thu, 8 Apr 2021 10:57:07 +0200 Message-Id: <20210408085710.19379-6-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.15 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 enum XML attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 5 ++++ 3 files changed, 57 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc6c9191c8..79eb4dba50 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3544,6 +3544,7 @@ virXMLNodeSanitizeNamespaces; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropEnum; virXMLPropInt; virXMLPropString; virXMLPropStringLimit; diff --git a/src/util/virxml.c b/src/util/virxml.c index 4d8cda3985..a994a404d4 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -762,6 +762,57 @@ virXMLPropUInt(xmlNodePtr node, const char* name, int = base, } =20 =20 +/** + * virXMLPropEnum: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @strToInt: Conversion function to turn enum name to value. Expected to + * return negative value on failure. + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * + * Convenience function to return value of an enum 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 +virXMLPropEnum(xmlNodePtr node, const char* name, int (*strToInt)(const ch= ar*), + virXMLPropFlags flags, unsigned int *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + + if (!node || !name || !strToInt || !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; + } + + ret =3D strToInt(tmp); + if ((ret < 0) || ((flags & VIR_XML_PROP_NONZERO) && (ret =3D=3D 0))) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'."), + name, node->name, NULLSTR(tmp)); + return -1; + } + + *result =3D ret; + return 0; +} + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index 82d5d16375..cbe4cc32dc 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -103,6 +103,11 @@ int virXMLPropUInt(xmlNodePtr node, int base, virXMLPropFlags flags, unsigned int *result); +int virXMLPropEnum(xmlNodePtr node, + const char* name, + int (*strToInt)(const char*), + virXMLPropFlags flags, + unsigned int *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872397; cv=none; d=zohomail.com; s=zohoarc; b=IHThZ3Bk5DA9+Td3HstVSk73yXWPdEs6BZWGsS6RGNCAGscCLu24k44lMYBSLcTt3w86Zx/e/98veZMRkH+HeJNIYx23Q6tOrZN6sVBuaHAQ9d9Uil61jOiilcgsiy3iw5u38yAX1rxcpnn6rtCab8cBKfZYdXOy5M4xEc1bAX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872397; 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=5mwLGNYDzRWVBV9UUqJr/JKglTHhpuujhLTYBsWpo4o=; b=B21wTUTmP5g4b6nhEuGZSKIfb04wq5SLM8EkZmSl5PndcOwW+lNpjNjLCpUe9X4aeV+GBkKyG4wudCDOQUqD/DRxus3iqphQlGrKNTWlFsDF/cMLjUzkpXlY51Hn4FNJ+kS6wjNEtqvzTA9zseZ7j70fMxQbqLt88Mu+6N00siU= 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 1617872397802763.8865946818867; Thu, 8 Apr 2021 01:59:57 -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-477-uTnoP9EpPvKstSiUFhQ3QA-1; Thu, 08 Apr 2021 04:59:54 -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 5D35D79EDB; Thu, 8 Apr 2021 08:59:48 +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 36EE15D9DC; Thu, 8 Apr 2021 08:59:48 +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 EFF255533F; Thu, 8 Apr 2021 08:59:47 +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 1388vPNc013723 for ; Thu, 8 Apr 2021 04:57:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 63A735D9E3; Thu, 8 Apr 2021 08:57:25 +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 957625D9D0; Thu, 8 Apr 2021 08:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872396; 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=5mwLGNYDzRWVBV9UUqJr/JKglTHhpuujhLTYBsWpo4o=; b=KTQ09v1yQ9Hb8AS0PtMKzCQotXbo3YPmDbPPDzvuUiJxLm2ksYzFboN93rqVeesPOiBqdy 5YgIeY/XR8+YzERuSdLNA7T2IKzhLuBOUVnH/aIuW6QfDUkqd5J7X+SDi/IjdYZ/nuS4yt L9tBdDBrTlr/CLVSOE8k/6zGlkBf7gk= X-MC-Unique: uTnoP9EpPvKstSiUFhQ3QA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 6/8] virNetworkForwardNatDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 10:57:08 +0200 Message-Id: <20210408085710.19379-7-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" Signed-off-by: Tim Wiederhake --- src/conf/network_conf.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 4cf4aa4840..19b84cbdd1 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1321,7 +1321,6 @@ virNetworkForwardNatDefParseXML(const char *networkNa= me, g_autofree xmlNodePtr *natPortNodes =3D NULL; g_autofree char *addrStart =3D NULL; g_autofree char *addrEnd =3D NULL; - g_autofree char *ipv6 =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 ctxt->node =3D node; @@ -1333,18 +1332,9 @@ virNetworkForwardNatDefParseXML(const char *networkN= ame, return -1; } =20 - ipv6 =3D virXMLPropString(node, "ipv6"); - if (ipv6) { - int natIPv6; - if ((natIPv6 =3D virTristateBoolTypeFromString(ipv6)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid ipv6 setting '%s' " - "in network '%s' NAT"), - ipv6, networkName); - return -1; - } - def->natIPv6 =3D natIPv6; - } + if (virXMLPropTristateBool(node, "ipv6", VIR_XML_PROP_OPTIONAL, + &def->natIPv6) < 0) + return -1; =20 /* addresses for SNAT */ nNatAddrs =3D virXPathNodeSet("./address", ctxt, &natAddrNodes); --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872299; cv=none; d=zohomail.com; s=zohoarc; b=IASQkTEzmIWDxkovX6gDM8Jis63ileZGEo/iW19U/l3ZZcviHyD6DS7SGSjK3ckTLOur7m0bYOI9W27VQAvMQ0kD7chQ5DX1UR1iY7DKTmww1oJLeYaWnNRX9cPetDL4O/9l2seHxJkOdpuPmKfAfJpXLJjDKVKW2QASIvGm494= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872299; 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=c4MTW3VSkR6FxyjOn5nGgLaKYLJo3EpuJNDThdgh+D4=; b=k53RubN+zfYSUIJ+8BCWs7ZC+WLHaits/wGqo7m2gKKENktN83ouZM8ox/JU3k1M+KSkb9r6KJGoxLEEgEVqHPJ5Qxwn0nKJNKqApMaor+MlHFiqC4lWhetT+Xy3bU2sJoSDNV207MyicywQIn78MhqaPU5u/fFobRfjIVoKJq4= 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 1617872299678223.27185596780112; Thu, 8 Apr 2021 01:58:19 -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-367-2Neg_nJ6PfiwYJPujaEMAQ-1; Thu, 08 Apr 2021 04:58:16 -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 99503107ACE4; Thu, 8 Apr 2021 08:58:10 +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 75A9D5DAA5; Thu, 8 Apr 2021 08:58:10 +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 3AD8455348; Thu, 8 Apr 2021 08:58:10 +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 1388vTwP013744 for ; Thu, 8 Apr 2021 04:57:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E7F25D9CC; Thu, 8 Apr 2021 08:57:29 +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 913745D9DC; Thu, 8 Apr 2021 08:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872298; 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=c4MTW3VSkR6FxyjOn5nGgLaKYLJo3EpuJNDThdgh+D4=; b=DKYT78UyUb0C9jdFa+nRX+GLwZ4z0j+8e7NfbV7IuEsiObsthtOpWF5TBK8ts0IW+U8nk0 0gZvTFmQXggT4wGUdzouiR0he2RMiUwDW/WYF8Kn3r74R1QEIxrkyl3naDvklHLMgfssm5 ISC+7CJAQptghcmIIxgZj+YWZ9jydCU= X-MC-Unique: 2Neg_nJ6PfiwYJPujaEMAQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 7/8] virDomainIOThreadIDDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 10:57:09 +0200 Message-Id: <20210408085710.19379-8-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" Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1e72171586..fb22695dd3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18180,21 +18180,13 @@ static virDomainIOThreadIDDefPtr virDomainIOThreadIDDefParseXML(xmlNodePtr node) { virDomainIOThreadIDDefPtr iothrid; - g_autofree char *tmp =3D NULL; =20 iothrid =3D g_new0(virDomainIOThreadIDDef, 1); =20 - if (!(tmp =3D virXMLPropString(node, "id"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'id' attribute in element")); - goto error; - } - if (virStrToLong_uip(tmp, NULL, 10, &iothrid->iothread_id) < 0 || - iothrid->iothread_id =3D=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid iothread 'id' value '%s'"), tmp); + if (virXMLPropUInt(node, "id", 10, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, + &iothrid->iothread_id) < 0) goto error; - } =20 return iothrid; =20 --=20 2.26.2 From nobody Fri Apr 26 12:41:02 2024 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=1617872319; cv=none; d=zohomail.com; s=zohoarc; b=azHY2HCt/cQk0tjmw9h0iwEY8hToBVNQGepaUQKQ7l+SERyUyIf8uLQrILpw5xNDJYKf/QBvH9SLvSlnsGcqFv9l7HeshCMvZjzCTDmIyLZC1eoHNKgX+xkNk/NJqY5ASXqGvFtLOrL6RZyBJ5bJ2J2xT667GKtItHZs6phI4Ak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872319; 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=VkWp8wZN4PkAPoUcahBkqhQgw64MGSNW1lbOHzB90ZA=; b=UTBY46OJwO1e1ixI7z2uGIOLwZ1zsjNS3pwtlG3qU3ta6A2nu9AXL2lrvOaXlsqUYqnZNy8NCnhpL6tcFD49QCxhruCxASJ79V/6Rvm6eHcNVtZy/vzwcg8faHxH/SjRlYHygnooKo4YHq7Ua1aAA6asioSsJJMcwoIdEzi5QmY= 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 1617872319273624.4586485082488; Thu, 8 Apr 2021 01:58:39 -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-248-T7-zFm7WNSCrmscSpHUXZA-1; Thu, 08 Apr 2021 04:58:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94F4D800D53; Thu, 8 Apr 2021 08:58:31 +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 720865B698; Thu, 8 Apr 2021 08:58:31 +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 3919E1806D11; Thu, 8 Apr 2021 08:58:31 +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 1388vUdW013750 for ; Thu, 8 Apr 2021 04:57:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5FF985D9DC; Thu, 8 Apr 2021 08:57:30 +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 A4ABA5D9CC; Thu, 8 Apr 2021 08:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872318; 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=VkWp8wZN4PkAPoUcahBkqhQgw64MGSNW1lbOHzB90ZA=; b=ZknLpDCXlcSx+QpTj8EgQZ1VYrjqK9Hu0N2rAUc7mVWOkriLlXQr567nS8pBnYXuwfrizB NddeB9UKGb6jHA9HUNNrs5ED3A9LNDRrMYlLWpKTTh2ad5havovp+514evXBcOibfLGlhb qAue2XBLOQ0N/6pcy+j7/N0iibjCLTY= X-MC-Unique: T7-zFm7WNSCrmscSpHUXZA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 8/8] virCPUDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 10:57:10 +0200 Message-Id: <20210408085710.19379-9-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.15 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" Signed-off-by: Tim Wiederhake --- src/conf/cpu_conf.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 43629068c3..ee7feb1186 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -423,7 +423,6 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST) { g_autofree char *match =3D virXMLPropString(ctxt->node, "match"); - g_autofree char *check =3D NULL; =20 if (match) { def->match =3D virCPUMatchTypeFromString(match); @@ -435,16 +434,9 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, } } =20 - if ((check =3D virXMLPropString(ctxt->node, "check"))) { - int value =3D virCPUCheckTypeFromString(check); - if (value < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid check attribute for CPU " - "specification")); - return -1; - } - def->check =3D value; - } + if (virXMLPropEnum(ctxt->node, "check", virCPUCheckTypeFromString, + VIR_XML_PROP_OPTIONAL, &def->check) < 0) + return -1; } =20 if (def->type =3D=3D VIR_CPU_TYPE_HOST) { --=20 2.26.2