On Thu, Mar 29, 2018 at 16:35:59 +0200, Jiri Denemark wrote: > My commit 2e0d6cdec41 claimed qemuMonitorJSONCheckError guarantees > "return" object exists in the JSON reply. But it only makes sure the key > is there, while the type of the value is not checked. A lot of callers > do not care since they only want to see whether their QMP command failed > or not, but any caller which needs to read some data from the reply > wants to make sure the correct data type was returned. > > This patch adds a new API called qemuMonitorJSONCheckReply which calls > qemuMonitorJSONCheckError and checks "return" contains a value of the > specified type. > > Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> > --- > src/qemu/qemu_monitor_json.c | 261 ++++++++++++++++++------------------------- > 1 file changed, 108 insertions(+), 153 deletions(-) > > diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c > index d80c4f18d1..b251fc9964 100644 > --- a/src/qemu/qemu_monitor_json.c > +++ b/src/qemu/qemu_monitor_json.c > @@ -413,6 +413,36 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd, > } > > > +static int > +qemuMonitorJSONCheckReply(virJSONValuePtr cmd, > + virJSONValuePtr reply, > + virJSONType type) > +{ > + virJSONValuePtr data; > + > + if (qemuMonitorJSONCheckError(cmd, reply) < 0) > + return -1; > + > + data = virJSONValueObjectGet(reply, "return"); > + if (data->type != type) { Please use virJSONValueGetType instead of direct access. > + char *cmdstr = virJSONValueToString(cmd, false); > + char *retstr = virJSONValueToString(data, false); > + > + VIR_DEBUG("Unexpected return type %d (expecting %d) for command %s: %s", > + data->type, type, cmdstr, retstr); Same here. > + virReportError(VIR_ERR_INTERNAL_ERROR, > + _("unexpected type returned by QEMU command '%s'"), > + qemuMonitorJSONCommandName(cmd)); > + ACK
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list