parser CHANGE lys_path uses options instead of a flag
diff --git a/src/extensions/nacm.c b/src/extensions/nacm.c
index 5611afe..18c9ae2 100644
--- a/src/extensions/nacm.c
+++ b/src/extensions/nacm.c
@@ -112,7 +112,7 @@
}
if (c > 1) {
- path = lys_path((struct lys_node *)(ext->parent), 1);
+ path = lys_path((struct lys_node *)(ext->parent), LYS_PATH_FIRST_PREFIX);
LYEXT_LOG(LY_LLERR, "NACM", "Extension nacm:%s can appear only once, but %d instances found in %s.",
ext->def->name, c, path);
free(path);
diff --git a/src/parser.c b/src/parser.c
index f36a022..8312223 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -3457,7 +3457,7 @@
}
if (!found) {
- path = lys_path(target, 1);
+ path = lys_path(target, LYS_PATH_FIRST_PREFIX);
LOGERR(LY_EVALID, "Extension deviation: extension \"%s\" to delete not found in \"%s\".", ext->def->name, path)
free(path);
return EXIT_FAILURE;
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 3f3d20e..6b6fc88 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -2434,7 +2434,7 @@
* and fix the schema by inheriting */
if (!(node->flags & (LYS_STATUS_MASK))) {
/* status not explicitely specified on the current node -> inherit */
- str = lys_path(node, 1);
+ str = lys_path(node, LYS_PATH_FIRST_PREFIX);
LOGWRN("Missing status in %s subtree (%s), inheriting.",
parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", str);
free(str);
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 25a5203..c3a597b 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -3904,10 +3904,10 @@
if (stmt_type == LYEXT_PAR_NODE) {
p = node->parent;
node->parent = parent;
- str = lys_path(node, 1);
+ str = lys_path(node, LYS_PATH_FIRST_PREFIX);
node->parent = p;
} else {
- str = lys_path(parent, 1);
+ str = lys_path(parent, LYS_PATH_FIRST_PREFIX);
}
LOGWRN("Missing status in %s subtree (%s), inheriting.", parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", str);
free(str);
diff --git a/src/resolve.c b/src/resolve.c
index 3edd5f7..6a39906 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -5626,7 +5626,7 @@
assert(ly_err_main.vlog_hide);
ly_vlog_hide(0);
LOGWRN("Default value \"%s\" in the list key \"%s\" is ignored. (%s)", list->keys[i]->dflt,
- list->keys[i]->name, s = lys_path((struct lys_node*)list, 1));
+ list->keys[i]->name, s = lys_path((struct lys_node*)list, LYS_PATH_FIRST_PREFIX));
ly_vlog_hide(1);
free(s);
}
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 5a8dbdf..28b08da 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -4525,7 +4525,7 @@
}
API char *
-lys_path(const struct lys_node *node, int shorten)
+lys_path(const struct lys_node *node, int options)
{
char *buf, *result;
uint16_t start_idx, len;
@@ -4540,7 +4540,7 @@
start_idx = LY_BUF_SIZE - 1;
buf[start_idx] = '\0';
- if (ly_vlog_build_path_reverse(LY_VLOG_LYS, node, &buf, &start_idx, &len, 1, !shorten)) {
+ if (ly_vlog_build_path_reverse(LY_VLOG_LYS, node, &buf, &start_idx, &len, 1, !options)) {
free(buf);
return NULL;
}
diff --git a/src/tree_schema.h b/src/tree_schema.h
index ce37b0d..7623b14 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -2178,15 +2178,20 @@
/**
* @brief Build schema path (usable as path, see @ref howtoxpath) of the schema node.
+ *
+ * The path includes prefixes of all the nodes and is hence unequivocal in any context.
+ * Options can be specified to use a different format of the path.
+ *
* @param[in] node Schema node to be processed.
- * @param[in] shorten Whether to shorten the schema path by not including prefixes for nodes
- * from the same module as \p node except the first node in the path. If shortened, the path is
- * not usable without a specific current module or node (more at @ref howtoxpath) at hence less
- * suitable for further processing but better for displaying.
+ * @param[in] options Additional path modification options (#LYS_PATH_FIRST_PREFIX).
* @return NULL on error, on success the buffer for the resulting path is allocated and caller is supposed to free it
* with free().
*/
-char *lys_path(const struct lys_node *node, int shorten);
+char *lys_path(const struct lys_node *node, int options);
+
+#define LYS_PATH_FIRST_PREFIX 0x01 /**< lys_path() option for the path not to include prefixes of all the nodes,
+ * but only for the first one that will be interpreted as the current module (more at @ref howtoxpath). This path is
+ * less suitable for further processing but better for displaying as it is shorter. */
/**
* @brief Build data path (usable as path, see @ref howtoxpath) of the schema node.
diff --git a/src/xpath.c b/src/xpath.c
index 6f4c108..a385fe6 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -6501,7 +6501,7 @@
}
}
if (i == -1) {
- path = lys_path((struct lys_node *)cur_node, 1);
+ path = lys_path((struct lys_node *)cur_node, LYS_PATH_FIRST_PREFIX);
LOGWRN("Schema node \"%.*s\" not found (%.*s) with context node \"%s\".",
exp->tok_len[*exp_idx], &exp->expr[exp->expr_pos[*exp_idx]],
exp->expr_pos[*exp_idx] + exp->tok_len[*exp_idx], exp->expr, path);
@@ -8482,7 +8482,7 @@
if (when) {
if (lyxp_atomize(when->cond, node, LYXP_NODE_ELEM, &tmp_set, LYXP_SNODE_WHEN | opts, &ctx_snode)) {
free(tmp_set.val.snodes);
- path = lys_path(ctx_snode, 1);
+ path = lys_path(ctx_snode, LYS_PATH_FIRST_PREFIX);
LOGVAL(LYE_SPEC, LY_VLOG_LYS, node, "Invalid when condition \"%s\" with context node \"%s\".", when->cond, path);
ret = -1;
goto finish;
@@ -8519,7 +8519,7 @@
for (i = 0; i < must_size; ++i) {
if (lyxp_atomize(must[i].expr, node, LYXP_NODE_ELEM, &tmp_set, LYXP_SNODE_MUST | opts, &ctx_snode)) {
free(tmp_set.val.snodes);
- path = lys_path(ctx_snode, 1);
+ path = lys_path(ctx_snode, LYS_PATH_FIRST_PREFIX);
LOGVAL(LYE_SPEC, LY_VLOG_LYS, node, "Invalid must restriction \"%s\" with context node \"%s\".", must[i].expr, path);
ret = -1;
goto finish;