Introduce virTypedParamsCheck internal API

This API is useful for checking whether only a specific subset of
supported typed parameters were passed.
This commit is contained in:
Jiri Denemark 2013-05-06 12:04:06 +02:00
parent 40369ea674
commit 637a7c865a
4 changed files with 33 additions and 0 deletions

View File

@ -67,6 +67,7 @@ ignored_functions = {
"virTypedParamsValidate": "internal function in virtypedparam.c",
"virTypedParameterAssign": "internal function in virtypedparam.c",
"virTypedParameterAssignFromStr": "internal function in virtypedparam.c",
"virTypedParamsCheck": "internal function in virtypedparam.c",
}
ignored_macros = {

View File

@ -1943,6 +1943,7 @@ virTPMCreateCancelPath;
# util/virtypedparam.h
virTypedParameterAssign;
virTypedParameterAssignFromStr;
virTypedParamsCheck;
virTypedParamsValidate;

View File

@ -109,6 +109,32 @@ cleanup:
}
/* Check if params contains only specified parameter names. Return true if
* only specified names are present in params, false if params contains any
* unspecified parameter name. */
bool
virTypedParamsCheck(virTypedParameterPtr params,
int nparams,
const char **names,
int nnames)
{
int i, j;
for (i = 0; i < nparams; i++) {
bool found = false;
for (j = 0; j < nnames; j++) {
if (STREQ(params[i].field, names[j])) {
found = true;
break;
}
}
if (!found)
return false;
}
return true;
}
/* Assign name, type, and the appropriately typed arg to param; in the
* case of a string, the caller is assumed to have malloc'd a string,
* or can pass NULL to have this function malloc an empty string.

View File

@ -29,6 +29,11 @@ int virTypedParamsValidate(virTypedParameterPtr params, int nparams,
/* const char *name, int type ... */ ...)
ATTRIBUTE_SENTINEL ATTRIBUTE_RETURN_CHECK;
bool virTypedParamsCheck(virTypedParameterPtr params,
int nparams,
const char **names,
int nnames);
int virTypedParameterAssign(virTypedParameterPtr param, const char *name,
int type, /* TYPE arg */ ...)
ATTRIBUTE_RETURN_CHECK;