plugins types FEATURE empty LYB value support
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 78da33d..66b7a59 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -702,8 +702,7 @@
*/
/**
- * @brief Validate and store value of the YANG built-in empty type.
- * Implementation of the ::lyplg_type_store_clb.
+ * @brief Implementation of ::lyplg_type_store_clb for the built-in empty type.
*/
LY_ERR lyplg_type_store_empty(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len,
uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node,
diff --git a/src/plugins_types/empty.c b/src/plugins_types/empty.c
index 915ef72..eb2306d 100644
--- a/src/plugins_types/empty.c
+++ b/src/plugins_types/empty.c
@@ -12,8 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#define _GNU_SOURCE
-
#include "plugins_types.h"
#include <stdint.h>
@@ -27,6 +25,15 @@
#include "compat.h"
#include "plugins_internal.h" /* LY_TYPE_*_STR */
+/**
+ * @page howtoDataLYB LYB Binary Format
+ * @subsection howtoDataLYBTypesEmpty empty (built-in)
+ *
+ * | Size (B) | Mandatory | Type | Meaning |
+ * | :------ | :-------: | :--: | :-----: |
+ * | 0 | yes | `void` | none |
+ */
+
API LY_ERR
lyplg_type_store_empty(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len,
uint32_t options, LY_VALUE_FORMAT UNUSED(format), void *UNUSED(prefix_data), uint32_t hints,
@@ -35,32 +42,41 @@
{
LY_ERR ret = LY_SUCCESS;
- *err = NULL;
+ /* clear storage */
+ memset(storage, 0, sizeof *storage);
/* check hints */
ret = lyplg_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
- LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
+ LY_CHECK_GOTO(ret, cleanup);
+ /* validation */
if (value_len) {
- ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid empty value \"%.*s\".", (int)value_len,
- (char *)value);
+ ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid empty value length %zu.", value_len);
goto cleanup;
}
- if (options & LYPLG_TYPE_STORE_DYNAMIC) {
- ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
- options &= ~LYPLG_TYPE_STORE_DYNAMIC;
- LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
- } else {
- ret = lydict_insert(ctx, "", value_len, &storage->_canonical);
- LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
- }
+ /* init storage */
+ storage->_canonical = NULL;
storage->ptr = NULL;
storage->realtype = type;
+ /* store canonical value */
+ if (options & LYPLG_TYPE_STORE_DYNAMIC) {
+ ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
+ options &= ~LYPLG_TYPE_STORE_DYNAMIC;
+ LY_CHECK_GOTO(ret, cleanup);
+ } else {
+ ret = lydict_insert(ctx, "", value_len, &storage->_canonical);
+ LY_CHECK_GOTO(ret, cleanup);
+ }
+
cleanup:
if (options & LYPLG_TYPE_STORE_DYNAMIC) {
- free((char *)value);
+ free((void *)value);
+ }
+
+ if (ret) {
+ lyplg_type_free_simple(ctx, storage);
}
return ret;
}
diff --git a/tests/utests/data/test_types.c b/tests/utests/data/test_types.c
index 4a59581..cddda2a 100644
--- a/tests/utests/data/test_types.c
+++ b/tests/utests/data/test_types.c
@@ -461,9 +461,9 @@
lyd_free_all(tree);
/* invalid value */
- TEST_TYPE_ERROR("empty", "x", "Invalid empty value \"x\".", "1");
+ TEST_TYPE_ERROR("empty", "x", "Invalid empty value length 1.", "1");
- TEST_TYPE_ERROR("empty", " ", "Invalid empty value \" \".", "1");
+ TEST_TYPE_ERROR("empty", " ", "Invalid empty value length 1.", "1");
}
static void
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 1b8ed65..90ea8fd 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -318,7 +318,7 @@
CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/aa:ll");
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "Schema location /bb:ll.");
+ CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value length 1.).", "Schema location /bb:ll.");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
"leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG, &mod));
@@ -1843,7 +1843,7 @@
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"leaf l {type empty; default x;}}", LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "Schema location /aa:l.");
+ CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value length 1.).", "Schema location /aa:l.");
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
"leaf l {type mytype;}}", LYS_IN_YANG, NULL));