virjson: add convenience wrapper for appending string to array

Upcoming patches need an array of strings for use in QMP
block-dirty-bitmap-merge.  A convenience wrapper cuts down
on the verbosity of creating the array, similar to the
existing virJSONValueObjectAppendString().

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Eric Blake 2019-01-24 21:32:55 -06:00
parent 4ea5a41e16
commit 484370dcf1
3 changed files with 18 additions and 0 deletions

View File

@ -2092,6 +2092,7 @@ virISCSIScanTargets;
# util/virjson.h # util/virjson.h
virJSONStringReformat; virJSONStringReformat;
virJSONValueArrayAppend; virJSONValueArrayAppend;
virJSONValueArrayAppendString;
virJSONValueArrayForeachSteal; virJSONValueArrayForeachSteal;
virJSONValueArrayGet; virJSONValueArrayGet;
virJSONValueArraySize; virJSONValueArraySize;

View File

@ -795,6 +795,21 @@ virJSONValueArrayAppend(virJSONValuePtr array,
} }
int
virJSONValueArrayAppendString(virJSONValuePtr object,
const char *value)
{
virJSONValuePtr jvalue = virJSONValueNewString(value);
if (!jvalue)
return -1;
if (virJSONValueArrayAppend(object, jvalue) < 0) {
virJSONValueFree(jvalue);
return -1;
}
return 0;
}
int int
virJSONValueObjectHasKey(virJSONValuePtr object, virJSONValueObjectHasKey(virJSONValuePtr object,
const char *key) const char *key)

View File

@ -138,6 +138,8 @@ int virJSONValueObjectRemoveKey(virJSONValuePtr object, const char *key,
virJSONValuePtr *value) virJSONValuePtr *value)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virJSONValueArrayAppendString(virJSONValuePtr object, const char *value);
virJSONValuePtr virJSONValueFromString(const char *jsonstring); virJSONValuePtr virJSONValueFromString(const char *jsonstring);
char *virJSONValueToString(virJSONValuePtr object, char *virJSONValueToString(virJSONValuePtr object,
bool pretty); bool pretty);