QMP: Drop old client argument checker

Previous two commits added qmp_check_client_args(), which
fully replaces this code and is way better.

It's important to note that the new checker doesn't support
the '/' arg type. As we don't have any of those handlers
converted to QMP, this is just dead code.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
Luiz Capitulino 2010-05-28 17:24:49 -03:00
parent 4af9193ae9
commit f6b4fc8b23

176
monitor.c
View File

@ -3973,177 +3973,6 @@ static int monitor_can_read(void *opaque)
return (mon->suspend_cnt == 0) ? 1 : 0;
}
typedef struct CmdArgs {
QString *name;
int type;
int flag;
int optional;
} CmdArgs;
static int check_opt(const CmdArgs *cmd_args, const char *name, QDict *args)
{
if (!cmd_args->optional) {
qerror_report(QERR_MISSING_PARAMETER, name);
return -1;
}
return 0;
}
static int check_arg(const CmdArgs *cmd_args, QDict *args)
{
QObject *value;
const char *name;
name = qstring_get_str(cmd_args->name);
if (!args) {
return check_opt(cmd_args, name, args);
}
value = qdict_get(args, name);
if (!value) {
return check_opt(cmd_args, name, args);
}
switch (cmd_args->type) {
case 'F':
case 'B':
case 's':
if (qobject_type(value) != QTYPE_QSTRING) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "string");
return -1;
}
break;
case '/': {
int i;
const char *keys[] = { "count", "format", "size", NULL };
for (i = 0; keys[i]; i++) {
QObject *obj = qdict_get(args, keys[i]);
if (!obj) {
qerror_report(QERR_MISSING_PARAMETER, name);
return -1;
}
if (qobject_type(obj) != QTYPE_QINT) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "int");
return -1;
}
}
break;
}
case 'i':
case 'l':
case 'M':
if (qobject_type(value) != QTYPE_QINT) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "int");
return -1;
}
break;
case 'f':
case 'T':
if (qobject_type(value) != QTYPE_QINT && qobject_type(value) != QTYPE_QFLOAT) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "number");
return -1;
}
break;
case 'b':
if (qobject_type(value) != QTYPE_QBOOL) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "bool");
return -1;
}
break;
case '-':
if (qobject_type(value) != QTYPE_QINT &&
qobject_type(value) != QTYPE_QBOOL) {
qerror_report(QERR_INVALID_PARAMETER_TYPE, name, "bool");
return -1;
}
break;
case 'O':
default:
/* impossible */
abort();
}
return 0;
}
static void cmd_args_init(CmdArgs *cmd_args)
{
cmd_args->name = qstring_new();
cmd_args->type = cmd_args->flag = cmd_args->optional = 0;
}
static int check_opts(QemuOptsList *opts_list, QDict *args)
{
assert(!opts_list->desc->name);
return 0;
}
/*
* This is not trivial, we have to parse Monitor command's argument
* type syntax to be able to check the arguments provided by clients.
*
* In the near future we will be using an array for that and will be
* able to drop all this parsing...
*/
static int monitor_check_qmp_args(const mon_cmd_t *cmd, QDict *args)
{
int err;
const char *p;
CmdArgs cmd_args;
QemuOptsList *opts_list;
if (cmd->args_type == NULL) {
return (qdict_size(args) == 0 ? 0 : -1);
}
err = 0;
cmd_args_init(&cmd_args);
opts_list = NULL;
for (p = cmd->args_type;; p++) {
if (*p == ':') {
cmd_args.type = *++p;
p++;
if (cmd_args.type == '-') {
cmd_args.flag = *p++;
cmd_args.optional = 1;
} else if (cmd_args.type == 'O') {
opts_list = qemu_find_opts(qstring_get_str(cmd_args.name));
assert(opts_list);
} else if (*p == '?') {
cmd_args.optional = 1;
p++;
}
assert(*p == ',' || *p == '\0');
if (opts_list) {
err = check_opts(opts_list, args);
opts_list = NULL;
} else {
err = check_arg(&cmd_args, args);
QDECREF(cmd_args.name);
cmd_args_init(&cmd_args);
}
if (err < 0) {
break;
}
} else {
qstring_append_chr(cmd_args.name, *p);
}
if (*p == '\0') {
break;
}
}
QDECREF(cmd_args.name);
return err;
}
static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name)
{
int is_cap = compare_cmd(cmd_name, "qmp_capabilities");
@ -4420,11 +4249,6 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
goto err_out;
}
err = monitor_check_qmp_args(cmd, args);
if (err < 0) {
goto err_out;
}
if (monitor_handler_is_async(cmd)) {
err = qmp_async_cmd_handler(mon, cmd, args);
if (err) {