From nobody Wed May 14 17:00:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407583007909.3404811626259; Fri, 30 Mar 2018 03:59:43 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 549C628132; Fri, 30 Mar 2018 10:59:41 +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 31A2060BEF; Fri, 30 Mar 2018 10:59:41 +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 F2EF1181BA07; Fri, 30 Mar 2018 10:59:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2UAxSEB011069 for ; Fri, 30 Mar 2018 06:59:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 058BE63537; Fri, 30 Mar 2018 10:59:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834D96352A; Fri, 30 Mar 2018 10:59:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:13 +0200 Message-Id: <17118230d51f211d6d2dc556f0b0ceaefee7936f.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 6/9] util: json: Add accessor for geting a VIR_JSON_TYPE_NUMBER as string 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 30 Mar 2018 10:59:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sometimes it's desired to get a JSON number as string. Add a helper. This will help in cases where we'd want to conver the internal type from string to something else. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virjson.c | 10 ++++++++++ src/util/virjson.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03fe3b315f..989411cdca 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2038,6 +2038,7 @@ virJSONValueGetBoolean; virJSONValueGetNumberDouble; virJSONValueGetNumberInt; virJSONValueGetNumberLong; +virJSONValueGetNumberString; virJSONValueGetNumberUint; virJSONValueGetNumberUlong; virJSONValueGetString; diff --git a/src/util/virjson.c b/src/util/virjson.c index 212c158da0..6f2b52257f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1043,6 +1043,16 @@ virJSONValueGetString(virJSONValuePtr string) } +const char * +virJSONValueGetNumberString(virJSONValuePtr number) +{ + if (number->type !=3D VIR_JSON_TYPE_NUMBER) + return NULL; + + return number->data.number; +} + + int virJSONValueGetNumberInt(virJSONValuePtr number, int *value) diff --git a/src/util/virjson.h b/src/util/virjson.h index 017a1f20ed..e80d10dea1 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -134,6 +134,7 @@ const char *virJSONValueObjectGetKey(virJSONValuePtr ob= ject, unsigned int n); virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigne= d int n); const char *virJSONValueGetString(virJSONValuePtr object); +const char *virJSONValueGetNumberString(virJSONValuePtr number); int virJSONValueGetNumberInt(virJSONValuePtr object, int *value); int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value); int virJSONValueGetNumberLong(virJSONValuePtr object, long long *value); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list