Skip to content

Commit

Permalink
plugins exts UPDATE data node for ext data cb is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Oct 1, 2024
1 parent 29088f8 commit 50c97ed
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/plugins_exts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/plugins_exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 */

Expand Down
28 changes: 16 additions & 12 deletions src/plugins_exts/schema_mount.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* @file schema_mount.c
* @author Tadeas Vintrlik <[email protected]>
* @author Michal Vasko <[email protected]>
* @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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tree_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/utests/extensions/test_schema_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/utests/schema/test_printer_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tools/lint/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion tools/lint/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 50c97ed

Please sign in to comment.