data tree FEATURE function for finding inst-id target
Deprecating lyd_target() with unsuitable prototype.
Refs #1617
diff --git a/src/tree_data.c b/src/tree_data.c
index bbb1505..f0b9575 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -4312,6 +4312,28 @@
return ret;
}
+API LY_ERR
+lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct lyd_node **match)
+{
+ LY_ERR ret;
+ struct lyd_node *m;
+
+ LY_CHECK_ARG_RET(NULL, path, LY_EINVAL);
+
+ ret = ly_path_eval(path, tree, &m);
+ if (ret) {
+ if (match) {
+ *match = NULL;
+ }
+ return LY_ENOTFOUND;
+ }
+
+ if (match) {
+ *match = m;
+ }
+ return LY_SUCCESS;
+}
+
API uint32_t
lyd_list_pos(const struct lyd_node *instance)
{
diff --git a/src/tree_data.h b/src/tree_data.h
index f58dd01..a9f836a 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -102,6 +102,7 @@
* - ::lyd_get_meta_value()
* - ::lyd_find_xpath()
* - ::lyd_find_path()
+ * - ::lyd_find_target()
* - ::lyd_find_sibling_val()
* - ::lyd_find_sibling_first()
* - ::lyd_find_sibling_opaq_next()
@@ -553,7 +554,8 @@
uint64_t uint64; /**< 64-bit unsigned integer */
struct lysc_type_bitenum_item *enum_item; /**< pointer to the definition of the enumeration value */
struct lysc_ident *ident; /**< pointer to the schema definition of the identityref value */
- struct ly_path *target; /**< Instance-identifier target path. */
+ struct ly_path *target; /**< Instance-identifier target path, use ::lyd_find_target() to evaluate
+ it on data. */
struct lyd_value_union *subvalue; /** Union value with some metadata. */
void *dyn_mem; /**< pointer to generic data type value stored in dynamic memory */
@@ -2161,7 +2163,7 @@
LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff);
/**
- * @brief Find the target in data of a compiled instance-identifier path (the target member in ::lyd_value).
+ * @brief Deprecated, use ::lyd_find_target() instead.
*
* @param[in] path Compiled path structure.
* @param[in] tree Data tree to be searched.
@@ -2304,6 +2306,18 @@
LY_ERR lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output, struct lyd_node **match);
/**
+ * @brief Find the target node of a compiled path (::lyd_value instance-identifier).
+ *
+ * @param[in] path Compiled path structure.
+ * @param[in] tree Data tree to be searched.
+ * @param[out] match Can be NULL, otherwise the found data node.
+ * @return LY_SUCCESS on success, @p match is set to the found node.
+ * @return LY_ENOTFOUND if no match was found.
+ * @return LY_ERR on other errors.
+ */
+LY_ERR lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct lyd_node **match);
+
+/**
* @brief Convert date-and-time from string to UNIX timestamp and fractions of a second.
*
* @param[in] value Valid string date-and-time value.