[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 12/14] QMP: Introduce qmp_check_input_obj()
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 12/14] QMP: Introduce qmp_check_input_obj() |
Date: |
Thu, 24 Jun 2010 18:33:38 -0300 |
This is similar to qmp_check_client_args(), but it checks if
the input object follows the specification (QMP/qmp-spec.txt
section 2.3).
As we're limited to three keys, the work here is quite simple:
we iterate over the input object, checking each time if the
current argument complies to the specification.
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 61 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 8d3e788..fab553a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4162,6 +4162,62 @@ out:
return err;
}
+/*
+ * Input object checking rules
+ *
+ * 1. Input object must be a dict
+ * 2. The "execute" key must exist
+ * 3. The "execute" key must be a string
+ * 4. If the "arguments" key exists, it must be a dict
+ * 5. If the "id" key exists, it can be anything (ie. json-value)
+ * 6. Any argument not listed above is considered invalid
+ */
+static QDict *qmp_check_input_obj(QObject *input_obj)
+{
+ const QDictEntry *ent;
+ int has_exec_key = 0;
+ QDict *input_dict;
+
+ if (qobject_type(input_obj) != QTYPE_QDICT) {
+ qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "object");
+ return NULL;
+ }
+
+ input_dict = qobject_to_qdict(input_obj);
+
+ for (ent = qdict_first(input_dict); ent; ent = qdict_next(input_dict,
ent)){
+ const char *arg_name = qdict_entry_key(ent);
+ const QObject *arg_obj = qdict_entry_value(ent);
+
+ if (!strcmp(arg_name, "execute")) {
+ if (qobject_type(arg_obj) != QTYPE_QSTRING) {
+ qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "execute",
+ "string");
+ return NULL;
+ }
+ has_exec_key = 1;
+ } else if (!strcmp(arg_name, "arguments")) {
+ if (qobject_type(arg_obj) != QTYPE_QDICT) {
+ qerror_report(QERR_QMP_BAD_INPUT_OBJECT_MEMBER, "arguments",
+ "object");
+ return NULL;
+ }
+ } else if (!strcmp(arg_name, "id")) {
+ /* FIXME: check duplicated IDs for async commands */
+ } else {
+ qerror_report(QERR_QMP_EXTRA_MEMBER, arg_name);
+ return NULL;
+ }
+ }
+
+ if (!has_exec_key) {
+ qerror_report(QERR_QMP_BAD_INPUT_OBJECT, "execute");
+ return NULL;
+ }
+
+ return input_dict;
+}
+
static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
{
int err;
@@ -4184,7 +4240,11 @@ static void handle_qmp_command(JSONMessageParser
*parser, QList *tokens)
goto err_out;
}
- input = qobject_to_qdict(obj);
+ input = qmp_check_input_obj(obj);
+ if (!input) {
+ qobject_decref(obj);
+ goto err_out;
+ }
mon->mc->id = qdict_get(input, "id");
qobject_incref(mon->mc->id);
--
1.7.1.359.gd0b8d
- [Qemu-devel] [PATCH 03/14] QDict: Introduce functions to retrieve QDictEntry values, (continued)
- [Qemu-devel] [PATCH 03/14] QDict: Introduce functions to retrieve QDictEntry values, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 04/14] QDict: Introduce new iteration API, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 05/14] check-qdict: Introduce test for the new iteration API, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 06/14] QDict: Introduce qdict_get_try_bool(), Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 07/14] Monitor: handle optional '-' arg as a bool, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 08/14] QMP: New argument checker (first part), Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 09/14] QMP: New argument checker (second part), Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 10/14] QMP: Drop old client argument checker, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 11/14] QError: Introduce QERR_QMP_EXTRA_MEMBER, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 13/14] QMP: Drop old input object checking, Luiz Capitulino, 2010/06/24
- [Qemu-devel] [PATCH 12/14] QMP: Introduce qmp_check_input_obj(),
Luiz Capitulino <=
- [Qemu-devel] [PATCH 14/14] QMP: handle_qmp_command(): Small cleanup, Luiz Capitulino, 2010/06/24
- Re: [Qemu-devel] [PATCH v3 00/14]: QMP: Replace client argument checker, Luiz Capitulino, 2010/06/24