diff --git a/src/context.h b/src/context.h index 722f946fe2..ae2f8e9571 100644 --- a/src/context.h +++ b/src/context.h @@ -449,13 +449,15 @@ LIBYANG_API_DECL void ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_im * @brief Callback for getting arbitrary run-time data required by an extension instance. * * @param[in] ext Compiled extension instance. + * @param[in] parent Data parent node instance of a schema node with @p ext instance. In special cases + * (when not working with data) it be NULL! * @param[in] user_data User-supplied callback data. * @param[out] ext_data Provided extension instance data. * @param[out] ext_data_free Whether the extension instance should free @p ext_data or not. * @return LY_ERR value. */ -typedef LY_ERR (*ly_ext_data_clb)(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, - ly_bool *ext_data_free); +typedef LY_ERR (*ly_ext_data_clb)(const struct lysc_ext_instance *ext, const struct lyd_node *parent, void *user_data, + void **ext_data, ly_bool *ext_data_free); /** * @brief Set callback providing run-time extension instance data. The expected data depend on the extension. diff --git a/src/plugins_exts.c b/src/plugins_exts.c index 2168c94566..a45fc5567f 100644 --- a/src/plugins_exts.c +++ b/src/plugins_exts.c @@ -675,7 +675,8 @@ lyplg_ext_parsed_get_storage(const struct lysc_ext_instance *ext, int stmt, uint } LIBYANG_API_DEF LY_ERR -lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, void **ext_data, ly_bool *ext_data_free) +lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, const struct lyd_node *parent, + void **ext_data, ly_bool *ext_data_free) { LY_ERR rc; @@ -684,7 +685,7 @@ lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext return LY_EINVAL; } - if ((rc = ctx->ext_clb(ext, ctx->ext_clb_data, ext_data, ext_data_free))) { + if ((rc = ctx->ext_clb(ext, parent, ctx->ext_clb_data, ext_data, ext_data_free))) { lyplg_ext_compile_log(NULL, ext, LY_LLERR, rc, "Callback for getting ext data failed."); } return rc; diff --git a/src/plugins_exts.h b/src/plugins_exts.h index cbfc9d38d8..21db6e8e52 100644 --- a/src/plugins_exts.h +++ b/src/plugins_exts.h @@ -1012,13 +1012,14 @@ LIBYANG_API_DECL LY_ERR lyplg_ext_parsed_get_storage(const struct lysc_ext_insta * * @param[in] ctx Context with the callback. * @param[in] ext Compiled extension instance. + * @param[in] parent Data parent node instance of a schema node with @p ext instance. * @param[out] ext_data Provided extension instance data. * @param[out] ext_data_free Whether the extension instance should free @p ext_data or not. * @return LY_SUCCESS on success. * @return LY_ERR on error. */ -LIBYANG_API_DECL LY_ERR lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, void **ext_data, - ly_bool *ext_data_free); +LIBYANG_API_DECL LY_ERR lyplg_ext_get_data(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, + const struct lyd_node *parent, void **ext_data, ly_bool *ext_data_free); /** * @brief Insert extension instance data into a parent. @@ -1034,20 +1035,24 @@ LIBYANG_API_DECL LY_ERR lyplg_ext_insert(struct lyd_node *parent, struct lyd_nod * @brief Expand parent-reference xpath expressions * * @param[in] ext Context allocated for extension. + * @param[in] parent Data parent node instance of a schema node with @p ext instance. * @param[out] refs Set of schema node matching parent-reference XPaths. * @return LY_ERR value. */ -LIBYANG_API_DECL LY_ERR lyplg_ext_schema_mount_get_parent_ref(const struct lysc_ext_instance *ext, struct ly_set **refs); +LIBYANG_API_DECL LY_ERR lyplg_ext_schema_mount_get_parent_ref(const struct lysc_ext_instance *ext, + const struct lyd_node *parent, struct ly_set **refs); /** * @brief Allocate a new context for a particular instance of the yangmnt:mount-point extension. * Caller is responsible for **freeing** the created context. * * @param[in] ext Compiled extension instance. + * @param[in] parent Data parent node instance of a schema node with @p ext instance. * @param[out] ctx Context with modules loaded from the list found in the extension data. * @return LY_ERR value. */ -LIBYANG_API_DECL LY_ERR lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, struct ly_ctx **ctx); +LIBYANG_API_DECL LY_ERR lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, + const struct lyd_node *parent, struct ly_ctx **ctx); /** @} pluginsExtensions */ diff --git a/src/plugins_exts/schema_mount.c b/src/plugins_exts/schema_mount.c index e812053ef4..eb71ee4ee9 100644 --- a/src/plugins_exts/schema_mount.c +++ b/src/plugins_exts/schema_mount.c @@ -1,9 +1,10 @@ /** * @file schema_mount.c * @author Tadeas Vintrlik + * @author Michal Vasko * @brief libyang extension plugin - Schema Mount (RFC 8528) * - * Copyright (c) 2021 CESNET, z.s.p.o. + * Copyright (c) 2021 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -628,11 +629,12 @@ schema_mount_get_ctx_inline(struct lysc_ext_instance *ext, const struct lyd_node * @brief Get schema (context) for a mount point. * * @param[in] ext Compiled extension instance. + * @param[in] parent Data parent node instance of a schema node with @p ext instance. * @param[out] ext_ctx Schema to use for parsing the data. * @return LY_ERR value. */ static LY_ERR -schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct ly_ctx **ext_ctx) +schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct lyd_node *parent, const struct ly_ctx **ext_ctx) { LY_ERR ret = LY_SUCCESS, r; struct lyd_node *iter, *ext_data = NULL; @@ -641,7 +643,7 @@ schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct ly_ctx **ext_ct *ext_ctx = NULL; /* get operational data with ietf-yang-library and ietf-yang-schema-mount data */ - if ((r = lyplg_ext_get_data(ext->module->ctx, ext, (void **)&ext_data, &ext_data_free))) { + if ((r = lyplg_ext_get_data(ext->module->ctx, ext, parent, (void **)&ext_data, &ext_data_free))) { ret = r; goto cleanup; } @@ -693,7 +695,7 @@ schema_mount_snode(struct lysc_ext_instance *ext, const struct lyd_node *parent, const struct ly_ctx *ext_ctx = NULL; /* get context based on ietf-yang-library data */ - if ((r = schema_mount_get_ctx(ext, &ext_ctx))) { + if ((r = schema_mount_get_ctx(ext, parent, &ext_ctx))) { return r; } @@ -840,8 +842,9 @@ schema_mount_dup_parent_ref(const struct lysc_ext_instance *ext, const struct ly return ret; } -LY_ERR -lyplg_ext_schema_mount_get_parent_ref(const struct lysc_ext_instance *ext, struct ly_set **refs) +LIBYANG_API_DEF LY_ERR +lyplg_ext_schema_mount_get_parent_ref(const struct lysc_ext_instance *ext, const struct lyd_node *parent, + struct ly_set **refs) { LY_ERR rc; struct ly_set *pref_set = NULL; @@ -851,7 +854,7 @@ lyplg_ext_schema_mount_get_parent_ref(const struct lysc_ext_instance *ext, struc ly_bool ext_data_free; /* get operational data with ietf-yang-library and ietf-yang-schema-mount data */ - if ((rc = lyplg_ext_get_data(ext->module->ctx, ext, (void **)&ext_data, &ext_data_free))) { + if ((rc = lyplg_ext_get_data(ext->module->ctx, ext, parent, (void **)&ext_data, &ext_data_free))) { return rc; } @@ -916,7 +919,7 @@ schema_mount_validate(struct lysc_ext_instance *ext, struct lyd_node *sibling, c } /* get operational data with ietf-yang-library and ietf-yang-schema-mount data */ - if ((ret = lyplg_ext_get_data(ext->module->ctx, ext, (void **)&ext_data, &ext_data_free))) { + if ((ret = lyplg_ext_get_data(ext->module->ctx, ext, lyd_parent(sibling), (void **)&ext_data, &ext_data_free))) { goto cleanup; } @@ -1062,7 +1065,8 @@ schema_mount_cfree(const struct ly_ctx *ctx, struct lysc_ext_instance *ext) } LIBYANG_API_DEF LY_ERR -lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, struct ly_ctx **ctx) +lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, const struct lyd_node *parent, + struct ly_ctx **ctx) { struct lyd_node *ext_data = NULL; ly_bool ext_data_free = 0, config; @@ -1077,7 +1081,7 @@ lyplg_ext_schema_mount_create_context(const struct lysc_ext_instance *ext, struc } /* get operational data with ietf-yang-library and ietf-yang-schema-mount data */ - if ((rc = lyplg_ext_get_data(ext->module->ctx, ext, (void **)&ext_data, &ext_data_free))) { + if ((rc = lyplg_ext_get_data(ext->module->ctx, ext, parent, (void **)&ext_data, &ext_data_free))) { return rc; } @@ -1206,12 +1210,12 @@ schema_mount_sprinter_ctree(struct lysc_ext_instance *ext, const struct lyspr_tr return LY_SUCCESS; } - if (lyplg_ext_schema_mount_create_context(ext, &ext_ctx)) { + if (lyplg_ext_schema_mount_create_context(ext, NULL, &ext_ctx)) { /* Void mount point */ return LY_SUCCESS; } - rc = lyplg_ext_schema_mount_get_parent_ref(ext, &refs); + rc = lyplg_ext_schema_mount_get_parent_ref(ext, NULL, &refs); LY_CHECK_GOTO(rc, cleanup); /* build new list of modules to print. This list will omit internal diff --git a/src/tree_schema.c b/src/tree_schema.c index 3877da11ea..ce713204a2 100644 --- a/src/tree_schema.c +++ b/src/tree_schema.c @@ -258,7 +258,7 @@ lys_getnext_(const struct lysc_node *last, const struct lysc_node *parent, const LY_ARRAY_FOR(parent->exts, u) { if (!strcmp(parent->exts[u].def->name, "mount-point") && !strcmp(parent->exts[u].def->module->name, "ietf-yang-schema-mount")) { - lyplg_ext_schema_mount_create_context(&parent->exts[u], &sm_ctx); + lyplg_ext_schema_mount_create_context(&parent->exts[u], NULL, &sm_ctx); if (sm_ctx) { /* some usable context created */ break; diff --git a/tests/utests/extensions/test_schema_mount.c b/tests/utests/extensions/test_schema_mount.c index f27e16821d..f324372be7 100644 --- a/tests/utests/extensions/test_schema_mount.c +++ b/tests/utests/extensions/test_schema_mount.c @@ -162,7 +162,8 @@ test_schema(void **state) } static LY_ERR -test_ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free) +test_ext_data_clb(const struct lysc_ext_instance *ext, const struct lyd_node *UNUSED(parent), void *user_data, + void **ext_data, ly_bool *ext_data_free) { void **state = glob_state; struct lyd_node *data = NULL; diff --git a/tests/utests/schema/test_printer_tree.c b/tests/utests/schema/test_printer_tree.c index 5438c6114b..591ed20816 100644 --- a/tests/utests/schema/test_printer_tree.c +++ b/tests/utests/schema/test_printer_tree.c @@ -1920,7 +1920,8 @@ yang_data(void **state) } static LY_ERR -getter(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free) +getter(const struct lysc_ext_instance *ext, const struct lyd_node *UNUSED(parent), void *user_data, void **ext_data, + ly_bool *ext_data_free) { struct ly_ctx *ctx; struct lyd_node *data = NULL; diff --git a/tools/lint/common.c b/tools/lint/common.c index d86c54f1bb..a69ce83794 100644 --- a/tools/lint/common.c +++ b/tools/lint/common.c @@ -262,7 +262,8 @@ find_schema_path(const struct ly_ctx *ctx, const char *schema_path) } LY_ERR -ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free) +ext_data_clb(const struct lysc_ext_instance *ext, const struct lyd_node *UNUSED(parent), void *user_data, + void **ext_data, ly_bool *ext_data_free) { struct ly_ctx *ctx; struct lyd_node *data = NULL; diff --git a/tools/lint/common.h b/tools/lint/common.h index 7c50e7280e..8f3e8a1bf1 100644 --- a/tools/lint/common.h +++ b/tools/lint/common.h @@ -138,12 +138,14 @@ const struct lysc_node *find_schema_path(const struct ly_ctx *ctx, const char *s * @brief General callback providing run-time extension instance data. * * @param[in] ext Compiled extension instance. + * @param[in] parent Data aprent, unused. * @param[in] user_data User-supplied callback data. * @param[out] ext_data Provided extension instance data. * @param[out] ext_data_free Whether the extension instance should free @p ext_data or not. * @return LY_ERR value. */ -LY_ERR ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free); +LY_ERR ext_data_clb(const struct lysc_ext_instance *ext, const struct lyd_node *parent, void *user_data, + void **ext_data, ly_bool *ext_data_free); /** * @brief Concatenation of paths into one string.