Skip to content

Commit

Permalink
Add support for NETCONF XPATH 1.0
Browse files Browse the repository at this point in the history
Added a new function to return the root schema for an instance.
Exposed match_name and sch_ns_match needed by netconf.c
  • Loading branch information
gcampbell512 authored and carlgsmith committed Nov 20, 2023
1 parent 3315a32 commit 113bbd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions apteryx-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ sch_node *sch_node_child (sch_node *parent, const char *name);
sch_node *sch_node_child_first (sch_node * parent);
sch_node *sch_node_next_sibling (sch_node * node);
sch_node *sch_preorder_next (sch_node *current, sch_node *root);
sch_node *sch_get_root_schema (sch_instance * instance);

char *sch_name (sch_node * node);
char *sch_model (sch_node * node, bool ignore_ancestors);
Expand All @@ -86,6 +87,8 @@ bool sch_is_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);
gboolean sch_match_name (const char *s1, const char *s2);
bool sch_ns_match (sch_node *node, void *ns);

/* Data translation/manipulation */
typedef enum
Expand Down
24 changes: 18 additions & 6 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ sch_get_loaded_models (sch_instance * instance)
return instance->models_list;
}

static gboolean
match_name (const char *s1, const char *s2)
gboolean
sch_match_name (const char *s1, const char *s2)
{
char c1, c2;
do
Expand Down Expand Up @@ -943,7 +943,7 @@ sch_dump_xml (sch_instance * instance)
}

static bool
sch_ns_match (xmlNode *node, xmlNs *ns)
_sch_ns_match (xmlNode *node, xmlNs *ns)
{
sch_instance *instance = node->doc->_private;

Expand Down Expand Up @@ -972,6 +972,18 @@ sch_ns_match (xmlNode *node, xmlNs *ns)
return false;
}

bool
sch_ns_match (sch_node *node, void *ns)
{
return _sch_ns_match (node, ns);
}

sch_node *
sch_get_root_schema (sch_instance * instance)
{
return (instance ? xmlDocGetRootElement (instance->doc) : NULL);
}

static xmlNs *
sch_lookup_ns (sch_instance * instance, xmlNode *schema, const char *name, int flags, bool href)
{
Expand Down Expand Up @@ -1079,7 +1091,7 @@ lookup_node (sch_instance *instance, xmlNs *ns, xmlNode *node, const char *path)
if (lk)
key[lk - key] = '\0';
}
if (name && (name[0] == '*' || match_name (name, key)) && sch_ns_match (n, ns))
if (name && (name[0] == '*' || sch_match_name (name, key)) && _sch_ns_match (n, ns))
{
free (key);
if (path)
Expand Down Expand Up @@ -1130,7 +1142,7 @@ _sch_node_child (xmlNs *ns, sch_node * parent, const char *child)
if (n->type == XML_ELEMENT_NODE && n->name[0] == 'N')
{
char *name = (char *) xmlGetProp (n, (xmlChar *) "name");
if (name && (name[0] == '*' || match_name (name, child)) && sch_ns_match (n, ns))
if (name && (name[0] == '*' || sch_match_name (name, child)) && _sch_ns_match (n, ns))
{
xmlFree (name);
break;
Expand All @@ -1155,7 +1167,7 @@ _sch_node_find_name (xmlNs *ns, sch_node * parent, const char *path_name, GList
if (n->type == XML_ELEMENT_NODE && n->name[0] == 'N')
{
char *name = (char *) xmlGetProp (n, (xmlChar *) "name");
if (match_name (name, path_name) && sch_ns_match (n, ns))
if (sch_match_name (name, path_name) && _sch_ns_match (n, ns))
{
xmlFree (name);
found = true;
Expand Down

0 comments on commit 113bbd6

Please sign in to comment.