[PATCH 03/21] Introduce virTypedParamsCheck internal API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This API is useful for checking whether only a specific subset of
supported typed parameters were passed.
---
 docs/apibuild.py         |  1 +
 src/libvirt_private.syms |  1 +
 src/util/virtypedparam.c | 26 ++++++++++++++++++++++++++
 src/util/virtypedparam.h |  5 +++++
 4 files changed, 33 insertions(+)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index 686a234..c816197 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -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 = {
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f61fe55..ae9f356 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1899,6 +1899,7 @@ virTPMCreateCancelPath;
 # util/virtypedparam.h
 virTypedParameterAssign;
 virTypedParameterAssignFromStr;
+virTypedParamsCheck;
 virTypedParamsValidate;
 
 
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index eef9e30..825148b 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -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.
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 8f6bd1b..b0f8522 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -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;
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]