validation CHANGE validating single module data
... instead of module array. It simplifies the API
considerably and in case several modules need to
be validated, the function can be called repeatedly
without any performance impact.
diff --git a/src/parser_data.h b/src/parser_data.h
index f0d5a29..e12b65e 100644
--- a/src/parser_data.h
+++ b/src/parser_data.h
@@ -254,16 +254,15 @@
LY_ERR lyd_validate(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts);
/**
- * @brief Fully validate a data tree.
+ * @brief Fully validate a data tree of a module.
*
* @param[in,out] tree Data tree to recursively validate. May be changed by validation.
- * @param[in] modules Array of modules to validate.
- * @param[in] mod_count Number of @p modules.
+ * @param[in] module Module whose data (and schema restrictions) to validate.
* @param[in] val_opts Validation options (@ref datavalidationoptions).
* @return LY_SUCCESS on success.
* @return LY_ERR error on error.
*/
-LY_ERR lyd_validate_modules(struct lyd_node **tree, const struct lys_module **modules, int mod_count, int val_opts);
+LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, int val_opts);
/**
* @brief Validate an RPC/action, notification, or RPC/action reply.
diff --git a/src/parser_xml.c b/src/parser_xml.c
index c435643..8c1e36d 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -701,7 +701,7 @@
if (validate_options & LYD_VALIDATE_PRESENT) {
mod = lyd_data_next_module(&next, &first);
} else {
- mod = lyd_mod_next_module(next, NULL, 0, ctx, &i, &first);
+ mod = lyd_mod_next_module(next, NULL, ctx, &i, &first);
}
if (!mod) {
break;
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 599a5bc..8356961 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -87,18 +87,19 @@
}
const struct lys_module *
-lyd_mod_next_module(struct lyd_node *tree, const struct lys_module **modules, int mod_count, const struct ly_ctx *ctx,
- uint32_t *i, struct lyd_node **first)
+lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t *i,
+ struct lyd_node **first)
{
struct lyd_node *iter;
const struct lys_module *mod;
/* get the next module */
- if (modules && mod_count) {
- if (*i < (unsigned)mod_count) {
- mod = modules[(*i)++];
- } else {
+ if (module) {
+ if (*i) {
mod = NULL;
+ } else {
+ mod = module;
+ ++(*i);
}
} else {
do {
diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h
index 3055dbf..e9e58ac 100644
--- a/src/tree_data_internal.h
+++ b/src/tree_data_internal.h
@@ -460,15 +460,14 @@
* @brief Iterate over implemented modules for functions that accept specific modules or the whole context.
*
* @param[in] tree Data tree.
- * @param[in] modules Selected modules, NULL for all.
- * @param[in] mod_count Count of @p modules.
+ * @param[in] module Selected module, NULL for all.
* @param[in] ctx Context, NULL for selected modules.
* @param[in,out] i Iterator, set to 0 on first call.
* @param[out] first First sibling of the returned module.
* @return Next module.
* @return NULL if all modules were traversed.
*/
-const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module **modules, int mod_count,
+const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module,
const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first);
/**
diff --git a/src/validation.c b/src/validation.c
index 799c2bf..007f8eb 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -1192,8 +1192,7 @@
* @return LY_ERR value.
*/
static LY_ERR
-_lyd_validate(struct lyd_node **tree, const struct lys_module **modules, int mod_count, const struct ly_ctx *ctx,
- int val_opts)
+_lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, int val_opts)
{
LY_ERR ret = LY_SUCCESS;
struct lyd_node *first, *next, **first2;
@@ -1201,14 +1200,14 @@
struct ly_set type_check = {0}, type_meta_check = {0}, when_check = {0};
uint32_t i = 0;
- LY_CHECK_ARG_RET(NULL, tree, *tree || ctx || (modules && mod_count), LY_EINVAL);
+ LY_CHECK_ARG_RET(NULL, tree, *tree || ctx || module, LY_EINVAL);
next = *tree;
while (1) {
if (val_opts & LYD_VALIDATE_PRESENT) {
mod = lyd_data_next_module(&next, &first);
} else {
- mod = lyd_mod_next_module(next, modules, mod_count, ctx, &i, &first);
+ mod = lyd_mod_next_module(next, module, ctx, &i, &first);
}
if (!mod) {
break;
@@ -1249,13 +1248,13 @@
API LY_ERR
lyd_validate(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts)
{
- return _lyd_validate(tree, NULL, 0, ctx, val_opts);
+ return _lyd_validate(tree, NULL, ctx, val_opts);
}
API LY_ERR
-lyd_validate_modules(struct lyd_node **tree, const struct lys_module **modules, int mod_count, int val_opts)
+lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, int val_opts)
{
- return _lyd_validate(tree, modules, mod_count, NULL, val_opts);
+ return _lyd_validate(tree, module, NULL, val_opts);
}
/**