Sometimes it's desired to get a JSON number as string. Add a helper.
This will help in cases where we'd want to conver the internal type from
string to something else.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virjson.c | 10 ++++++++++
src/util/virjson.h | 1 +
3 files changed, 12 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 03fe3b315f..989411cdca 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2038,6 +2038,7 @@ virJSONValueGetBoolean;
virJSONValueGetNumberDouble;
virJSONValueGetNumberInt;
virJSONValueGetNumberLong;
+virJSONValueGetNumberString;
virJSONValueGetNumberUint;
virJSONValueGetNumberUlong;
virJSONValueGetString;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 212c158da0..6f2b52257f 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1043,6 +1043,16 @@ virJSONValueGetString(virJSONValuePtr string)
}
+const char *
+virJSONValueGetNumberString(virJSONValuePtr number)
+{
+ if (number->type != VIR_JSON_TYPE_NUMBER)
+ return NULL;
+
+ return number->data.number;
+}
+
+
int
virJSONValueGetNumberInt(virJSONValuePtr number,
int *value)
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 017a1f20ed..e80d10dea1 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -134,6 +134,7 @@ const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned
int n);
virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigned int n);
const char *virJSONValueGetString(virJSONValuePtr object);
+const char *virJSONValueGetNumberString(virJSONValuePtr number);
int virJSONValueGetNumberInt(virJSONValuePtr object, int *value);
int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value);
int virJSONValueGetNumberLong(virJSONValuePtr object, long long *value);
--
2.16.2