Skip to content

Commit 402ab07

Browse files
committed
Merge branch 'devel'
2 parents deb38d5 + 438a766 commit 402ab07

File tree

13 files changed

+343
-28
lines changed

13 files changed

+343
-28
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ set(CMAKE_MACOSX_RPATH TRUE)
2121
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
2222
set(LIBYANG_MAJOR_VERSION 1)
2323
set(LIBYANG_MINOR_VERSION 0)
24-
set(LIBYANG_MICRO_VERSION 101)
24+
set(LIBYANG_MICRO_VERSION 109)
2525
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
2626

2727
# Version of the library
2828
# Major version is changed with every backward non-compatible API/ABI change in libyang, minor version changes
2929
# with backward compatible change and micro version is connected with any internal change of the library.
3030
set(LIBYANG_MAJOR_SOVERSION 1)
31-
set(LIBYANG_MINOR_SOVERSION 4)
32-
set(LIBYANG_MICRO_SOVERSION 1)
31+
set(LIBYANG_MINOR_SOVERSION 5)
32+
set(LIBYANG_MICRO_SOVERSION 5)
3333
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
3434
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})
3535

src/parser_lyb.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ lyb_read_start_subtree(const char *data, struct lyb_state *lybs)
242242
}
243243

244244
static int
245-
lyb_parse_model(const char *data, const struct lys_module **mod, struct lyb_state *lybs)
245+
lyb_parse_model(const char *data, const struct lys_module **mod, int options, struct lyb_state *lybs)
246246
{
247247
int r, ret = 0;
248248
char *mod_name = NULL, mod_rev[11];
@@ -259,6 +259,14 @@ lyb_parse_model(const char *data, const struct lys_module **mod, struct lyb_stat
259259
if (rev) {
260260
sprintf(mod_rev, "%04u-%02u-%02u", ((rev & 0xFE00) >> 9) + 2000, (rev & 0x01E0) >> 5, rev & 0x001Fu);
261261
*mod = ly_ctx_get_module(lybs->ctx, mod_name, mod_rev, 0);
262+
if ((options & LYD_OPT_LYB_MOD_UPDATE) && !(*mod)) {
263+
/* try to use an updated module */
264+
*mod = ly_ctx_get_module(lybs->ctx, mod_name, NULL, 1);
265+
if (*mod && (!(*mod)->implemented || !(*mod)->rev_size || (strcmp((*mod)->rev[0].date, mod_rev) < 0))) {
266+
/* not an implemented module in a newer revision */
267+
*mod = NULL;
268+
}
269+
}
262270
} else {
263271
*mod = ly_ctx_get_module(lybs->ctx, mod_name, NULL, 0);
264272
}
@@ -823,7 +831,7 @@ lyb_parse_attributes(struct lyd_node *node, const char *data, int options, struc
823831
LYB_HAVE_READ_GOTO(r, data, error);
824832

825833
/* find model */
826-
ret += (r = lyb_parse_model(data, &mod, lybs));
834+
ret += (r = lyb_parse_model(data, &mod, options, lybs));
827835
LYB_HAVE_READ_GOTO(r, data, error);
828836

829837
if (mod) {
@@ -1027,7 +1035,7 @@ lyb_parse_subtree(const char *data, struct lyd_node *parent, struct lyd_node **f
10271035

10281036
if (!parent) {
10291037
/* top-level, read module name */
1030-
ret += (r = lyb_parse_model(data, &mod, lybs));
1038+
ret += (r = lyb_parse_model(data, &mod, options, lybs));
10311039
LYB_HAVE_READ_GOTO(r, data, error);
10321040

10331041
if (mod) {
@@ -1149,7 +1157,7 @@ lyb_parse_subtree(const char *data, struct lyd_node *parent, struct lyd_node **f
11491157
}
11501158

11511159
static int
1152-
lyb_parse_data_models(const char *data, struct lyb_state *lybs)
1160+
lyb_parse_data_models(const char *data, int options, struct lyb_state *lybs)
11531161
{
11541162
int i, r, ret = 0;
11551163

@@ -1163,7 +1171,7 @@ lyb_parse_data_models(const char *data, struct lyb_state *lybs)
11631171

11641172
/* read modules */
11651173
for (i = 0; i < lybs->mod_count; ++i) {
1166-
ret += (r = lyb_parse_model(data, &lybs->models[i], lybs));
1174+
ret += (r = lyb_parse_model(data, &lybs->models[i], options, lybs));
11671175
LYB_HAVE_READ_RETURN(r, data, -1);
11681176
}
11691177
}
@@ -1249,7 +1257,7 @@ lyd_parse_lyb(struct ly_ctx *ctx, const char *data, int options, const struct ly
12491257
LYB_HAVE_READ_GOTO(r, data, finish);
12501258

12511259
/* read used models */
1252-
ret += (r = lyb_parse_data_models(data, &lybs));
1260+
ret += (r = lyb_parse_data_models(data, options, &lybs));
12531261
LYB_HAVE_READ_GOTO(r, data, finish);
12541262

12551263
/* read subtree(s) */

src/printer_tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ tree_print_subtree(struct lyout *out, const struct lys_node *node, tp_opts *opts
783783
{
784784
unsigned int depth, i, j;
785785
int level = 0;
786+
uint16_t max_child_len;
786787
const struct lys_node *parent;
787788

788789
/* learn the depth of the node */
@@ -823,7 +824,8 @@ tree_print_subtree(struct lyout *out, const struct lys_node *node, tp_opts *opts
823824
}
824825

825826
/* print the node and its descendants */
826-
tree_print_snode(out, level, 0, node, LYS_ANY, NULL, 2, opts);
827+
max_child_len = tree_get_max_name_len(node, NULL, LYS_LEAF|LYS_LEAFLIST|LYS_ANYDATA, opts);
828+
tree_print_snode(out, level, max_child_len, node, LYS_ANY, NULL, 2, opts);
827829
}
828830

829831
static int

src/resolve.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,12 +3482,9 @@ check_default(struct lys_type *type, const char **value, struct lys_module *modu
34823482
/* the type was not resolved yet, nothing to do for now */
34833483
ret = EXIT_FAILURE;
34843484
goto cleanup;
3485-
} else if (!tpdf && !module->implemented) {
3486-
/* do not check defaults in not implemented module's data */
3487-
goto cleanup;
3488-
} else if (tpdf && !module->implemented && type->base == LY_TYPE_IDENT) {
3489-
/* identityrefs are checked when instantiated in data instead of typedef,
3490-
* but in typedef the value has to be modified to include the prefix */
3485+
} else if (!module->implemented && ((type->base == LY_TYPE_IDENT) || (type->base == LY_TYPE_INST))) {
3486+
/* /instidsidentityrefs are checked when instantiated in data instead of typedef,
3487+
* but the value has to be modified to include the prefix */
34913488
if (*value) {
34923489
if (strchr(*value, ':')) {
34933490
dflt = transform_schema2json(module, *value);
@@ -5472,7 +5469,7 @@ resolve_uses(struct lys_node_uses *uses, struct unres_schema *unres)
54725469
if (usize1) {
54735470
/* there is something to duplicate */
54745471
/* duplicate compiled expression */
5475-
usize = (usize1 / 4) + (usize1 % 4) ? 1 : 0;
5472+
usize = (usize1 / 4) + ((usize1 % 4) ? 1 : 0);
54765473
iff[j].expr = malloc(usize * sizeof *iff[j].expr);
54775474
LY_CHECK_ERR_GOTO(!iff[j].expr, LOGMEM(ctx), fail);
54785475
memcpy(iff[j].expr, rfn->iffeature[k].expr, usize * sizeof *iff[j].expr);

src/tree_data.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ lyd_hash(struct lyd_node *node)
350350
struct lyd_node *iter;
351351
int i;
352352

353-
assert(!node->hash || ((node->schema->nodetype == LYS_LIST) && !((struct lys_node_list *)node->schema)->keys_size));
354-
355353
if ((node->schema->nodetype != LYS_LIST) || lyd_list_has_keys(node)) {
356354
node->hash = dict_hash_multi(0, lyd_node_module(node)->name, strlen(lyd_node_module(node)->name));
357355
node->hash = dict_hash_multi(node->hash, node->schema->name, strlen(node->schema->name));
@@ -498,8 +496,6 @@ _lyd_unlink_hash(struct lyd_node *node, struct lyd_node *orig_parent, int keyles
498496

499497
/* if the parent is missing a key now, remove hash, also from parent */
500498
if (lys_is_key((struct lys_node_leaf *)node->schema, NULL) && orig_parent->hash) {
501-
assert((orig_parent->schema->nodetype == LYS_LIST) && !lyd_list_has_keys(orig_parent));
502-
503499
_lyd_unlink_hash(orig_parent, orig_parent->parent, 0);
504500
orig_parent->hash = 0;
505501
}

src/tree_data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ char *lyd_path(const struct lyd_node *node);
538538
preserved and option is ignored. */
539539
#define LYD_OPT_VAL_DIFF 0x40000 /**< Flag only for validation, store all the data node changes performed by the validation
540540
in a diff structure. */
541+
#define LYD_OPT_LYB_MOD_UPDATE 0x80000 /**< Allow to parse data using an updated revision of a module, relevant only for LYB format. */
541542
#define LYD_OPT_DATA_TEMPLATE 0x1000000 /**< Data represents YANG data template. */
542543

543544
/**@} parseroptions */

src/tree_schema.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,9 @@ lys_check_id(struct lys_node *node, struct lys_node *parent, struct lys_module *
660660
case LYS_LIST:
661661
case LYS_CONTAINER:
662662
case LYS_CHOICE:
663+
case LYS_RPC:
664+
case LYS_NOTIF:
665+
case LYS_ACTION:
663666
case LYS_ANYDATA:
664667
/* 6.2.1, rule 7 */
665668
if (parent) {
@@ -700,8 +703,8 @@ lys_check_id(struct lys_node *node, struct lys_node *parent, struct lys_module *
700703
continue;
701704
}
702705

703-
if (iter->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_CONTAINER | LYS_CHOICE | LYS_ANYDATA)) {
704-
if (iter->module == node->module && ly_strequal(iter->name, node->name, 1)) {
706+
if (iter->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_CONTAINER | LYS_CHOICE | LYS_RPC | LYS_NOTIF | LYS_ACTION | LYS_ANYDATA)) {
707+
if (lys_node_module(iter) == lys_node_module(node) && ly_strequal(iter->name, node->name, 1)) {
705708
LOGVAL(module->ctx, LYE_DUPID, LY_VLOG_LYS, node, strnodetype(node->nodetype), node->name);
706709
return EXIT_FAILURE;
707710
}

src/validation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ lyv_data_context(const struct lyd_node *node, int options, struct unres_data *un
6969
for (op = node->schema; op && !(op->nodetype & (LYS_NOTIF | LYS_RPC | LYS_ACTION)); op = lys_parent(op));
7070

7171
if (!(options & (LYD_OPT_NOTIF_FILTER | LYD_OPT_EDIT | LYD_OPT_GET | LYD_OPT_GETCONFIG))
72-
&& (!(options & (LYD_OPT_RPC | LYD_OPT_NOTIF)) || op)) {
72+
&& (!(options & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF)) || op)) {
7373
if (node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
7474
/* if union with leafref/intsid, leafref itself (invalid) or instance-identifier, store the node for later resolving */
7575
if ((((struct lys_node_leaf *)leaf->schema)->type.base == LY_TYPE_UNION)
@@ -700,7 +700,7 @@ lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres)
700700
break;
701701
}
702702
}
703-
if (!diter && (options & (LYD_OPT_NOTIF | LYD_OPT_RPC))) {
703+
if (!diter && (options & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF))) {
704704
/* validating parent of a nested notification/action, skip most checks */
705705
options |= LYD_OPT_TRUSTED;
706706
}

src/xpath.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,15 @@ set_insert_node_hash(struct lyxp_set *set, struct lyd_node *node, enum lyxp_node
633633
r = lyht_insert(set->ht, &hnode, hash, NULL);
634634
assert(!r);
635635
(void)r;
636+
637+
if (hnode.node == node) {
638+
/* it was just added, do not add it twice */
639+
node = NULL;
640+
}
636641
}
637-
} else if (set->ht) {
638-
assert(node);
642+
}
639643

644+
if (set->ht && node) {
640645
/* add the new node into hash table */
641646
hnode.node = node;
642647
hnode.type = type;

0 commit comments

Comments
 (0)