From nobody Sat May 18 21:45:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615555340; cv=none; d=zohomail.com; s=zohoarc; b=KuJGXjbAlh27FEkGUL/GR5oyo3hA7gHV5XVa+PsZkQddm+FXt/SGMgqamaa144Pfek0EzLnoTxkimHTBj4FbQk4x6Sz3i2WQlxFx7B8HuJNzFyBVDprXA4lO6KT9jkwu4X0UxcEDR8q04rog8w+Y/KnLE32f3POluHj5Hf4lA7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615555340; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=NiVh9a+s5xJmZwKdaW1j2o8lJQu15+edSMc644xjHto=; b=CELR02gtuwzLPo8lPvaK6nf5cTa9pmZjCEH3HOBoxLB5en+nDnWq1aLURk6ExMx0anzaHH6ElgqR/TYvNf5gB9glXf+jqtX6DajlnjyEeYzRcYwet9gDFlhLreZje5LLhIlZE0wIjj6pVX1hQnzsdJ7MTetbT8sOvNtpaqKA5Ik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615555340152932.9339376192811; Fri, 12 Mar 2021 05:22:20 -0800 (PST) Received: from localhost ([::1]:35822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKhkA-0005ez-9k for importer@patchew.org; Fri, 12 Mar 2021 08:22:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKhhj-0004BP-EO for qemu-devel@nongnu.org; Fri, 12 Mar 2021 08:19:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lKhhb-0007s1-0a for qemu-devel@nongnu.org; Fri, 12 Mar 2021 08:19:43 -0500 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-567-m0MLrCUhOxeZRT4HxOgKaA-1; Fri, 12 Mar 2021 08:19:33 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 536B419057A0 for ; Fri, 12 Mar 2021 13:19:32 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-110.ams2.redhat.com [10.36.114.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 349345D6CF; Fri, 12 Mar 2021 13:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615555177; h=from:from: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; bh=NiVh9a+s5xJmZwKdaW1j2o8lJQu15+edSMc644xjHto=; b=QHrb2v9bVHvHbubpIL9ShFw/UPyZoQyEbr43IoZqYkMC+1aEeBqVIcRJw3irUEvcKfqs39 1k2SeXfqsivjwffS+UiNe4CiexIPFMyLuOUkLRGkRxgtjKtXIWy6MWLvimklp2945SLIYX xUa6q0fdN4ggzCWRsalURcdIp+egl+M= X-MC-Unique: m0MLrCUhOxeZRT4HxOgKaA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH] qom: Support JSON in user_creatable_parse_str() Date: Fri, 12 Mar 2021 14:19:21 +0100 Message-Id: <20210312131921.421023-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, pkrempa@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Support JSON for --object in all tools and in HMP object_add in the same way as it is supported in qobject_input_visitor_new_str(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- Based-on: <20210311144811.313451-1-kwolf@redhat.com> qom/object_interfaces.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 62d7db7629..f5ea84b6c4 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -295,25 +295,35 @@ static void user_creatable_print_help_from_qdict(QDic= t *args) ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp) { ERRP_GUARD(); - QDict *args; + QObject *obj; bool help; Visitor *v; ObjectOptions *options; =20 - args =3D keyval_parse(optarg, "qom-type", &help, errp); - if (*errp) { - return NULL; - } - if (help) { - user_creatable_print_help_from_qdict(args); - qobject_unref(args); - return NULL; + if (optarg[0] =3D=3D '{') { + obj =3D qobject_from_json(optarg, errp); + if (!obj) { + return NULL; + } + v =3D qobject_input_visitor_new(obj); + } else { + QDict *args =3D keyval_parse(optarg, "qom-type", &help, errp); + if (*errp) { + return NULL; + } + if (help) { + user_creatable_print_help_from_qdict(args); + qobject_unref(args); + return NULL; + } + + obj =3D QOBJECT(args); + v =3D qobject_input_visitor_new_keyval(obj); } =20 - v =3D qobject_input_visitor_new_keyval(QOBJECT(args)); visit_type_ObjectOptions(v, NULL, &options, errp); visit_free(v); - qobject_unref(args); + qobject_unref(obj); =20 return options; } --=20 2.30.2