static int testQEMUSchemaValidateBuiltin(virJSONValuePtr obj, virJSONValuePtr root, virBufferPtr debug) { const char *t = virJSONValueObjectGetString(root, "json-type"); const char *s = NULL; bool b = false; int ret = -1; if (STREQ_NULLABLE(t, "value")) { s = "{any}"; ret = 0; goto cleanup; } switch (virJSONValueGetType(obj)) { case VIR_JSON_TYPE_STRING: if (STRNEQ_NULLABLE(t, "string")) goto cleanup; s = virJSONValueGetString(obj); break; case VIR_JSON_TYPE_NUMBER: if (STRNEQ_NULLABLE(t, "int") && STRNEQ_NULLABLE(t, "number")) goto cleanup; s = "{number}"; break; case VIR_JSON_TYPE_BOOLEAN: if (STRNEQ_NULLABLE(t, "boolean")) goto cleanup; virJSONValueGetBoolean(obj, &b); if (b) s = "true"; else s = "false"; break; case VIR_JSON_TYPE_NULL: if (STRNEQ_NULLABLE(t, "null")) goto cleanup; break; case VIR_JSON_TYPE_OBJECT: case VIR_JSON_TYPE_ARRAY: goto cleanup; } ret = 0; cleanup: if (ret == 0) virBufferAsprintf(debug, "'%s': OK", s); else virBufferAsprintf(debug, "ERROR: expected type '%s', actual type %d", t, virJSONValueGetType(obj)); return ret; }
int virJSONValueObjectGetBoolean(virJSONValuePtr object, const char *key, bool *value) { virJSONValuePtr val; if (object->type != VIR_JSON_TYPE_OBJECT) return -1; val = virJSONValueObjectGet(object, key); if (!val) return -1; return virJSONValueGetBoolean(val, value); }