From nobody Mon Feb 9 16:02:09 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=1605895847; cv=none; d=zohomail.com; s=zohoarc; b=Y/rrP91Hgz5DKZ3xb4xAkoYCePzuTdanyV6zWC3hMOtVFZOGS4QC2AxGyRYbxQMwcgDZYarRUf6bD5KJS279H7853ghvRSUhMAftDzBDEbxM9C6J0gZX7hUfEkgTwVl7XEAigAoDlUZshgU/hh+SR75J8ZX9XXo9vRA3VVTUA2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605895847; 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=HknMPJEdwxcA1Fu/wMyxr4JwZXQy16xSE9i1QghURAY=; b=Z9G/jvDEdwFeYSDt9oJqIPLePobvLCD+NPKoddh+CA6bowvsgtx/yqveJVCR8IWEU4zY6F7P/4e84v/HyI/8msIxjsuGs9lu8GTdcace7dSXfwRiSRj332niobRU7n8xl9us+LmIaY+VjL3kwqQYcO4WkBuH9OsJ90eqqV8C2MQ= 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 160589584700844.79463934178068; Fri, 20 Nov 2020 10:10:47 -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-581-waTHH2atPmGyic5WAHqluw-1; Fri, 20 Nov 2020 13:10:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88217802B53; Fri, 20 Nov 2020 18:10:35 +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 64EF4620D7; Fri, 20 Nov 2020 18:10:35 +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 320284E58E; Fri, 20 Nov 2020 18:10:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AKIAYT8010425 for ; Fri, 20 Nov 2020 13:10:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 247C85D6D1; Fri, 20 Nov 2020 18:10:34 +0000 (UTC) Received: from localhost (unknown [10.36.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id C76985D6CF; Fri, 20 Nov 2020 18:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605895846; 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=HknMPJEdwxcA1Fu/wMyxr4JwZXQy16xSE9i1QghURAY=; b=eesQbMxUOf0alZ0NAw+CjwDR6ZZL46K8YzdutDO4Y/HssduzZ+YQFrtEM/WBdEMgihkZF1 PHi+TqD1YIiUyGLC5UMAfeHFXc5OvUytm9B00AG5lLBYo8E9klpzeurikXgjQuVphF+0nQ FDItUhuqSRgClAKeb7xF3pjuA4dZZcY= X-MC-Unique: waTHH2atPmGyic5WAHqluw-1 From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] util: json: add virJSONValueObjectGetStringArray convenience Date: Fri, 20 Nov 2020 22:09:43 +0400 Message-Id: <20201120180948.203254-5-marcandre.lureau@redhat.com> In-Reply-To: <20201120180948.203254-1-marcandre.lureau@redhat.com> References: <20201120180948.203254-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Michal=20Pr=C3=ADvozn=C3=ADk?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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.11 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- src/libvirt_private.syms | 1 + src/util/virjson.c | 30 ++++++++++++++++++++++++++++++ src/util/virjson.h | 1 + 3 files changed, 32 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 79a23f34cb..0f8447cfbb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2408,6 +2408,7 @@ virJSONValueObjectGetNumberUint; virJSONValueObjectGetNumberUlong; virJSONValueObjectGetObject; virJSONValueObjectGetString; +virJSONValueObjectGetStringArray; virJSONValueObjectGetValue; virJSONValueObjectHasKey; virJSONValueObjectIsNull; diff --git a/src/util/virjson.c b/src/util/virjson.c index 3fa9a9ca24..05c4804410 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1463,6 +1463,36 @@ virJSONValueObjectIsNull(virJSONValuePtr object, return virJSONValueIsNull(val); } =20 +char ** +virJSONValueObjectGetStringArray(virJSONValuePtr object, const char *key) +{ + g_auto(GStrv) ret =3D NULL; + virJSONValuePtr data; + size_t n; + size_t i; + + data =3D virJSONValueObjectGetArray(object, key); + if (!data) + return NULL; + + n =3D virJSONValueArraySize(data); + ret =3D g_new0(char *, n + 1); + for (i =3D 0; i < n; i++) { + virJSONValuePtr child =3D virJSONValueArrayGet(data, i); + const char *tmp; + + if (!(tmp =3D virJSONValueGetString(child))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s array element does not contain a string"), + key); + return NULL; + } + + ret[i] =3D g_strdup(tmp); + } + + return g_steal_pointer(&ret); +} =20 /** * virJSONValueObjectForeachKeyValue: diff --git a/src/util/virjson.h b/src/util/virjson.h index 588c977650..4dc7ed1a2d 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -117,6 +117,7 @@ virJSONValuePtr virJSONValueObjectStealObject(virJSONVa= luePtr object, const char *key); =20 const char *virJSONValueObjectGetString(virJSONValuePtr object, const char= *key); +char **virJSONValueObjectGetStringArray(virJSONValuePtr object, const char= *key); const char *virJSONValueObjectGetStringOrNumber(virJSONValuePtr object, co= nst char *key); int virJSONValueObjectGetNumberInt(virJSONValuePtr object, const char *key= , int *value); int virJSONValueObjectGetNumberUint(virJSONValuePtr object, const char *ke= y, unsigned int *value); --=20 2.29.0