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 typedef struct QListCompareHelper
{
27 static void compare_helper(QObject
*obj
, void *opaque
)
29 QListCompareHelper
*helper
= opaque
;
31 if (!helper
->result
) {
35 if (helper
->objs
[helper
->index
].type
== QTYPE_NONE
) {
36 helper
->result
= false;
41 qlit_equal_qobject(&helper
->objs
[helper
->index
++], obj
);
44 bool qlit_equal_qobject(QLitObject
*lhs
, QObject
*rhs
)
48 if (!rhs
|| lhs
->type
!= qobject_type(rhs
)) {
54 g_assert(qnum_get_try_int(qobject_to_qnum(rhs
), &val
));
55 return lhs
->value
.qnum
== val
;
57 return (strcmp(lhs
->value
.qstr
,
58 qstring_get_str(qobject_to_qstring(rhs
))) == 0);
62 for (i
= 0; lhs
->value
.qdict
[i
].key
; i
++) {
63 QObject
*obj
= qdict_get(qobject_to_qdict(rhs
),
64 lhs
->value
.qdict
[i
].key
);
66 if (!qlit_equal_qobject(&lhs
->value
.qdict
[i
].value
, obj
)) {
74 QListCompareHelper helper
;
77 helper
.objs
= lhs
->value
.qlist
;
80 qlist_iter(qobject_to_qlist(rhs
), compare_helper
, &helper
);