data tree FEATURE optional use of any value
But must now be explicitily specified.
diff --git a/src/tree_data.c b/src/tree_data.c
index 2760a65..cc51c8f 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -987,8 +987,8 @@
}
API LY_ERR
-lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, void *value,
- LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node)
+lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
+ ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node)
{
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
@@ -1003,7 +1003,7 @@
schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYD_NODE_ANY, output ? LYS_GETNEXT_OUTPUT : 0);
LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Any node \"%s\" not found.", name), LY_ENOTFOUND);
- LY_CHECK_RET(lyd_create_any(schema, value, value_type, 1, &ret));
+ LY_CHECK_RET(lyd_create_any(schema, value, value_type, use_value, &ret));
if (parent) {
lyd_insert_node(parent, NULL, ret);
}
diff --git a/src/tree_data.h b/src/tree_data.h
index e5ad560..bcea739 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -969,15 +969,16 @@
* @param[in] parent Parent node for the node being created. NULL in case of creating a top level element.
* @param[in] module Module of the node being created. If NULL, @p parent module will be used.
* @param[in] name Schema node name of the new data node. The node can be #LYS_ANYDATA or #LYS_ANYXML.
- * @param[in] value Value to be directly assigned to the node. Expected type is determined by @p value_type.
+ * @param[in] value Value for the node. Expected type is determined by @p value_type.
+ * @param[in] use_value Whether to directly take @p value and assign it to the node or make a copy.
* @param[in] value_type Type of the provided value in @p value.
* @param[in] output Flag in case the @p parent is RPC/Action. If value is 0, the input's data nodes of the RPC/Action are
* taken into consideration. Otherwise, the output's data node is going to be created.
* @param[out] node Optional created node.
* @return LY_ERR value.
*/
-LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, void *value,
- LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node);
+LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
+ ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node);
/**
* @brief Create new metadata.
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index a7776d0..a0a573c 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -128,7 +128,7 @@
CHECK_LOG_CTX("Inner node (and not a list) \"l2\" not found.", NULL);
/* anydata */
- assert_int_equal(lyd_new_any(NULL, mod, "any", "some-value", LYD_ANYDATA_STRING, 0, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_any(NULL, mod, "any", "some-value", 0, LYD_ANYDATA_STRING, 0, &node), LY_SUCCESS);
lyd_free_tree(node);
/* key-less list */