Add an internal helper for fetching a typed parameter which can be
either of the '_UINT' or '_ULONG' type and store it in a unsigned long
long variable.
Since this is an internal helper it offers less protections against
invalid use compared to those we expose as public API.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virtypedparam.c | 51 ++++++++++++++++++++++++++++++++++++++++
src/util/virtypedparam.h | 5 ++++
3 files changed, 57 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4e21851c53..62c296bf5f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3567,6 +3567,7 @@ virTypedParamsCopy;
virTypedParamsDeserialize;
virTypedParamsFilter;
virTypedParamsGetStringList;
+virTypedParamsGetUnsigned;
virTypedParamsRemoteFree;
virTypedParamsReplaceString;
virTypedParamsSerialize;
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 52eea0fc54..d0e6cf6d9b 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -456,6 +456,57 @@ virTypedParamsGetStringList(virTypedParameterPtr params,
}
+/**
+ * virTypedParamsGetUnsigned:
+ * @params: array of typed parameters
+ * @nparams: number of parameters in the @params array
+ * @name: name of the parameter to find
+ * @value: where to store the parameter's value
+ *
+ * Finds typed parameter called @name and store its 'unsigned long long' or
+ * 'unsigned int' value in @value.
+ *
+ * This is an internal variand which expects that the typed parameters were
+ * already validated by calling virTypedParamsValidate and the appropriate
+ * parameter has the expected type.
+ *
+ * Returns 1 on success, 0 when the parameter does not exist in @params, or
+ * -1 on invalid usage.
+ */
+int
+virTypedParamsGetUnsigned(virTypedParameterPtr params,
+ int nparams,
+ const char *name,
+ unsigned long long *value)
+{
+ virTypedParameterPtr param;
+
+ if (!(param = virTypedParamsGet(params, nparams, name)))
+ return 0;
+
+ switch ((virTypedParameterType) param->type) {
+ case VIR_TYPED_PARAM_UINT:
+ *value = param->value.ui;
+ break;
+
+ case VIR_TYPED_PARAM_ULLONG:
+ *value = param->value.ul;
+ break;
+
+ case VIR_TYPED_PARAM_INT:
+ case VIR_TYPED_PARAM_LLONG:
+ case VIR_TYPED_PARAM_DOUBLE:
+ case VIR_TYPED_PARAM_BOOLEAN:
+ case VIR_TYPED_PARAM_STRING:
+ case VIR_TYPED_PARAM_LAST:
+ default:
+ return -1;
+ }
+
+ return 1;
+}
+
+
/**
* virTypedParamsRemoteFree:
* @remote_params_val: array of typed parameters as specified by
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 88f810bf78..c2f58e994c 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -79,6 +79,11 @@ virTypedParamsFilter(virTypedParameterPtr params,
virTypedParameterPtr **ret)
G_GNUC_WARN_UNUSED_RESULT;
+int
+virTypedParamsGetUnsigned(virTypedParameterPtr params,
+ int nparams,
+ const char *name,
+ unsigned long long *value);
int
virTypedParameterAssign(virTypedParameterPtr param,
--
2.39.2