blob: 60afdf67d7e9efe8ce51c7e35834dd4bb14b0ab9 [file] [log] [blame]
Radek Krejcie7b95092019-05-15 11:03:07 +02001/**
2 * @file tree_data_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief internal functions for YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_DATA_INTERNAL_H_
16#define LY_TREE_DATA_INTERNAL_H_
17
18#include "tree_data.h"
Radek Krejciaca74032019-06-04 08:53:06 +020019#include "plugins_types.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020020
21/**
22 * @brief Get address of a node's child pointer if any.
23 *
24 * Decides the node's type and in case it has a children list, returns its address.
25 * @param[in] node Node to check.
26 * @return Address of the node's child member if any, NULL otherwise.
27 */
28struct lyd_node **lyd_node_children_p(struct lyd_node *node);
29
30/**
Radek Krejci5819f7c2019-05-31 14:53:29 +020031 * @brief Validate, canonize and store the given @p value into the node according to the node's type's rules.
Radek Krejcie7b95092019-05-15 11:03:07 +020032 *
Radek Krejci38d85362019-09-05 16:26:38 +020033 * @param[in] node Data node for the @p value.
Radek Krejci084289f2019-07-09 17:35:30 +020034 * @param[in] value String value to be parsed, must not be NULL.
Radek Krejci5819f7c2019-05-31 14:53:29 +020035 * @param[in] value_len Length of the give @p value (mandatory).
36 * @param[in] dynamic Flag if @p value is a dynamically allocated memory and should be directly consumed/freed inside the function.
Radek Krejci3c9758d2019-07-11 16:49:10 +020037 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
Radek Krejci084289f2019-07-09 17:35:30 +020038 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
Radek Krejciaca74032019-06-04 08:53:06 +020039 * @param[in] parser Parser's data for @p get_prefix
Radek Krejci084289f2019-07-09 17:35:30 +020040 * @param[in] format Input format of the data.
Radek Krejcie553e6d2019-06-07 15:33:18 +020041 * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required
42 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
43 * then LY_EINCOMPLETE can be returned.
44 * @return LY_SUCCESS on success
45 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
46 * @return LY_ERR value if an error occurred.
Radek Krejcie7b95092019-05-15 11:03:07 +020047 */
Radek Krejci3c9758d2019-07-11 16:49:10 +020048LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int dynamic, int second,
Radek Krejci576b23f2019-07-12 14:06:32 +020049 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node **trees);
Radek Krejcie7b95092019-05-15 11:03:07 +020050
51/**
Radek Krejci38d85362019-09-05 16:26:38 +020052 * @brief Validate, canonize and store the given @p value into the attribute according to the metadata annotation type's rules.
53 *
54 * @param[in] attr Data attribute for the @p value.
55 * @param[in] value String value to be parsed, must not be NULL.
56 * @param[in] value_len Length of the give @p value (mandatory).
57 * @param[in] dynamic Flag if @p value is a dynamically allocated memory and should be directly consumed/freed inside the function.
58 * @param[in] second Flag for the second call after returning LY_EINCOMPLETE
59 * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string.
60 * @param[in] parser Parser's data for @p get_prefix
61 * @param[in] format Input format of the data.
62 * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required
63 * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete,
64 * then LY_EINCOMPLETE can be returned.
65 * @return LY_SUCCESS on success
66 * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
67 * @return LY_ERR value if an error occurred.
68 */
69LY_ERR lyd_value_parse_attr(struct lyd_attr *attr, const char *value, size_t value_len, int dynamic, int second,
70 ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node **trees);
71
72/**
Radek Krejcie7b95092019-05-15 11:03:07 +020073 * @brief Parse XML string as YANG data tree.
74 *
75 * @param[in] ctx libyang context
76 * @param[in] data Pointer to the XML string representation of the YANG data to parse.
77 * @param[in] options @ref dataparseroptions
78 * @param[out] result Resulting list of the parsed data trees. Note that NULL can be a valid result.
79 * @reutn LY_ERR value.
80 */
Michal Vaskoa3881362020-01-21 15:57:35 +010081LY_ERR lyd_parse_xml(struct ly_ctx *ctx, const char *data, int options, struct lyd_node **result);
Radek Krejcie7b95092019-05-15 11:03:07 +020082
83/**
84 * @defgroup datahash Data nodes hash manipulation
85 * @ingroup datatree
86 */
87
88/**
Radek Krejci1f05b6a2019-07-18 16:15:06 +020089 * @brief Generate hash for the node.
90 *
91 * @param[in] node Data node to (re)generate hash value.
92 * @return LY_ERR value.
93 */
94LY_ERR lyd_hash(struct lyd_node *node);
95
96/**
97 * @brief Insert hash of the node into the hash table of its parent.
98 *
99 * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent.
100 * @return LY_ERR value.
101 */
102LY_ERR lyd_insert_hash(struct lyd_node *node);
103
104/**
Radek Krejcie7b95092019-05-15 11:03:07 +0200105 * @brief Maintain node's parent's children hash table when unlinking the node.
106 *
107 * When completely freeing data tree, it is expected to free the parent's children hash table first, at once.
108 *
109 * @param[in] node The data node being unlinked from its parent.
110 */
111void lyd_unlink_hash(struct lyd_node *node);
112
113/** @} datahash */
114
Radek Krejci084289f2019-07-09 17:35:30 +0200115/**
116 * @brief Free path (target) structure of the lyd_value.
117 *
118 * @param[in] ctx libyang context.
119 * @param[in] path The structure ([sized array](@ref sizedarrays)) to free.
120 */
121void lyd_value_free_path(struct ly_ctx *ctx, struct lyd_value_path *path);
122
Radek Krejcie7b95092019-05-15 11:03:07 +0200123#endif /* LY_TREE_DATA_INTERNAL_H_ */