From nobody Tue Feb 10 01:19:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617872250; cv=none; d=zohomail.com; s=zohoarc; b=JQXlLCZJvAw36pih0ejFUUpW4kGU0cQugUBS6evQ0+l1pcE1rCj+1ToAukWtPRUm0X8g91mk4Cw2UosopEiMAYAN0fnk9Wp7ZGN/5f/iRHi7AX9N0a0IaWTba3eUFWd5YvoMj3MrmxYW0DhSySvnzqlMYKqJOZxbFYnJH0/KONE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617872250; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n7bDuN4Se9+NAHCpTaC34Ev42Ir8ch1gG7+2/9FS0ek=; b=nAlwxEU5G5ZB8bHI7aEe/gZwKyS1rxBJSsVN7Q4OB794/ZvgttA12CsAn/H5G9+yu//THmVgdsy0vvouwZLTqzbEVANdsF5vFKAbM3AlLxERn4CKyZepkalVVQO0y5hrl76ZGpv8kfvU4HegA5+Jb7r7pmKREwTnYN4a45ohkdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1617872250978774.2163885211103; Thu, 8 Apr 2021 01:57:30 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-l2aKKSLJMh6gbtRLAOBvzw-1; Thu, 08 Apr 2021 04:57:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A79AB1006C80; Thu, 8 Apr 2021 08:57:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BFD15D755; Thu, 8 Apr 2021 08:57:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 28E5A1806D06; Thu, 8 Apr 2021 08:57:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1388vKfi013687 for ; Thu, 8 Apr 2021 04:57:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id F02A75D9E3; Thu, 8 Apr 2021 08:57:20 +0000 (UTC) Received: from work.redhat.com (ovpn-112-196.ams2.redhat.com [10.36.112.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A68E5D9CC; Thu, 8 Apr 2021 08:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617872249; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=n7bDuN4Se9+NAHCpTaC34Ev42Ir8ch1gG7+2/9FS0ek=; b=W4y3OrzEszyvG1ksHdVdVnzHm/TdS/8PnjOy5ryXokyRiCOd/y0O5FuILNkJaa2Ovj+VVB Iopp0lxy1b9f8vTjJxHlxkWva1hpDKA1eP58Db9yt3FcymSOF09ZwItNM+prPwThnQ+X25 m1VlTgjaTj8LHQY+InBIApoRErKFdoE= X-MC-Unique: l2aKKSLJMh6gbtRLAOBvzw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 3/8] virxml: Add virXMLPropInt Date: Thu, 8 Apr 2021 10:57:05 +0200 Message-Id: <20210408085710.19379-4-twiederh@redhat.com> In-Reply-To: <20210408085710.19379-1-twiederh@redhat.com> References: <20210408085710.19379-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Convenience function to return the value of an integer XML attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 +++++ 3 files changed, 58 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 776387e6b3..bdb63349ee 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3544,6 +3544,7 @@ virXMLNodeSanitizeNamespaces; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropInt; virXMLPropString; virXMLPropStringLimit; virXMLPropTristateBool; diff --git a/src/util/virxml.c b/src/util/virxml.c index f62c5c39c4..807cb7dae9 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -656,6 +656,57 @@ virXMLPropTristateSwitch(xmlNodePtr node, const char* = name, } =20 =20 +/** + * virXMLPropInt: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @base: Number base, see strtol + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * + * Convenience function to return value of an integer attribute. + * + * Returns 1 in case of success in which case @result is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropInt(xmlNodePtr node, const char *name, int base, + virXMLPropFlags flags, int *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + + if (!node || !name || !result) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid argument to %s"), + __FUNCTION__); + return -1; + } + + if (!(tmp =3D virXMLPropString(node, name))) { + if ((flags & VIR_XML_PROP_REQUIRED) !=3D VIR_XML_PROP_REQUIRED) + return 0; + + virReportError(VIR_ERR_XML_ERROR, + _("Missing required attribute '%s' in element '%s'"= ), + name, node->name); + return -1; + } + + ret =3D virStrToLong_i(tmp, NULL, base, result); + + if ((ret < 0) || ((flags & VIR_XML_PROP_NONZERO) && (*result =3D=3D 0)= )) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + name, node->name, tmp); + return -1; + } + + return 1; +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index a5ecfbb01a..aba863ae11 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -36,6 +36,7 @@ xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) typedef enum { VIR_XML_PROP_OPTIONAL =3D 0, /* Attribute may be absent */ VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be abse= nt */ + VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero= */ } virXMLPropFlags; =20 int virXPathBoolean(const char *xpath, @@ -91,6 +92,11 @@ int virXMLPropTristateSwitch(xmlNodePtr node, const char *name, virXMLPropFlags flags, virTristateSwitch *result); +int virXMLPropInt(xmlNodePtr node, + const char *name, + int base, + virXMLPropFlags flags, + int *result); =20 /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.26.2