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

Add support for NETCONF XPATH 1.0 #86

Merged
merged 1 commit into from
Nov 20, 2023
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 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
Loading