libyang UPDATE optional value validation and context type plugins (#2171)
This patch separates the build-in type validations from store
operations to allow storing a node even if the value doesn't pass the
validations. To do multiple changes were done:
- introduces LY_CTX_BASIC_PLUGINS_ONLY flag, which prevents loading of
any advanced plugins
- introduces LYPLG_TYPE_STORE_ONLY flag, which skip validation and
perform just storing
- introduces LYD_PARSE_STORE_ONLY flag, which implies usage of LYPLG_TYPE_STORE_ONLY
- introduces options for lyd_new_* API
- removes lyd_new_(term|list)_(bin|canon) API
- added sanity checks within lyd_new_(term|list) APIs for proper
combinations of options
- refactored lyd_new_* APIs to use common flags to use common options attributes
diff --git a/src/tree_data_common.c b/src/tree_data_common.c
index eb14433..9746faa 100644
--- a/src/tree_data_common.c
+++ b/src/tree_data_common.c
@@ -505,8 +505,8 @@
LY_ERR
lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const void *value,
- size_t value_len, ly_bool is_utf8, ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints,
- const struct lysc_node *ctx_node, ly_bool *incomplete)
+ size_t value_len, ly_bool is_utf8, ly_bool store_only, ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data,
+ uint32_t hints, const struct lysc_node *ctx_node, ly_bool *incomplete)
{
LY_ERR ret;
struct ly_err_item *err = NULL;
@@ -525,6 +525,9 @@
if (is_utf8) {
options |= LYPLG_TYPE_STORE_IS_UTF8;
}
+ if (store_only) {
+ options |= LYPLG_TYPE_STORE_ONLY;
+ }
ret = type->plugin->store(ctx, type, value, value_len, options, format, prefix_data, hints, ctx_node, val, NULL, &err);
if (dynamic) {
@@ -688,7 +691,7 @@
/* store the value */
LOG_LOCSET(NULL, &node->node);
- ret = lyd_value_store(ctx, &val, type, value, value_len, 0, NULL, LY_VALUE_JSON, NULL, LYD_HINT_DATA, node->schema, NULL);
+ ret = lyd_value_store(ctx, &val, type, value, value_len, 0, 0, NULL, LY_VALUE_JSON, NULL, LYD_HINT_DATA, node->schema, NULL);
LOG_LOCBACK(0, 1);
LY_CHECK_RET(ret);