It appends boolean from virTristateBool/virTristateSwitch value.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/libvirt_private.syms | 1 +
src/util/virjson.c | 25 +++++++++++++++++++++++++
src/util/virjson.h | 1 +
3 files changed, 27 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 179dcec..f7f133c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2386,6 +2386,7 @@ virJSONValueObjectAdd;
virJSONValueObjectAddVArgs;
virJSONValueObjectAppend;
virJSONValueObjectAppendBoolean;
+virJSONValueObjectAppendBooleanTristate;
virJSONValueObjectAppendNull;
virJSONValueObjectAppendNumberDouble;
virJSONValueObjectAppendNumberInt;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 4f92464..78ddc4b 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -767,6 +767,31 @@ virJSONValueObjectAppendBoolean(virJSONValuePtr object,
int
+virJSONValueObjectAppendBooleanTristate(virJSONValuePtr object,
+ const char *key,
+ int value)
+{
+ g_autoptr(virJSONValue) jvalue = NULL;
+ int v;
+
+ if (value == VIR_TRISTATE_SWITCH_ABSENT)
+ return 0;
+
+ if (value == VIR_TRISTATE_SWITCH_OFF)
+ v = 0;
+ else
+ v = 1;
+
+ jvalue = virJSONValueNewBoolean(v);
+ if (virJSONValueObjectAppend(object, key, jvalue) < 0)
+ return -1;
+ jvalue = NULL;
+
+ return 0;
+}
+
+
+int
virJSONValueObjectAppendNull(virJSONValuePtr object,
const char *key)
{
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 4dc7ed1..aa4ae82 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -137,6 +137,7 @@ int virJSONValueObjectAppendNumberLong(virJSONValuePtr object, const
char *key,
int virJSONValueObjectAppendNumberUlong(virJSONValuePtr object, const char *key, unsigned
long long number);
int virJSONValueObjectAppendNumberDouble(virJSONValuePtr object, const char *key, double
number);
int virJSONValueObjectAppendBoolean(virJSONValuePtr object, const char *key, int
boolean);
+int virJSONValueObjectAppendBooleanTristate(virJSONValuePtr object, const char *key, int
value);
int virJSONValueObjectAppendNull(virJSONValuePtr object, const char *key);
int virJSONValueObjectRemoveKey(virJSONValuePtr object, const char *key,
--
1.8.3.1