xpath BUGFIX handle top-level foreign augments
In case there is a top-level choice and
a foreign module augments it.
diff --git a/src/xpath.c b/src/xpath.c
index 40cec6e..ba16ede 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -5598,6 +5598,7 @@
uint32_t orig_used, i;
uint32_t mod_idx;
const struct lysc_node *iter, *start_parent;
+ const struct lys_module *moveto_mod;
if (!set) {
return LY_SUCCESS;
@@ -5632,14 +5633,15 @@
start_parent = set->val.scnodes[i].scnode;
if ((set->val.scnodes[i].type == LYXP_NODE_ROOT_CONFIG) || (set->val.scnodes[i].type == LYXP_NODE_ROOT)) {
- /* it can actually be in any module, it's all <running>, but we know it's mod (if set),
- * so use it directly (root node itself is useless in this case) */
+ /* it can actually be in any module, it's all <running>, and even if it's mod (if set),
+ * it can be in a top-level augment (the root node itself is useless in this case) */
mod_idx = 0;
- while (mod || (mod = (struct lys_module *)ly_ctx_get_module_iter(set->ctx, &mod_idx))) {
+ moveto_mod = mod;
+ while ((mod = (struct lys_module *)ly_ctx_get_module_iter(set->ctx, &mod_idx))) {
iter = NULL;
/* module may not be implemented */
while (mod->implemented && (iter = lys_getnext(iter, NULL, mod->compiled, getnext_opts))) {
- if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, mod)) {
+ if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, moveto_mod)) {
LY_CHECK_RET(lyxp_set_scnode_insert_node(set, iter, LYXP_NODE_ELEM, &idx));
/* we need to prevent these nodes from being considered in this moveto */
@@ -5649,19 +5651,13 @@
}
}
}
-
- if (!mod_idx) {
- /* mod was specified, we are not going through the whole context */
- break;
- }
- /* next iteration */
- mod = NULL;
}
} else if (set->val.scnodes[i].type == LYXP_NODE_ELEM) {
iter = NULL;
+ moveto_mod = mod ? mod : set->local_mod;
while ((iter = lys_getnext(iter, start_parent, NULL, getnext_opts))) {
- if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, (mod ? mod : set->local_mod))) {
+ if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, moveto_mod)) {
LY_CHECK_RET(lyxp_set_scnode_insert_node(set, iter, LYXP_NODE_ELEM, &idx));
if ((idx < orig_used) && (idx > i)) {
@@ -7052,7 +7048,9 @@
}
}
if (i == -1) {
- path = lysc_path(set->ctx_scnode, LYSC_PATH_LOG, NULL, 0);
+ const struct lysc_node *real_ctx_scnode = set->ctx_scnode->nodetype & (LYS_CHOICE | LYS_CASE) ?
+ lysc_data_parent(set->ctx_scnode) : set->ctx_scnode;
+ path = lysc_path(real_ctx_scnode, LYSC_PATH_LOG, NULL, 0);
LOGWRN(set->ctx, "Schema node \"%.*s\" not found (%.*s) with context node \"%s\".",
ncname_len, ncname, ncname - exp->expr, exp->expr, path);
free(path);