From nobody Sat Apr 27 14:06:26 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1535386635874322.0651486661725; Mon, 27 Aug 2018 09:17:15 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id DBE8837E74; Mon, 27 Aug 2018 16:17:13 +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 98EE35B681; Mon, 27 Aug 2018 16:17:13 +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 1FB98180610F; Mon, 27 Aug 2018 16:17:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7RGHB9H001585 for ; Mon, 27 Aug 2018 12:17:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01A851012335; Mon, 27 Aug 2018 16:17:11 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9231F10075FC for ; Mon, 27 Aug 2018 16:17:08 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 27 Aug 2018 18:17:05 +0200 Message-Id: <9c4ed4cc393cf33c1548cbe1a2d40288bbc3f542.1535386625.git.pkrempa@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: json: Allow converting a virTristate(Bool|Switch) into JSON 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 27 Aug 2018 16:17:14 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new modifier letter for virJSONValueObjectAddVArgs which will add a boolean value with our tristate semantics. The value is omitted when the _ABSENT value is used. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- src/util/virjson.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/virjson.c b/src/util/virjson.c index 29530dcb15..e45f1fab06 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -142,6 +142,8 @@ virJSONValueGetType(const virJSONValue *value) * * b: boolean value * B: boolean value, omitted if false + * T: boolean value specified by a virTristate(Bool|Switch) value, omitted= on + * the _ABSENT value * * d: double precision floating point number * n: json null value @@ -266,12 +268,23 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, } break; case 'B': + case 'T': case 'b': { int val =3D va_arg(args, int); if (!val && type =3D=3D 'B') continue; + if (type =3D=3D 'T') { + if (val =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + continue; + + if (val =3D=3D VIR_TRISTATE_BOOL_NO) + val =3D 0; + else + val =3D 1; + } + rc =3D virJSONValueObjectAppendBoolean(obj, key, val); } break; --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list