Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# set version of the project
set(LIBYANG_MAJOR_VERSION 6)
set(LIBYANG_MINOR_VERSION 4)
set(LIBYANG_MICRO_VERSION 20)
set(LIBYANG_MICRO_VERSION 21)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})

# set version of the library
set(LIBYANG_MAJOR_SOVERSION 5)
set(LIBYANG_MINOR_SOVERSION 11)
set(LIBYANG_MICRO_SOVERSION 17)
set(LIBYANG_MICRO_SOVERSION 18)
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})

Expand Down
18 changes: 16 additions & 2 deletions src/parser_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,17 @@ lydcbor_parse_any(struct lyd_cbor_ctx *lydctx, const struct lysc_node *snode, st
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);

/* parse data tree with correct options */
lydctx->parse_opts &= ~LYD_PARSE_STRICT;
lydctx->parse_opts |= LYD_PARSE_OPAQ | (ext ? LYD_PARSE_ONLY : 0);
if (lydctx->parse_opts & LYD_PARSE_ANYDATA_STRICT) {
/* explicit strict data parsing */
lydctx->parse_opts |= LYD_PARSE_STRICT;
} else if ((lydctx->int_opts & LYD_INTOPT_ENVELOPE) && !(lydctx->int_opts & LYD_INTOPT_ANY)) {
/* the notification in the envelope contents, parsed as data like any other notification */
} else {
/* make the parser process data as opaq nodes */
lydctx->parse_opts &= ~LYD_PARSE_STRICT;
lydctx->parse_opts |= LYD_PARSE_OPAQ;
}
lydctx->parse_opts |= (ext ? LYD_PARSE_ONLY : 0);
lydctx->int_opts |= LYD_INTOPT_ANY | LYD_INTOPT_WITH_SIBLINGS;
lydctx->any_schema = snode;

Expand Down Expand Up @@ -1382,6 +1391,11 @@ lydcbor_parse_instance(struct lyd_cbor_ctx *lydctx, struct lyd_node *parent, str
}
LY_CHECK_GOTO(!*node, cleanup);

/* extension instance data */
if (ext) {
(*node)->flags |= LYD_EXT;
}

/* add/correct flags */
r = lyd_parser_set_data_flags(*node, &(*node)->meta, (struct lyd_ctx *)lydctx, ext);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
Expand Down
18 changes: 17 additions & 1 deletion src/parser_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,26 @@ lyd_parser_check_schema(struct lyd_ctx *lydctx, const struct lysc_node *snode)
LY_ERR rc = LY_SUCCESS;

if (lydctx->int_opts & LYD_INTOPT_ANY) {
/* nothing to check, everything is allowed */
if ((lydctx->int_opts & LYD_INTOPT_ENVELOPE) && (snode->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF))) {
/* only one notification and no RPC/action in the envelope */
if (snode->nodetype != LYS_NOTIF) {
goto error_node_inval;
}
if (lydctx->op_node) {
goto error_node_dup;
}
}

/* nothing else to check, everything is allowed */
goto cleanup;
}

if ((lydctx->int_opts & LYD_INTOPT_ENVELOPE) && !snode->parent && (strcmp(snode->name, "envelope") ||
strcmp(snode->module->name, "ietf-yp-notification"))) {
/* the root must be the envelope */
goto error_node_inval;
}

