[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/23] QMP: New argument checker (second part)
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 17/23] QMP: New argument checker (second part) |
Date: |
Thu, 1 Jul 2010 16:21:45 -0300 |
This commit introduces the second (and last) part of QMP's new
argument checker.
The job is done by check_client_args_type(), it iterates over
the client's argument qdict and for for each argument it checks
if it exists and if its type is valid.
It's important to observe the following changes from the existing
argument checker:
- If the handler accepts an O-type argument, unknown arguments
are passed down to it. It's up to O-type handlers to validate
their arguments
- Boolean types (eg. 'b' and '-') don't accept integers anymore,
only json-bool
- Argument types '/' and '.' are currently unsupported under QMP,
thus they're not handled
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 93 insertions(+), 1 deletions(-)
diff --git a/monitor.c b/monitor.c
index 222622b..2fd8005 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4151,6 +4151,95 @@ static int invalid_qmp_mode(const Monitor *mon, const
char *cmd_name)
}
/*
+ * Argument validation rules:
+ *
+ * 1. The argument must exist in cmd_args qdict
+ * 2. The argument type must be the expected one
+ *
+ * Special case: If the argument doesn't exist in cmd_args and
+ * the QMP_ACCEPT_UNKNOWNS flag is set, then the
+ * checking is skipped for it.
+ */
+static int check_client_args_type(const QDict *client_args,
+ const QDict *cmd_args, int flags)
+{
+ const QDictEntry *ent;
+
+ for (ent = qdict_first(client_args); ent;ent =
qdict_next(client_args,ent)){
+ QObject *obj;
+ QString *arg_type;
+ const QObject *client_arg = qdict_entry_value(ent);
+ const char *client_arg_name = qdict_entry_key(ent);
+
+ obj = qdict_get(cmd_args, client_arg_name);
+ if (!obj) {
+ if (flags & QMP_ACCEPT_UNKNOWNS) {
+ /* handler accepts unknowns */
+ continue;
+ }
+ /* client arg doesn't exist */
+ qerror_report(QERR_INVALID_PARAMETER, client_arg_name);
+ return -1;
+ }
+
+ arg_type = qobject_to_qstring(obj);
+ assert(arg_type != NULL);
+
+ /* check if argument's type is correct */
+ switch (qstring_get_str(arg_type)[0]) {
+ case 'F':
+ case 'B':
+ case 's':
+ if (qobject_type(client_arg) != QTYPE_QSTRING) {
+ qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
+ "string");
+ return -1;
+ }
+ break;
+ case 'i':
+ case 'l':
+ case 'M':
+ if (qobject_type(client_arg) != QTYPE_QINT) {
+ qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
+ "int");
+ return -1;
+ }
+ break;
+ case 'f':
+ case 'T':
+ if (qobject_type(client_arg) != QTYPE_QINT &&
+ qobject_type(client_arg) != QTYPE_QFLOAT) {
+ qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
+ "number");
+ return -1;
+ }
+ break;
+ case 'b':
+ case '-':
+ if (qobject_type(client_arg) != QTYPE_QBOOL) {
+ qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
+ "bool");
+ return -1;
+ }
+ break;
+ case 'O':
+ assert(flags & QMP_ACCEPT_UNKNOWNS);
+ break;
+ case '/':
+ case '.':
+ /*
+ * These types are not supported by QMP and thus are not
+ * handled here. Fall through.
+ */
+ default:
+ abort();
+ }
+ }
+
+ return 0;
+}
+
+/*
* - Check if the client has passed all mandatory args
* - Set special flags for argument validation
*/
@@ -4227,6 +4316,9 @@ out:
* Client argument checking rules:
*
* 1. Client must provide all mandatory arguments
+ * 2. Each argument provided by the client must be expected
+ * 3. Each argument provided by the client must have the type expected
+ * by the command
*/
static int qmp_check_client_args(const mon_cmd_t *cmd, QDict *client_args)
{
@@ -4241,7 +4333,7 @@ static int qmp_check_client_args(const mon_cmd_t *cmd,
QDict *client_args)
goto out;
}
- /* TODO: Check client args type */
+ err = check_client_args_type(client_args, cmd_args, flags);
out:
QDECREF(cmd_args);
--
1.7.2.rc0
- [Qemu-devel] [PATCH 07/23] QMP: Fix error reporting in the async API, (continued)
- [Qemu-devel] [PATCH 07/23] QMP: Fix error reporting in the async API, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 09/23] QDict: Rename 'err_value', Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 08/23] QError: Enhance QERR_DEVICE_NOT_ACTIVE's user desc, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 11/23] QDict: Introduce functions to retrieve QDictEntry values, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 10/23] QDict: Small terminology change, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 13/23] check-qdict: Introduce test for the new iteration API, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 14/23] QDict: Introduce qdict_get_try_bool(), Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 12/23] QDict: Introduce new iteration API, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 15/23] Monitor: handle optional '-' arg as a bool, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 16/23] QMP: New argument checker (first part), Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 17/23] QMP: New argument checker (second part),
Luiz Capitulino <=
- [Qemu-devel] [PATCH 18/23] QMP: Drop old client argument checker, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 19/23] QError: Introduce QERR_QMP_EXTRA_MEMBER, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 20/23] QMP: Introduce qmp_check_input_obj(), Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 21/23] QMP: Drop old input object checking, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 22/23] QMP: handle_qmp_command(): Small cleanup, Luiz Capitulino, 2010/07/01
- [Qemu-devel] [PATCH 23/23] monitor: Allow to exclude commands from QMP, Luiz Capitulino, 2010/07/01
- Re: [Qemu-devel] [PATCH 00/23][PULL]: QMP/Monitor queue, Anthony Liguori, 2010/07/06