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/parser_common.c b/src/parser_common.c
index dadd1d7..06544f1 100644
--- a/src/parser_common.c
+++ b/src/parser_common.c
@@ -284,8 +284,10 @@
{
LY_ERR r;
ly_bool incomplete;
+ ly_bool store_only = (lydctx->parse_opts & LYD_PARSE_STORE_ONLY) ? 1 : 0;
- if ((r = lyd_create_term(schema, value, value_len, 1, dynamic, format, prefix_data, hints, &incomplete, node))) {
+ if ((r = lyd_create_term(schema, value, value_len, 1, store_only, dynamic, format, prefix_data,
+ hints, &incomplete, node))) {
if (lydctx->data_ctx->ctx != schema->module->ctx) {
/* move errors to the main context */
ly_err_move(schema->module->ctx, (struct ly_ctx *)lydctx->data_ctx->ctx);
@@ -308,6 +310,7 @@
char *dpath = NULL, *path = NULL;
ly_bool incomplete;
struct lyd_meta *first = NULL;
+ ly_bool store_only = (lydctx->parse_opts & LYD_PARSE_STORE_ONLY) ? 1 : 0;
if (meta && *meta) {
/* remember the first metadata */
@@ -323,7 +326,7 @@
}
ly_log_location(NULL, NULL, path, NULL);
- LY_CHECK_GOTO(rc = lyd_create_meta(parent, meta, mod, name, name_len, value, value_len, 1, dynamic, format,
+ LY_CHECK_GOTO(rc = lyd_create_meta(parent, meta, mod, name, name_len, value, value_len, 1, store_only, dynamic, format,
prefix_data, hints, ctx_node, 0, &incomplete), cleanup);
if (incomplete && !(lydctx->parse_opts & LYD_PARSE_ONLY)) {