From 3f94c08aff298ec59ba503675eae24fde9f3bed8 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Tue, 20 Mar 2012 14:07:25 -0300 Subject: [RHEL6 qemu-kvm PATCH 05/21] QMP: Drop old client argument checker RH-Author: Jeffrey Cody Message-id: Patchwork-id: 38629 O-Subject: [RHEL6.3 qemu-kvm PATCH v3 05/21] QMP: Drop old client argument checker Bugzilla: 784153 RH-Acked-by: Kevin Wolf RH-Acked-by: Paolo Bonzini RH-Acked-by: Markus Armbruster From: Luiz Capitulino 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 (cherry picked from commit f6b4fc8b23b1154577c72937b70e565716bb0a60) Conflicts: monitor.c Signed-off-by: Jeff Cody --- monitor.c | 177 ------------------------------------------------------------- 1 files changed, 0 insertions(+), 177 deletions(-) Signed-off-by: Eduardo Habkost --- monitor.c | 177 ------------------------------------------------------------- 1 files changed, 0 insertions(+), 177 deletions(-) diff --git a/monitor.c b/monitor.c index 448157f..9f662b5 100644 --- a/monitor.c +++ b/monitor.c @@ -4410,178 +4410,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': - case 'o': - 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"); @@ -4859,11 +4687,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) { -- 1.7.3.2