From nobody Thu May 9 08:38:48 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=1618566133; cv=none; d=zohomail.com; s=zohoarc; b=jSft3/zuVq5IXY19kpmT+FH49e7PBiP1ve4dHFIkUeejDr7Da+Nb7lncOOoUsFct4OQksFNTruvt8hK6LjMRA/PSDuZfnj9A367zo4FGFcTtCT7pV/PuW6mJz1XlhIu0HmtJvv3ogdX1NNfvMhBKV8OT+joYpzy2Zaw/01BPRcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566133; 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=0M5PW0+oLNWAuJJrf3AIECyu43k4fK9tv1n4IncjLD4=; b=IBx7dJ1mZ+GIDkH7X0ESy0xeEcHZFGKX1Y+dCSE25qFgRxAhVYJam2AJofSH+1zFy76Bcv2Y2GfNArl9CvwvAb83THeGI97n5I77xRXK+n7mlXzgBAnsh8Z5Azo9rr3k7ePrrPvlDLyw+Cqkhva3pe9983m9FWM0XiqfbY6Z3yM= 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 1618566133879652.6507776473803; Fri, 16 Apr 2021 02:42: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-99-woAODv-vMbO4_jTJwjNE3Q-1; Fri, 16 Apr 2021 05:42:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB175107ACE4; Fri, 16 Apr 2021 09:42:03 +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 76B265C8AA; Fri, 16 Apr 2021 09:42:03 +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 AC8B24E58D; Fri, 16 Apr 2021 09:42:00 +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 13G9fwCm006166 for ; Fri, 16 Apr 2021 05:41:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id A43DF6A04C; Fri, 16 Apr 2021 09:41:58 +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 C4E8A6A046; Fri, 16 Apr 2021 09:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566132; 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=0M5PW0+oLNWAuJJrf3AIECyu43k4fK9tv1n4IncjLD4=; b=LAH5v4j6I564tYiMZZdQq4r8NpBt/jLl7Qw26uGgXzVVa518VtF6fW/fLkKSRyiwVuwx+l 0x8CmyxdGqa8f6SJfjz5FCaq+O0gykm48YIlky+qLMgSaG9mK8vKNBF44n1hArgFddEXxH Ht4CqeWZ+5STgaV8Yv+FRDLifxLaM/0= X-MC-Unique: woAODv-vMbO4_jTJwjNE3Q-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 1/8] virxml: Add virXMLPropTristateBool Date: Fri, 16 Apr 2021 11:41:45 +0200 Message-Id: <20210416094152.202334-2-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.16 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 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 12 +++++++++++ 3 files changed, 57 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a727537c76..331cbb57d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3550,6 +3550,7 @@ virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; virXMLPropStringLimit; +virXMLPropTristateBool; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 117f50f2bf..6b197e0fff 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -558,6 +558,50 @@ 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 (!(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 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 de171dce12..bd246153f5 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 absent */ +} virXMLPropFlags; + int virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt); char * virXPathString(const char *xpath, @@ -78,6 +84,12 @@ char * virXMLPropStringLimit(xmlNodePtr node, size_t maxlen); char * virXMLNodeContentString(xmlNodePtr node); =20 +int virXMLPropTristateBool(xmlNodePtr node, + const char *name, + virXMLPropFlags flags, + virTristateBool *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 From nobody Thu May 9 08:38:48 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=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 From nobody Thu May 9 08:38:48 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=1618566136; cv=none; d=zohomail.com; s=zohoarc; b=P0iPytmDy5ba23cdnFZkvQkBKoGiOK1ENUENGAxGbhTIt8egnZGuf6yWyffP2S8snaLARcpB/BjrDUyqnBExCA6YfHpj92DtJLXLFa/BVJbE6rtULXeJnR5+JYDPMz7SRNPS+dyX1lDd7pC2B635cK4gN/xFijczlHgAr86inlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566136; 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=+JdjSjuZbH8YwXZ+w2Vk6jiNOX2X4Qmodv1NB9spK7w=; b=V8HDTrbLqfG5MlKsi+a2Ga9qAuna/r7udsCbDrEvgPMzEafBir1nc25Ohcc7Bgrr8JrOZEo9nfM5Oe6friY/vxLRg3EmFz8iZ8afG2W8O2KKSQ44YJFdB55z60Hkm0XCbjcJ/wP7iC5qZxLeMB2OZHNK5QjFsxYpVB9rNQ6LAaM= 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 1618566136023273.8228038026391; Fri, 16 Apr 2021 02:42:16 -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-577-2kYp2fK8NnK69FFdS_wJCg-1; Fri, 16 Apr 2021 05:42:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C29519251A3; Fri, 16 Apr 2021 09:42:05 +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 9D0E719744; Fri, 16 Apr 2021 09:42:04 +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 65A004ED86; Fri, 16 Apr 2021 09:42:02 +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 13G9g1Gp006189 for ; Fri, 16 Apr 2021 05:42:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2BEEF6E505; Fri, 16 Apr 2021 09:42:01 +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 49F9F6A046; Fri, 16 Apr 2021 09:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566133; 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=+JdjSjuZbH8YwXZ+w2Vk6jiNOX2X4Qmodv1NB9spK7w=; b=cqABzv647BWitx/5H6cpTMeJMRE2pDD9/duYPbNQI18KAhezc+y1+P116Cw1enUUC4Jue4 HgWDTXJwFMeq05lf+VhBjCUeXEWn6PcP3zqW+NLYEh4gfxPUsknJcgqdlxrBjB5Xyh/Rhw s9QdSdS3xRspKJKSc+oV3p0097sjTGE= X-MC-Unique: 2kYp2fK8NnK69FFdS_wJCg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 3/8] virxml: Add virXMLPropInt Date: Fri, 16 Apr 2021 11:41:47 +0200 Message-Id: <20210416094152.202334-4-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.84 on 10.5.11.23 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 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 53 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 8 ++++++ 3 files changed, 62 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ba70e8b4ca..11e7b0c741 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3548,6 +3548,7 @@ virXMLNodeSanitizeNamespaces; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropInt; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; diff --git a/src/util/virxml.c b/src/util/virxml.c index 1b1c3878e6..6da4a2b1f6 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -646,6 +646,59 @@ virXMLPropTristateSwitch(xmlNodePtr node, } =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 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 (virStrToLong_i(tmp, NULL, base, &val) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + name, node->name, tmp); + return -1; + } + + if ((flags & VIR_XML_PROP_NONZERO) && (val =3D=3D 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : Zero is not permitted"), + name, node->name); + 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 4c9497ba17..10c2404f5f 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 absent */ + VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero */ } virXMLPropFlags; =20 int virXPathBoolean(const char *xpath, @@ -96,6 +97,13 @@ int virXMLPropTristateSwitch(xmlNodePtr node, virTristateSwitch *result) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 +int virXMLPropInt(xmlNodePtr node, + const char *name, + int base, + virXMLPropFlags flags, + int *result) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, const char *filename, --=20 2.26.2 From nobody Thu May 9 08:38:48 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=1618566146; cv=none; d=zohomail.com; s=zohoarc; b=k2zM09TLSZeI03zOs1QdmWgcn7/BJDzXgPDah+ynUuOuYcLRjpuhISjYLS+ygQn6c/a6vwdUhEVIqQnh1c0QCL8gQsaclFr4GVsqX5dN2Ps1NZ/dLLtiaQQ9mtn2WtKF3L0vapzABDpZ/DVskhylpJgzbMf6WkqG3mdVLZegvlo= 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=4OHINDe66MtP0HX/+D6bJ6yLOegYn+BpGPJzL4nB8YE=; b=kutPV0UDnZnGaoTVVG8Ka9DsqokX3rOonsMRtbNzGFPWkSXnbOizSClr96iJw91YjvcWo9+vbcHATyGGUk4JsouHqBavelBIhJ3ap30nWdgiCEK67LlD+AjcS0UJtvkSSAiHHaZFpvRzNfCWYU9RcVy+E5m3RXfR2t55H1HIgK8= 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 1618566146737812.0950184403586; 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-454-Tmq-TrNmNTuAbboqUKxC-w-1; Fri, 16 Apr 2021 05:42:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E39B88026AD; Fri, 16 Apr 2021 09:42:17 +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 B76C52B3CD; 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 7F4F41806D16; 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 13G9g2KS006198 for ; Fri, 16 Apr 2021 05:42:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E40C6A046; Fri, 16 Apr 2021 09:42:02 +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 7F86A6F99C; Fri, 16 Apr 2021 09:42:01 +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=4OHINDe66MtP0HX/+D6bJ6yLOegYn+BpGPJzL4nB8YE=; b=fIqUbP41K4AIOlBL07N1s6Z6jZ2mXBLe2qTx7WdgH81UI1kWEgRDqutd/lABVYg2laN0eD Q/ulCPEMdNcrKmN4fInMr5gQ5ET+ioMOT5D4vLKhfxtb8ks5j2BpWGV21YUeJgjwFvqzKh SwgokicbO/3G0z0OpcfGaSYemsh7OGo= X-MC-Unique: Tmq-TrNmNTuAbboqUKxC-w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 4/8] virxml: Add virXMLPropUInt Date: Fri, 16 Apr 2021 11:41:48 +0200 Message-Id: <20210416094152.202334-5-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.84 on 10.5.11.23 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 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 60 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 8 ++++++ 3 files changed, 69 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 11e7b0c741..9c94edb523 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3553,6 +3553,7 @@ virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; virXMLPropTristateSwitch; +virXMLPropUInt; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 6da4a2b1f6..662a700262 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -699,6 +699,66 @@ virXMLPropInt(xmlNodePtr node, } =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; + unsigned 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 (flags & VIR_XML_PROP_WRAPNEGATIVE) { + ret =3D virStrToLong_ui(tmp, NULL, base, &val); + } else { + ret =3D virStrToLong_uip(tmp, NULL, base, &val); + } + + if (ret < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + name, node->name, tmp); + return -1; + } + + if ((flags & VIR_XML_PROP_NONZERO) && (val =3D=3D 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : Zero is not permitted"), + name, node->name); + 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 10c2404f5f..aed4715123 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 absent */ VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero */ + VIR_XML_PROP_WRAPNEGATIVE =3D 1 << 2, /* Wrap around negative values */ } virXMLPropFlags; =20 int virXPathBoolean(const char *xpath, @@ -104,6 +105,13 @@ int virXMLPropInt(xmlNodePtr node, int *result) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); =20 +int virXMLPropUInt(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + unsigned int *result) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, const char *filename, --=20 2.26.2 From nobody Thu May 9 08:38:48 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=1618566148; cv=none; d=zohomail.com; s=zohoarc; b=d5J+bnDiURtznHxt2x195pSFnZoZk7ga9sTR7WwA0tFlVq5fjfhNjgyktFQY7dx/gF+okg2SyoGFBkM4NsnlCNkDzY+h05hi99RzHStqa/gl0GELMRddJZIsU6LCLAXYwffQGKx9v5B6YHGsNzIN9yWdtOCmio/fYuDsIXXMQKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566148; 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=iAlMPP8fM6ylfGuAajRiMH8agK4kVCzSNwgARq8jNsA=; b=PkcPSxLPZU1eoxcDnhYeRsHQDxfSyvsxbPOaULnqnkLkC24XThk+rQ+9BKGW45rPU7UZYfBFpSwMkvIkzT7W6Y89OG9AJGS2lpAb9f2+Xsp8Z4hFdiwpW+VMERyMpuDxyU1IG6sHJ4tQRDiGG/TXKCZqqcsG7WqPzrITkebD91E= 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 161856614886247.038111075412075; Fri, 16 Apr 2021 02:42:28 -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-256-Za817UyQPrisyqxJ6xDiPg-1; Fri, 16 Apr 2021 05:42:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2E5C10054F6; Fri, 16 Apr 2021 09:42:20 +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 8803247; Fri, 16 Apr 2021 09:42:20 +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 4C662180B654; Fri, 16 Apr 2021 09:42:20 +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 13G9g3LF006210 for ; Fri, 16 Apr 2021 05:42:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 930276E505; Fri, 16 Apr 2021 09:42:03 +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 AF84C6F99C; Fri, 16 Apr 2021 09:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566147; 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=iAlMPP8fM6ylfGuAajRiMH8agK4kVCzSNwgARq8jNsA=; b=MR0Dzn/gpY7FIuwejdEDWRmcLnLDbgrFYMBijzMn6vLGCtsCzUvBoCHP/YKY7sePXA++Yt HyQDGv2cy0MMdx3cr36UNWpOrn3BbA1n6V9dCRnWlglxfgpE7AW4mpLh/qHrV7AB5mIo0f +C5x5TCsPMad7gry6okUGm5mHA2Es2g= X-MC-Unique: Za817UyQPrisyqxJ6xDiPg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 5/8] virxml: Add virXMLPropEnum Date: Fri, 16 Apr 2021 11:41:49 +0200 Message-Id: <20210416094152.202334-6-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.84 on 10.5.11.23 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 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virxml.c | 48 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 8 +++++++ 3 files changed, 57 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9c94edb523..0fcbf546a6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3548,6 +3548,7 @@ virXMLNodeSanitizeNamespaces; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropEnum; virXMLPropInt; virXMLPropString; virXMLPropStringLimit; diff --git a/src/util/virxml.c b/src/util/virxml.c index 662a700262..94948ca021 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -759,6 +759,54 @@ virXMLPropUInt(xmlNodePtr node, } =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 char*), + virXMLPropFlags flags, + unsigned int *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + + 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; + } + + 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 aed4715123..d362cfb794 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -112,6 +112,14 @@ int virXMLPropUInt(xmlNodePtr node, unsigned int *result) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); =20 +int virXMLPropEnum(xmlNodePtr node, + const char* name, + int (*strToInt)(const char*), + virXMLPropFlags flags, + unsigned int *result) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(4); + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, const char *filename, --=20 2.26.2 From nobody Thu May 9 08:38:48 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=1618566189; cv=none; d=zohomail.com; s=zohoarc; b=BjO4WJgEt3y7f3IfyP65QoFDUOnjpMN3T6YoNgBbavLJtHhv5Fv3waZdWdWuRytn2W1MfquAcBjeBUkHmnAERxOiuIoVV5ALUz9bTnGDdWffww/Abuai4mFgmA+5fGbwlVoZ1HY8rw/QXjY4n1tmqr1vbUMElGw+9lP8GI/Hr1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566189; 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=UyUo03QuvrQZZQazBUKk8OYQ9DCsz8aBPx1fPCSQcyY=; b=dQkEuMg3YInHULWzUI2zR4nANPI2ZPjEnA7g0Os3FtbXQBDKrKyeeO9SYWZsS0ISXQMLtocb2tLEyeHcrdZ7KAM1U0+4oizHQ0rFWg96EYIIIuu86cIOJ/W43KmlHxxFBi4avbNrUFHEVMzCHTqCQQs2NHsnohHMi2CLE7/NA10= 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 1618566189828504.4130690693577; Fri, 16 Apr 2021 02:43:09 -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-331-evwYY6o3PR-HW-WSiSrwtw-1; Fri, 16 Apr 2021 05:42:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F89EC744A; Fri, 16 Apr 2021 09:42:20 +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 71290107D5D1; Fri, 16 Apr 2021 09:42:20 +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 398161806D1A; Fri, 16 Apr 2021 09:42:20 +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 13G9g4cu006220 for ; Fri, 16 Apr 2021 05:42:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id C46E36A04C; Fri, 16 Apr 2021 09:42:04 +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 E64A66FEED; Fri, 16 Apr 2021 09:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566188; 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=UyUo03QuvrQZZQazBUKk8OYQ9DCsz8aBPx1fPCSQcyY=; b=EZXdy5ZQoFABVxHCOPnLDUfPJJ1QRbij5BsRqbUswdNDV4S5sEZUgTKQOObYAOcYtH4Nu3 2n2qpUm7KQhs2vFTP7n9IQmu+ab+2b5DyfPuU5SxAGWbGJVhUzHpJI5nyBX16UZDXjq1Kc Y9gINLQhT4JagMuSvnPEGTihkQIbBZE= X-MC-Unique: evwYY6o3PR-HW-WSiSrwtw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 6/8] virNetworkForwardNatDefParseXML: Use virXMLProp* Date: Fri, 16 Apr 2021 11:41:50 +0200 Message-Id: <20210416094152.202334-7-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.84 on 10.5.11.22 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 Reviewed-by: Peter Krempa --- 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 f0f5ef6f42..17835ac8d3 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 Thu May 9 08:38:48 2024 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=1618566186; cv=none; d=zohomail.com; s=zohoarc; b=Dll8NF0jBrWDohTiu42EVcULy2zLF5pueFj3bgnn71Kq226UFsw3ax+iOSUrfwdVRN20hfnlV0N4j2gpaWo7WcjXPMRzGLSUDSZ+MQXtcrP+PhTsWJV8/Y8yx5buhVzDHWWl7zLtPWmOGNThSh8LvhHx4BuHev636jBJSFOe0Kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566186; 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=G8rFMkAVngVjkyCyx28m+riS9pTcZtEaRmdKN8I6HbY=; b=L+J7beGU91zH1uidIZmdnJ7n0F8HY3GJIedFO8rqINPPWJdA78WzleyIyL4QCWZa6zpWE8ef1rmr5MszoldQYxrehEVbK8mZL0xXJy3e7wLjVFk4lfwwhJOwb0FKnGl0rNOFsL5aAsW3yzEt6qJg7W5F2WUWZKZ/0cKq/d68pss= 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 1618566186987961.5970636140189; Fri, 16 Apr 2021 02:43:06 -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-26-Kykn-FlEMe27diOKj-DSaw-1; Fri, 16 Apr 2021 05:42:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 242C8107ACF2; Fri, 16 Apr 2021 09:42:20 +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 F267047; Fri, 16 Apr 2021 09:42:19 +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 B38694ED86; Fri, 16 Apr 2021 09:42:19 +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 13G9g6tX006225 for ; Fri, 16 Apr 2021 05:42:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 10D9A6E505; Fri, 16 Apr 2021 09:42:06 +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 246A06A046; Fri, 16 Apr 2021 09:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566185; 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=G8rFMkAVngVjkyCyx28m+riS9pTcZtEaRmdKN8I6HbY=; b=ESY+2s++FOgPjnvHWwcArHkvn6CECLV3T8ujOwe1iAh/zkCyo1Udq3N3R4r0eZeuUT3/18 Eiw/HrxSpOXSUJ/B9t1tQFrqz/5YxgUIU6fSgBFNnNfT1gRWU0TnB0AAAXkoLnuGnWWJt2 dZlH5xfno/SZNSaE+S56cLxPh+UQE3g= X-MC-Unique: Kykn-FlEMe27diOKj-DSaw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 7/8] virDomainIOThreadIDDefParseXML: Use virXMLProp* Date: Fri, 16 Apr 2021 11:41:51 +0200 Message-Id: <20210416094152.202334-8-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.84 on 10.5.11.23 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 Reviewed-by: Peter Krempa --- 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 a0fb7731d9..858ef5db9d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18229,21 +18229,13 @@ static virDomainIOThreadIDDef * virDomainIOThreadIDDefParseXML(xmlNodePtr node) { virDomainIOThreadIDDef *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 Thu May 9 08:38:48 2024 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=1618566155; cv=none; d=zohomail.com; s=zohoarc; b=AaDAKxjVuDxcDg8J3JHwJpHKEfEqx/os6tpvRd8+sVkEiP8TEVh6h/nLp6slOXSH1dv5KJvbr6tN5pllRMTzlOazP9QGMlXLH8yN6+YQmXgv+e9GFRaKOrO8JAM8eS/nkjnmftds5aHcFzodT/MHcup86tKvWiIrkRA/8i/ah2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618566155; 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=H5W0hFVuFlmJzII/WU3leHrXoLS4d5LaYTfgkwuKg+s=; b=FEkbOSZD4/Y8mOFV8DkNE+JR9aXZ+t/5C5PQNmV8zaiUSkCKDAwuCwDg7UD0WfCiQn2mIFRw7p/CeUBm0VfMn38gNIJ50k3E3QajVG7KCtdtUY2HrYQhyNmZLAEt7zWPGbLfxXTvBiHJolra0RZjIEN0eb43xsMKNl7hXEr1OP4= 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 1618566155406612.2617844881264; Fri, 16 Apr 2021 02:42:35 -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-602-m7wAGVQeP6qn3cI5t9DUdQ-1; Fri, 16 Apr 2021 05:42:32 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 62C5D87A842; Fri, 16 Apr 2021 09:42:23 +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 305E519715; Fri, 16 Apr 2021 09:42:23 +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 6AE701806D1D; Fri, 16 Apr 2021 09:42:22 +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 13G9g7ol006235 for ; Fri, 16 Apr 2021 05:42:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FD4C6A04C; Fri, 16 Apr 2021 09:42:07 +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 647D26A046; Fri, 16 Apr 2021 09:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566154; 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=H5W0hFVuFlmJzII/WU3leHrXoLS4d5LaYTfgkwuKg+s=; b=UrZFnDyX1baq90JOk6DWvLq+HBk2nLF4s2ajYJFberxfeGDYaNu6lGw4ZaihbSGR4/C9N2 FEpPmp3Yyfaqg/c9RyY7i5+vMxPfKwZnuTaylFLGhIu5BasfC/Fclt73tIHFQBzbFD0Nik bslj04eX0WXYvEaaYsXq+O4F5DnJbhM= X-MC-Unique: m7wAGVQeP6qn3cI5t9DUdQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v6 8/8] virCPUDefParseXML: Use virXMLProp* Date: Fri, 16 Apr 2021 11:41:52 +0200 Message-Id: <20210416094152.202334-9-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.84 on 10.5.11.23 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 Reviewed-by: Peter Krempa --- 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 c095ab0e89..c7bea8ae00 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