Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent deletion of RO leaf-lists #136

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions models/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<NODE name="minutes" mode="r" help="minutes" range="0..59"/>
<NODE name="seconds" mode="r" help="seconds" range="0..59"/>
</NODE>
<NODE name="romembers" help="A read-only leaf-list">
<NODE name="*" mode="r" help="Member of group"/>
</NODE>
</NODE>
<NODE name="animals">
<NODE name="animal" help="This is a list of animals">
Expand Down
36 changes: 32 additions & 4 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
free ((void *)child->children->data);
free ((void *)child->data);
g_node_destroy (child);
child = NULL;
}
else if (!sch_is_writable (schema))
{
Expand Down Expand Up @@ -3369,8 +3370,10 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
}
else if (g_strcmp0 (name, "*") == 0)
{
for (GNode *child = parent->children; child; child = child->next)
child = parent->children;
while (child)
{
GNode *next = child->next;
for (sch_node *s = sch_node_child_first (schema); s; s = sch_node_next_sibling (s))
{
if (flags & SCH_F_FILTER_RDEPTH)
Expand All @@ -3384,6 +3387,13 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
if (!rc)
goto exit;
}
if (!child->children)
{
DEBUG (flags, "Throwing away node \"%s\"\n", APTERYX_NAME (child));
free ((void *)child->data);
g_node_destroy (child);
}
child = next;
}
}
else if (sch_is_leaf_list (schema))
Expand All @@ -3392,10 +3402,28 @@ _sch_traverse_nodes (sch_instance * instance, sch_node * schema, GNode * parent,
{
if (!(flags & SCH_F_FILTER_RDEPTH) || (depth >= rdepth))
{
for (GNode *leaf = child->children; leaf; leaf = leaf->next)
/* Access is stored on the * node */
sch_node *lschema = sch_node_child_first (schema);
if (sch_is_hidden (lschema) ||
(flags & SCH_F_CONFIG && !sch_is_writable (lschema)))
{
free (leaf->children->data);
leaf->children->data = g_strdup ("");
DEBUG (flags, "Silently ignoring leaf-list \"%s\"\n", name);
apteryx_free_tree (child);
carlgsmith marked this conversation as resolved.
Show resolved Hide resolved
child = NULL;
}
else if (!sch_is_writable (lschema))
{
ERROR (flags, SCH_E_NOTWRITABLE, "Node not writable \"%s\"\n", name);
rc = false;
goto exit;
}
else
{
for (GNode *leaf = child->children; leaf; leaf = leaf->next)
{
free (leaf->children->data);
leaf->children->data = g_strdup ("");
}
}
}
}
Expand Down
Loading