if ((lydctx->parse_opts & LYD_PARSE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
LOG_LOCSET(snode);
LOGVAL(lydctx->data_ctx->ctx, NULL, LY_VCODE_UNEXPNODE, "state", snode->name);
Expand Down
15 changes: 14 additions & 1 deletion src/parser_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ enum lyd_type {
LYD_TYPE_NOTIF_RESTCONF, /**< RESTCONF JSON or CBOR notification data
([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-6.4)), to parse
a notification in XML, use ::LYD_TYPE_NOTIF_NETCONF */
LYD_TYPE_REPLY_RESTCONF /**< message-body of a RESTCONF operation output parameters
LYD_TYPE_REPLY_RESTCONF, /**< message-body of a RESTCONF operation output parameters
([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.2)) */

LYD_TYPE_NOTIF_ENVELOPE /**< YANG-Push notification envelope, the 'envelope' structure of the
'ietf-yp-notification' module
([ref](https://datatracker.ietf.org/doc/draft-ietf-netconf-notif-envelope/)) */
};
/** @} datatype */

Expand Down Expand Up @@ -427,6 +431,15 @@ enum lyd_type {
* - @p op - must be NULL, @p parent points to the operation;
* Note that error reply should be parsed as 'yang-data' extension data.
*
* - ::LYD_TYPE_NOTIF_ENVELOPE:
* - @p ctx - must have the 'ietf-yp-notification' module implemented;
* - @p parent - must be NULL, the whole envelope is expected;
* - @p format - can be ::LYD_XML, ::LYD_JSON, or ::LYD_CBOR;
* - @p tree - must be provided, the envelope structure data tree with an empty 'contents' will be returned here,
* validate it using ::lyd_validate_all() with ::LYD_VALIDATE_PRESENT;
* - @p op - must be provided, the notification data tree separated from the envelope 'contents' will be returned
* here, pointing to the operation;
*
* - ::LYD_TYPE_RPC_YANG:
* - ::LYD_TYPE_NOTIF_YANG:
* - ::LYD_TYPE_REPLY_YANG:
Expand Down
1 change: 1 addition & 0 deletions src/parser_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx);
#define LYD_INTOPT_SKIP_SIBLINGS 0x40 /**< Perform the validation task only for the specfic subtree, skip other siblings. */
#define LYD_INTOPT_NO_SIBLINGS 0x80 /**< If there are any siblings, return an error. */
#define LYD_INTOPT_EVENTTIME 0x0100 /**< Parse notification eventTime node. */
#define LYD_INTOPT_ENVELOPE 0x0200 /**< YANG-Push notification envelope is being parsed. */

/**
* @brief Internal (common) context for YANG data parsers.
Expand Down
2 changes: 2 additions & 0 deletions src/parser_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,8 @@ lydjson_parse_any(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, co
if (lydctx->parse_opts & LYD_PARSE_ANYDATA_STRICT) {
/* explicit strict data parsing */
lydctx->parse_opts |= LYD_PARSE_STRICT;
} else if ((lydctx->int_opts & LYD_INTOPT_ENVELOPE) && !(lydctx->int_opts & LYD_INTOPT_ANY)) {
/* the notification in the envelope contents, parsed as data like any other notification */
} else {
/* make the parser process data as opaq nodes */
lydctx->parse_opts &= ~LYD_PARSE_STRICT;
Expand Down
2 changes: 2 additions & 0 deletions src/parser_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ lydxml_subtree_any(struct lyd_xml_ctx *lydctx, const struct lysc_node *snode, co
if (lydctx->parse_opts & LYD_PARSE_ANYDATA_STRICT) {
/* explicit strict data parsing */
lydctx->parse_opts |= LYD_PARSE_STRICT;
} else if ((lydctx->int_opts & LYD_INTOPT_ENVELOPE) && !(lydctx->int_opts & LYD_INTOPT_ANY)) {
/* the notification in the envelope contents, parsed as data like any other notification */
} else {
/* make the parser process data as opaq nodes */
lydctx->parse_opts &= ~LYD_PARSE_STRICT;
Expand Down
15 changes: 14 additions & 1 deletion src/tree_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in
LY_ERR rc = LY_SUCCESS;
struct lyd_ctx *lydctx = NULL;
struct ly_set parsed = {0};
struct lyd_node *first = NULL, *envp = NULL;
struct lyd_node *first = NULL, *envp = NULL, *top;
uint32_t i, val_opts, int_opts = 0;
ly_bool proto_msg = 0;

Expand Down Expand Up @@ -441,6 +441,13 @@ lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in
case LYD_TYPE_REPLY_YANG:
int_opts = LYD_INTOPT_REPLY | (parent ? LYD_INTOPT_WITH_SIBLINGS : LYD_INTOPT_NO_SIBLINGS);
break;
case LYD_TYPE_NOTIF_ENVELOPE:
LY_CHECK_ARG_RET(ctx, (format == LYD_XML) || (format == LYD_JSON) || (format == LYD_CBOR), !parent, tree, op,
LY_EINVAL);
LY_CHECK_ERR_RET(!ly_ctx_get_module_implemented(ctx, "ietf-yp-notification"),
LOGERR(ctx, LY_EINVAL, "Module \"ietf-yp-notification\" is not implemented."), LY_EINVAL);
int_opts = LYD_INTOPT_NOTIF | LYD_INTOPT_NO_SIBLINGS | LYD_INTOPT_ENVELOPE;
break;
default:
LOGINT(ctx);
rc = LY_EINT;
Expand Down Expand Up @@ -513,6 +520,12 @@ lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in
}
LY_CHECK_GOTO(rc, cleanup);

if (data_type == LYD_TYPE_NOTIF_ENVELOPE) {
/* unlink the notification from the envelope contents */
for (top = lydctx->op_node; top->parent->parent != first; top = lyd_parent(top)) {}
lyd_unlink(top);
}

/* set out params correctly */
if (tree) {
*tree = parent ? NULL : first;
Expand Down
Loading
Loading