Skip to content

Commit

Permalink
tree data UPDATE function for checking internal meta
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 29, 2024
1 parent d37ac21 commit f77ca9c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,7 @@ lyd_node_should_print(const struct lyd_node *node, uint32_t options)
LIBYANG_API_DEF ly_bool
lyd_metadata_should_print(const struct lyd_meta *meta)
{
const char *arg;

assert(meta->annotation);

arg = meta->annotation->argument;
if (!strcmp(arg, "lyds_tree")) {
return 0;
} else {
return 1;
}
return !lyd_meta_is_internal(meta);
}

LIBYANG_API_DEF LY_OUT_TYPE
Expand Down
9 changes: 9 additions & 0 deletions src/tree_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,15 @@ LIBYANG_API_DECL LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd
*/
LIBYANG_API_DECL const struct lysc_node *lyd_node_schema(const struct lyd_node *node);

/**
* @brief Check whether metadata are not an instance of internal metadata.
*
* @param[in] meta Metadata to check.
* @return 1 if @p meta are internal.
* @return 0 if @p meta are not internal.
*/
LIBYANG_API_DECL ly_bool lyd_meta_is_internal(const struct lyd_meta *meta);

/**
* @brief Create a new inner node in the data tree.
*
Expand Down
16 changes: 16 additions & 0 deletions src/tree_data_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "log.h"
#include "ly_common.h"
#include "lyb.h"
#include "metadata.h"
#include "parser_data.h"
#include "plugins_exts.h"
#include "printer_data.h"
Expand Down Expand Up @@ -1141,6 +1142,21 @@ lyd_node_schema(const struct lyd_node *node)
return schema;
}

LIBYANG_API_DEF ly_bool
lyd_meta_is_internal(const struct lyd_meta *meta)
{
const char *arg;

assert(meta->annotation);

arg = meta->annotation->argument;
if (!strcmp(meta->annotation->module->name, "yang") && !strcmp(arg, "lyds_tree")) {
return 1;
}

return 0;
}

void
lyd_cont_set_dflt(struct lyd_node *node)
{
Expand Down

0 comments on commit f77ca9c

Please sign in to comment.