From nobody Sat Apr 27 04:41:59 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=1617880819; cv=none; d=zohomail.com; s=zohoarc; b=SdO1/mfv3QAvT2Z+RNxNuv6ztj9z1Y22eIQz6fc4imxjTLfLrEiJaXiCIw5fvWGD0gtr7nPK3ss4dGTFw2jFs+7zwfDK9Apv00h2yUGzRcvMsfwIb7hRnIu6Kaxxck1/6j+47Rtmso9IiweCuXBFrySIMmzFZuwNgL/iA48kvv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880819; 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=cAtiLlfcYK3Q32PonsHjIXjpV33Exzg7TaNz+erd3xFFvOK058uge4PP7pJFYlZH0S/rBQijJSnX0XUUMNnt1HcHK0ig+0EqDs0oQRZJzDfzbwQgGsC6qnu3Xsif3a8d/I/xbPYpid04XPoAX3Q0NEZ4znTGxTLQxUNn2dx01po= 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 1617880819681918.4864330122786; Thu, 8 Apr 2021 04:20: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-57-6K-FYCIwP5CATphcdkr0cA-1; Thu, 08 Apr 2021 07:20:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75C5DA40C2; Thu, 8 Apr 2021 11:20:09 +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 1C9926EF51; Thu, 8 Apr 2021 11:20:09 +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 8568D4349A; Thu, 8 Apr 2021 11:20:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BK7jb009398 for ; Thu, 8 Apr 2021 07:20:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3385D5C5E1; Thu, 8 Apr 2021 11:20:07 +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 DAF205C1C4; Thu, 8 Apr 2021 11:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880818; 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=GsDJ5cs5Z7Qgaa5XK2EUvvhk7ksPO6HTlj3+Bh3qATE/CIKWL5HiuJR14eTb2AQWfv8pzF sdFTOA5XQFl5N+5awuh2mA9gx2t8Kx0F2ET6DKsnAHMiSHh4XAfsWXYZEFPul7/fFb7nUP 1ZXhnuAQJaXD3NVupB01s7hqjWMvkoc= X-MC-Unique: 6K-FYCIwP5CATphcdkr0cA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 1/8] virxml: Add virXMLPropTristateBool Date: Thu, 8 Apr 2021 13:19:51 +0200 Message-Id: <20210408111958.32678-2-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.13 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 | 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 Sat Apr 27 04:41:59 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=1617880819; cv=none; d=zohomail.com; s=zohoarc; b=M9QuOd0fpKhcOOH4YCBSvm4RLK+sZ3K2Ako77ouydmR1iF8zgDbR0M2gIcgSUEhWGmXYeS0WVyP62+vN9VHbf0TlN5bI6vDXsr8b8SBVx/8dEzKpVjtgZ0mAU/mMXF5s/Nw6I4jUGSRu5KUFU5qtpvYS1gA++Qirl1fKgffvGFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880819; 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=ZlvzCXS464odHkbHAJki6LozU8AT6eGKwuGt6s9tF6NA2w/iHYQGvDPbBXZBOt1AB65JVKnzfToxswRIYsdErFGdlZJ1evyAQQ4wBBfhw7RYHKZPZDEG/F98HiKOPc5ZeLx6p9Ple1QfgboNokBeFS2E6sgbjk0zXhoqpf/QI7Q= 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 1617880819102960.0524222478481; Thu, 8 Apr 2021 04:20: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-48-RpAs9nHKOE2K5Ny-EGGCLw-1; Thu, 08 Apr 2021 07:20:15 -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 2FE94802B40; Thu, 8 Apr 2021 11:20:11 +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 063725D9CC; Thu, 8 Apr 2021 11:20:11 +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 AAF861806D0F; Thu, 8 Apr 2021 11:20:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BK91o009410 for ; Thu, 8 Apr 2021 07:20:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90E685C5E1; Thu, 8 Apr 2021 11:20:09 +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 1CB715C1C4; Thu, 8 Apr 2021 11:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880818; 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=CWz8rddLYWldKDy5XSwUYPp42TQEVWJV4GviFmX+R/w8ii53w9qkP0XXexI0eHNeRzqd2h ffbGN0BuKD+kzGac+HXVbSZfEdwLBoY/Fl6jnIMHjbN5IX0TZyGzSBREhnL10Qjb2kacJL AP3pwI4YJib3U145+y4W/qK5FJuNLs4= X-MC-Unique: RpAs9nHKOE2K5Ny-EGGCLw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 2/8] virxml: Add virXMLPropTristateSwitch Date: Thu, 8 Apr 2021 13:19:52 +0200 Message-Id: <20210408111958.32678-3-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 Sat Apr 27 04:41:59 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=1617880829; cv=none; d=zohomail.com; s=zohoarc; b=YtWtw2W++E178kec50xzia37iq3vjQHKSDYwIQiyii3oy4j1HWFVgzs5UHj0nFchXLLIFdgwAPhW1YiiZ4TnZgmhoE9gbSs/iqgHiAxBsQo7Bq5Qt55xXZMCBDIMLwLlK/XHalFi+IJQg7xUFnUa9gEJumFVskB0Z1ATRq03xI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880829; 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=B6DdiEaRGUOCq1xHmvXWmb3YZqbaDsQJ2UcbVkOjNc4=; b=Jau7+T12MmhhDZWiex9ewgouzGiJHEtP/4pu6/khSC/cERByMZ5YKIpHKfK68+NJNO3HWe7UEIjVBxmfBtDaU1fvccRAxNRgLk7zlRpE7QOLUFLII1gk/jaM5wpholAlSRiWEodOI0t+PaUXbDlK0oOPp8wxTR+I+iGLQ+HxSB8= 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 1617880829519237.13967523253143; Thu, 8 Apr 2021 04:20:29 -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-505-Din8CGCENAul_o4HLwe_Qg-1; Thu, 08 Apr 2021 07:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DB17189C447; Thu, 8 Apr 2021 11:20:18 +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 45C97690F2; Thu, 8 Apr 2021 11:20:18 +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 0153855348; Thu, 8 Apr 2021 11:20:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKBqt009420 for ; Thu, 8 Apr 2021 07:20:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id A73FB5C1C4; Thu, 8 Apr 2021 11:20:11 +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 43A224DA32; Thu, 8 Apr 2021 11:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880826; 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=B6DdiEaRGUOCq1xHmvXWmb3YZqbaDsQJ2UcbVkOjNc4=; b=ae6mUIRqqcHS51Kxz8SkG7BLLCYKtAU92k10hK/KX6w05fCUZ1nJlBx0yg6/1kDW/Ga6RM VTeXrc2WdQ310Vu0pWTPPvZKT3ME75mcEWbydra1q3Z7mVycAlI/KLL2EQypIPCxgHLOFr 7qc5c9waMiworMlnmbL723rmSnQkJYI= X-MC-Unique: Din8CGCENAul_o4HLwe_Qg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 3/8] virxml: Add virXMLPropInt Date: Thu, 8 Apr 2021 13:19:53 +0200 Message-Id: <20210408111958.32678-4-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.11 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 | 57 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 +++++ 3 files changed, 64 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..bd6b75150e 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -656,6 +656,63 @@ 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) { + 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) && (*result =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; +} + + /** * 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 Sat Apr 27 04:41:59 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=1617880864; cv=none; d=zohomail.com; s=zohoarc; b=WrwXvuIV+XcXjgTV0MpOTqAz2O4hkMbiSveA0jBV0lXhg3bY89biVtrnbyKMrpFQYBJpEkmO8EXODC53JXU5t5bfQd3sbs5bmUwF+uz3oWGgfcH6/gwDRodtR/hAwprPa3b8CejJMf+urr/rlkXHwqwPc3ASk8/4jYdbS3726kg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880864; 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=xdYIZD1g5Lp/VG5nT6E0DfERa4t+Y7kgAwiwclh9sJE=; b=SEXt6wRaf2rdK7Ah7LcpcVaqg3B5RoOhnz8k3RjAcSNNiV7uMYN3wehZzZeJDDNdVsBKRKXuUyK9ExYNDgJiLsg+A4GBhD8awSs4Rld9zCZGVFeE0zEG1Na589wy4YxRCm008jWJG7lCMi8heTVmD3XPTeXrX0eGIaTsCsEwaXE= 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 1617880864923636.9918613405888; Thu, 8 Apr 2021 04:21:04 -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-555-1VZlyXshPUW11xgu0p1Oqg-1; Thu, 08 Apr 2021 07:20: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 31894A40C3; Thu, 8 Apr 2021 11:20:18 +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 F29A419D9F; Thu, 8 Apr 2021 11:20: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 A54E81806D12; Thu, 8 Apr 2021 11:20:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKFId009431 for ; Thu, 8 Apr 2021 07:20:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 674D95171E; Thu, 8 Apr 2021 11:20:15 +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 A6FCF4DA32; Thu, 8 Apr 2021 11:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880863; 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=xdYIZD1g5Lp/VG5nT6E0DfERa4t+Y7kgAwiwclh9sJE=; b=WK6wcvvTiBeRAFV5maFZGMeChbzTYTSlY50AnDAw2Ai2L9uIqUU/6b/PD/HldKhLN2bLPh T9EsLKnCIQKR4ZXMFGT/wZAEJ+BFq6eUSkATZooRzH47HTyvv64reae4SyOnGg5NERjhW+ 6nDYyc7h/TdeD0e4dcPzEznM7+CYrTY= X-MC-Unique: 1VZlyXshPUW11xgu0p1Oqg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 4/8] virxml: Add virXMLPropUInt Date: Thu, 8 Apr 2021 13:19:54 +0200 Message-Id: <20210408111958.32678-5-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.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 --- src/libvirt_private.syms | 1 + src/util/virxml.c | 61 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 ++++ 3 files changed, 68 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 bd6b75150e..fba02900f5 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -713,6 +713,67 @@ 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) { + 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) && (*result =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; +} + + /** * 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 Sat Apr 27 04:41:59 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=1617880832; cv=none; d=zohomail.com; s=zohoarc; b=URmWwsD1MV3BpxPYsYN1L3jj2f6LoRCV50+xfEiLD8jEt1LHFzxs4RE3PcIOLcLRviBuBe2bVU/DE/AWiuQ2++NsHl5LaSbJ4XIo4LitjfwQAr72sviT5vZfeGNhuL22WQioQdyBLwLz5dmfJ2s6+cpYUsiLkTMzIY/qQsP78Bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880832; 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=xwx0PoDDUoLTFqfqtGpqqgQh5/XLd4tbgXfbvo5YEfk=; b=BZmiMLfYK2JzD0TN8R94mM5vKF7Dti5pI/dNzpiwYWjpid9oagWXvfasXBxyKvSHhSNfINLsvtHN1bvDwdrc3jVrHGkUpD27+tcu0FAY7HEPnU968OSiqloVJpwinideS6hibEEr2B4YJ/lPzi9UruqQpHFNo8COziuncrGuoKU= 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 1617880832837825.919504066745; Thu, 8 Apr 2021 04:20:32 -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-133-U_fze0B_OMSTWdx7WfL9kg-1; Thu, 08 Apr 2021 07:20:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B61FF801597; Thu, 8 Apr 2021 11:20:21 +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 8DF9371288; Thu, 8 Apr 2021 11:20:21 +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 5567D5534A; Thu, 8 Apr 2021 11:20:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKGXC009436 for ; Thu, 8 Apr 2021 07:20:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 906F65C5E1; Thu, 8 Apr 2021 11:20:16 +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 CE0FA5C1C4; Thu, 8 Apr 2021 11:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880831; 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=xwx0PoDDUoLTFqfqtGpqqgQh5/XLd4tbgXfbvo5YEfk=; b=TkYNVmJ3ADvl8gz3eihW8XaRm4wH2zz6GdBuzbTA1n3OR12tpKisisEOp4GkIx1I56JqBh 0925m5GfHEF7SFZsZgeiz7AcWRoFbZ0CC2gzAMGBYLUQ/QIQwNZch9Smda2gnymRHxGNQ2 Q9Gbhqw3MqdvqW4m4NTCatW7k4VnJA8= X-MC-Unique: U_fze0B_OMSTWdx7WfL9kg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 5/8] virxml: Add virXMLPropEnum Date: Thu, 8 Apr 2021 13:19:55 +0200 Message-Id: <20210408111958.32678-6-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.13 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 | 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 fba02900f5..8147266557 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -774,6 +774,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 Sat Apr 27 04:41:59 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=1617880831; cv=none; d=zohomail.com; s=zohoarc; b=D7C+MdNU2Ulx30607K/PaPUWmgSj+rcbt6rUIyXK6InNJweJ17asybDCRy9GaJa4uhOp2HyWMGAMPrtgbdKhiHP1LnvEb9MYFuHT5xMDVusfYSvIJyLFZS0IrvCTKkubHmb3mYJvkBa8M6v7IbhZBVrglLr8MjdsQCBi8p3BA4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880831; 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=CX2uJAqShz1kfKiBc/5gnCO9aMYsBUKOI/006oCGtFFGvRhJd/5g7IBqW8IMK8juctCCQWNS+dOml9qoWpQLFO3vmomVSvTVitJGu12P1CqlVJ4AUEUwykMMCCE4BlIEbmmR2UDGE1jW0eufDvtKGpfDZ+QSSbs/NkEQrDV1OW0= 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 1617880831878107.95902246957769; Thu, 8 Apr 2021 04:20:31 -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-268-YBtOKnQdPxmkQL94uK_nLQ-1; Thu, 08 Apr 2021 07:20:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CCE9107ACC7; Thu, 8 Apr 2021 11:20:22 +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 D9ACF690F7; Thu, 8 Apr 2021 11:20:21 +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 9EDD55534B; Thu, 8 Apr 2021 11:20:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKJjW009454 for ; Thu, 8 Apr 2021 07:20:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 923904DA32; Thu, 8 Apr 2021 11:20:19 +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 144075C1C4; Thu, 8 Apr 2021 11:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880830; 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=bCj4TB+WPZLXFG3vBTp60+awotdXtuO5w6k2W7PzNqPTIKNG+pTD4TzjDRNEL1Y4I2fACl 3AyrzPKj4mdiIRagDMhmN2yhOHfVfqjHh/Ex7npcmerZ3nz1ZENm/TLUDWqj+Y3b41g2SH Vl5Oem8UseVj/HMceWXyz2R958LJhV8= X-MC-Unique: YBtOKnQdPxmkQL94uK_nLQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 6/8] virNetworkForwardNatDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 13:19:56 +0200 Message-Id: <20210408111958.32678-7-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.11 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 Sat Apr 27 04:41:59 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=1617880933; cv=none; d=zohomail.com; s=zohoarc; b=IbxWM7lxnEmrr4jdpMmqygQHr/DzVSV8P/9o/TAOzz+o3nd99t1XhsnIcoCm7Ygnj4jcNQGxmHAE9J4JgR9/DJKHa9UwZeJ3NgvMJwZjXnWcvZEA9Wq1pNIFOl9qc2Tvo94ZyDAuNaceInodwkK4xGkjyiY2rqfEItJ1bKJygiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880933; 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=MdXaMQxVsaGjubyYMM4wHtVSsN+U7syHu3kdg5hDaa/1w4DMQZN/cSH/KHg5oO6gBMCeR3lr4tXr9IouIzF2YqWtzGKxeDKGxrnBQjejKnydeNGUtj/GTzYAZR3zYxkHG4/FdEGUr4EsaMyEqLg1tWMXILwx4Z+yqfle89gwxxc= 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 1617880933403724.51382608616; Thu, 8 Apr 2021 04:22: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-57-8igZK3aKOLqxFj5U5VANlw-1; Thu, 08 Apr 2021 07:20:39 -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 B82E6A40C3; Thu, 8 Apr 2021 11:20:33 +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 90C645DAA5; Thu, 8 Apr 2021 11:20:33 +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 415B51806D10; Thu, 8 Apr 2021 11:20:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKVDo009572 for ; Thu, 8 Apr 2021 07:20:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E4B7F5171E; Thu, 8 Apr 2021 11:20:31 +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 E86FC5C5E1; Thu, 8 Apr 2021 11:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880932; 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=XH7/Cu0h9/EbLTQzXPEynSWOyVNSZ6LT+W41L93TOqFs2Oic3FUmLlR75YaJ9263z4cXV4 FN1/qG3nrSzKrhcZ9IXnmkJCYBM2nfGji5LkHirWH6CU30vGgjPIW5EJSYyVAtHYQucq2F UPgbikAmon+PGJoQKvObY54lZe/Ci+8= X-MC-Unique: 8igZK3aKOLqxFj5U5VANlw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 7/8] virDomainIOThreadIDDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 13:19:57 +0200 Message-Id: <20210408111958.32678-8-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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 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 Sat Apr 27 04:41:59 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=1617880843; cv=none; d=zohomail.com; s=zohoarc; b=VVl4k7ec59qDLbOiPqs7tiNwcm88lXj82VInIT9g7HvTmt1A2b2fqhYt4e/SrWjKWW0cErSzzQgILOnMk0jZuj9NPsLsjfSAdnEzEUeTEOc5F3XFxuU32qs1mT3yjHO02WTyh6oW3nevWxpjDabL76dueFuTN0vx1pe6hO8ocUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617880843; 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=O8svXr+qsW18tjs3lGXeSrip1FX72SPt6GD6C1HOS+MkOi5GqEKbbL4isrTx7h1O7XdYbNlf6hKhkJQApWv4FgOQRLtxK7e10WDzeWjg0DmFbSie/GY6+vO+8hpreWWrzQ4AjP2It29scYUr0ytUua3+n/IU5mFBQiaL57mKHac= 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 1617880843867352.7635700423681; Thu, 8 Apr 2021 04:20:43 -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-530-kLX7npqTMfCxlm_q4ZEYfg-1; Thu, 08 Apr 2021 07:20:40 -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 AEB3D106BB49; Thu, 8 Apr 2021 11:20:35 +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 8B5215B698; Thu, 8 Apr 2021 11:20:35 +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 514705534D; Thu, 8 Apr 2021 11:20:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 138BKYY9009604 for ; Thu, 8 Apr 2021 07:20:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14EE25171E; Thu, 8 Apr 2021 11:20:34 +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 CDAEF4DA32; Thu, 8 Apr 2021 11:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617880842; 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=KhifpWMI0hKgz4By4WdUGGUOkevU9PWYY6TmhGmCIxIZSoUu8I2zb+XgmCNejZ48ic5sFu Hj/xZRpoVBKSemlqBhRdiKHGiEnB6vg/EaHP7YPb1lzZIsYYzTraHilgwTMGznVEQENtac zWoIjSRrWjkY803JPiRxGeu4ewH3DNI= X-MC-Unique: kLX7npqTMfCxlm_q4ZEYfg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 8/8] virCPUDefParseXML: Use virXMLProp* Date: Thu, 8 Apr 2021 13:19:58 +0200 Message-Id: <20210408111958.32678-9-twiederh@redhat.com> In-Reply-To: <20210408111958.32678-1-twiederh@redhat.com> References: <20210408111958.32678-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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