data tree FEATURE optional realtype of validated value
diff --git a/src/tree_data.c b/src/tree_data.c
index 866a64f..9b4abd7 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -196,19 +196,21 @@
API LY_ERR
lyd_value_validate(const struct ly_ctx *ctx, const struct lyd_node_term *node, const char *value, size_t value_len,
- ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format, const struct lyd_node *tree)
+ ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format,
+ const struct lyd_node *tree, struct lysc_type **realtype)
{
LY_ERR rc;
struct ly_err_item *err = NULL;
struct lysc_type *type;
- int options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
+ struct lyd_value val = {0};
+ int options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA) | (realtype ? LY_TYPE_OPTS_STORE : 0);
LY_CHECK_ARG_RET(ctx, node, value, LY_EINVAL);
type = ((struct lysc_node_leaf*)node->schema)->type;
rc = type->plugin->store(ctx ? ctx : node->schema->module->ctx, type, value, value_len, options,
get_prefix, get_prefix_data, format, tree ? (void*)node : (void*)node->schema, tree,
- NULL, NULL, &err);
+ &val, NULL, &err);
if (rc == LY_EINCOMPLETE) {
return rc;
} else if (rc) {
@@ -222,6 +224,11 @@
return rc;
}
+ if (realtype) {
+ *realtype = val.realtype;
+ }
+
+ type->plugin->free(ctx ? ctx : node->schema->module->ctx, &val);
return LY_SUCCESS;
}
diff --git a/src/tree_data.h b/src/tree_data.h
index c5fab5d..531bb2f 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -818,12 +818,14 @@
* @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required data instance (leafref target,
* instance-identifier) can be placed. NULL in case the data tree is not yet complete,
* then LY_EINCOMPLETE can be returned.
+ * @param[out] realtype Optional real type of the value.
* @return LY_SUCCESS on success
* @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation (e.g. due to require-instance).
* @return LY_ERR value if an error occurred.
*/
LY_ERR lyd_value_validate(const struct ly_ctx *ctx, const struct lyd_node_term *node, const char *value, size_t value_len,
- ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format, const struct lyd_node *tree);
+ ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format,
+ const struct lyd_node *tree, struct lysc_type **realtype);
/**
* @brief Compare the node's value with the given string value. The string value is first validated according to the node's type.
diff --git a/tests/utests/data/test_types.c b/tests/utests/data/test_types.c
index 1a501c9..8492f5b 100644
--- a/tests/utests/data/test_types.c
+++ b/tests/utests/data/test_types.c
@@ -945,17 +945,17 @@
/* key-predicate */
data = "/a:list2[a:id='a'][a:value='b']/a:id";
assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term*)tree->prev->prev, data, strlen(data),
- test_instanceid_getprefix, tree->schema->module, LYD_XML, tree));
+ test_instanceid_getprefix, tree->schema->module, LYD_XML, tree, NULL));
logbuf_assert("Invalid instance-identifier \"/a:list2[a:id='a'][a:value='b']/a:id\" value - instance not found. /");
/* leaf-list-predicate */
data = "/a:leaflisttarget[.='c']";
assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term*)tree->prev->prev, data, strlen(data),
- test_instanceid_getprefix, tree->schema->module, LYD_XML, tree));
+ test_instanceid_getprefix, tree->schema->module, LYD_XML, tree, NULL));
logbuf_assert("Invalid instance-identifier \"/a:leaflisttarget[.='c']\" value - instance not found. /");
/* position predicate */
data = "/a:list_keyless[4]";
assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term*)tree->prev->prev, data, strlen(data),
- test_instanceid_getprefix, tree->schema->module, LYD_XML, tree));
+ test_instanceid_getprefix, tree->schema->module, LYD_XML, tree, NULL));
logbuf_assert("Invalid instance-identifier \"/a:list_keyless[4]\" value - instance not found. /");
lyd_free_all(tree);