From nobody Tue Feb 10 05:45:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1640183095; cv=none; d=zohomail.com; s=zohoarc; b=I15j7kUTSr85jcWXwVRRLxqB19YCRKfBdp6EspDkd+ny+1uFtBnnPjDNK4eUI+xRpUN3FIrU2eyD6zVJEHfq1JNOfmP/S15A0FlAWqqhteVgM5yZqwhFmGS0ib8MV+8bFUYwhp+e9GnbNM3a/5923+2kssq7/h2y4G2wjrcYixE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183095; 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=ZeDHUgbS/+o10rV2xDgS2Q0NIB9Ak78DtnnBEATHHTg=; b=MdMzFTSwBgKZlbXZ3stK55q56U69jT1nCyJx/9SWyNJAnlTthTZ1yHDAoDe0E3vwQE3+rAVP/pLv5K/MdboOVaHuk91x6L0rpKc4+2jMDKLIfVxKgDyQXDtlG5ET0z3Z8f6QfI2L+otdKyedr6mJgTeTZ8j5DRymuUBX8irlM28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 164018309549339.79514996134037; Wed, 22 Dec 2021 06:24:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-Mn2FwivKOlWxZ_S6FzW8aw-1; Wed, 22 Dec 2021 09:24:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1EEB801AAB; Wed, 22 Dec 2021 14:24:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3F27ADD6; Wed, 22 Dec 2021 14:24:43 +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 25F8F4BB7C; Wed, 22 Dec 2021 14:24:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1BMEOVU3029912 for ; Wed, 22 Dec 2021 09:24:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 12E0170D28; Wed, 22 Dec 2021 14:24:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6288370D24 for ; Wed, 22 Dec 2021 14:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183094; 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=ZeDHUgbS/+o10rV2xDgS2Q0NIB9Ak78DtnnBEATHHTg=; b=Qwi20FB0MeBWgiTI9YMJ1srATWTJqcTyPFwzqeGBrxQ4593HN9pYS8F8p4JD5MAekDCdvs oV5ScLR0JXvhI4gBtF2MDRoTua6LbqrSN+51G2gtVttEVR6d0JOD6kxfU/gzdGNR7kFErX yH6OCp/QAO19GQjodZHbWxy8IkH8pBY= X-MC-Unique: Mn2FwivKOlWxZ_S6FzW8aw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] util: json: Introduce virJSONValueObjectReplaceValue Date: Wed, 22 Dec 2021 15:24:06 +0100 Message-Id: <9745a29eb1450643543c5461543357b52c584398.1640182750.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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.14 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) X-ZM-MESSAGEID: 1640183096520100001 Content-Type: text/plain; charset="utf-8" The new helper replaces the 'value' part of the key-value tuple in an object. The advantage of this new helper is that it preserves the ordering of the key in the object when compared to a combination of stealing the old key and adding a new value. This will be needed for a new test/helper for validating and modifying qemu capabilities data. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virjson.c | 20 ++++++++++++++++++++ src/util/virjson.h | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 435ee8054c..431075899d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2567,6 +2567,7 @@ virJSONValueObjectHasKey; virJSONValueObjectKeysNumber; virJSONValueObjectPrependString; virJSONValueObjectRemoveKey; +virJSONValueObjectReplaceValue; virJSONValueObjectStealArray; virJSONValueObjectStealObject; virJSONValueToBuffer; diff --git a/src/util/virjson.c b/src/util/virjson.c index 1c6fef22da..6e13e97e15 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1149,6 +1149,26 @@ virJSONValueObjectGetString(virJSONValue *object, } +void +virJSONValueObjectReplaceValue(virJSONValue *object, + const char *key, + virJSONValue **newval) +{ + size_t i; + + if (object->type !=3D VIR_JSON_TYPE_OBJECT || + !*newval) + return; + + for (i =3D 0; i < object->data.object.npairs; i++) { + if (STREQ(object->data.object.pairs[i].key, key)) { + virJSONValueFree(object->data.object.pairs[i].value); + object->data.object.pairs[i].value =3D g_steal_pointer(newval); + } + } +} + + /** * virJSONValueObjectGetStringOrNumber: * @object: JSON value object diff --git a/src/util/virjson.h b/src/util/virjson.h index f0b8c419de..aced48a538 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -248,6 +248,12 @@ virJSONValueObjectRemoveKey(virJSONValue *object, virJSONValue **value) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +void +virJSONValueObjectReplaceValue(virJSONValue *object, + const char *key, + virJSONValue **newval) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); + int virJSONValueArrayAppendString(virJSONValue *object, const char *value); --=20 2.31.1