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
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
options: "-DENABLE_TESTS=ON",
packager: "sudo apt-get",
# no expect because stdout seems to be redirected
packages: "libcmocka-dev libxxhash-dev",
packages: "libcmocka-dev libxxhash-dev libcbor-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -36,7 +36,7 @@ jobs:
cc: "clang",
options: "-DENABLE_TESTS=ON",
packager: "sudo apt-get",
packages: "libcmocka-dev libxxhash-dev",
packages: "libcmocka-dev libxxhash-dev libcbor-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -47,7 +47,7 @@ jobs:
cc: "gcc",
options: "",
packager: "sudo apt-get",
packages: "libcmocka-dev libxxhash-dev valgrind",
packages: "libcmocka-dev libxxhash-dev libcbor-dev valgrind",
snaps: "",
build-cmd: "make"
}
Expand All @@ -59,7 +59,7 @@ jobs:
options: "",
packager: "sudo apt-get",
# no valgrind because it does not support DWARF5 yet generated by clang 14
packages: "libcmocka-dev libxxhash-dev",
packages: "libcmocka-dev libxxhash-dev libcbor-dev",
snaps: "",
build-cmd: "make"
}
Expand All @@ -70,7 +70,7 @@ jobs:
cc: "clang",
options: "-DENABLE_TESTS=ON -DPATH_EXPECT=",
packager: "brew",
packages: "cmocka xxhash tcl-tk",
packages: "cmocka xxhash tcl-tk libcbor",
snaps: "",
build-cmd: "make"
}
Expand All @@ -81,7 +81,7 @@ jobs:
cc: "clang",
options: "-DCMAKE_C_FLAGS=-fsanitize=address,undefined -DENABLE_TESTS=ON -DENABLE_VALGRIND_TESTS=OFF",
packager: "sudo apt-get",
packages: "libcmocka-dev libxxhash-dev",
packages: "libcmocka-dev libxxhash-dev libcbor-dev",
snaps: "",
build-cmd: "make"
}
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
prepare: |
echo "Installing dependencies..."
pkg update -f
pkg install -y cmake cmocka xxhash bash git pcre2
pkg install -y cmake cmocka xxhash bash git pcre2 libcbor

run: |
set -e
Expand All @@ -308,7 +308,7 @@ jobs:
i386/ubuntu \
/bin/bash -c " \
apt-get update -q && \
apt-get install -y -q git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev && \
apt-get install -y -q git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev libcbor-dev && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON .. && \
make && \
Expand Down Expand Up @@ -338,7 +338,7 @@ jobs:
# install dependencies inside the emulated container
install: |
apt-get update -q -y
apt-get install -q -y git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev
apt-get install -q -y git cmake gcc libcmocka-dev libxxhash-dev libpcre2-dev libcbor-dev

