mirror of
https://github.com/qemu/qemu.git
synced 2024-12-02 16:23:35 +08:00
240f64b6dc
The following uses of a QMP input visitor should be strict (that is, excess keys in QDict input should be flagged if not converted to QAPI): - Testsuite code unrelated to explicitly testing non-strict mode (test-qmp-commands, test-visitor-serialization); since we want more code to be strict by default, having more tests of strict mode doesn't hurt - Code used for cloning QAPI objects (replay-input.c, qemu-sockets.c); we are reparsing a QObject just barely produced by the qmp output visitor and which therefore should not have any garbage, so while it is extra work to be strict, it validates that our clone is correct [note that a later patch series will simplify these two uses by creating an actual clone visitor that is much more efficient than a generate/reparse cycle] - qmp_object_add(), which calls into user_creatable_add_type(). Since command line parsing for '-object' uses the same user_creatable_add_type() through the OptsVisitor, and that is always strict, we want to ensure that any nested dictionaries would be treated the same in QMP and from the command line (I don't actually know if such nested dictionaries exist). Note that on this code change, strictness only matters for nested dictionaries (if even possible), since we already flag excess input at the top level during an earlier object_property_set() on an unknown key, whether from QemuOpts: $ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio -object secret,id=sec0,data=letmein,format=raw,foo=bar qemu-system-x86_64: -object secret,id=sec0,data=letmein,format=raw,foo=bar: Property '.foo' not found or from QMP: $ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio {"QMP": {"version": {"qemu": {"micro": 93, "minor": 5, "major": 2}, "package": ""}, "capabilities": []}} {"execute":"qmp_capabilities"} {"return": {}} {"execute":"object-add","arguments":{"qom-type":"secret","id":"sec0","props":{"format":"raw","data":"letmein","foo":"bar"}}} {"error": {"class": "GenericError", "desc": "Property '.foo' not found"}} The only remaining uses of non-strict input visits are: - QMP 'qom-set' (which eventually executes object_property_set_qobject()) - mark it as something to revisit in the future (I didn't want to spend any more time on this patch auditing if we have any QOM dictionary properties that might be impacted, and couldn't easily prove whether this code path is shared with anything else). - test-qmp-input-visitor: explicit tests of non-strict mode. If we later get rid of users that don't need strictness, then this test should be merged with test-qmp-input-strict Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1461879932-9020-7-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
170 lines
4.5 KiB
C
170 lines
4.5 KiB
C
/*
|
|
* replay-input.c
|
|
*
|
|
* Copyright (c) 2010-2015 Institute for System Programming
|
|
* of the Russian Academy of Sciences.
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qapi/error.h"
|
|
#include "qemu-common.h"
|
|
#include "sysemu/replay.h"
|
|
#include "replay-internal.h"
|
|
#include "qemu/notify.h"
|
|
#include "ui/input.h"
|
|
#include "qapi/qmp-output-visitor.h"
|
|
#include "qapi/qmp-input-visitor.h"
|
|
#include "qapi-visit.h"
|
|
|
|
static InputEvent *qapi_clone_InputEvent(InputEvent *src)
|
|
{
|
|
QmpOutputVisitor *qov;
|
|
QmpInputVisitor *qiv;
|
|
Visitor *ov, *iv;
|
|
QObject *obj;
|
|
InputEvent *dst = NULL;
|
|
|
|
qov = qmp_output_visitor_new();
|
|
ov = qmp_output_get_visitor(qov);
|
|
visit_type_InputEvent(ov, NULL, &src, &error_abort);
|
|
obj = qmp_output_get_qobject(qov);
|
|
qmp_output_visitor_cleanup(qov);
|
|
if (!obj) {
|
|
return NULL;
|
|
}
|
|
|
|
qiv = qmp_input_visitor_new(obj, true);
|
|
iv = qmp_input_get_visitor(qiv);
|
|
visit_type_InputEvent(iv, NULL, &dst, &error_abort);
|
|
qmp_input_visitor_cleanup(qiv);
|
|
qobject_decref(obj);
|
|
|
|
return dst;
|
|
}
|
|
|
|
void replay_save_input_event(InputEvent *evt)
|
|
{
|
|
InputKeyEvent *key;
|
|
InputBtnEvent *btn;
|
|
InputMoveEvent *move;
|
|
replay_put_dword(evt->type);
|
|
|
|
switch (evt->type) {
|
|
case INPUT_EVENT_KIND_KEY:
|
|
key = evt->u.key.data;
|
|
replay_put_dword(key->key->type);
|
|
|
|
switch (key->key->type) {
|
|
case KEY_VALUE_KIND_NUMBER:
|
|
replay_put_qword(key->key->u.number.data);
|
|
replay_put_byte(key->down);
|
|
break;
|
|
case KEY_VALUE_KIND_QCODE:
|
|
replay_put_dword(key->key->u.qcode.data);
|
|
replay_put_byte(key->down);
|
|
break;
|
|
case KEY_VALUE_KIND__MAX:
|
|
/* keep gcc happy */
|
|
break;
|
|
}
|
|
break;
|
|
case INPUT_EVENT_KIND_BTN:
|
|
btn = evt->u.btn.data;
|
|
replay_put_dword(btn->button);
|
|
replay_put_byte(btn->down);
|
|
break;
|
|
case INPUT_EVENT_KIND_REL:
|
|
move = evt->u.rel.data;
|
|
replay_put_dword(move->axis);
|
|
replay_put_qword(move->value);
|
|
break;
|
|
case INPUT_EVENT_KIND_ABS:
|
|
move = evt->u.abs.data;
|
|
replay_put_dword(move->axis);
|
|
replay_put_qword(move->value);
|
|
break;
|
|
case INPUT_EVENT_KIND__MAX:
|
|
/* keep gcc happy */
|
|
break;
|
|
}
|
|
}
|
|
|
|
InputEvent *replay_read_input_event(void)
|
|
{
|
|
InputEvent evt;
|
|
KeyValue keyValue;
|
|
InputKeyEvent key;
|
|
key.key = &keyValue;
|
|
InputBtnEvent btn;
|
|
InputMoveEvent rel;
|
|
InputMoveEvent abs;
|
|
|
|
evt.type = replay_get_dword();
|
|
switch (evt.type) {
|
|
case INPUT_EVENT_KIND_KEY:
|
|
evt.u.key.data = &key;
|
|
evt.u.key.data->key->type = replay_get_dword();
|
|
|
|
switch (evt.u.key.data->key->type) {
|
|
case KEY_VALUE_KIND_NUMBER:
|
|
evt.u.key.data->key->u.number.data = replay_get_qword();
|
|
evt.u.key.data->down = replay_get_byte();
|
|
break;
|
|
case KEY_VALUE_KIND_QCODE:
|
|
evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword();
|
|
evt.u.key.data->down = replay_get_byte();
|
|
break;
|
|
case KEY_VALUE_KIND__MAX:
|
|
/* keep gcc happy */
|
|
break;
|
|
}
|
|
break;
|
|
case INPUT_EVENT_KIND_BTN:
|
|
evt.u.btn.data = &btn;
|
|
evt.u.btn.data->button = (InputButton)replay_get_dword();
|
|
evt.u.btn.data->down = replay_get_byte();
|
|
break;
|
|
case INPUT_EVENT_KIND_REL:
|
|
evt.u.rel.data = &rel;
|
|
evt.u.rel.data->axis = (InputAxis)replay_get_dword();
|
|
evt.u.rel.data->value = replay_get_qword();
|
|
break;
|
|
case INPUT_EVENT_KIND_ABS:
|
|
evt.u.abs.data = &abs;
|
|
evt.u.abs.data->axis = (InputAxis)replay_get_dword();
|
|
evt.u.abs.data->value = replay_get_qword();
|
|
break;
|
|
case INPUT_EVENT_KIND__MAX:
|
|
/* keep gcc happy */
|
|
break;
|
|
}
|
|
|
|
return qapi_clone_InputEvent(&evt);
|
|
}
|
|
|
|
void replay_input_event(QemuConsole *src, InputEvent *evt)
|
|
{
|
|
if (replay_mode == REPLAY_MODE_PLAY) {
|
|
/* Nothing */
|
|
} else if (replay_mode == REPLAY_MODE_RECORD) {
|
|
replay_add_input_event(qapi_clone_InputEvent(evt));
|
|
} else {
|
|
qemu_input_event_send_impl(src, evt);
|
|
}
|
|
}
|
|
|
|
void replay_input_sync_event(void)
|
|
{
|
|
if (replay_mode == REPLAY_MODE_PLAY) {
|
|
/* Nothing */
|
|
} else if (replay_mode == REPLAY_MODE_RECORD) {
|
|
replay_add_input_sync_event();
|
|
} else {
|
|
qemu_input_event_sync_impl();
|
|
}
|
|
}
|