libyang REFACTOR minor improvements
diff --git a/src/plugins.c b/src/plugins.c
index 1f76049..ab264f0 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -444,7 +444,7 @@
#endif
LY_ERR
-lyplg_init(ly_bool builtin_plugins_only)
+lyplg_init(ly_bool builtin_type_plugins_only)
{
LY_ERR ret;
@@ -470,7 +470,7 @@
LY_CHECK_GOTO(ret = plugins_insert(LYPLG_TYPE, plugins_string), error);
LY_CHECK_GOTO(ret = plugins_insert(LYPLG_TYPE, plugins_union), error);
- if (!builtin_plugins_only) {
+ if (!builtin_type_plugins_only) {
/* yang */
LY_CHECK_GOTO(ret = plugins_insert(LYPLG_TYPE, plugins_instanceid_keys), error);
diff --git a/src/plugins_internal.h b/src/plugins_internal.h
index f624624..59adacf 100644
--- a/src/plugins_internal.h
+++ b/src/plugins_internal.h
@@ -48,12 +48,12 @@
*
* Covers both the types and extensions plugins.
*
- * @param[in] builtin_plugins_only Whether to load only built-in YANG plugin types and extensions.
+ * @param[in] builtin_type_plugins_only Whether to load only built-in YANG type plugins and no included extension plugins.
* @return LY_SUCCESS in case of success
* @return LY_EINT in case of internal error
* @return LY_EMEM in case of memory allocation failure.
*/
-LY_ERR lyplg_init(ly_bool builtin_plugins_only);
+LY_ERR lyplg_init(ly_bool builtin_type_plugins_only);
/**
* @brief Remove (unload) all the plugins currently available.
diff --git a/src/tree_data.h b/src/tree_data.h
index ba33f26..784b34f 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1270,9 +1270,9 @@
#define LYD_NEW_VAL_OUTPUT 0x01 /**< 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. */
#define LYD_NEW_VAL_STORE_ONLY 0x02 /**< Whether to perform only storing operation with no or minimum valitions */
-#define LYD_NEW_VAL_BIN_VALUE 0x04 /**< Interpret the provided leaf/leaf-list @p value as being in the binary
+#define LYD_NEW_VAL_BIN 0x04 /**< Interpret the provided leaf/leaf-list @p value as being in the binary
::LY_VALUE_LYB format, to learn what exactly is expected see @ref howtoDataLYB. */
-#define LYD_NEW_VAL_CANON_VALUE 0x08 /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
+#define LYD_NEW_VAL_CANON 0x08 /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
(or JSON if no defined) ::LY_VALUE_CANON format. If it is not, it may lead
to unexpected behavior. */
#define LYD_NEW_META_CLEAR_DFLT 0x10 /**< Whether to clear the default flag starting from @p parent, recursively all NP containers. */
@@ -1428,13 +1428,13 @@
* @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 for the node. Expected type is determined by @p value_type.
- * @param[in] options Bitmask of options, see @ref newvalueoptions.
* @param[in] value_type Type of the provided value in @p value.
+ * @param[in] options Bitmask of options, see @ref newvaloptions.
* @param[out] node Optional created node.
* @return LY_ERR value.
*/
LIBYANG_API_DECL LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name,
- const void *value, uint32_t options, LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node);
+ const void *value, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node);
/**
* @brief Create a new top-level any node defined in the given extension instance.
@@ -1445,13 +1445,13 @@
* @param[in] ext Extension instance where the any node being created is defined.
* @param[in] name Schema node name of the new data node. The node can be #LYS_ANYDATA or #LYS_ANYXML.
* @param[in] value Value for the node. Expected type is determined by @p value_type.
- * @param[in] options Bitmask of options, see @ref newvalueoptions.
* @param[in] value_type Type of the provided value in @p value.
+ * @param[in] options Bitmask of options, see @ref newvaloptions.
* @param[out] node The created node.
* @return LY_ERR value.
*/
LIBYANG_API_DECL LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value,
- uint32_t options, LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node);
+ LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node);
/**
* @brief Create a new metadata.
diff --git a/src/tree_data_new.c b/src/tree_data_new.c
index 4051aab..5c37712 100644
--- a/src/tree_data_new.c
+++ b/src/tree_data_new.c
@@ -475,17 +475,17 @@
* @brief Gets format from lyd_new_* options
*
* @param[in] options Bitmask of options, see @ref newvalueoptions.
- * @param[out] format The output format.
+ * @param[out] format Value format.
* @return LY_ERR value.
*/
static LY_ERR
-_lyd_new_val_format(const uint32_t options, LY_VALUE_FORMAT *format)
+lyd_new_val_get_format(uint32_t options, LY_VALUE_FORMAT *format)
{
- LY_CHECK_ARG_RET(NULL, format, !((options & LYD_NEW_VAL_BIN_VALUE) && (options & LYD_NEW_VAL_CANON_VALUE)), LY_EVALID);
+ LY_CHECK_ARG_RET(NULL, format, !((options & LYD_NEW_VAL_BIN) && (options & LYD_NEW_VAL_CANON)), LY_EVALID);
- if (options & LYD_NEW_VAL_BIN_VALUE) {
+ if (options & LYD_NEW_VAL_BIN) {
*format = LY_VALUE_LYB;
- } else if (options & LYD_NEW_VAL_CANON_VALUE) {
+ } else if (options & LYD_NEW_VAL_CANON) {
*format = LY_VALUE_CANON;
} else {
*format = LY_VALUE_JSON;
@@ -622,7 +622,7 @@
LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, module ? module->ctx : NULL, LY_EINVAL);
- LY_CHECK_RET(_lyd_new_val_format(options, &format));
+ LY_CHECK_RET(lyd_new_val_get_format(options, &format));
LY_CHECK_ARG_RET(ctx, !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)), LY_EINVAL);
/* create the list node */
@@ -672,7 +672,7 @@
LY_VALUE_FORMAT format;
LY_CHECK_ARG_RET(ctx, ext, node, name, LY_EINVAL);
- LY_CHECK_RET(_lyd_new_val_format(options, &format));
+ LY_CHECK_RET(lyd_new_val_get_format(options, &format));
LY_CHECK_ARG_RET(ctx, !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)), LY_EINVAL);
schema = lysc_ext_find_node(ext, NULL, name, 0, LYS_LIST, 0);
@@ -791,7 +791,7 @@
ly_bool store_only = (options & LYD_NEW_VAL_STORE_ONLY) ? 1 : 0;
LY_VALUE_FORMAT format;
- LY_CHECK_RET(_lyd_new_val_format(options, &format));
+ LY_CHECK_RET(lyd_new_val_get_format(options, &format));
LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, (format != LY_VALUE_LYB) || value_lengths, LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, module ? module->ctx : NULL, LY_EINVAL);
LY_CHECK_ARG_RET(ctx, !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)), LY_EINVAL);
@@ -876,7 +876,7 @@
LY_CHECK_ARG_RET(ctx, parent || module, parent || node, name, LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, module ? module->ctx : NULL, LY_EINVAL);
- LY_CHECK_RET(_lyd_new_val_format(options, &format));
+ LY_CHECK_RET(lyd_new_val_get_format(options, &format));
LY_CHECK_ARG_RET(ctx, !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)), LY_EINVAL);
if (!module) {
@@ -911,7 +911,7 @@
{
const struct ly_ctx *ctx = parent ? LYD_CTX(parent) : (module ? module->ctx : NULL);
- LY_CHECK_ARG_RET(ctx, !(options & LYD_NEW_VAL_BIN_VALUE), LY_EINVAL);
+ LY_CHECK_ARG_RET(ctx, !(options & LYD_NEW_VAL_BIN), LY_EINVAL);
return _lyd_new_term(parent, module, name, value, value ? strlen(value) : 0, options, node);
}
@@ -919,7 +919,8 @@
lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name,
const void *value, size_t value_len, uint32_t options, struct lyd_node **node)
{
- options |= LYD_NEW_VAL_BIN_VALUE;
+ options |= LYD_NEW_VAL_BIN;
+
return _lyd_new_term(parent, module, name, value, value_len, options, node);
}
@@ -935,7 +936,7 @@
LY_VALUE_FORMAT format;
LY_CHECK_ARG_RET(ctx, ext, node, name, LY_EINVAL);
- LY_CHECK_RET(_lyd_new_val_format(options, &format));
+ LY_CHECK_RET(lyd_new_val_get_format(options, &format));
LY_CHECK_ARG_RET(ctx, !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)), LY_EINVAL);
schema = lysc_ext_find_node(ext, NULL, name, 0, LYD_NODE_TERM, 0);
@@ -958,7 +959,7 @@
LIBYANG_API_DEF LY_ERR
lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
- uint32_t options, LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node)
+ LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node)
{
LY_ERR r;
struct lyd_node *ret = NULL;
@@ -999,8 +1000,8 @@
}
LIBYANG_API_DEF LY_ERR
-lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, uint32_t options,
- LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node)
+lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, LYD_ANYDATA_VALUETYPE value_type,
+ uint32_t options, struct lyd_node **node)
{
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
@@ -1658,7 +1659,6 @@
assert(parent || ctx);
assert(path && ((path[0] == '/') || parent));
- assert(!(options & LYD_NEW_VAL_BIN_VALUE) || !(options & LYD_NEW_VAL_CANON_VALUE));
if (!ctx) {
ctx = LYD_CTX(parent);
@@ -1666,13 +1666,7 @@
if (value && !value_len) {
value_len = strlen(value);
}
- if (options & LYD_NEW_VAL_BIN_VALUE) {
- format = LY_VALUE_LYB;
- } else if (options & LYD_NEW_VAL_CANON_VALUE) {
- format = LY_VALUE_CANON;
- } else {
- format = LY_VALUE_JSON;
- }
+ lyd_new_val_get_format(options, &format);
/* parse path */
LY_CHECK_GOTO(ret = ly_path_parse(ctx, NULL, path, strlen(path), 0, LY_PATH_BEGIN_EITHER, LY_PATH_PREFIX_FIRST,
@@ -1867,7 +1861,7 @@
struct lyd_node **node)
{
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent,
- !(options & LYD_NEW_VAL_BIN_VALUE) || !(options & LYD_NEW_VAL_CANON_VALUE), LY_EINVAL);
+ !(options & LYD_NEW_VAL_BIN) || !(options & LYD_NEW_VAL_CANON), LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, ctx, LY_EINVAL);
return lyd_new_path_(parent, ctx, NULL, path, value, 0, LYD_ANYDATA_STRING, options, node, NULL);
@@ -1879,7 +1873,7 @@
struct lyd_node **new_node)
{
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent,
- !(options & LYD_NEW_VAL_BIN_VALUE) || !(options & LYD_NEW_VAL_CANON_VALUE), LY_EINVAL);
+ !(options & LYD_NEW_VAL_BIN) || !(options & LYD_NEW_VAL_CANON), LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, ctx, LY_EINVAL);
return lyd_new_path_(parent, ctx, NULL, path, value, value_len, value_type, options, new_parent, new_node);
@@ -1892,7 +1886,7 @@
const struct ly_ctx *ctx = ext ? ext->module->ctx : NULL;
LY_CHECK_ARG_RET(ctx, ext, path, (path[0] == '/') || parent,
- !(options & LYD_NEW_VAL_BIN_VALUE) || !(options & LYD_NEW_VAL_CANON_VALUE), LY_EINVAL);
+ !(options & LYD_NEW_VAL_BIN) || !(options & LYD_NEW_VAL_CANON), LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(parent ? LYD_CTX(parent) : NULL, ctx, LY_EINVAL);
return lyd_new_path_(parent, ctx, ext, path, value, 0, LYD_ANYDATA_STRING, options, node, NULL);
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index df1d8c5..ea7945a 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -143,19 +143,19 @@
assert_int_equal(lyd_new_list3_bin(NULL, mod, "l1", (const void **)key_vals, val_lens, LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (_lyd_new_list3()).", NULL, 0);
- assert_int_equal(lyd_new_list3(NULL, mod, "l1", key_vals, val_lens, LYD_NEW_VAL_CANON_VALUE, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_list3(NULL, mod, "l1", key_vals, val_lens, LYD_NEW_VAL_CANON, &node), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_list3(NULL, mod, "l1", key_vals, val_lens, LYD_NEW_VAL_CANON_VALUE | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
+ assert_int_equal(lyd_new_list3(NULL, mod, "l1", key_vals, val_lens, LYD_NEW_VAL_CANON | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (_lyd_new_list3()).", NULL, 0);
- assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN_VALUE, &node, "val_a", 5, "val_b", 5), LY_SUCCESS);
+ assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN, &node, "val_a", 5, "val_b", 5), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN_VALUE | LYD_NEW_VAL_STORE_ONLY, &node, "val_a", 5, "val_b", 5), LY_EINVAL);
+ assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN | LYD_NEW_VAL_STORE_ONLY, &node, "val_a", 5, "val_b", 5), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (lyd_new_list()).", NULL, 0);
- assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_CANON_VALUE, &node, "val_a", "val_b"), LY_SUCCESS);
+ assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_CANON, &node, "val_a", "val_b"), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_CANON_VALUE | LYD_NEW_VAL_STORE_ONLY, &node, "val_a", "val_b"), LY_EINVAL);
+ assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_CANON | LYD_NEW_VAL_STORE_ONLY, &node, "val_a", "val_b"), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (lyd_new_list()).", NULL, 0);
/* leaf */
@@ -168,16 +168,16 @@
assert_int_equal(lyd_new_term(NULL, mod, "foo", "256", 0, &node), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_BIN_VALUE, &node), LY_EINVAL);
+ assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_BIN, &node), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(options & 0x04) (lyd_new_term()).", NULL, 0);
- assert_int_equal(lyd_new_term_bin(NULL, mod, "foo", "25", 2, LYD_NEW_VAL_BIN_VALUE, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_term_bin(NULL, mod, "foo", "25", 2, LYD_NEW_VAL_BIN, &node), LY_SUCCESS);
lyd_free_tree(node);
assert_int_equal(lyd_new_term_bin(NULL, mod, "foo", "25", 2, LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (_lyd_new_term()).", NULL, 0);
- assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON_VALUE, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON, &node), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON_VALUE | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
+ assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (_lyd_new_term()).", NULL, 0);
/* leaf-list */
@@ -195,9 +195,9 @@
CHECK_LOG_CTX("Inner node (container, notif, RPC, or action) \"l2\" not found.", NULL, 0);
/* anydata */
- assert_int_equal(lyd_new_any(NULL, mod, "any", "{\"node\":\"val\"}", 0, LYD_ANYDATA_STRING, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_any(NULL, mod, "any", "{\"node\":\"val\"}", LYD_ANYDATA_STRING, 0, &node), LY_SUCCESS);
lyd_free_tree(node);
- assert_int_equal(lyd_new_any(NULL, mod, "any", "<node>val</node>", 0, LYD_ANYDATA_STRING, &node), LY_SUCCESS);
+ assert_int_equal(lyd_new_any(NULL, mod, "any", "<node>val</node>", LYD_ANYDATA_STRING, 0, &node), LY_SUCCESS);
lyd_free_tree(node);
/* key-less list */