4 * Copyright IBM, Corp. 2009
5 * Copyright (c) 2013, 2015, 2017 Red Hat Inc.
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Markus Armbruster <armbru@redhat.com>
10 * Marc-André Lureau <marcandre.lureau@redhat.com>
12 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
13 * See the COPYING.LIB file in the top-level directory.
16 #include "qemu/osdep.h"
18 #include "qapi/qmp/qlit.h"
19 #include "qapi/qmp/types.h"
21 static bool qlit_equal_qdict(const QLitObject
*lhs
, const QDict
*qdict
)
25 for (i
= 0; lhs
->value
.qdict
[i
].key
; i
++) {
26 QObject
*obj
= qdict_get(qdict
, lhs
->value
.qdict
[i
].key
);
28 if (!qlit_equal_qobject(&lhs
->value
.qdict
[i
].value
, obj
)) {
33 /* Note: the literal qdict must not contain duplicates, this is
34 * considered a programming error and it isn't checked here. */
35 if (qdict_size(qdict
) != i
) {
42 static bool qlit_equal_qlist(const QLitObject
*lhs
, const QList
*qlist
)
47 QLIST_FOREACH_ENTRY(qlist
, e
) {
48 QObject
*obj
= qlist_entry_obj(e
);
50 if (!qlit_equal_qobject(&lhs
->value
.qlist
[i
], obj
)) {
56 return !e
&& lhs
->value
.qlist
[i
].type
== QTYPE_NONE
;
59 bool qlit_equal_qobject(const QLitObject
*lhs
, const QObject
*rhs
)
61 if (!rhs
|| lhs
->type
!= qobject_type(rhs
)) {
67 return lhs
->value
.qbool
== qbool_get_bool(qobject_to_qbool(rhs
));
69 return lhs
->value
.qnum
== qnum_get_int(qobject_to_qnum(rhs
));
71 return (strcmp(lhs
->value
.qstr
,
72 qstring_get_str(qobject_to_qstring(rhs
))) == 0);
74 return qlit_equal_qdict(lhs
, qobject_to_qdict(rhs
));
76 return qlit_equal_qlist(lhs
, qobject_to_qlist(rhs
));