mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virTypedParamsValidate: Allow typed params to be both _UINT and _ULLONG
For certain typed parameters we want to extend the supproted range by switching to VIR_TYPED_PARAM_ULLONG. To preserve compatibility we've added APIs such as 'virTypedParamsGetUnsigned' and 'virTypedParamListAddUnsigned' which automatically select the bigger type if necessary. This patch adds a new internal macro VIR_TYPED_PARAM_UNSIGNED which is used with virTypedParamsValidate to allow both types and adjusts the code to handle it properly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b5ee977d17
commit
07652410a7
@ -63,7 +63,6 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
size_t j;
|
||||
const char *name;
|
||||
const char *last_name = NULL;
|
||||
int type;
|
||||
size_t nkeys = 0;
|
||||
size_t nkeysalloc = 0;
|
||||
g_autofree virTypedParameterPtr sorted = NULL;
|
||||
@ -79,7 +78,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
|
||||
name = va_arg(ap, const char *);
|
||||
while (name) {
|
||||
type = va_arg(ap, int);
|
||||
int type = va_arg(ap, int);
|
||||
VIR_RESIZE_N(keys, nkeysalloc, nkeys, 1);
|
||||
|
||||
if (virStrcpyStatic(keys[nkeys].field, name) < 0) {
|
||||
@ -105,6 +104,9 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
if (STRNEQ(sorted[i].field, keys[j].field)) {
|
||||
j++;
|
||||
} else {
|
||||
const char *expecttype = virTypedParameterTypeToString(keys[j].type);
|
||||
int type = sorted[i].type;
|
||||
|
||||
if (STREQ_NULLABLE(last_name, sorted[i].field) &&
|
||||
!(keys[j].value.i & VIR_TYPED_PARAM_MULTIPLE)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
@ -112,7 +114,15 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
sorted[i].field);
|
||||
return -1;
|
||||
}
|
||||
if (sorted[i].type != keys[j].type) {
|
||||
|
||||
if (keys[j].type == VIR_TYPED_PARAM_UNSIGNED &&
|
||||
(type == VIR_TYPED_PARAM_UINT ||
|
||||
type == VIR_TYPED_PARAM_ULLONG)) {
|
||||
type = VIR_TYPED_PARAM_UNSIGNED;
|
||||
expecttype = "uint, ullong";
|
||||
}
|
||||
|
||||
if (type != keys[j].type) {
|
||||
const char *badtype;
|
||||
|
||||
badtype = virTypedParameterTypeToString(sorted[i].type);
|
||||
@ -120,8 +130,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
|
||||
badtype = virTypedParameterTypeToString(0);
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("invalid type '%1$s' for parameter '%2$s', expected '%3$s'"),
|
||||
badtype, sorted[i].field,
|
||||
virTypedParameterTypeToString(keys[j].type));
|
||||
badtype, sorted[i].field, expecttype);
|
||||
return -1;
|
||||
}
|
||||
last_name = sorted[i].field;
|
||||
|
@ -24,6 +24,15 @@
|
||||
#include "internal.h"
|
||||
#include "virenum.h"
|
||||
|
||||
|
||||
/**
|
||||
* VIR_TYPED_PARAM_UNSIGNED:
|
||||
*
|
||||
* Special typed parameter type only used with virTypedParamsValidate to
|
||||
* indicate that both VIR_TYPED_PARAM_UINT and VIR_TYPED_PARAM_ULLONG types
|
||||
* are acceptable for given value.
|
||||
*/
|
||||
#define VIR_TYPED_PARAM_UNSIGNED (VIR_TYPED_PARAM_LAST + 1)
|
||||
/**
|
||||
* VIR_TYPED_PARAM_MULTIPLE:
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user