From: Luiz Capitulino <lcapitulino@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 05/10] json-parser: Accept 'null' in QMP
Date: Fri, 8 May 2015 09:34:06 -0400 [thread overview]
Message-ID: <1431092051-31046-6-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1431092051-31046-1-git-send-email-lcapitulino@redhat.com>
From: Eric Blake <eblake@redhat.com>
We document that in QMP, the client may send any json-value
for the optional "id" key, and then return that same value
on reply (both success and failures, insofar as the failure
happened after parsing the id). [Note that the output may
not be identical to the input, as whitespace may change and
since we may reorder keys within a json-object, but that this
still constitutes the same json-value]. However, we were not
handling the JSON literal null, which counts as a json-value
per RFC 7159.
Also, down the road, given the QAPI schema of {'*foo':'str'} or
{'*foo':'ComplexType'}, we could decide to allow the QMP client
to pass { "foo":null } instead of the current representation of
{ } where omitting the key is the only way to get at the default
NULL value. Such a change might be useful for argument
introspection (if a type in older qemu lacks 'foo' altogether,
then an explicit "foo":null probe will force an easily
distinguished error message for whether the optional "foo" key
is even understood in newer qemu). And if we add default values
to optional arguments, allowing an explicit null would be
required for getting a NULL value associated with an optional
string that has a non-null default. But all that can come at a
later day.
The 'check-unit' testsuite is enhanced to test that parsing
produces the same object as explicitly requesting a reference
to the special qnull object. In addition, I tested with:
$ ./x86_64-softmmu/qemu-system-x86_64 -qmp stdio -nodefaults
{"QMP": {"version": {"qemu": {"micro": 91, "minor": 2, "major": 2}, "package": ""}, "capabilities": []}}
{"execute":"qmp_capabilities","id":null}
{"return": {}, "id": null}
{"id":{"a":null,"b":[1,null]},"execute":"quit"}
{"return": {}, "id": {"a": null, "b": [1, null]}}
{"timestamp": {"seconds": 1427742379, "microseconds": 423128}, "event": "SHUTDOWN"}
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
qobject/json-parser.c | 2 ++
tests/check-qjson.c | 15 +++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 4288267..717cb8f 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -561,6 +561,8 @@ static QObject *parse_keyword(JSONParserContext *ctxt)
ret = QOBJECT(qbool_from_int(true));
} else if (token_is_keyword(token, "false")) {
ret = QOBJECT(qbool_from_int(false));
+ } else if (token_is_keyword(token, "null")) {
+ ret = qnull();
} else {
parse_error(ctxt, token, "invalid keyword `%s'", token_get_value(token));
goto out;
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 95497a0..60e5b22 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1,6 +1,6 @@
/*
* Copyright IBM, Corp. 2009
- * Copyright (c) 2013 Red Hat Inc.
+ * Copyright (c) 2013, 2015 Red Hat Inc.
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
@@ -1005,6 +1005,7 @@ static void keyword_literal(void)
{
QObject *obj;
QBool *qbool;
+ QObject *null;
QString *str;
obj = qobject_from_json("true");
@@ -1041,7 +1042,7 @@ static void keyword_literal(void)
g_assert(qbool_get_int(qbool) == 0);
QDECREF(qbool);
-
+
obj = qobject_from_jsonf("%i", true);
g_assert(obj != NULL);
g_assert(qobject_type(obj) == QTYPE_QBOOL);
@@ -1050,6 +1051,16 @@ static void keyword_literal(void)
g_assert(qbool_get_int(qbool) != 0);
QDECREF(qbool);
+
+ obj = qobject_from_json("null");
+ g_assert(obj != NULL);
+ g_assert(qobject_type(obj) == QTYPE_QNULL);
+
+ null = qnull();
+ g_assert(null == obj);
+
+ qobject_decref(obj);
+ qobject_decref(null);
}
typedef struct LiteralQDictEntry LiteralQDictEntry;
--
1.9.3
next prev parent reply other threads:[~2015-05-08 13:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 13:34 [Qemu-devel] [PULL 00/10] QMP queue Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 01/10] monitor: add memory search commands s, sp Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 02/10] QJSON: Use OBJECT_CHECK Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 03/10] qobject: Clean up around qtype_code Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 04/10] qobject: Add a special null QObject Luiz Capitulino
2015-05-08 13:34 ` Luiz Capitulino [this message]
2015-05-08 13:34 ` [Qemu-devel] [PULL 06/10] MAINTAINERS: New maintainer for QMP and QAPI Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 07/10] scripts: qmp-shell: refactor helpers Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 08/10] scripts: qmp-shell: Expand support for QMP expressions Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 09/10] scripts: qmp-shell: add transaction subshell Luiz Capitulino
2015-05-08 13:34 ` [Qemu-devel] [PULL 10/10] scripts: qmp-shell: Add verbose flag Luiz Capitulino
2015-05-11 12:53 ` [Qemu-devel] [PULL 00/10] QMP queue Peter Maydell
2015-05-11 13:17 ` Luiz Capitulino
2015-05-12 9:40 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431092051-31046-6-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).