From nobody Mon Feb 9 11:05:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488318075750581.134343708728; Tue, 28 Feb 2017 13:41:15 -0800 (PST) Received: from localhost ([::1]:37115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cipWE-0001wt-IO for importer@patchew.org; Tue, 28 Feb 2017 16:41:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cipIt-0007Z3-1Y for qemu-devel@nongnu.org; Tue, 28 Feb 2017 16:27:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cipIq-0000yQ-KE for qemu-devel@nongnu.org; Tue, 28 Feb 2017 16:27:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cipIk-0000rb-Ot; Tue, 28 Feb 2017 16:27:18 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEB2780479; Tue, 28 Feb 2017 21:27:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SLRG5G025947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 16:27:18 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 758E9113861C; Tue, 28 Feb 2017 22:27:10 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 22:27:06 +0100 Message-Id: <1488317230-26248-21-git-send-email-armbru@redhat.com> In-Reply-To: <1488317230-26248-1-git-send-email-armbru@redhat.com> References: <1488317230-26248-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 28 Feb 2017 21:27:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 20/24] qapi: New qobject_input_visitor_new_str() for convenience X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, mdroth@linux.vnet.ibm.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf --- include/qapi/qobject-input-visitor.h | 12 ++++++++++++ qapi/qobject-input-visitor.c | 36 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 48 insertions(+) diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-in= put-visitor.h index 282f9d2..b399285 100644 --- a/include/qapi/qobject-input-visitor.h +++ b/include/qapi/qobject-input-visitor.h @@ -68,4 +68,16 @@ Visitor *qobject_input_visitor_new(QObject *obj); */ Visitor *qobject_input_visitor_new_keyval(QObject *obj); =20 +/* + * Create a QObject input visitor for parsing @str. + * + * If @str looks like JSON, parse it as JSON, else as KEY=3DVALUE,... + * @implied_key applies to KEY=3DVALUE, and works as in keyval_parse(). + * On failure, store an error through @errp and return NULL. + * On success, return a new QObject input visitor for the parse. + */ +Visitor *qobject_input_visitor_new_str(const char *str, + const char *implied_key, + Error **errp); + #endif diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 6c56040..1a484d5 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -18,9 +18,11 @@ #include "qapi/visitor-impl.h" #include "qemu/queue.h" #include "qemu-common.h" +#include "qapi/qmp/qjson.h" #include "qapi/qmp/types.h" #include "qapi/qmp/qerror.h" #include "qemu/cutils.h" +#include "qemu/option.h" =20 typedef struct StackObject { const char *name; /* Name of @obj in its parent, if any */ @@ -656,3 +658,37 @@ Visitor *qobject_input_visitor_new_keyval(QObject *obj) =20 return &v->visitor; } + +Visitor *qobject_input_visitor_new_str(const char *str, + const char *implied_key, + Error **errp) +{ + bool is_json =3D str[0] =3D=3D '{'; + QObject *obj; + QDict *args; + Visitor *v; + + if (is_json) { + obj =3D qobject_from_json(str, errp); + if (!obj) { + /* Work around qobject_from_json() lossage TODO fix that */ + if (errp && !*errp) { + error_setg(errp, "JSON parse error"); + return NULL; + } + return NULL; + } + args =3D qobject_to_qdict(obj); + assert(args); + v =3D qobject_input_visitor_new(QOBJECT(args)); + } else { + args =3D keyval_parse(str, implied_key, errp); + if (!args) { + return NULL; + } + v =3D qobject_input_visitor_new_keyval(QOBJECT(args)); + } + QDECREF(args); + + return v; +} --=20 2.7.4