data tree FEATURE lyd_new_path() and lyd_change_term()
With tests included. Also, another missing API
function lyd_new_opaq() added.
diff --git a/src/path.h b/src/path.h
index c973add..c75387c 100644
--- a/src/path.h
+++ b/src/path.h
@@ -18,6 +18,7 @@
#include <stdint.h>
#include "log.h"
+#include "tree.h"
#include "tree_data.h"
struct lysc_node;
@@ -116,25 +117,47 @@
uint8_t pred, struct lyxp_expr **expr);
/**
+ * @defgroup path_oper_options Path operation options.
+ * @{
+ */
+#define LY_PATH_OPER_INPUT 0x01 /**< if any RPC/action is traversed, its input nodes are used */
+#define LY_PATH_OPER_OUTPUT 0x02 /**< if any RPC/action is traversed, its output nodes are used */
+/** @} */
+
+/* lref */
+
+/**
+ * @defgroup path_target_options Path target options.
+ * @{
+ */
+#define LY_PATH_TARGET_SINGLE 0x10 /**< last (target) node must identify an exact instance */
+#define LY_PATH_TARGET_MANY 0x20 /**< last (target) node may identify all instances (of leaf-list/list) */
+/** @} */
+
+/**
* @brief Compile path into ly_path structure. Any predicates of a leafref are only checked, not compiled.
*
+ * @param[in] ctx libyang context.
* @param[in] cur_mod Module of the current (original context) node. Used for nodes without prefix for ::LYD_SCHEMA format.
* @param[in] ctx_node Context node. Can be NULL for absolute paths.
* @param[in] expr Parsed path.
* @param[in] lref Lref option (@ref path_lref_options).
+ * @param[in] oper Oper option (@ref path_oper_options).
+ * @param[in] target Target option (@ref path_target_options).
* @param[in] resolve_prefix Callback for prefix resolution.
* @param[in] prefix_data Data for @p resolve_prefix.
* @param[in] format Format of the path.
* @param[out] path Compiled path.
* @return LY_ERR value.
*/
-LY_ERR ly_path_compile(const struct lys_module *cur_mod, const struct lysc_node *ctx_node, const struct lyxp_expr *expr,
- uint8_t lref, ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format,
- struct ly_path **path);
+LY_ERR ly_path_compile(const struct ly_ctx *ctx, const struct lys_module *cur_mod, const struct lysc_node *ctx_node,
+ const struct lyxp_expr *expr, uint8_t lref, uint8_t oper, uint8_t target,
+ ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format, struct ly_path **path);
/**
* @brief Compile predicate into ly_path_predicate structure. Only simple predicates (not leafref) are supported.
*
+ * @param[in] ctx libyang context.
* @param[in] cur_mod Module of the current (original context) node. Used for nodes without prefix for ::LYD_SCHEMA format.
* @param[in] ctx_node Context node, node for which the predicate is defined.
* @param[in] expr Parsed path.
@@ -146,10 +169,25 @@
* @param[out] pred_type Type of the compiled predicate(s).
* @return LY_ERR value.
*/
-LY_ERR ly_path_compile_predicate(const struct lys_module *cur_mod, const struct lysc_node *ctx_node,
- const struct lyxp_expr *expr, uint16_t *tok_idx, ly_clb_resolve_prefix resolve_prefix,
- void *prefix_data, LYD_FORMAT format, struct ly_path_predicate **predicates,
- enum ly_path_pred_type *pred_type);
+LY_ERR ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lys_module *cur_mod,
+ const struct lysc_node *ctx_node, const struct lyxp_expr *expr, uint16_t *tok_idx,
+ ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format,
+ struct ly_path_predicate **predicates, enum ly_path_pred_type *pred_type);
+
+/**
+ * @brief Resolve at least partially the target defined by ly_path structure. Not supported for leafref!
+ *
+ * @param[in] path Path structure specifying the target.
+ * @param[in] start Starting node for relative paths, can be any for absolute paths.
+ * @param[out] path_idx Last found path segment index, can be NULL, set to 0 if not found.
+ * @param[out] match Last found matching node, can be NULL, set to NULL if not found.
+ * @return LY_ENOTFOUND if no nodes were found,
+ * @return LY_EINCOMPLETE if some node was found but not the last one,
+ * @return LY_SUCCESS when the last node in the path was found,
+ * @return LY_ERR on another error.
+ */
+LY_ERR ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, LY_ARRAY_SIZE_TYPE *path_idx,
+ struct lyd_node **match);
/**
* @brief Resolve the target defined by ly_path structure. Not supported for leafref!