From nobody Mon Feb 9 20:09:36 2026 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=1619020320; cv=none; d=zohomail.com; s=zohoarc; b=RNvp6Nm9DJgqh47kcvULTsbR3sCfWMnG/a2CrCP1EzTnQPGkVeFldKVUxpP8RJimn8HQjigFfNpbB+pKjXWUSkxdCJeEgZu8pDKiIzihCKLtwU+xYAbm0ImpKmX45SkeM3DoDKvVsq+idbmDLbaDWrggSmXlb6vrNlE3YJA9E0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619020320; 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=3epzn8FWn76vj4i8TuuCwCRrUj5HEVTkXulpb5qbnyg=; b=KnWTt2YWUFyApb7lQ2SGPF0/U6v+UUrmR22Ja9pelV+3LbsXpd732xemtWaQh4rVaOMN+I0blOAUf9IkDh39IZWlwHDrgG78xV6tHXCmF8hJbMNjyLZUXKjTX/nS/K8ij9UkDKQNtyuKZ8gYLYt0ASsrX1Qvb36L7Vmyf7RYvVY= 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 1619020320420537.2352357973331; Wed, 21 Apr 2021 08:52:00 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-123-14eHwNtHNrO1aw-JZmU-wA-1; Wed, 21 Apr 2021 11:51:57 -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 00356343A4; Wed, 21 Apr 2021 15:51:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA1171972B; Wed, 21 Apr 2021 15:51:50 +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 94C7F1806D1D; Wed, 21 Apr 2021 15:51:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13LFphkJ006898 for ; Wed, 21 Apr 2021 11:51:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC0B4100AE2C; Wed, 21 Apr 2021 15:51:43 +0000 (UTC) Received: from work.redhat.com (ovpn-112-172.ams2.redhat.com [10.36.112.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08CF110016DB; Wed, 21 Apr 2021 15:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619020319; 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=3epzn8FWn76vj4i8TuuCwCRrUj5HEVTkXulpb5qbnyg=; b=BAnHOte6Z60hy6UCqfuJYCT02q5WzV+YP0PR2ONnfYsTolzN0a/6BXqFbGH4mVDKV/twZO fdRZwf5v3ZCqxEEbgQ1Cedk2g735+uQ5KaHLodz7gfmqz37+5dEnKpIJtXuamsViFFQ++B bocqwCJEP1wMHy0hQDMvw8MEHx0VElI= X-MC-Unique: 14eHwNtHNrO1aw-JZmU-wA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 04/10] virxml: Add virXMLPropULongLong Date: Wed, 21 Apr 2021 17:51:27 +0200 Message-Id: <20210421155133.162030-5-twiederh@redhat.com> In-Reply-To: <20210421155133.162030-1-twiederh@redhat.com> References: <20210421155133.162030-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 long long XML attribute. Signed-off-by: Tim Wiederhake --- src/libvirt_private.syms | 1 + src/util/virxml.c | 56 ++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 8 ++++++ 3 files changed, 65 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index abd3dc4bd1..0e6bf3d5b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3554,6 +3554,7 @@ virXMLPropStringLimit; virXMLPropTristateBool; virXMLPropTristateSwitch; virXMLPropUInt; +virXMLPropULongLong; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index 5ceef73814..b79050db35 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -755,6 +755,62 @@ virXMLPropUInt(xmlNodePtr node, } =20 =20 +/** + * virXMLPropULongLong: + * @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 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 +virXMLPropULongLong(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + unsigned long long *result) +{ + g_autofree char *tmp =3D NULL; + int ret; + unsigned long long 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; + } + + ret =3D virStrToLong_ullp(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; +} + + /** * virXMLPropEnum: * @node: XML dom node pointer diff --git a/src/util/virxml.h b/src/util/virxml.h index c83d16a14a..13c543fbb6 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -134,6 +134,14 @@ virXMLPropUInt(xmlNodePtr node, unsigned int *result) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); =20 +int +virXMLPropULongLong(xmlNodePtr node, + const char* name, + int base, + virXMLPropFlags flags, + unsigned long long *result) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); + int virXMLPropEnum(xmlNodePtr node, const char* name, --=20 2.26.3