data tree REFCTOR move prefix callbacks to plugins types
Meaning they are still public but needed only when
implementing plugins. Common API functions do not
require these callbacks.
diff --git a/src/diff.c b/src/diff.c
index 83acef8..e5d96a9 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1155,8 +1155,7 @@
meta = lyd_find_meta(diff_match->meta, mod, "orig-value");
LY_CHECK_ERR_RET(!meta, LOGINT(LYD_NODE_CTX(diff_match)), LY_EINT);
str_val = lyd_meta2str(meta, &dynamic);
- ret = lyd_value_compare((struct lyd_node_term *)diff_match, str_val, strlen(str_val), lydjson_resolve_prefix,
- NULL, LYD_JSON, NULL);
+ ret = lyd_value_compare((struct lyd_node_term *)diff_match, str_val, strlen(str_val), NULL);
if (dynamic) {
free((char *)str_val);
}
diff --git a/src/parser_xml.c b/src/parser_xml.c
index cb1955d..0254a81 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -246,7 +246,7 @@
assert(xmlctx->status == LYXML_ELEM_CONTENT);
if (i < key_set.count) {
/* validate the value */
- r = lys_value_validate(NULL, snode, xmlctx->value, xmlctx->value_len, lydxml_resolve_prefix, xmlctx, LYD_XML);
+ r = _lys_value_validate(NULL, snode, xmlctx->value, xmlctx->value_len, lydxml_resolve_prefix, xmlctx, LYD_XML);
if (!r) {
/* key with a valid value, remove from the set */
ly_set_rm_index(&key_set, i, NULL);
@@ -369,7 +369,7 @@
if ((*snode)->nodetype & LYD_NODE_TERM) {
/* value may not be valid in which case we parse it as an opaque node */
- if (lys_value_validate(NULL, *snode, xmlctx->value, xmlctx->value_len, lydxml_resolve_prefix, xmlctx, LYD_XML)) {
+ if (_lys_value_validate(NULL, *snode, xmlctx->value, xmlctx->value_len, lydxml_resolve_prefix, xmlctx, LYD_XML)) {
*snode = NULL;
}
} else {
diff --git a/src/path.h b/src/path.h
index 2e32f91..d57cd31 100644
--- a/src/path.h
+++ b/src/path.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include "log.h"
+#include "plugins_types.h"
#include "tree.h"
#include "tree_data.h"
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 67da438..62d2d38 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -103,6 +103,37 @@
void ly_err_free(void *ptr);
/**
+ * @brief Callback provided by the data/schema parsers to type plugins to resolve (format-specific) mapping between prefixes used
+ * in the value strings to the YANG schemas.
+ *
+ * Reverse function to ly_clb_get_prefix.
+ *
+ * XML uses XML namespaces, JSON uses schema names as prefixes, YIN/YANG uses prefixes of the imports.
+ *
+ * @param[in] ctx libyang context to find the schema.
+ * @param[in] prefix Prefix found in the value string
+ * @param[in] prefix_len Length of the @p prefix.
+ * @param[in] private Internal data needed by the callback.
+ * @return Pointer to the YANG schema identified by the provided prefix or NULL if no mapping found.
+ */
+typedef const struct lys_module *(*ly_clb_resolve_prefix)(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
+ void *private);
+
+/**
+ * @brief Callback provided by the data/schema printers to type plugins to resolve (format-specific) mapping between YANG module of a data object
+ * to prefixes used in the value strings.
+ *
+ * Reverse function to ly_clb_resolve_prefix.
+ *
+ * XML uses XML namespaces, JSON uses schema names as prefixes, YIN/YANG uses prefixes of the imports.
+ *
+ * @param[in] mod YANG module of the object.
+ * @param[in] private Internal data needed by the callback.
+ * @return String representing prefix for the object of the given YANG module @p mod.
+ */
+typedef const char *(*ly_clb_get_prefix)(const struct lys_module *mod, void *private);
+
+/**
* @defgroup plugintypeopts Options for type plugin callbacks. The same set of the options is passed to all the type's callbacks used together.
*
* Options applicable to ly_type_validate_clb() and ly_type_store_clb.
diff --git a/src/tree_data.c b/src/tree_data.c
index 9b4abd7..f9887dd 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -159,9 +159,9 @@
return ret;
}
-API LY_ERR
-lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
- ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format)
+LY_ERR
+_lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
+ ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format)
{
LY_ERR rc = LY_SUCCESS;
struct ly_err_item *err = NULL;
@@ -177,7 +177,7 @@
type = ((struct lysc_node_leaf*)node)->type;
/* just validate, no storing of enything */
rc = type->plugin->store(ctx ? ctx : node->module->ctx, type, value, value_len, LY_TYPE_OPTS_INCOMPLETE_DATA,
- get_prefix, get_prefix_data, format, node, NULL, NULL, NULL, &err);
+ resolve_prefix, prefix_data, format, node, NULL, NULL, NULL, &err);
if (rc == LY_EINCOMPLETE) {
/* actually success since we do not provide the context tree and call validation with
* LY_TYPE_OPTS_INCOMPLETE_DATA */
@@ -195,8 +195,13 @@
}
API LY_ERR
+lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len)
+{
+ return _lys_value_validate(ctx, node, value, value_len, lydjson_resolve_prefix, NULL, LYD_JSON);
+}
+
+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, struct lysc_type **realtype)
{
LY_ERR rc;
@@ -209,7 +214,7 @@
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,
+ lydjson_resolve_prefix, NULL, LYD_JSON, tree ? (void*)node : (void*)node->schema, tree,
&val, NULL, &err);
if (rc == LY_EINCOMPLETE) {
return rc;
@@ -233,8 +238,7 @@
}
API LY_ERR
-lyd_value_compare(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)
+lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len, const struct lyd_node *tree)
{
LY_ERR ret = LY_SUCCESS, rc;
struct ly_err_item *err = NULL;
@@ -247,8 +251,8 @@
ctx = node->schema->module->ctx;
type = ((struct lysc_node_leaf*)node->schema)->type;
- rc = type->plugin->store(ctx, type, value, value_len, options, get_prefix, get_prefix_data, format, (struct lyd_node*)node,
- tree, &data, NULL, &err);
+ rc = type->plugin->store(ctx, type, value, value_len, options, lydjson_resolve_prefix, NULL, LYD_JSON,
+ (struct lyd_node *)node, tree, &data, NULL, &err);
if (rc == LY_EINCOMPLETE) {
ret = rc;
/* continue with comparing, just remember what to return if storing is ok */
@@ -1189,7 +1193,7 @@
r = LY_SUCCESS;
if (options & LYD_NEWOPT_OPAQ) {
- r = lys_value_validate(NULL, schema, value, strlen(value), lydjson_resolve_prefix, NULL, LYD_JSON);
+ r = lys_value_validate(NULL, schema, value, strlen(value));
}
if (!r) {
LY_CHECK_GOTO(ret = lyd_value_store(&pred->value, schema, value, strlen(value), NULL, lydjson_resolve_prefix,
@@ -1268,7 +1272,7 @@
r = LY_SUCCESS;
if (options & LYD_NEWOPT_OPAQ) {
- r = lys_value_validate(NULL, schema, value, strlen(value), lydjson_resolve_prefix, NULL, LYD_JSON);
+ r = lys_value_validate(NULL, schema, value, strlen(value));
}
if (!r) {
LY_CHECK_GOTO(ret = lyd_create_term(schema, value, strlen(value), NULL, lydjson_resolve_prefix, NULL,
diff --git a/src/tree_data.h b/src/tree_data.h
index 531bb2f..1cbed06 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -269,37 +269,6 @@
/** @} */
/**
- * @brief Callback provided by the data/schema parsers to type plugins to resolve (format-specific) mapping between prefixes used
- * in the value strings to the YANG schemas.
- *
- * Reverse function to ly_clb_get_prefix.
- *
- * XML uses XML namespaces, JSON uses schema names as prefixes, YIN/YANG uses prefixes of the imports.
- *
- * @param[in] ctx libyang context to find the schema.
- * @param[in] prefix Prefix found in the value string
- * @param[in] prefix_len Length of the @p prefix.
- * @param[in] private Internal data needed by the callback.
- * @return Pointer to the YANG schema identified by the provided prefix or NULL if no mapping found.
- */
-typedef const struct lys_module *(*ly_clb_resolve_prefix)(const struct ly_ctx *ctx, const char *prefix, size_t prefix_len,
- void *private);
-
-/**
- * @brief Callback provided by the data/schema printers to type plugins to resolve (format-specific) mapping between YANG module of a data object
- * to prefixes used in the value strings.
- *
- * Reverse function to ly_clb_resolve_prefix.
- *
- * XML uses XML namespaces, JSON uses schema names as prefixes, YIN/YANG uses prefixes of the imports.
- *
- * @param[in] mod YANG module of the object.
- * @param[in] private Internal data needed by the callback.
- * @return String representing prefix for the object of the given YANG module @p mod.
- */
-typedef const char *(*ly_clb_get_prefix)(const struct lys_module *mod, void *private);
-
-/**
* @brief Generic structure for a data node.
*/
struct lyd_node {
@@ -810,11 +779,8 @@
*
* @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
* @param[in] node Data node for the @p value.
- * @param[in] value String value to be checked.
+ * @param[in] value String value to be checked, it is expected to be in JSON format.
* @param[in] value_len Length of the given @p value (mandatory).
- * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
- * @param[in] get_prefix_data Private data for the @p get_prefix callback.
- * @param[in] format Input format of the data.
* @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.
@@ -824,7 +790,6 @@
* @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, struct lysc_type **realtype);
/**
@@ -832,11 +797,8 @@
*
* @param[in] node Data node to compare.
* @param[in] value String value to be compared. It does not need to be in a canonical form - as part of the process,
- * it is validated and canonized if possible.
+ * it is validated and canonized if possible. But it is expected to be in JSON format.
* @param[in] value_len Length of the given @p value (mandatory).
- * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
- * @param[in] get_prefix_data Private data for the @p get_prefix callback.
- * @param[in] format Input format of the data.
* @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.
@@ -846,8 +808,7 @@
* @return LY_ENOT if the values do not match.
* @return LY_ERR value if an error occurred.
*/
-LY_ERR lyd_value_compare(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_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len, const struct lyd_node *tree);
/**
* @defgroup datacompareoptions Data compare options
diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h
index 980af5e..9de80fc 100644
--- a/src/tree_data_internal.h
+++ b/src/tree_data_internal.h
@@ -286,6 +286,10 @@
int *dynamic, int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format,
const struct lysc_node *ctx_snode, const struct lyd_node *tree);
+/* generic function lys_value_validate */
+LY_ERR _lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
+ ly_clb_resolve_prefix resolve_prefix, void *prefix_data, LYD_FORMAT format);
+
/**
* @brief Parse XML string as YANG data tree.
*
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 7bc1193..b6498d0 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -2039,16 +2039,12 @@
*
* @param[in] ctx libyang context for logging (function does not log errors when @p ctx is NULL)
* @param[in] node Schema node for the @p value.
- * @param[in] value String value to be checked.
+ * @param[in] value String value to be checked, expected to be in JSON format.
* @param[in] value_len Length of the given @p value (mandatory).
- * @param[in] get_prefix Callback function to resolve prefixes used in the @p value string.
- * @param[in] get_prefix_data Private data for the @p get_prefix callback.
- * @param[in] format Input format of the @p value.
* @return LY_SUCCESS on success
* @return LY_ERR value if an error occurred.
*/
-LY_ERR lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len,
- ly_clb_resolve_prefix get_prefix, void *get_prefix_data, LYD_FORMAT format);
+LY_ERR lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len);
/**
* @brief Stringify schema nodetype.
diff --git a/src/validation.h b/src/validation.h
index d6d1f17..4f1c4c1 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -17,6 +17,7 @@
#include "log.h"
#include "parser_data.h"
+#include "plugins_types.h"
#include "tree_data.h"
/**