From nobody Mon Feb 9 00:02:37 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=1663577885; cv=none; d=zohomail.com; s=zohoarc; b=nlfnS+nVQlRSKLIcHOX63OZg9p4YOamXDPDvUArJoUptEgBWxTTud3mAnM+23jwSJQoqpoiu5ZcwGXQf8tvTk+Dg0pfDbwjNIxW6OUhxReUFxi01Sq/kLkFxWT8IthcQc2vLRZXPN5difhModbQPGHXw6fVvJCQf48Ac6mvNil8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663577885; h=Content-Type:Content-Transfer-Encoding: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=DXzhKrrqge/+JBu+Hit1mfeDvvHDOltZEesusjP69Ac=; b=hFp0lb76IbrSv3LxBQHc1w8g+ceHgM0Rb7OHRon/ePBNiV6+K+fNPeX9OA7yY29NsiAy/1CctOkHTem/1Bv05dlNF7oSmSxIXr/PXtHDSe7luQqDBHYq4GDefxQRPTT3ERfiqj99oyUudKvH0HyrFh9F8cfgEqpaTa3uZdlqnkM= 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) 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 1663577885294831.2651508621042; Mon, 19 Sep 2022 01:58:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-CETWpB66OfqUZZyp90Q-PQ-1; Mon, 19 Sep 2022 04:55:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A5EA5800B30; Mon, 19 Sep 2022 08:55:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93CC735429; Mon, 19 Sep 2022 08:55:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 78D4319465A3; Mon, 19 Sep 2022 08:55:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9529319465A3 for ; Mon, 19 Sep 2022 08:55:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 84C4540C6EC3; Mon, 19 Sep 2022 08:55:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id F096140C6EC2 for ; Mon, 19 Sep 2022 08:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663577884; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=DXzhKrrqge/+JBu+Hit1mfeDvvHDOltZEesusjP69Ac=; b=TreO3caE1vW3DHKlTnV/toiei7u86evCLfrP2wBRS5eqU9j3zUKh8M04cC+vn7f4bIedNL DWlp1osjY5hJgaOP9heQS42mlcXDvm//AwMhOlqe89f7gBlsA3bByjIBmiAqvG0v01T8NN YAOvwwV7fWyEDIpWjxdOalND4rF0XfM= X-MC-Unique: CETWpB66OfqUZZyp90Q-PQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/37] util: xml: Introduce virXMLPropLongLong Date: Mon, 19 Sep 2022 10:55:02 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663577886056100002 Content-Type: text/plain; charset="utf-8" Add a helper for parsing long long values from XML properties with semantics like virXMLPropInt. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virxml.c | 64 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 9 ++++++ 3 files changed, 74 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 01bb349e05..5be40dbefe 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3682,6 +3682,7 @@ virXMLPickShellSafeComment; virXMLPropEnum; virXMLPropEnumDefault; virXMLPropInt; +virXMLPropLongLong; virXMLPropString; virXMLPropStringRequired; virXMLPropTristateBool; diff --git a/src/util/virxml.c b/src/util/virxml.c index b94af9c7a3..0a91fd237e 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -750,6 +750,70 @@ virXMLPropUInt(xmlNodePtr node, } +/** + * virXMLPropLongLong: + * @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 + * @defaultResult: default value of @result in case the property is not fo= und + * + * Convenience function to return value of a long long 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 +virXMLPropLongLong(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + long long *result, + long long defaultResult) +{ + g_autofree char *tmp =3D NULL; + long long val; + + *result =3D defaultResult; + + 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_ll(tmp, NULL, base, &val) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected long long integer value"), + name, node->name, tmp); + return -1; + } + + if ((flags & VIR_XML_PROP_NONNEGATIVE) && (val < 0)) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected non-negative 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; +} + + /** * virXMLPropULongLong: * @node: XML dom node pointer diff --git a/src/util/virxml.h b/src/util/virxml.h index 42d3740c58..3b00d20ea9 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -141,6 +141,15 @@ virXMLPropUInt(xmlNodePtr node, unsigned int *result) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5); +int +virXMLPropLongLong(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + long long *result, + long long defaultResult) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5); + int virXMLPropULongLong(xmlNodePtr node, const char* name, --=20 2.37.1