Skip to content

Commit ae63fde

Browse files
committed
tree data UPDATE remove bin value functions
LYB values are complex and no longer more efficient to use than string ones.
1 parent 6aa7a20 commit ae63fde

File tree

5 files changed

+20
-73
lines changed

5 files changed

+20
-73
lines changed

src/tree_data.h

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ struct rb_node;
255255
* --------------
256256
* - ::lyd_new_inner()
257257
* - ::lyd_new_term()
258-
* - ::lyd_new_term_bin()
259258
* - ::lyd_new_list()
260259
* - ::lyd_new_list2()
261260
* - ::lyd_new_list3()
@@ -1260,23 +1259,21 @@ LIBYANG_API_DECL LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_
12601259
#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
12611260
taken into consideration. Otherwise, the output's data node is going to be created. */
12621261
#define LYD_NEW_VAL_STORE_ONLY 0x02 /**< Whether to perform only storing operation with no or minimum valitions */
1263-
#define LYD_NEW_VAL_BIN 0x04 /**< Interpret the provided leaf/leaf-list @p value as being in the binary
1264-
::LY_VALUE_LYB format, to learn what exactly is expected see @ref howtoDataLYB. */
1265-
#define LYD_NEW_VAL_CANON 0x08 /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
1262+
#define LYD_NEW_VAL_CANON 0x04 /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
12661263
(or JSON if no defined) ::LY_VALUE_CANON format. If it is not, it may lead
12671264
to unexpected behavior. */
1268-
#define LYD_NEW_META_CLEAR_DFLT 0x10 /**< Whether to clear the default flag starting from @p parent, recursively all NP containers. */
1269-
#define LYD_NEW_PATH_UPDATE 0x20 /**< If the target node exists, is a leaf, and it is updated with a new value or its
1265+
#define LYD_NEW_META_CLEAR_DFLT 0x08 /**< Whether to clear the default flag starting from @p parent, recursively all NP containers. */
1266+
#define LYD_NEW_PATH_UPDATE 0x10 /**< If the target node exists, is a leaf, and it is updated with a new value or its
12701267
default flag is changed, it is returned. If the target node exists and is not
12711268
a leaf or generally no change occurs in the @p parent tree, NULL is returned and
12721269
no error set. */
1273-
#define LYD_NEW_PATH_OPAQ 0x40 /**< Enables the creation of opaque nodes with some specific rules. If the __last node__
1270+
#define LYD_NEW_PATH_OPAQ 0x20 /**< Enables the creation of opaque nodes with some specific rules. If the __last node__
12741271
in the path is not uniquely defined ((leaf-)list without a predicate) or has an
12751272
invalid value (leaf/leaf-list), it is created as opaque. Otherwise a regular node
12761273
is created. */
1277-
#define LYD_NEW_PATH_WITH_OPAQ 0x80 /**< Consider opaque nodes normally when searching for existing nodes. */
1278-
#define LYD_NEW_PATH_ANY_DATATREE 0x100 /**< The @p value is actually a data tree, not a string. */
1279-
#define LYD_NEW_ANY_USE_VALUE 0x200 /**< Whether to use dynamic @p value or make a copy. */
1274+
#define LYD_NEW_PATH_WITH_OPAQ 0x40 /**< Consider opaque nodes normally when searching for existing nodes. */
1275+
#define LYD_NEW_PATH_ANY_DATATREE 0x80 /**< The @p value is actually a data tree, not a string. */
1276+
#define LYD_NEW_ANY_USE_VALUE 0x0100 /**< Whether to use dynamic @p value or make a copy. */
12801277

12811278
/** @} newvaloptions */
12821279

