From nobody Mon Feb 9 00:26:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580481257782569.5943078649136; Fri, 31 Jan 2020 06:34:17 -0800 (PST) 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-282-6RgmNGTnMWy3qafr8nO6qA-1; Fri, 31 Jan 2020 09:34:13 -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 201D2DB22; Fri, 31 Jan 2020 14:34:07 +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 F334D5D9E5; Fri, 31 Jan 2020 14:34:06 +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 AFC271803C40; Fri, 31 Jan 2020 14:34:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00VEVhkL019790 for ; Fri, 31 Jan 2020 09:31:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9B4FA89E7A; Fri, 31 Jan 2020 14:31:43 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C889F86C4B; Fri, 31 Jan 2020 14:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580481256; 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=Cn9tQm0/x3pAgzdr4bjWkqZaMGxrjIsrz+pVQVr455I=; b=Dk6/uWIfW2gAwmVCGrGlpEZZV8QDGD8Yjb3YOVF1HK7SgLKc4UETnnpPgJ1uvCo/k1mVjR bHxpKKM4JYocW/OZvH8wY9Hd0LLWZFYZJxnnyCUrcvzydQDMmFei86stm2Jmdj9XUzKevw KptiEeov9cvXius97XOAFzfr7iMgKL0= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/19] util: json: Introduce virJSONValueArrayConcat Date: Fri, 31 Jan 2020 15:31:13 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Peter Krempa 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 X-MC-Unique: 6RgmNGTnMWy3qafr8nO6qA-1 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" Add a helper that concatenates the second array into the first. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virjson.c | 31 +++++++++++++++++++++++++++++++ src/util/virjson.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ebf830791e..b2d2420415 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2284,6 +2284,7 @@ virISCSIScanTargets; virJSONStringReformat; virJSONValueArrayAppend; virJSONValueArrayAppendString; +virJSONValueArrayConcat; virJSONValueArrayForeachSteal; virJSONValueArrayGet; virJSONValueArraySize; diff --git a/src/util/virjson.c b/src/util/virjson.c index 988a09e956..50993648eb 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -811,6 +811,37 @@ virJSONValueArrayAppendString(virJSONValuePtr object, } +/** + * virJSONValueArrayConcat: + * @a: JSON value array (destination) + * @c: JSON value array (source) + * + * Merges the members of @c array into @a. The values are stolen from @c. + */ +int +virJSONValueArrayConcat(virJSONValuePtr a, + virJSONValuePtr c) +{ + size_t i; + + if (a->type !=3D VIR_JSON_TYPE_ARRAY || + c->type !=3D VIR_JSON_TYPE_ARRAY) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("expecting JSON arr= ay")); + return -1; + } + + a->data.array.values =3D g_renew(virJSONValuePtr, a->data.array.values, + a->data.array.nvalues + c->data.array.n= values); + + for (i =3D 0; i < c->data.array.nvalues; i++) + a->data.array.values[a->data.array.nvalues++] =3D g_steal_pointer(= &c->data.array.values[i]); + + c->data.array.nvalues =3D 0; + + return 0; +} + + int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key) diff --git a/src/util/virjson.h b/src/util/virjson.h index 7a6b063b17..0894e91b59 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -71,6 +71,8 @@ virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapP= tr bitmap); int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJ= SONValuePtr value); int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value); +int virJSONValueArrayConcat(virJSONValuePtr a, + virJSONValuePtr c); int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key); virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *= key); --=20 2.24.1