schema tree FEATURE functions for lysc node full dfs
diff --git a/src/plugins_exts_nacm.c b/src/plugins_exts_nacm.c
index 7012e66..8589bce 100644
--- a/src/plugins_exts_nacm.c
+++ b/src/plugins_exts_nacm.c
@@ -24,6 +24,49 @@
LYEXT_VERSION_CHECK
*/
+struct nacm_dfs_arg {
+ struct lysc_ext_instance *c_ext;
+ struct lysc_node *parent;
+};
+
+/**
+ * @brief DFS callback implementation for inheriting the NACM extension.
+ */
+static LY_ERR
+nacm_inherit_clb(struct lysc_node *node, void *data, ly_bool *dfs_continue)
+{
+ struct nacm_dfs_arg *arg = data;
+ struct lysc_ext_instance *inherited;
+ LY_ARRAY_COUNT_TYPE u;
+
+ /* ignore the parent from which we inherit and input/output nodes */
+ if ((node != arg->parent) && !(node->nodetype & (LYS_INPUT | LYS_OUTPUT))) {
+ /* check that the node does not have its own NACM extension instance */
+ LY_ARRAY_FOR(node->exts, u) {
+ if (node->exts[u].def == arg->c_ext->def) {
+ /* the child already have its own NACM flag, so skip the subtree */
+ *dfs_continue = 1;
+ return LY_SUCCESS;
+ }
+ }
+
+ /* duplicate this one to inherit it to the child */
+ LY_ARRAY_NEW_RET(node->module->ctx, node->exts, inherited, LY_EMEM);
+
+ inherited->def = lysc_ext_dup(arg->c_ext->def);
+ inherited->parent = node;
+ inherited->parent_type = LYEXT_PAR_NODE;
+ if (arg->c_ext->argument) {
+ LY_CHECK_RET(lydict_insert(node->module->ctx, arg->c_ext->argument, strlen(arg->c_ext->argument),
+ &inherited->argument));
+ }
+ /* TODO duplicate extension instances */
+ inherited->data = arg->c_ext->data;
+ }
+
+ return LY_SUCCESS;
+}
+
/**
* @brief Compile NAMC's extension instances.
*
@@ -32,9 +75,9 @@
LY_ERR
nacm_compile(struct lysc_ctx *cctx, const struct lysp_ext_instance *p_ext, struct lysc_ext_instance *c_ext)
{
- struct lysc_node *parent = NULL, *iter;
- struct lysc_ext_instance *inherited;
+ struct lysc_node *parent = NULL;
LY_ARRAY_COUNT_TYPE u;
+ struct nacm_dfs_arg dfs_arg;
static const uint8_t nacm_deny_all = 1;
static const uint8_t nacm_deny_write = 2;
@@ -85,33 +128,9 @@
}
/* inherit the extension instance to all the children nodes */
- LYSC_TREE_DFS_BEGIN(parent, iter) {
- /* ignore the parent from which we inherit and input/output nodes */
- if ((iter != parent) && !(iter->nodetype & (LYS_INPUT | LYS_OUTPUT))) {
- /* check that the node does not have its own NACM extension instance */
- LY_ARRAY_FOR(iter->exts, u) {
- if (iter->exts[u].def == c_ext->def) {
- /* the child already have its own NACM flag, so skip the subtree */
- LYSC_TREE_DFS_continue = 1;
- break;
- }
- }
- if (!LYSC_TREE_DFS_continue) {
- /* duplicate this one to inherit it to the child */
- LY_ARRAY_NEW_RET(cctx->ctx, iter->exts, inherited, LY_EMEM);
-
- inherited->def = lysc_ext_dup(c_ext->def);
- inherited->parent = iter;
- inherited->parent_type = LYEXT_PAR_NODE;
- if (c_ext->argument) {
- LY_CHECK_RET(lydict_insert(cctx->ctx, c_ext->argument, strlen(c_ext->argument), &inherited->argument));
- }
- /* TODO duplicate extension instances */
- inherited->data = c_ext->data;
- }
- }
- LYSC_TREE_DFS_END(parent, iter)
- }
+ dfs_arg.c_ext = c_ext;
+ dfs_arg.parent = parent;
+ LY_CHECK_RET(lysc_tree_dfs_full(parent, nacm_inherit_clb, &dfs_arg));
return LY_SUCCESS;
}