[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 21/32] qobject: New qdict_from_jsonf_nofail()
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 21/32] qobject: New qdict_from_jsonf_nofail() |
Date: |
Mon, 2 Jul 2018 18:22:07 +0200 |
Many uses of qobject_from_jsonf() convert JSON objects. Create new
convenience function qdict_from_jsonf_nofail() that includes the
conversion to QDict. The next few commits will put it to use.
Signed-off-by: Markus Armbruster <address@hidden>
---
include/qapi/qmp/qjson.h | 2 ++
qobject/qjson.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h
index b274ac3a86..43b2ce2f33 100644
--- a/include/qapi/qmp/qjson.h
+++ b/include/qapi/qmp/qjson.h
@@ -19,6 +19,8 @@ QObject *qobject_from_jsonf(const char *string, ...)
GCC_FMT_ATTR(1, 2);
QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp)
GCC_FMT_ATTR(1, 0);
+QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2);
+
QString *qobject_to_json(const QObject *obj);
QString *qobject_to_json_pretty(const QObject *obj);
diff --git a/qobject/qjson.c b/qobject/qjson.c
index 9816a65c7d..0df3120202 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -76,6 +76,24 @@ QObject *qobject_from_jsonf(const char *string, ...)
return obj;
}
+/*
+ * Parse @string as JSON object with %-escapes interpolated.
+ * Abort on error. Do not use with untrusted @string.
+ * Return the resulting QDict. It is never null.
+ */
+QDict *qdict_from_jsonf_nofail(const char *string, ...)
+{
+ QDict *obj;
+ va_list ap;
+
+ va_start(ap, string);
+ obj = qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort));
+ va_end(ap);
+
+ assert(obj);
+ return obj;
+}
+
typedef struct ToJsonIterState
{
int indent;
--
2.17.1
- Re: [Qemu-devel] [PATCH 07/32] qmp: Make "id" optional again even in "oob" monitors, (continued)
[Qemu-devel] [PATCH 04/32] qmp: Document COMMAND_DROPPED design flaw, Markus Armbruster, 2018/07/02
[Qemu-devel] [PATCH 05/32] qmp: Get rid of x-oob-test command, Markus Armbruster, 2018/07/02
[Qemu-devel] [PATCH 21/32] qobject: New qdict_from_jsonf_nofail(),
Markus Armbruster <=
[Qemu-devel] [PATCH 15/32] qmp: Simplify code around monitor_qmp_dispatch_one(), Markus Armbruster, 2018/07/02
[Qemu-devel] [PATCH 19/32] monitor: Rename use_io_thr to use_io_thread, Markus Armbruster, 2018/07/02
[Qemu-devel] [PATCH 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id", Markus Armbruster, 2018/07/02
[Qemu-devel] [PATCH 14/32] qmp: Always free QMPRequest with qmp_request_free(), Markus Armbruster, 2018/07/02