}
KR_EXPORT struct lyd_node* node_child_first(struct lyd_node* parent) {
- assert(
- parent->schema->nodetype == LYS_CONTAINER ||
- parent->schema->nodetype == LYS_LIST ||
- parent->schema->nodetype == LYS_CHOICE
- );
+ assert(parent != NULL);
+
+ /* return null when the node does not contain children */
+ if(
+ parent->schema->nodetype != LYS_CONTAINER &&
+ parent->schema->nodetype != LYS_LIST &&
+ parent->schema->nodetype != LYS_CHOICE
+ ) {
+ return NULL;
+ }
return parent->child;
}
KR_EXPORT struct lyd_node* node_child_next(struct lyd_node* prev_child) {
+ assert(prev_child != NULL);
return prev_child->next;
}
KR_EXPORT const char* node_get_name(struct lyd_node* node) {
+ assert(node != NULL);
return node->schema->name;
}
KR_EXPORT const char* node_get_value_str(struct lyd_node* node) {
+ assert(node != NULL);
+
assert(
node->schema->nodetype == LYS_LEAF ||
node->schema->nodetype == LYS_LEAFLIST
KR_EXPORT const struct lys_node* schema_child_first(const struct lys_node* parent) {
assert(parent != NULL);
- assert(
- parent->nodetype == LYS_CONTAINER ||
- parent->nodetype == LYS_LIST ||
- parent->nodetype == LYS_CHOICE
- );
+
+ /* if the node does not contain children, return NULL */
+ if (
+ parent->nodetype != LYS_CONTAINER &&
+ parent->nodetype != LYS_LIST &&
+ parent->nodetype != LYS_CHOICE
+ ) {
+ return NULL;
+ }
return parent->child;
}
KR_EXPORT int sysrepo_init(apply_conf_f apply_conf_callback, read_conf_f read_conf_callback);
KR_EXPORT int sysrepo_deinit(void);
-/** Given a libyang node, returns it's first child */
+/** Given a libyang node, returns it's first child (or NULL if there aren't any) */
KR_EXPORT struct lyd_node* node_child_first(struct lyd_node* parent);
/** Given a libyang node, return next sibling or NULL if there isn't any */
KR_EXPORT struct lyd_node* node_child_next(struct lyd_node* prev_child);
KR_EXPORT struct lyd_node* node_new_container(struct lyd_node* parent, const struct lys_module* module, const char* name);
/** Returns module given a schema node */
KR_EXPORT const struct lys_module* schema_get_module(const struct lys_node* schema);
-/** Given a libyang schema node, returns it's first child */
+/** Given a libyang schema node, returns it's first child (or NULL if there aren't any) */
KR_EXPORT const struct lys_node* schema_child_first(const struct lys_node* parent);
/** Given a libyang schema node, return next sibling or NULL if there isn't any */
KR_EXPORT const struct lys_node* schema_child_next(const struct lys_node* prev_child);
-- apply to all children
for _,v in ipairs(container_model) do
-- all children have node property, so we initialize just that
- v.node:initialize_schema(child_schema_nodes[v.name])
+ v.node:initialize_schema(child_schema_nodes[v.node.name])
end
end
local initialized_schema = false
local function init_schema()
+ local depth = 0
+ local function print_schema_tree(schema_node)
+ debug.log("{}{}", string.rep(" ", depth), ffi.string(clib().schema_get_name(schema_node)))
+ depth = depth + 1
+ local children = Helpers.get_schema_children_table(schema_node)
+ for _,node in pairs(children) do
+ print_schema_tree(node)
+ end
+ depth = depth - 1
+ end
+
+
if not initialized_schema then
+ -- dump schema tree for debugging purpose
+ debug.log("Loaded schema tree:")
+ debug.log("")
+ print_schema_tree(clib().schema_root())
+ debug.log("")
+ debug.log("Schema tree end")
+
model:initialize_schema(clib().schema_root())
initialized_schema = true
end