Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Dec 13, 2019
2 parents deb38d5 + 438a766 commit 402ab07
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 28 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ set(CMAKE_MACOSX_RPATH TRUE)
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
set(LIBYANG_MAJOR_VERSION 1)
set(LIBYANG_MINOR_VERSION 0)
set(LIBYANG_MICRO_VERSION 101)
set(LIBYANG_MICRO_VERSION 109)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})

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

Expand Down
20 changes: 14 additions & 6 deletions src/parser_lyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ lyb_read_start_subtree(const char *data, struct lyb_state *lybs)
}

static int
lyb_parse_model(const char *data, const struct lys_module **mod, struct lyb_state *lybs)
lyb_parse_model(const char *data, const struct lys_module **mod, int options, struct lyb_state *lybs)
{
int r, ret = 0;
char *mod_name = NULL, mod_rev[11];
Expand All @@ -259,6 +259,14 @@ lyb_parse_model(const char *data, const struct lys_module **mod, struct lyb_stat
if (rev) {
sprintf(mod_rev, "%04u-%02u-%02u", ((rev & 0xFE00) >> 9) + 2000, (rev & 0x01E0) >> 5, rev & 0x001Fu);
*mod = ly_ctx_get_module(lybs->ctx, mod_name, mod_rev, 0);
if ((options & LYD_OPT_LYB_MOD_UPDATE) && !(*mod)) {
/* try to use an updated module */
*mod = ly_ctx_get_module(lybs->ctx, mod_name, NULL, 1);
if (*mod && (!(*mod)->implemented || !(*mod)->rev_size || (strcmp((*mod)->rev[0].date, mod_rev) < 0))) {
/* not an implemented module in a newer revision */
*mod = NULL;
}
}
} else {
*mod = ly_ctx_get_module(lybs->ctx, mod_name, NULL, 0);
}
Expand Down Expand Up @@ -823,7 +831,7 @@ lyb_parse_attributes(struct lyd_node *node, const char *data, int options, struc
LYB_HAVE_READ_GOTO(r, data, error);

/* find model */
ret += (r = lyb_parse_model(data, &mod, lybs));
ret += (r = lyb_parse_model(data, &mod, options, lybs));
LYB_HAVE_READ_GOTO(r, data, error);

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

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

if (mod) {
Expand Down Expand Up @@ -1149,7 +1157,7 @@ lyb_parse_subtree(const char *data, struct lyd_node *parent, struct lyd_node **f
}

static int
lyb_parse_data_models(const char *data, struct lyb_state *lybs)
lyb_parse_data_models(const char *data, int options, struct lyb_state *lybs)
{
int i, r, ret = 0;

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

/* read modules */
for (i = 0; i < lybs->mod_count; ++i) {
ret += (r = lyb_parse_model(data, &lybs->models[i], lybs));
ret += (r = lyb_parse_model(data, &lybs->models[i], options, lybs));
LYB_HAVE_READ_RETURN(r, data, -1);
}
}
Expand Down Expand Up @@ -1249,7 +1257,7 @@ lyd_parse_lyb(struct ly_ctx *ctx, const char *data, int options, const struct ly
LYB_HAVE_READ_GOTO(r, data, finish);

/* read used models */
ret += (r = lyb_parse_data_models(data, &lybs));
ret += (r = lyb_parse_data_models(data, options, &lybs));
LYB_HAVE_READ_GOTO(r, data, finish);

/* read subtree(s) */
Expand Down
4 changes: 3 additions & 1 deletion src/printer_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ tree_print_subtree(struct lyout *out, const struct lys_node *node, tp_opts *opts
{
unsigned int depth, i, j;
int level = 0;
uint16_t max_child_len;
const struct lys_node *parent;

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

/* print the node and its descendants */
tree_print_snode(out, level, 0, node, LYS_ANY, NULL, 2, opts);
max_child_len = tree_get_max_name_len(node, NULL, LYS_LEAF|LYS_LEAFLIST|LYS_ANYDATA, opts);
tree_print_snode(out, level, max_child_len, node, LYS_ANY, NULL, 2, opts);
}

static int
Expand Down
11 changes: 4 additions & 7 deletions src/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -3482,12 +3482,9 @@ check_default(struct lys_type *type, const char **value, struct lys_module *modu
/* the type was not resolved yet, nothing to do for now */
ret = EXIT_FAILURE;
goto cleanup;
} else if (!tpdf && !module->implemented) {
/* do not check defaults in not implemented module's data */
goto cleanup;
} else if (tpdf && !module->implemented && type->base == LY_TYPE_IDENT) {
/* identityrefs are checked when instantiated in data instead of typedef,
* but in typedef the value has to be modified to include the prefix */
} else if (!module->implemented && ((type->base == LY_TYPE_IDENT) || (type->base == LY_TYPE_INST))) {
/* /instidsidentityrefs are checked when instantiated in data instead of typedef,
* but the value has to be modified to include the prefix */
if (*value) {
if (strchr(*value, ':')) {
dflt = transform_schema2json(module, *value);
Expand Down Expand Up @@ -5472,7 +5469,7 @@ resolve_uses(struct lys_node_uses *uses, struct unres_schema *unres)
if (usize1) {
/* there is something to duplicate */
/* duplicate compiled expression */
usize = (usize1 / 4) + (usize1 % 4) ? 1 : 0;
usize = (usize1 / 4) + ((usize1 % 4) ? 1 : 0);
iff[j].expr = malloc(usize * sizeof *iff[j].expr);
LY_CHECK_ERR_GOTO(!iff[j].expr, LOGMEM(ctx), fail);
memcpy(iff[j].expr, rfn->iffeature[k].expr, usize * sizeof *iff[j].expr);
Expand Down
4 changes: 0 additions & 4 deletions src/tree_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ lyd_hash(struct lyd_node *node)
struct lyd_node *iter;
int i;

assert(!node->hash || ((node->schema->nodetype == LYS_LIST) && !((struct lys_node_list *)node->schema)->keys_size));

if ((node->schema->nodetype != LYS_LIST) || lyd_list_has_keys(node)) {
node->hash = dict_hash_multi(0, lyd_node_module(node)->name, strlen(lyd_node_module(node)->name));
node->hash = dict_hash_multi(node->hash, node->schema->name, strlen(node->schema->name));
Expand Down Expand Up @@ -498,8 +496,6 @@ _lyd_unlink_hash(struct lyd_node *node, struct lyd_node *orig_parent, int keyles

/* if the parent is missing a key now, remove hash, also from parent */
if (lys_is_key((struct lys_node_leaf *)node->schema, NULL) && orig_parent->hash) {
assert((orig_parent->schema->nodetype == LYS_LIST) && !lyd_list_has_keys(orig_parent));

_lyd_unlink_hash(orig_parent, orig_parent->parent, 0);
orig_parent->hash = 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/tree_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ char *lyd_path(const struct lyd_node *node);
preserved and option is ignored. */
#define LYD_OPT_VAL_DIFF 0x40000 /**< Flag only for validation, store all the data node changes performed by the validation
in a diff structure. */
#define LYD_OPT_LYB_MOD_UPDATE 0x80000 /**< Allow to parse data using an updated revision of a module, relevant only for LYB format. */
#define LYD_OPT_DATA_TEMPLATE 0x1000000 /**< Data represents YANG data template. */

/**@} parseroptions */
Expand Down
7 changes: 5 additions & 2 deletions src/tree_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ lys_check_id(struct lys_node *node, struct lys_node *parent, struct lys_module *
case LYS_LIST:
case LYS_CONTAINER:
case LYS_CHOICE:
case LYS_RPC:
case LYS_NOTIF:
case LYS_ACTION:
case LYS_ANYDATA:
/* 6.2.1, rule 7 */
if (parent) {
Expand Down Expand Up @@ -700,8 +703,8 @@ lys_check_id(struct lys_node *node, struct lys_node *parent, struct lys_module *
continue;
}

if (iter->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_CONTAINER | LYS_CHOICE | LYS_ANYDATA)) {
if (iter->module == node->module && ly_strequal(iter->name, node->name, 1)) {
if (iter->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_CONTAINER | LYS_CHOICE | LYS_RPC | LYS_NOTIF | LYS_ACTION | LYS_ANYDATA)) {
if (lys_node_module(iter) == lys_node_module(node) && ly_strequal(iter->name, node->name, 1)) {
LOGVAL(module->ctx, LYE_DUPID, LY_VLOG_LYS, node, strnodetype(node->nodetype), node->name);
return EXIT_FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions src/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ lyv_data_context(const struct lyd_node *node, int options, struct unres_data *un
for (op = node->schema; op && !(op->nodetype & (LYS_NOTIF | LYS_RPC | LYS_ACTION)); op = lys_parent(op));

if (!(options & (LYD_OPT_NOTIF_FILTER | LYD_OPT_EDIT | LYD_OPT_GET | LYD_OPT_GETCONFIG))
&& (!(options & (LYD_OPT_RPC | LYD_OPT_NOTIF)) || op)) {
&& (!(options & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF)) || op)) {
if (node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
/* if union with leafref/intsid, leafref itself (invalid) or instance-identifier, store the node for later resolving */
if ((((struct lys_node_leaf *)leaf->schema)->type.base == LY_TYPE_UNION)
Expand Down Expand Up @@ -700,7 +700,7 @@ lyv_data_content(struct lyd_node *node, int options, struct unres_data *unres)
break;
}
}
if (!diter && (options & (LYD_OPT_NOTIF | LYD_OPT_RPC))) {
if (!diter && (options & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF))) {
/* validating parent of a nested notification/action, skip most checks */
options |= LYD_OPT_TRUSTED;
}
Expand Down
9 changes: 7 additions & 2 deletions src/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,15 @@ set_insert_node_hash(struct lyxp_set *set, struct lyd_node *node, enum lyxp_node
r = lyht_insert(set->ht, &hnode, hash, NULL);
assert(!r);
(void)r;

if (hnode.node == node) {
/* it was just added, do not add it twice */
node = NULL;
}
}
} else if (set->ht) {
assert(node);
}

if (set->ht && node) {
/* add the new node into hash table */
hnode.node = node;
hnode.type = type;
Expand Down
Loading

0 comments on commit 402ab07

Please sign in to comment.