# run the build
run: |
Expand Down
2 changes: 2 additions & 0 deletions src/lcbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void
lycbor_ctx_free(struct lycbor_ctx *cborctx)
{
if (cborctx) {
ly_log_location_revert(0, 0, 1);

if (cborctx->cbor_data) {
cbor_decref(&cborctx->cbor_data);
}
Expand Down
38 changes: 19 additions & 19 deletions src/parser_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ lydcbor_meta_attr(struct lyd_cbor_ctx *lydctx, const struct lysc_node *snode, st
LY_ERR rc = LY_SUCCESS, r;
enum cbor_type type;
const char *expected;
ly_bool in_parent = 0;
const char *name, *prefix = NULL;
size_t name_len, prefix_len = 0;
struct lys_module *mod;
Expand Down Expand Up @@ -693,7 +692,8 @@ lydcbor_meta_attr(struct lyd_cbor_ctx *lydctx, const struct lysc_node *snode, st
next_entry:
instance++;
if (!node || (node->schema != prev->schema)) {
LOGVAL(ctx, NULL, LYVE_REFERENCE, "Missing CBOR data instance #%" PRIu32 " of %s:%s to be coupled with metadata.", instance, prev->schema->module->name, prev->schema->name);
LOGVAL(ctx, NULL, LYVE_REFERENCE, "Missing CBOR data instance #%" PRIu32 " of %s:%s to be coupled with metadata.",
instance, prev->schema->module->name, prev->schema->name);
rc = LY_EVALID;
goto cleanup;
}
Expand Down Expand Up @@ -726,7 +726,6 @@ lydcbor_meta_attr(struct lyd_cbor_ctx *lydctx, const struct lysc_node *snode, st
case LYS_NOTIF:
case LYS_ACTION:
case LYS_RPC:
in_parent = 1;
expected = "@/object";
LY_CHECK_GOTO(type != CBOR_TYPE_MAP, representation_error);
break;
Expand Down Expand Up @@ -862,11 +861,9 @@ lydcbor_meta_attr(struct lyd_cbor_ctx *lydctx, const struct lysc_node *snode, st
* @param[in,out] first_p Pointer to the first sibling.
* @param[in,out] node_p Pointer to the node to insert.
* @param[in] last If set, insert at the end.
* @param[in] ext Extension instance.
*/
static void
lydcbor_maintain_children(struct lyd_node *parent, struct lyd_node **first_p, struct lyd_node **node_p, ly_bool last,
struct lysc_ext_instance *ext)
lydcbor_maintain_children(struct lyd_node *parent, struct lyd_node **first_p, struct lyd_node **node_p, ly_bool last)
{
if (!*node_p) {
return;
Expand Down Expand Up @@ -998,7 +995,7 @@ lydcbor_parse_opaq(struct lyd_cbor_ctx *lydctx, const char *name, size_t name_le
/* continue with next instance */
assert(*node_p);
lydcbor_maintain_children(parent, first_p, node_p,
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT, NULL);
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT);

LOG_LOCBACK(0);

Expand Down Expand Up @@ -1303,20 +1300,22 @@ lydcbor_parse_instance(struct lyd_cbor_ctx *lydctx, struct lyd_node *parent, str

if (lydcbor_is_null(handle[0])) {
/* [null] case */
goto cleanup;
str_val = strdup("");
str_len = 0;
}
}
if (!str_val) {
if ((type != CBOR_TYPE_ARRAY) && (type != CBOR_TYPE_UINT) && (type != CBOR_TYPE_NEGINT) &&
(type != CBOR_TYPE_STRING) && (type != CBOR_TYPE_FLOAT_CTRL)) {
rc = LY_ENOT;
goto cleanup;
}

if ((type != CBOR_TYPE_ARRAY) && (type != CBOR_TYPE_UINT) && (type != CBOR_TYPE_NEGINT) &&
(type != CBOR_TYPE_STRING) && (type != CBOR_TYPE_FLOAT_CTRL)) {
rc = LY_ENOT;
goto cleanup;
/* create terminal node */
r = lydcbor_item_to_string(cbor_value, &str_val, &str_len);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
}

/* create terminal node */
r = lydcbor_item_to_string(cbor_value, &str_val, &str_len);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);

r = lyd_parser_create_term((struct lyd_ctx *)lydctx, snode, parent, str_val, str_len * 8,
NULL, LY_VALUE_CBOR, NULL, type_hints, node);
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
Expand Down Expand Up @@ -1478,6 +1477,7 @@ lydcbor_subtree_r(struct lyd_cbor_ctx *lydctx, struct lyd_node *parent, struct l
/* parse opaq */
r = lydcbor_parse_opaq(lydctx, name, name_len, prefix, prefix_len, parent, value_item, first_p, &node);
free(key_str);
key_str = NULL;
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
}
} else {
Expand Down Expand Up @@ -1532,7 +1532,7 @@ lydcbor_subtree_r(struct lyd_cbor_ctx *lydctx, struct lyd_node *parent, struct l
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);

lydcbor_maintain_children(parent, first_p, &node,
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT, ext);
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT);
}
break;
case LYS_LEAF:
Expand Down Expand Up @@ -1568,7 +1568,7 @@ lydcbor_subtree_r(struct lyd_cbor_ctx *lydctx, struct lyd_node *parent, struct l

/* finally connect the parsed node */
lydcbor_maintain_children(parent, first_p, &node,
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT, ext);
lydctx->parse_opts & LYD_PARSE_ORDERED ? LYD_INSERT_NODE_LAST : LYD_INSERT_NODE_DEFAULT);
}

/* success */
Expand Down Expand Up @@ -1654,7 +1654,7 @@ lyd_parse_cbor(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, st
r = lydcbor_subtree_r(lydctx, parent, first_p, parsed, lydctx->cborctx->cbor_data);
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);

if ((int_opts & LYD_INTOPT_NO_SIBLINGS)) {
if ((int_opts & LYD_INTOPT_NO_SIBLINGS) && *first_p && (*first_p)->next) {
LOGVAL(ctx, NULL, LYVE_SYNTAX, "Unexpected sibling node.");
r = LY_EVALID;
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
Expand Down
3 changes: 2 additions & 1 deletion src/parser_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ LIBYANG_API_DECL LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char
* @param[in] data Pointer to the memory buffer containing the data to parse.
* @param[in] data_len Length of the memory buffer.
* @param[in] format Data format (e.g., XML, JSON, LYD_LYB).
* @param[in] options Parsing options, see @ref dataparseroptions.
* @param[in] parse_options Options for parser, see @ref dataparseroptions.
* @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
* @param[in] ctx_node Optional context node for parsing (can be NULL).
* @param[out] tree Pointer to the resulting data tree (set on success).
* @return LY_ERR value indicating success or error reason.
Expand Down
4 changes: 2 additions & 2 deletions src/parser_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx);
/**
* @brief Internal (common) context for YANG data parsers.
*
* Covers ::lyd_xml_ctx, ::lyd_json_ctx and ::lyd_lyb_ctx.
* Covers ::lyd_xml_ctx, ::lyd_json_ctx, ::lyd_lyb_ctx and ::lyd_cbor_ctx.
*/
struct lyd_ctx {
uint32_t parse_opts; /**< various @ref dataparseroptions. */
Expand Down Expand Up @@ -196,9 +196,9 @@ struct lyd_cbor_ctx {
/* callbacks */
lyd_ctx_free_clb free; /**< destructor */

struct lycbor_ctx *cborctx; /**< CBOR context for low-level operations */
const struct lysc_ext_instance *ext; /**< extension instance possibly changing document root context, NULL if none */
struct ly_set ext_node; /**< set of nodes with extension instances to validate */
struct lycbor_ctx *cborctx; /**< CBOR context for low-level operations */
const struct lysc_node *any_schema; /**< parent anyxml/anydata schema node if parsing nested data tree */
};

Expand Down
8 changes: 7 additions & 1 deletion src/plugins_types/instanceid.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,20 @@ lyplg_type_print_instanceid(const struct ly_ctx *UNUSED(ctx), const struct lyd_v
{
char *ret;

if ((format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) || (format == LY_VALUE_LYB)) {
switch (format) {
case LY_VALUE_CANON:
case LY_VALUE_JSON:
case LY_VALUE_LYB:
case LY_VALUE_CBOR:
if (dynamic) {
*dynamic = 0;
}
if (value_size_bits) {
*value_size_bits = strlen(value->_canonical) * 8;
}
return value->_canonical;
default:
break;
}

/* print the value in the specific format */
Expand Down
2 changes: 1 addition & 1 deletion src/plugins_types/xpath1.0.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value

/* LY_VALUE_STR_NS should never be transformed */
if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
(format == LY_VALUE_LYB)) {
(format == LY_VALUE_LYB) || (format == LY_VALUE_CBOR)) {
/* canonical */
if (dynamic) {
*dynamic = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/printer_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,6 @@ cbor_print_leaf_list(struct cborpr_ctx *pctx, const struct lyd_node *node, cbor_
*array_p = cbor_new_indefinite_array();
LY_CHECK_RET(!*array_p, LY_EMEM);

key = cbor_print_member_name(pctx, node, 0);
LY_CHECK_ERR_RET(!key, cbor_decref(array_p), LY_EMEM);

LY_CHECK_RET(cbor_print_array_open(pctx, node));
}

Expand Down Expand Up @@ -942,6 +939,7 @@ cbor_print_leaf_list(struct cborpr_ctx *pctx, const struct lyd_node *node, cbor_
}

if (cbor_print_array_is_last_inst(pctx, node)) {
key = cbor_print_member_name(pctx, node, 0);
/* add completed array to parent map */
if (key) {
struct cbor_pair pair = {
Expand All @@ -956,6 +954,9 @@ cbor_print_leaf_list(struct cborpr_ctx *pctx, const struct lyd_node *node, cbor_
cbor_decref(&pair.value);
return LY_EMEM;
}
} else {
cbor_decref(array_p);
return LY_EMEM;
}
cbor_print_array_close(pctx);
*array_p = NULL;
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function(ly_add_utest)
# Set common attributes of all tests
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS})
if (CBOR_FOUND)
target_link_libraries(${TEST_NAME} ${CBOR_LIBRARY})
endif()
if (NOT WIN32)
target_link_libraries(${TEST_NAME} m)
else()
Expand Down
Loading
Loading