blob: d1f050d32ccb21767abe00b74eed7d2e8d626495 [file] [log] [blame]
Michal Vasko1a7a7bd2020-10-16 14:39:15 +02001/**
2 * @file schema_compile_node.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Header for schema compilation of common nodes.
5 *
6 * Copyright (c) 2015 - 2020 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_SCHEMA_COMPILE_NODE_H_
16#define LY_SCHEMA_COMPILE_NODE_H_
17
18#include <stddef.h>
Radek Krejci47fab892020-11-05 17:02:41 +010019#include <stdint.h>
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020020
21#include "log.h"
Radek Krejci77114102021-03-10 15:21:57 +010022#include "tree.h"
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020023#include "tree_schema.h"
24
Radek Krejci47fab892020-11-05 17:02:41 +010025struct ly_ctx;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020026struct ly_set;
27struct lysc_ctx;
28
29/**
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020030 * @brief Compile information from the when statement by either standard compilation or by reusing
31 * another compiled when structure.
32 *
33 * @param[in] ctx Compile context.
34 * @param[in] when_p Parsed when structure.
Michal Vaskodfd254d2021-06-24 09:24:59 +020035 * @param[in] parent_flags Flags of the parsed node with the when statement.
36 * @param[in] compiled_parent Closest compiled parent of the when statement.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020037 * @param[in] ctx_node Context node for the when statement.
38 * @param[in] node Compiled node to which add the compiled when.
39 * @param[in,out] when_c Optional, pointer to the previously compiled @p when_p to be reused. Set to NULL
40 * for the first call.
41 * @return LY_ERR value.
42 */
Michal Vaskodfd254d2021-06-24 09:24:59 +020043LY_ERR lys_compile_when(struct lysc_ctx *ctx, struct lysp_when *when_p, uint16_t parent_flags,
44 const struct lysc_node *compiled_parent, const struct lysc_node *ctx_node, struct lysc_node *node,
45 struct lysc_when **when_c);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020046
47/**
Michal Vaskoedb0fa52022-10-04 10:36:00 +020048 * @brief Compile information from the must statement
49 *
50 * @param[in] ctx Compile context.
51 * @param[in] must_p The parsed must statement structure.
52 * @param[in,out] must Prepared (empty) compiled must structure to fill.
53 * @return LY_ERR value.
54 */
55LY_ERR lys_compile_must(struct lysc_ctx *ctx, struct lysp_restr *must_p, struct lysc_must *must);
56
57/**
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020058 * @brief Checks pattern syntax.
59 *
60 * @param[in] ctx Context.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020061 * @param[in] pattern Pattern to check.
Radek Krejci84d7fd72021-07-14 18:32:21 +020062 * @param[in,out] code Compiled PCRE2 pattern. If NULL, the compiled information used to validate pattern are freed.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020063 * @return LY_ERR value - LY_SUCCESS, LY_EMEM, LY_EVALID.
64 */
Radek Krejci2efc45b2020-12-22 16:25:44 +010065LY_ERR lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *pattern, pcre2_code **code);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020066
67/**
Michal Vasko51de7b72022-04-29 09:50:22 +020068 * @brief Compile parsed pattern restriction in conjunction with the patterns from base type.
Michal Vaskoedb0fa52022-10-04 10:36:00 +020069 *
Michal Vasko51de7b72022-04-29 09:50:22 +020070 * @param[in] ctx Compile context.
71 * @param[in] patterns_p Array of parsed patterns from the current type to compile.
72 * @param[in] base_patterns Compiled patterns from the type from which the current type is derived.
73 * Patterns from the base type are inherited to have all the patterns that have to match at one place.
74 * @param[out] patterns Pointer to the storage for the patterns of the current type.
75 * @return LY_ERR LY_SUCCESS, LY_EMEM, LY_EVALID.
76 */
77LY_ERR lys_compile_type_patterns(struct lysc_ctx *ctx, struct lysp_restr *patterns_p,
78 struct lysc_pattern **base_patterns, struct lysc_pattern ***patterns);
79
80/**
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020081 * @brief Compile information about the leaf/leaf-list's type.
82 *
83 * @param[in] ctx Compile context.
84 * @param[in] context_pnode Schema node where the type/typedef is placed to correctly find the base types.
85 * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of referencing and referenced objects.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020086 * @param[in] context_name Name of the context node or referencing typedef for logging.
87 * @param[in] type_p Parsed type to compile.
88 * @param[out] type Newly created (or reused with increased refcount) type structure with the filled information about the type.
89 * @param[out] units Storage for inheriting units value from the typedefs the current type derives from.
90 * @param[out] dflt Default value for the type.
91 * @return LY_ERR value.
92 */
93LY_ERR lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags,
Michal Vaskoa99b3572021-02-01 11:54:58 +010094 const char *context_name, struct lysp_type *type_p, struct lysc_type **type, const char **units,
95 struct lysp_qname **dflt);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020096
97/**
Michal Vasko0b50f6b2022-10-05 15:07:55 +020098 * @brief Find the node according to the given descendant/absolute schema nodeid.
99 * Used in unique, refine and augment statements.
100 *
101 * @param[in] ctx Compile context
102 * @param[in] nodeid Descendant-schema-nodeid (according to the YANG grammar)
103 * @param[in] nodeid_len Length of the given nodeid, if it is not NULL-terminated string.
104 * @param[in] ctx_node Context node for a relative nodeid.
105 * @param[in] format Format of any prefixes.
106 * @param[in] prefix_data Format-specific prefix data (see ::ly_resolve_prefix).
107 * @param[in] nodetype Optional (can be 0) restriction for target's nodetype. If target exists, but does not match
108 * the given nodetype, LY_EDENIED is returned (and target is provided), but no error message is printed.
109 * The value can be even an ORed value to allow multiple nodetypes.
110 * @param[out] target Found target node if any.
111 * @param[out] result_flag Output parameter to announce if the schema nodeid goes through the action's input/output or a Notification.
112 * The LYSC_OPT_RPC_INPUT, LYSC_OPT_RPC_OUTPUT and LYSC_OPT_NOTIFICATION are used as flags.
113 * @return LY_ERR values - LY_ENOTFOUND, LY_EVALID, LY_EDENIED or LY_SUCCESS.
114 */
115LY_ERR lysc_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t nodeid_len, const struct lysc_node *ctx_node,
116 LY_VALUE_FORMAT format, void *prefix_data, uint16_t nodetype, const struct lysc_node **target, uint16_t *result_flag);
117
118/**
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200119 * @brief Compile choice children.
120 *
121 * @param[in] ctx Compile context
122 * @param[in] child_p Parsed choice children nodes.
123 * @param[in] node Compiled choice node to compile and add children to.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200124 * @param[in,out] child_set Optional set to add all the compiled nodes into (can be more in case of uses).
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200125 * @return LY_ERR value - LY_SUCCESS or LY_EVALID.
126 */
127LY_ERR lys_compile_node_choice_child(struct lysc_ctx *ctx, struct lysp_node *child_p, struct lysc_node *node,
128 struct ly_set *child_set);
129
130/**
131 * @brief Set LYS_MAND_TRUE flag for the non-presence container parents.
132 *
133 * A non-presence container is mandatory in case it has at least one mandatory children. This function propagate
134 * the flag to such parents from a mandatory children.
135 *
136 * @param[in] parent A schema node to be examined if the mandatory child make it also mandatory.
137 * @param[in] add Flag to distinguish adding the mandatory flag (new mandatory children appeared) or removing the flag
138 * (mandatory children was removed).
139 */
140void lys_compile_mandatory_parents(struct lysc_node *parent, ly_bool add);
141
142/**
143 * @brief Validate grouping that was defined but not used in the schema itself.
144 *
145 * The grouping does not need to be compiled (and it is compiled here, but the result is forgotten immediately),
146 * but to have the complete result of the schema validity, even such groupings are supposed to be checked.
147 *
148 * @param[in] ctx Compile context.
149 * @param[in] pnode Parsed parent node of the grouping, NULL for top-level.
150 * @param[in] grp Parsed grouping node to check.
151 * @return LY_ERR value.
152 */
Radek Krejci2a9fc652021-01-22 17:44:34 +0100153LY_ERR lys_compile_grouping(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysp_node_grp *grp);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200154
155/**
156 * @brief Compile parsed schema node information.
157 *
158 * @param[in] ctx Compile context
159 * @param[in] pnode Parsed schema node.
160 * @param[in] parent Compiled parent node where the current node is supposed to be connected. It is
161 * NULL for top-level nodes, in such a case the module where the node will be connected is taken from
162 * the compile context.
Michal Vaskoedb0fa52022-10-04 10:36:00 +0200163 * @param[in] inherited_status Explicitly inherited status (from uses/extension instance), if any.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200164 * @param[in,out] child_set Optional set to add all the compiled nodes into (can be more in case of uses).
165 * @return LY_ERR value - LY_SUCCESS or LY_EVALID.
166 */
Michal Vaskoedb0fa52022-10-04 10:36:00 +0200167LY_ERR lys_compile_node(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc_node *parent,
168 const uint16_t *inherited_status, struct ly_set *child_set);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200169
170#endif /* LY_SCHEMA_COMPILE_NODE_H_ */