@@ -1290,7 +1287,6 @@ LIBYANG_API_DECL LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_
12901287
* @param[out] node Optional created node.
12911288
* @param[in] ... Ordered key values of the new list instance, all must be set. In case of an instance-identifier
12921289
* or identityref value, the JSON format is expected (module names instead of prefixes). No keys are expected for key-less lists.
1293-
* In case options include ::LYD_NEW_VAL_BIN, every key value must be followed by its size in bits (uint32_t).
12941290
* @return LY_ERR value.
12951291
*/
12961292
LIBYANG_API_DECL LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name,
@@ -1331,8 +1327,6 @@ LIBYANG_API_DECL LY_ERR lyd_new_list3(struct lyd_node *parent, const struct lys_
13311327
/**
13321328
* @brief Create a new term node in the data tree.
13331329
*
1334-
* To create a term node based on binary value, use ::lyd_new_term_bin().
1335-
*
13361330
* @param[in] parent Parent node for the node being created. NULL in case of creating a top level element.
13371331
* @param[in] module Module of the node being created. If NULL, @p parent module will be used.
13381332
* @param[in] name Schema node name of the new data node. The node can be #LYS_LEAF or #LYS_LEAFLIST.
@@ -1344,21 +1338,6 @@ LIBYANG_API_DECL LY_ERR lyd_new_list3(struct lyd_node *parent, const struct lys_
13441338
LIBYANG_API_DECL LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name,
13451339
const char *value, uint32_t options, struct lyd_node **node);
13461340

1347-
/**
1348-
* @brief Create a new term node in the data tree based on binary value.
1349-
*
1350-
* @param[in] parent Parent node for the node being created. NULL in case of creating a top level element.
1351-
* @param[in] module Module of the node being created. If NULL, @p parent module will be used.
1352-
* @param[in] name Schema node name of the new data node. The node can be #LYS_LEAF or #LYS_LEAFLIST.
1353-
* @param[in] value Binary value of the node. To learn what exactly is expected see @ref howtoDataLYB.
1354-
* @param[in] value_size_bits Size of @p value in bits.
1355-
* @param[in] options Bitmask of options, see @ref newvaloptions.
1356-
* @param[out] node Optional created node.
1357-
* @return LY_ERR value.
1358-
*/
1359-
LIBYANG_API_DECL LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name,
1360-
const void *value, uint32_t value_size_bits, uint32_t options, struct lyd_node **node);
1361-
13621341
/**
13631342
* @brief Create a new any node in the data tree.
13641343
*

src/tree_data_new.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,9 @@ lyd_create_opaq(const struct ly_ctx *ctx, const char *name, uint32_t name_len, c
427427
static LY_ERR
428428
lyd_new_val_get_format(uint32_t options, LY_VALUE_FORMAT *format)
429429
{
430-
LY_CHECK_ARG_RET(NULL, format, !((options & LYD_NEW_VAL_BIN) && (options & LYD_NEW_VAL_CANON)), LY_EVALID);
430+
LY_CHECK_ARG_RET(NULL, format, LY_EVALID);
431431

432-
if (options & LYD_NEW_VAL_BIN) {
433-
*format = LY_VALUE_LYB;
434-
} else if (options & LYD_NEW_VAL_CANON) {
432+
if (options & LYD_NEW_VAL_CANON) {
435433
*format = LY_VALUE_CANON;
436434
} else {
437435
*format = LY_VALUE_JSON;
@@ -740,22 +738,9 @@ LIBYANG_API_DEF LY_ERR
740738
lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *value,
741739
uint32_t options, struct lyd_node **node)
742740
{
743-
const struct ly_ctx *ctx = parent ? LYD_CTX(parent) : (module ? module->ctx : NULL);
744-
745-
LY_CHECK_ARG_RET(ctx, !(options & LYD_NEW_VAL_BIN), LY_EINVAL);
746-
747741
return _lyd_new_term(parent, module, name, value, value ? strlen(value) * 8 : 0, options, node);
748742
}
749743

750-
LIBYANG_API_DEF LY_ERR
751-
lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name,
752-
const void *value, uint32_t value_size_bits, uint32_t options, struct lyd_node **node)
753-
{
754-
options |= LYD_NEW_VAL_BIN;
755-
756-
return _lyd_new_term(parent, module, name, value, value_size_bits, options, node);
757-
}
758-
759744
LIBYANG_API_DEF LY_ERR
760745
lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const struct lyd_node *child,
761746
const char *value, uint32_t hints, uint32_t options, struct lyd_node **node)
@@ -1796,7 +1781,7 @@ LIBYANG_API_DEF LY_ERR
17961781
lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, uint32_t options,
17971782
struct lyd_node **node)
17981783
{
1799-
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent, !(options & LYD_NEW_VAL_BIN), LY_EINVAL);
1784+
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent, LY_EINVAL);
18001785
LY_CHECK_CTX_EQUAL_RET(__func__, parent ? LYD_CTX(parent) : NULL, ctx, LY_EINVAL);
18011786

18021787
return lyd_new_path_(parent, ctx, path, value, value ? strlen(value) * 8 : 0, 0, options, node, NULL);
@@ -1807,11 +1792,10 @@ lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *pat
18071792
uint32_t value_size_bits, uint32_t any_hints, uint32_t options, struct lyd_node **new_parent,
18081793
struct lyd_node **new_node)
18091794
{
1810-
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent,
1811-
!(options & LYD_NEW_VAL_BIN) || !(options & LYD_NEW_VAL_CANON), LY_EINVAL);
1795+
LY_CHECK_ARG_RET(ctx, parent || ctx, path, (path[0] == '/') || parent, LY_EINVAL);
18121796
LY_CHECK_CTX_EQUAL_RET(__func__, parent ? LYD_CTX(parent) : NULL, ctx, LY_EINVAL);
18131797

1814-
if (!(options & LYD_NEW_VAL_BIN) && !value_size_bits && value) {
1798+
if (!value_size_bits && value) {
18151799
value_size_bits = strlen(value) * 8;
18161800
}
18171801

tests/perf/perf.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ test_create_new_bin(struct test_state *state, struct timespec *ts_start, struct
367367
{
368368
LY_ERR r;
369369
struct lyd_node *data = NULL;
370-
uint32_t i, k2_len, l_len;
371-
char k2_val[32], l_val[32];
370+
uint32_t i;
371+
char k_val[32], k2_val[32], l_val[32];
372372
struct lyd_node *list;
373373

374374
*size = 0;
@@ -379,13 +379,14 @@ test_create_new_bin(struct test_state *state, struct timespec *ts_start, struct
379379
}
380380

381381
for (i = 0; i < state->count; ++i) {
382-
k2_len = sprintf(k2_val, "str%" PRIu32, i);
383-
l_len = sprintf(l_val, "l%" PRIu32, i);
382+
sprintf(k_val, "%" PRIu32, i);
383+
sprintf(k2_val, "str%" PRIu32, i);
384+
sprintf(l_val, "l%" PRIu32, i);
384385

385-
if ((r = lyd_new_list(data, NULL, "lst", LYD_NEW_VAL_BIN, &list, &i, sizeof i * 8, k2_val, k2_len * 8))) {
386+
if ((r = lyd_new_list(data, NULL, "lst", 0, &list, &i, k2_val))) {
386387
return r;
387388
}
388-
if ((r = lyd_new_term_bin(list, NULL, "l", l_val, l_len * 8, 0, NULL))) {
389+
if ((r = lyd_new_term(list, NULL, "l", l_val, 0, NULL))) {
389390
return r;
390391
}
391392
}

tests/utests/data/test_new.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,11 @@ test_top_level(void **state)
136136

137137
uint32_t val_lens[] = {8, 8};
138138

139-
assert_int_equal(lyd_new_list3(NULL, mod, "l1", (const void **)key_vals, val_lens, LYD_NEW_VAL_BIN, &node), LY_SUCCESS);
140-
lyd_free_tree(node);
141-
142139
assert_int_equal(lyd_new_list3(NULL, mod, "l1", (const void **)key_vals, val_lens, LYD_NEW_VAL_CANON, &node), LY_SUCCESS);
143140
lyd_free_tree(node);
144141
assert_int_equal(lyd_new_list3(NULL, mod, "l1", (const void **)key_vals, val_lens, LYD_NEW_VAL_CANON | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
145142
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (lyd_new_list3()).", NULL, 0);
146143

147-
assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN, &node, "val_a", 5 * 8, "val_b", 5 * 8), LY_SUCCESS);
148-
lyd_free_tree(node);
149-
assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_BIN | LYD_NEW_VAL_STORE_ONLY, &node, "val_a", 5 * 8, "val_b", 5 * 8), LY_EINVAL);
150-
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (lyd_new_list()).", NULL, 0);
151-
152144
assert_int_equal(lyd_new_list(NULL, mod, "l1", LYD_NEW_VAL_CANON, &node, "val_a", "val_b"), LY_SUCCESS);
153145
lyd_free_tree(node);
154146
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);
@@ -164,13 +156,6 @@ test_top_level(void **state)
164156
assert_int_equal(lyd_new_term(NULL, mod, "foo", "256", 0, &node), LY_SUCCESS);
165157
lyd_free_tree(node);
166158

167-
assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_BIN, &node), LY_EINVAL);
168-
CHECK_LOG_CTX("Invalid argument !(options & 0x04) (lyd_new_term()).", NULL, 0);
169-
assert_int_equal(lyd_new_term_bin(NULL, mod, "foo", "25", 16, LYD_NEW_VAL_BIN, &node), LY_SUCCESS);
170-
lyd_free_tree(node);
171-
assert_int_equal(lyd_new_term_bin(NULL, mod, "foo", "25", 16, LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);
172-
CHECK_LOG_CTX("Invalid argument !(store_only && (format == LY_VALUE_CANON || format == LY_VALUE_LYB)) (_lyd_new_term()).", NULL, 0);
173-
174159
assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON, &node), LY_SUCCESS);
175160
lyd_free_tree(node);
176161
assert_int_equal(lyd_new_term(NULL, mod, "foo", "25", LYD_NEW_VAL_CANON | LYD_NEW_VAL_STORE_ONLY, &node), LY_EINVAL);

tests/utests/types/union.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ test_validation(void **state)
192192
const char *schema, *data;
193193
struct lyd_node *tree;
194194
char *out;
195-
uint32_t uint_val;
196195

197196
schema = MODULE_CREATE_YANG("val",
198197
"leaf l1 {\n"
@@ -290,8 +289,7 @@ test_validation(void **state)
290289

291290
/* remove the target and create another, which is represented the same way in LYB */
292291
lyd_free_tree(lyd_child(tree));
293-
uint_val = 1;
294-
assert_int_equal(LY_SUCCESS, lyd_new_list(tree, NULL, "b", LYD_NEW_VAL_BIN, NULL, &uint_val, sizeof uint_val * 8));
292+
assert_int_equal(LY_SUCCESS, lyd_new_list(tree, NULL, "b", 0, NULL, "1"));
295293
assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
296294
CHECK_LOG_CTX("Invalid LYB union value - no matching subtype found:\n"
297295
" ly2 leafref: Invalid leafref value \"one\" - no target instance \"../../a/name\" with the same value.\n"

0 commit comments

Comments
 (0)