Skip to content

Commit

Permalink
Add support for read-only proxy trees
Browse files Browse the repository at this point in the history
This change allows a remote apteryx database to be mounted at a
proxy node as a read only tree.

The logical-element model has been extended to contain a read only
logical element for testing purposes.
  • Loading branch information
gcampbell512 authored and carlgsmith committed Aug 27, 2024
1 parent 6cf2223 commit 7e9abec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apteryx-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ bool sch_is_executable (sch_node * node);
bool sch_is_hidden (sch_node * node);
bool sch_is_config (sch_node * node);
bool sch_is_proxy (sch_node * node);
bool sch_is_read_only_proxy (sch_node * node);
char *sch_translate_to (sch_node * node, char *value);
char *sch_translate_from (sch_node * node, char *value);
bool sch_validate_pattern (sch_node * node, const char *value);
Expand All @@ -120,6 +121,7 @@ typedef enum
SCH_F_SET_NULL = (1 << 13), /* Set all nodes to NULL */
SCH_F_FILTER_RDEPTH = (1 << 14), /* Set filter based on depth value */
SCH_F_IDREF_VALUES = (1 << 15), /* Expand identityref based values to include type information */
SCH_F_MODIFY_DATA = (1 << 16), /* The created tree will be used to modify the associated model */
} sch_flags;
GNode *sch_path_to_gnode (sch_instance * instance, sch_node * schema, const char * path, int flags, sch_node ** rschema);
bool sch_query_to_gnode (sch_instance * instance, sch_node * schema, GNode *parent, const char * query, int flags, int *rflags);
Expand Down
10 changes: 8 additions & 2 deletions models/logical-element.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
<NODE name="logical-elements" help="Allows a device to support multiple logical element (device) instances.">
<NODE name="logical-element" help="List of logical elements.">
<NODE name="*" mode="p" help="The logical-element entry with key name">
<NODE name="name" mode="rw" help="Device-wide unique identifier for the logical element."/>
<NODE name="root" help="Container for mount point."/>
<NODE name="name" mode="rw" help="Device-wide unique identifier for the logical element." />
<NODE name="root" help="Container for mount point." />
</NODE>
</NODE>
<NODE name="logical-element-ro" help="List of read only logical elements.">
<NODE name="*" mode="pr" help="The logical-element entry with key name">
<NODE name="name" mode="rw" help="Device-wide unique identifier for the logical element." />
<NODE name="root" help="Container for mount point." />
</NODE>
</NODE>
</NODE>
Expand Down
22 changes: 22 additions & 0 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,20 @@ sch_is_proxy (sch_node * node)
return access;
}

bool
sch_is_read_only_proxy (sch_node * node)
{
xmlNode *xml = (xmlNode *) node;
bool read_only = false;
char *mode = (char *) xmlGetProp (xml, (xmlChar *) "mode");
if (mode && strchr (mode, 'p') != NULL && strchr (mode, 'r') != NULL)
{
read_only = true;
}
free (mode);
return read_only;
}

char *
sch_translate_to (sch_node * node, char *value)
{
Expand Down Expand Up @@ -2590,6 +2604,7 @@ _sch_path_to_gnode (sch_instance * instance, sch_node ** rschema, xmlNs *ns, con
char *name = NULL;
sch_node *last_good_schema = NULL;
bool is_proxy = false;
bool read_only = false;

if (path && path[0] == '/')
{
Expand Down Expand Up @@ -2656,6 +2671,7 @@ _sch_path_to_gnode (sch_instance * instance, sch_node ** rschema, xmlNs *ns, con
if (!child)
{
is_proxy = sch_is_proxy (schema);
read_only = sch_is_read_only_proxy (schema);
}
}

Expand Down Expand Up @@ -2686,6 +2702,12 @@ _sch_path_to_gnode (sch_instance * instance, sch_node ** rschema, xmlNs *ns, con

last_good_schema = schema;
schema = _sch_node_child (ns, schema, name);
if ((flags & SCH_F_MODIFY_DATA) && schema && read_only)
{
ERROR (flags, SCH_E_NOTWRITABLE, "Node not writable \"%s\"\n", name);
goto exit;
}

if ((flags & SCH_F_XPATH) && schema == NULL && g_strcmp0 (name, "*") == 0)
{
GList *path_list = NULL;
Expand Down

0 comments on commit 7e9abec

Please sign in to comment.