mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 12:05:17 +00:00
virjson: Change virJSONValueObjectHasKey() signature
Currently, virJSONValueObjectHasKey() can return one of three values: -1 if passed object type is not VIR_JSON_TYPE_OBJECT, 0 if the key is not present, and finally 1 if the key is present. But, neither of callers is interested in the -1 case. In fact, some callers call this function treating -1 and 1 cases the same. Therefore, make the function return just true/false and fix few callers that explicitly checked for == 1 case. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
e5c34c983c
commit
42ca6d6f33
@ -231,12 +231,12 @@ qemuAgentIOProcessLine(qemuAgent *agent,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectHasKey(obj, "QMP") == 1) {
|
||||
if (virJSONValueObjectHasKey(obj, "QMP")) {
|
||||
return 0;
|
||||
} else if (virJSONValueObjectHasKey(obj, "event") == 1) {
|
||||
} else if (virJSONValueObjectHasKey(obj, "event")) {
|
||||
return qemuAgentIOProcessEvent(agent, obj);
|
||||
} else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
|
||||
virJSONValueObjectHasKey(obj, "return") == 1) {
|
||||
} else if (virJSONValueObjectHasKey(obj, "error") ||
|
||||
virJSONValueObjectHasKey(obj, "return")) {
|
||||
if (msg) {
|
||||
if (msg->sync) {
|
||||
unsigned long long id;
|
||||
|
@ -203,14 +203,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectHasKey(obj, "QMP") == 1) {
|
||||
if (virJSONValueObjectHasKey(obj, "QMP")) {
|
||||
return 0;
|
||||
} else if (virJSONValueObjectHasKey(obj, "event") == 1) {
|
||||
} else if (virJSONValueObjectHasKey(obj, "event")) {
|
||||
PROBE(QEMU_MONITOR_RECV_EVENT,
|
||||
"mon=%p event=%s", mon, line);
|
||||
return qemuMonitorJSONIOProcessEvent(mon, obj);
|
||||
} else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
|
||||
virJSONValueObjectHasKey(obj, "return") == 1) {
|
||||
} else if (virJSONValueObjectHasKey(obj, "error") ||
|
||||
virJSONValueObjectHasKey(obj, "return")) {
|
||||
PROBE(QEMU_MONITOR_RECV_REPLY,
|
||||
"mon=%p reply=%s", mon, line);
|
||||
if (msg) {
|
||||
@ -270,7 +270,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon,
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
if (virJSONValueObjectHasKey(cmd, "execute") == 1) {
|
||||
if (virJSONValueObjectHasKey(cmd, "execute")) {
|
||||
g_autofree char *id = qemuMonitorNextCommandID(mon);
|
||||
|
||||
if (virJSONValueObjectAppendString(cmd, "id", id) < 0) {
|
||||
|
@ -798,21 +798,21 @@ virJSONValueArrayConcat(virJSONValue *a,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
bool
|
||||
virJSONValueObjectHasKey(virJSONValue *object,
|
||||
const char *key)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (object->type != VIR_JSON_TYPE_OBJECT)
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
for (i = 0; i < object->data.object.npairs; i++) {
|
||||
if (STREQ(object->data.object.pairs[i].key, key))
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ int
|
||||
virJSONValueArrayConcat(virJSONValue *a,
|
||||
virJSONValue *c);
|
||||
|
||||
int
|
||||
bool
|
||||
virJSONValueObjectHasKey(virJSONValue *object,
|
||||
const char *key);
|
||||
virJSONValue *
|
||||
|
@ -289,7 +289,7 @@ testQEMUSchemaValidateObjectMandatoryMember(size_t pos G_GNUC_UNUSED,
|
||||
{
|
||||
struct testQEMUSchemaValidateObjectMemberData *data = opaque;
|
||||
|
||||
if (virJSONValueObjectHasKey(item, "default") != 1) {
|
||||
if (!virJSONValueObjectHasKey(item, "default")) {
|
||||
virBufferAsprintf(data->ctxt->debug, "ERROR: missing mandatory attribute '%s'\n",
|
||||
NULLSTR(virJSONValueObjectGetString(item, "name")));
|
||||
data->missingMandatory = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user